View previous topic :: View next topic |
Author |
Message |
catchpole Tux's lil' helper
Joined: 03 Sep 2014 Posts: 103 Location: Leeds UK
|
Posted: Tue Nov 04, 2014 1:43 pm Post subject: Chroot in with shell script [SOLVED] |
|
|
Newbie.
I'm in the process of installing Gentoo and need to frequently chroot into the sda4 partition from Linux Mint on sda3, so I thought I'd write a script to do that.
However, it won't work.
I've followed the handbook down to section 8 so far.
Here's the script:
Code: | #!/bin/bash
#Attempt to automate loading Gentoo items into sda4 for chrooting in and working on the Gentoo operating system
x-terminal-emulator
su
sudo mount /dev/sda4 /mnt/gentoo
sudo mount -t proc proc /mnt/gentoo/proc
sudo mount --rbind /sys /mnt/gentoo/sys
sudo mount --rbind /dev /mnt/gentoo/dev
chroot /mnt/gentoo |
When I run the script, nothing happens.
If I type the commands in manually it works OK.
What am I doing wrong? _________________ Noob
With experience of Mint and trying to learn more by intalling Gentoo
Motherboard = MS-7211- MICRO-STAR INTERNATIONAL CO., LTD
CPU = Intel(R) Celeron(R) CPU 2.80GHz version: 15.4.9
Memory = 2GB
Last edited by catchpole on Wed Nov 05, 2014 2:12 pm; edited 1 time in total |
|
Back to top |
|
|
guitou Guru
Joined: 02 Oct 2003 Posts: 534 Location: France
|
Posted: Tue Nov 04, 2014 2:00 pm Post subject: |
|
|
Hello.
First, if you do "su", doing "sudo" after is useless.
Then, regarding your issue, it's probably a matter of environment: try "su -" to load env for root, or type full command path ("/sbin/mount")
++
Gi) |
|
Back to top |
|
|
Nicias Guru
Joined: 06 Dec 2005 Posts: 446
|
Posted: Tue Nov 04, 2014 4:20 pm Post subject: |
|
|
you "su" command starts a new shell. Your script is waiting for that shell to finish.
remove the "su" command. See if that works. |
|
Back to top |
|
|
steveL Watchman
Joined: 13 Sep 2006 Posts: 5153 Location: The Peanut Gallery
|
Posted: Wed Nov 05, 2014 10:06 am Post subject: |
|
|
Code: | chroot /mnt/gentoo /bin/bash |
or:
Code: | if chroot /mnt/gentoo /path/to/script "${arg[@]}"; then
# successful
else
# handle err $?
fi |
|
|
Back to top |
|
|
catchpole Tux's lil' helper
Joined: 03 Sep 2014 Posts: 103 Location: Leeds UK
|
Posted: Wed Nov 05, 2014 10:07 am Post subject: |
|
|
Hi Niclas, guitou,
I've tried your suggestions and every combination of the "x-teminal-emulator" and su lines but all I can get it to do is open the x-terminal in the host Mint xfce where I'm starting from.
Just to check if it was executing the other commands but not letting me chroot in, I tried "sudo chroot /mnt/gentoo" in the terminal.
I got an error message:
Quote: | chroot: failed to run command ' /bin/bash' : No such file or directory |
My cursor prompt is "/ $" so I think I'm in the root directory.
I can see the /bin directory and bash is a file within it so everything looks to be in order on the host sda3 partition.
I did " tail bash" from the /bin directory and can see the end of the bash file.
It won't stop me from continuing to install Gentoo but its something I'd like to clear up just to learn from the experience.
How can I debug the script, or what else do I need to do? _________________ Noob
With experience of Mint and trying to learn more by intalling Gentoo
Motherboard = MS-7211- MICRO-STAR INTERNATIONAL CO., LTD
CPU = Intel(R) Celeron(R) CPU 2.80GHz version: 15.4.9
Memory = 2GB |
|
Back to top |
|
|
steveL Watchman
Joined: 13 Sep 2006 Posts: 5153 Location: The Peanut Gallery
|
Posted: Wed Nov 05, 2014 12:27 pm Post subject: |
|
|
catchpole wrote: | How can I debug the script, or what else do I need to do? |
You need to untar the stage to the chroot first, so that there is a /mnt/gentoo/bin/bash and associated libraries. |
|
Back to top |
|
|
catchpole Tux's lil' helper
Joined: 03 Sep 2014 Posts: 103 Location: Leeds UK
|
Posted: Wed Nov 05, 2014 12:43 pm Post subject: |
|
|
Hi steveL,
I've followed the handbook down to section 8 so I'm past the the tarball untar stage.
If I put the commands in manually everything works and I'm chrooted in.
Its the script that's not working.
I start up with the already installed Mint 13 xfce on sda3 and chroot in from there to sda4 where I untarred stage 3.
bash is present on both partitions. _________________ Noob
With experience of Mint and trying to learn more by intalling Gentoo
Motherboard = MS-7211- MICRO-STAR INTERNATIONAL CO., LTD
CPU = Intel(R) Celeron(R) CPU 2.80GHz version: 15.4.9
Memory = 2GB |
|
Back to top |
|
|
py-ro Veteran
Joined: 24 Sep 2002 Posts: 1734 Location: Velbert
|
Posted: Wed Nov 05, 2014 12:49 pm Post subject: |
|
|
Maybe you should describe what you realy try to archive.
If read your post i would guess:
Start a Terminal Emulator, getting root inside, mount the partitions and then do the chroot.
Your can't do this, like you tried. The commands would be executed after your terminal has finished, but you need to do it inside.
Following a small example (untested) which could work:
(I substitute x-terminal-emulator with xterm, since i don't know which program is behind that)
Code: | xterm -e "su -c 'mount /dev/sda4 /mnt/gentoo && mount -t proc proc /mnt/gentoo/proc && mount --rbind /sys /mnt/gentoo/sys && sudo mount --rbind /dev /mnt/gentoo/dev && chroot /mnt/gentoo /bin/bash' "
|
Well the mount code could be moved before the xterm call, but then you need sudo or become root 2x
Bye
Py |
|
Back to top |
|
|
catchpole Tux's lil' helper
Joined: 03 Sep 2014 Posts: 103 Location: Leeds UK
|
Posted: Wed Nov 05, 2014 2:11 pm Post subject: |
|
|
Hi py-ro,
I used your code and it worked.
Thanks very much. (Danke schön)
Just one question:
There is a "sudo" in with the 4th command. I guess this is not intended to be there because of the first "su".
Is that the case?
Thanks again, it will save me a lot of tedious typing.
(I'm still puzzled why it works when its in one line and not separate commands!) _________________ Noob
With experience of Mint and trying to learn more by intalling Gentoo
Motherboard = MS-7211- MICRO-STAR INTERNATIONAL CO., LTD
CPU = Intel(R) Celeron(R) CPU 2.80GHz version: 15.4.9
Memory = 2GB |
|
Back to top |
|
|
py-ro Veteran
Joined: 24 Sep 2002 Posts: 1734 Location: Velbert
|
Posted: Wed Nov 05, 2014 2:42 pm Post subject: |
|
|
Yeah, this sudo is not intended.
Your problem is who will execute the commands.
With my code the xterm calls su, which in return calls the mount and chroot command.
Your code resulted in opening a term, then calling su in the calling environment, not inside the term, and so on.
Bye
Py |
|
Back to top |
|
|
|