Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Chroot in with shell script [SOLVED]
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Installing Gentoo
View previous topic :: View next topic  
Author Message
catchpole
Tux's lil' helper
Tux's lil' helper


Joined: 03 Sep 2014
Posts: 103
Location: Leeds UK

PostPosted: Tue Nov 04, 2014 1:43 pm    Post subject: Chroot in with shell script [SOLVED] Reply with quote

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
View user's profile Send private message
guitou
Guru
Guru


Joined: 02 Oct 2003
Posts: 534
Location: France

PostPosted: Tue Nov 04, 2014 2:00 pm    Post subject: Reply with quote

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
View user's profile Send private message
Nicias
Guru
Guru


Joined: 06 Dec 2005
Posts: 446

PostPosted: Tue Nov 04, 2014 4:20 pm    Post subject: Reply with quote

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
View user's profile Send private message
steveL
Watchman
Watchman


Joined: 13 Sep 2006
Posts: 5153
Location: The Peanut Gallery

PostPosted: Wed Nov 05, 2014 10:06 am    Post subject: Reply with quote

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
View user's profile Send private message
catchpole
Tux's lil' helper
Tux's lil' helper


Joined: 03 Sep 2014
Posts: 103
Location: Leeds UK

PostPosted: Wed Nov 05, 2014 10:07 am    Post subject: Reply with quote

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
View user's profile Send private message
steveL
Watchman
Watchman


Joined: 13 Sep 2006
Posts: 5153
Location: The Peanut Gallery

PostPosted: Wed Nov 05, 2014 12:27 pm    Post subject: Reply with quote

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
View user's profile Send private message
catchpole
Tux's lil' helper
Tux's lil' helper


Joined: 03 Sep 2014
Posts: 103
Location: Leeds UK

PostPosted: Wed Nov 05, 2014 12:43 pm    Post subject: Reply with quote

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
View user's profile Send private message
py-ro
Veteran
Veteran


Joined: 24 Sep 2002
Posts: 1734
Location: Velbert

PostPosted: Wed Nov 05, 2014 12:49 pm    Post subject: Reply with quote

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
View user's profile Send private message
catchpole
Tux's lil' helper
Tux's lil' helper


Joined: 03 Sep 2014
Posts: 103
Location: Leeds UK

PostPosted: Wed Nov 05, 2014 2:11 pm    Post subject: Reply with quote

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
View user's profile Send private message
py-ro
Veteran
Veteran


Joined: 24 Sep 2002
Posts: 1734
Location: Velbert

PostPosted: Wed Nov 05, 2014 2:42 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Installing Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum