LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-30-2009, 02:47 PM   #1
kechlion
LQ Newbie
 
Registered: Dec 2009
Posts: 15

Rep: Reputation: 0
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:

+ text=
+ breakmenu=
+ 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
/home/ubuntu/Desktop/Releases/####.iso
+ 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
root@ubuntu-desktop:/#

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.

Thanks!
 
Old 12-30-2009, 03:10 PM   #2
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,681
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
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?).
 
Old 12-30-2009, 03:28 PM   #3
kechlion
LQ Newbie
 
Registered: Dec 2009
Posts: 15

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Skaperen View Post
(I see a shell prompt in your quoted text ... is that the original shell prompt or the one from the chroot tree?).
I'm not entirely certain what you are asking or more precisely how to answer you. The second set of text I have up there is what the terminal was displaying when I ran my script, while the first set is a small excerpt from the script itself.

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.

Thanks again!
 
Old 01-04-2010, 07:12 AM   #4
kechlion
LQ Newbie
 
Registered: Dec 2009
Posts: 15

Original Poster
Rep: Reputation: 0
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?
 
Old 01-04-2010, 09:28 AM   #5
kechlion
LQ Newbie
 
Registered: Dec 2009
Posts: 15

Original Poster
Rep: Reputation: 0
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
export HOME=/root
export LC_ALL=C
break_menu
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.
 
  


Reply

Tags
chroot, scripting



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
running shell script: command not found tripat Red Hat 3 04-14-2010 01:21 PM
Disconnect from SSH with command running - Shell script striker Programming 13 08-24-2009 08:18 PM
Error running command via shell script lowlifeish Linux - Software 2 08-31-2007 10:38 PM
running a command with args from a shell script KM3 Programming 3 10-19-2006 01:46 PM
Running a shell script remotely via 'ssh <hostname> <command>' davee Linux - General 4 10-09-2005 01:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration