Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Installing/fixing Gentoo with livedvd & chroot
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
bedtime
n00b
n00b


Joined: 19 Dec 2012
Posts: 71

PostPosted: Tue Jan 08, 2013 11:54 pm    Post subject: Installing/fixing Gentoo with livedvd & chroot Reply with quote

Why another tutorial on chroot? There are so many out there!

Well, there are many tutorials out there but none of them, at least through my searching, seemed to have all of the information in the one post. Many were missing critical information that would have saved a lot of hassle, such as turning swap on, adding the ability to use the network in chroot, or unmounting...

When should I use chroot?

1. You want to have a full suit of easy to use gui tools at your disposal when installing Gentoo, ie; internet browswer, xchat, partition manager...

2. You only have one computer and you don't want it tied down for a day or two whilst packages are being emerged.

3. You've messed something up badly and cannot boot the system.

Does this really work?
I've had success with doing a full Gentoo installation plus installing X, a window manager, all drivers, and several other packages... Only once did I reboot into my new Gentoo install to check if the initial install was okay, which it was. I will not promise this will work for you. You may end up destroying your partitions or ruining your install or just wasting your time. I'll not be responsible! You do this at your own risk!

Note: If you just want to chroot into an already installed system then jump down to the section: I want to chroot into my installed system - How do I do it?.

I'm in! Where do I start?
I'm going to assume you're installing using the Gentoo x86 manual and that you are 'going by the book'. If you've decided to install on different partitions then specified in the book then you'll have to change some steps accordingly to fit your situation. I did the install using the Gentoo 12.1 (at this time) livedvd installation medium which can be found here:
http://mirrors.us.kernel.org/gentoo//releases/x86/

Burn the dvd and boot it up. You'll be starting the install at chapter 4. So open up a browswer and go to this link:
http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?full=1#book_part1_chap4

Open a terminal and follow the handbooks instructions until you get to Chapter 5b: Code Listing 2.5: Unpacking the stage. Enter this command instead:

Code:
tar --numeric-owner -xvjpf stage3-*.tar.bz2


Continue on until you get to Chapter 6a: Copy DNS Info and then enter the following commands instead:

Mount the partitions:
Code:
mount /dev/sda3 /mnt/gentoo
mount /dev/sda1 /mnt/gentoo/boot
mount -t proc none /mnt/gentoo/proc
mount -o bind /dev /mnt/gentoo/dev


Copy DNS info to allow us to use the net within chroot:
Code:
cp -L /etc/resolv.conf /mnt/gentoo/etc/resolv.conf


Chroot into the system:
Code:
chroot /mnt/gentoo /bin/env -i TERM=$TERM /bin/bash
env-update
source /etc/profile
export PS1="(chroot) $PS1"



.. resume the install at Chapter 6.b. Configuring Portage and finish the install.

Reboot into the new Gentoo install, that is, without the livedvd, and check to see if all is fine. If something has messed up or you just want to keep using chroot then follow the section below:


I want to chroot into my installed system - How do I do it?

Boot the Gentoo livedvd and open a terminal and browser to this link.

Copy and paste this into the terminal:
Code:
# Create mounting directories
mkdir /mnt/gentoo
cd /mnt/gentoo
 
# Enter root
sudo -i
 
# Activate swap
swapon /dev/sda2
 
# Mount partitions
mount /dev/sda3 /mnt/gentoo
mount /dev/sda1 /mnt/gentoo/boot
mount -t proc none /mnt/gentoo/proc
mount -o bind /dev /mnt/gentoo/dev
 
# Copy netowrk information so we can use the net inside chroot
cp -L /etc/resolv.conf /mnt/gentoo/etc/resolv.conf
 
# Chroot into system
chroot /mnt/gentoo /bin/bash
env-update
source /etc/profile
export PS1="(chroot) $PS1"
 
# Do stuff here:


