私のスクリプトは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
。つまり、 で実行できても、コマンドは何もしません。
このコマンドは/executable
chrootコンテキストで実行されます/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"