내 스크립트는 chroot
GRUB를 USB에 설치하기 위한 케이지를 생성하고 물론 sudo로 실행합니다.
SYSTEM_DIRS=(etc bin sbin var lib lib64 usr proc sys dev tmp)
boot_partition=/media/user/boot
for dir in ${SYSTEM_DIRS[@]}; do
mount --bind /$dir ${boot_partition}/${dir}
done
그런 다음 내부에서 몇 가지 명령을 실행하십시오 chroot
.
chroot ${boot_partition}/ touch foo # works fine
...
하지만 명령을 실행하고 싶을 때exit
chroot ${boot_partition}/ exit
나는 얻다:
chroot: failed to execute the command <<exit>>: No such file or directory
왜 이런 일이 발생하며 해결 방법이 있습니까?
답변1
exit
은 독립 실행형 실행 파일이 아닌 셸 내장형이므로 에서 실행할 수 없습니다 chroot
. 그러나 가능하더라도 귀하의 명령은 아무 것도 수행하지 않습니다.
이 명령은 chroot /executable
의 컨텍스트에서 실행됩니다 /path
.
chroot /path /executable
해당 chroot 내부에 호출자를 두지 않습니다. 실행이 완료 되자마자 암시적 종료가 있습니다 /executable
.
mkdir -p /tmp/cr/{bin,lib,lib64}
cp -p /bin/pwd /tmp/cr/bin
cp -p $(find /lib* /usr/lib* -name 'libc.so*') /tmp/cr/lib
cp -p $(find /lib* /usr/lib* -name 'ld-linux-x86-64.so*') /tmp/cr/lib64
/bin/pwd # "/root"
chroot /tmp/cr /bin/pwd # "/"
/bin/pwd # "/root"
답변2
나는 같은 질문에 직면합니다. 내 해결책은 chroot를 실행할 때 그 뒤에 종료를 추가하는 것입니다.
chroot /chroot_path && exit
그런 다음 사용자가 chroot를 종료하면 전체 쉘이 종료됩니다.