chroot
를 통해 루트 디렉토리로 격리해서 실행 파일 테스트를 해야하는 상황
sudo cp /lib/libgdbm.so.6 lib/x86_64-linux-gnu/
위의 명령어들을 통해 동적 라이브러리를 복사했다.
$ sudo chroot /tmp/custom-rootfs/
위의 명령어를 통해 루트 디렉토리로 격리를 해서, 원하는 실행 파일을 실행해보았다.
(실행 파일 insert
)
# ./insert
Error loading shared library libgdbm.so.6: No such file or directory
이 에러가 발생했다. 해당 동적 라이브러리가 존재하지 않는 것이다.
하지만 분명 복사를 했는데 ..?
ldd
를 통해 라이브러리 의존성을 확인해보았다.
bash-5.0# ldd insert
/lib64/ld-linux-x86-64.so.2 (0x7f0125007000)
Error loading shared library libgdbm.so.6: No such file or directory (needed by insert)
libc.so.6 => /lib64/ld-linux-x86-64.so.2 (0x7f0125007000)
Error relocating insert: gdbm_store: symbol not found
Error relocating insert: gdbm_open: symbol not found
bash-5.0# exit
해당 디렉토리의 목록들을 찾아봤다.
# ls -al /lib/x86_64-linux-gnu/
total 2608
...
lrwxrwxrwx 1 root root 16 Dec 21 2020 libgdbm.so.6 -> libgdbm.so.6.0.0
...
파일이 링크되어 있었다. (libgdbm.so.6.0.0
)
libgdbm.so.6.0.0
까지 복사를 해야 한다.
복사를 하고 다시 실행
$ sudo chroot /tmp/custom-rootfs/
bash-5.0# cd bin
bash-5.0# ./insert
function running time[ms] : 3
그러면 성공!