re-entering chroot correctly

Dan Nicholson dbn.lists at gmail.com
Sun Oct 9 11:38:55 PDT 2005


Albert wrote:
> Sorry to bother everyone with this again, but I am on my third host and
> have lost the previous emails that address this.  Could someone please 
> verify that the commands below are the correct way to re-enter chroot, 
> chptr 6, after rebooting host:
> 
> export LFS=/mnt/hda6.lfs61
> 
> # 6.2. Mounting Virtual Kernel File Systems
> mount -t proc proc $LFS/proc
> mount -t sysfs sysfs $LFS/sys
> 
> # 6.3. Entering the Chroot Environment
> chroot "$LFS" /tools/bin/env -i \
>     HOME=/root TERM="$TERM" PS1='\[\033[1;33m\]# \w\n\r# \[\033[0m\]' \
>     PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
>     /tools/bin/bash --login +h
> 
> # 6.8.1. Creating Initial Device Nodes
> mknod -m 600 /dev/console c 5 1
> mknod -m 666 /dev/null c 1 3
> 
> # 6.8.2. Mounting tmpfs and Populating /dev
> mount -n -t tmpfs none /dev
> mknod -m 622 /dev/console c 5 1
> mknod -m 666 /dev/null c 1 3
> mknod -m 666 /dev/zero c 1 5
> mknod -m 666 /dev/ptmx c 5 2
> mknod -m 666 /dev/tty c 5 0
> mknod -m 444 /dev/random c 1 8
> mknod -m 444 /dev/urandom c 1 9
> chown root:tty /dev/{console,ptmx,tty}
> 
> ln -s /proc/self/fd /dev/fd
> ln -s /proc/self/fd/0 /dev/stdin
> ln -s /proc/self/fd/1 /dev/stdout
> ln -s /proc/self/fd/2 /dev/stderr
> ln -s /proc/kcore /dev/core
> mkdir /dev/pts
> mkdir /dev/shm
> 
> mount -t devpts -o gid=4,mode=620 none /dev/pts
> mount -t tmpfs none /dev/shm
> 

That would do it.  Although you don't need to redo any of these steps if 
you're just leaving chroot and coming back.  The device files and mount 
table should stay in place while the system is booted.  But you probably 
knew that.

Dan




More information about the lfs-support mailing list