Do whatever you want to do in choot. You will have net access and activated swap, so you can easily merge stuff, replace the kernel, edit files... like you would on an ordinary non-chrooted system. I should note that this chroot guide does not have the ability to run x, but that's not really necessary in most cases anyways.

When you're done simply paste the following into terminal:
Code:
# Exit chroot:
exit
 
# Unmount
umount /mnt/gentoo/boot /mnt/gentoo/dev /mnt/gentoo/proc /mnt/gentoo
 
# Deactivate swap
swapoff /dev/sda2
 
# Return to user prompt
exit



You're done!

If anyone has any suggestions or information to add please post and I'll add it and credit you. I'd love to get X working in chroot but have only got so far as to have X run the Gentoo livedvd's X, and not the X in the chroot environment.
Back to top
View user's profile Send private message
KeyZerZooZee
n00b
n00b


Joined: 27 Sep 2017
Posts: 2

PostPosted: Wed Sep 27, 2017 12:13 pm    Post subject: cp: dangling symlink Reply with quote

Hi thank you for the tutorial.

[My first ever contribution on any Linux/Gentoo forum - what a beautiful day :D ]

Maybe things have changed somewhat since 2013 regarding the cp command.

When I tried to chroot into my already installed Gentoo, doing the
Quote:
# Copy netowrk information so we can use the net inside chroot
cp -L /etc/resolv.conf /mnt/gentoo/etc/resolv.conf
I got:
Code:
livecd gentoo # cp -L /etc/resolv.conf /mnt/gentoo/etc/resolv.conf
cp: not writing through dangling symlink '/mnt/gentoo/etc/resolv.conf'


The solution I got from here: https://askubuntu.com/questions/551537/force-cp-to-copy-on-dangling-symlinks

Witch as a solution suggests to add '--remove-destination' to the cp command:
Code:
livecd gentoo # cp --remove-destination -L /etc/resolv.conf /mnt/gentoo/etc/resolv.conf


Have a very nice day 8)
_________________
***My memory is by prof the greatest liar of all times - yet it never fails trying to be my best friend***
Back to top
View user's profile Send private message
KeyZerZooZee
n00b
n00b


Joined: 27 Sep 2017
Posts: 2

PostPosted: Wed Sep 27, 2017 5:34 pm    Post subject: Openpty issue after chroot Reply with quote

Another small fix for the tutorial:

After chroot into installed system (trying to fix a boot failure resulting in my / mounted ro (as in read only)) I got this error:

Code:
openpty failed: 'out of pty devices'


When I did:

Code:
emerge -auNDv --with-bdeps=y @world


Solution:

I changed:
Code:
# Mount partitions
mount -o bind /dev /mnt/gentoo/dev


To:
Code:
mount --rbind /dev mnt/gentoo/dev


The solution I found in this post https://forums.gentoo.org/viewtopic-t-725408-start-0.html and waebbl's reply https://forums.gentoo.org/viewtopic-p-6781798.html#6781798:

Quote:
I know this post is quite old, but today I ran into the same problem, so there's a chance the post might still be interesting for some people.

It happens, although /dev was bind-mounted inside the chroot. I never noticed this before inside a chrooted environment.

The key here is to use --rbind instead of --bind, which also rebinds the /dev/pts and /dev/shm filesystems. By exiting the chroot, unmount ${CHROOT}/dev and mount it again using the rbind option, it worked. I was used to use the rbind option, because the handbook uses that option before changing into the chroot, but today I just used the bind option, just because I saw it on a lot of articles on the net.

_________________
***My memory is by prof the greatest liar of all times - yet it never fails trying to be my best friend***
Back to top
View user's profile Send private message
arvamircea
Tux's lil' helper
Tux's lil' helper


Joined: 21 May 2022
Posts: 105
Location: Swadlincote

PostPosted: Wed Dec 27, 2023 9:50 am    Post subject: Reply with quote

Bless you for this bedtime. Very useful
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks 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