Shell script exits after running a chroot command
I hope this is in the right place.
What I've been doing is creating a customized live cd for my place of work. The guide that I have been using is found here. I've had to make quite a few revisions to the cd and each time I have to go through the entire thing over again so I decided to try my hand at writing a script for it. (Note: Was a total linux virgin till 2 months ago).
The problem is that it runs until I get to a chroot command and then it seems to just exit out back to the terminal. Here is my script around that area :
sudo cp /etc/resolv.conf edit/etc/
sudo cp /etc/hosts edit/etc/
sudo mount --bind /dev/ edit/dev
sudo chroot edit
mount -t proc none /proc
mount -t sysfs none /sys
mount -t devpts none /dev/pts
I put the -x option up near bash so I could see where it was breaking and this is the terminal output:
+ mkdir /home/ubuntu/live
mkdir: cannot create directory `/home/ubuntu/live': File exists
+ echo -n 'Path to the .iso > '
Path to the .iso > + read text
+ cp /home/ubuntu/Desktop/Releases/####.iso /home/ubuntu/live
+ cd /home/ubuntu/live
+ mkdir mnt
+ sudo mount -o loop /home/ubuntu/Desktop/Releases/####.iso mnt
+ mkdir extract-cd
+ rsync --exclude=/casper/filesystem.squashfs -a mnt/ extract-cd
+ sudo unsquashfs mnt/casper/filesystem.squashfs
created 72746 files
created 10163 directories
created 11453 symlinks
created 95 devices
created 2 fifos
+ sudo mv squashfs-root edit
+ sudo cp /etc/resolv.conf edit/etc/
+ sudo cp /etc/hosts edit/etc/
+ sudo mount --bind /dev/ edit/dev
+ sudo chroot edit
Can anyone help with this? I'm not entirely sure what to do with it to get it to not kick out. If it just is going to kick out regardless then I can always write another script to run, however I would rather keep it down to just one.
The "chroot" command will either run the specified program inside the specified directory ("edit" in your example), or run a shell. Whatever is to be run, sufficient facilities to run things must be there. A statically linked shell interpreter must be there as "/bin/sh" within the chroot context (that would be "edit/bin/sh" in the context you have, for a full path of "/home/ubuntu/live/edit/bin/sh"). If it is not statically linked, you can do a dynamically linked one if ALL the libraries it needs are present, along with the library config and the dynamic linker. If it works, you should get a shell prompt (I see a shell prompt in your quoted text ... is that the original shell prompt or the one from the chroot tree?).
As for the rest of what you said it went waaaay over my head. The only thing I know about edit is that its the unsquashed file system from the cd, and I suppose I'll have to do some research to figure out whether to do (and how) a statically linked vs dynamic shell. However, I will be off the weekend so I'll post back Monday I suppose.
So I still do not know what to do and I haven't been able to find how to get it to work on my own, any suggestions as to where to look to find out how to get the script to continue on after chroot is called?
Well I have gotten it to work by doing this :
sudo chroot edit mount -t proc none /proc
sudo chroot edit mount -t sysfs none /sys
sudo chroot edit mount -t devpts none /dev/pts
sudo chroot edit aptitude clean
sudo chroot edit rm -rf /tmp/* ~/.bash_history
sudo chroot edit rm /etc/resolv.conf
sudo chroot edit umount /proc
sudo chroot edit umount /sys
sudo chroot edit umount /dev/pts
Which I suppose isn't too bad but its just tedious. I suppose it just seemed to me that you should be able to invoke chroot and it just keep on running the commands from my script, but now I know better.
|All times are GMT -5. The time now is 07:28 PM.|