You are not logged in.
Hi guys,
Is it possible to write a script that enters a chrooted environment, does something, exits, and continues? How?
I have a script that does most of what it's supposed to, but then I have to chroot manually to finish up. It would be nice to also automate the manual steps.
Thanks.
Last edited by scrawler (2020-04-05 01:43:13)
Offline
You'll notice that "entering a chroot" is actually just "running a command inside a chroot".
In many cases, you simply want to run an interactive shell, hence you do something like `chroot /dir /bin/bash`.
But you can also just run something else, e.g. copy/generate a script somewhere within that directory and then invoke it with `chroot /dir /path/to/some/script`.
Offline
mount /dev/sda1 /mnt
cat <<EOF > /mnt/runme
echo hello world
EOF
chmod 0755 /mnt/runme
chroot /mnt /runme
rm /mnt/runme
This script, living outside the chroot, echos 'hello world' from inside a chroot.
EDIT: see below ... that's much better. I've never bothered to make an automated installation script.
Last edited by Trilby (2020-04-04 17:49:12)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
^ Simpler version:
mount /dev/sda1 /mnt
chroot /mnt /bin/bash <<END
echo hello world
END
Para todos todo, para nosotros nada
Offline
Thank you guys, I'll tell you how it works. :-)
Offline
Worked great, as expected--will mark solved. Thanks again everybody.
Offline