Ubuntu – scripting chroot, how to

bashchroot

So I'm looking at:

https://help.ubuntu.com/community/LiveCDCustomizationFromScratch

and trying the following within a bash script:

sudo chroot chroot

mount none -t proc /proc
mount none -t sysfs /sys
mount none -t devpts /dev/pts

Running the script drops to a shell at sudo chroot chroot. When I exit that I get the expected warnings about mount needing root. Is there a way I can keep all this within one shell script?

Edit: I want this to be a repeatable process, which is why I want to script the whole thing rather than type it in time and time again.

Best Answer

Create a second script (e.g. chroot.sh) and place it in your chroot/ folder.

Now edit the command in your original script to this:

chroot chroot/ ./chroot.sh

Now the script chroot.sh will be executed inside your chroot.