User Tools

Site Tools


qLinux
… a distribution study


<< Prev
Temporary Tools (Part I)

Next >>
Temporary Tools (Part II)


Prepare the Chroot'ed Environment

This is based on the first part of chapter 7 (7.1 to 7.6) from the book, but with some major differences. First not all steps from the book will be done or even particular only. Second some additional (recommended) files will be created, which are not in the book. Third

However, it is recommended to (re)read the explanations between the commands in the book.

System Directories and Files

Create directories for the virtual kernel filesystems and for the extracted sources:

$> mkdir -pv $LFS/qlnx/{dev/pts,prc,run,sys}
$> for d in dev prc sys ; do ln -s qlnx/$d $d ; done
$> mkdir -pv /data/src

The  /qlnx/etc/password  and  /qlnx/etc/group  shall exists in the “chroot” environment. These files can be created similar to the book or simply:

cat "root:x:0:0:root:/home/admin:/qlnx/bin/bash" > $LFS/qlnx/etc/passwd
cat > $LFS/qlnx/etc/group << "EOF"
root:x:0:root
bin:x:1:daemon
sys:x:2:
kmem:x:3:
tty:x:5:
EOF

The root user shall have a home directory:

mkdir -p $LFS/home/admin

There is no need to create more files and directories right now!

Additional Files

Adjustment of the Shebang

Some of the files in  /qlnx/bin  are shell scripts and have a wrong shebang for our purposes - the final system shall not have  /bin/sh  but  /qlnx/bin/sh . To fix this a small file  qshebang  will be helpful:

qshebang
cat > $LFS/qlnx/bin/qshebang << EOF
cd \$LFS/qlnx/bin

for f in \`ls -R\` ; do
  head -1 \$f | grep '#!' &>/dev/null && sed -i "s/^#\!.*$/#\!\/qlnx\/bin\/bash/" \$f
done
EOF
chmod -v 755 $LFS/qlnx/bin/qshebang

It is highly reommended to create a backup of  $LFS/qlnx/bin  before continue

Execution of  qshebang :

$> cd $LFS/qlnx/bin
$> ./qshebang

Verify the result (e.g. on  znew ):

$> head -1 $LFS/qlnx/bin/znew

Even if  qshebang  is a special use case here, the principle could be used later on too.

The Presence or Absence of 'which'

See the related chapter in the blfs book. The following fits what's needed right now (do it as root, the  chown  will require root privileges anyway):

which
cat > $LFS/qlnx/bin/which << "EOF"
#!/qlnx/bin/bash
type -pa "$@" | head -n 1 ; exit ${PIPESTATUS[0]}
EOF
chmod -v 755 $LFS/qlnx/bin/which

Continue with the build

To easily (re-)enter the chroot environment create a file (e.g. dochroot) and make it executable:

dochroot
#!/bin/sh

mount | grep $LFS/qlnx/dev     || mount -v --bind /dev $LFS/qlnx/dev
mount | grep $LFS/qlnx/dev/pts || mount -v --bind /dev/pts $LFS/dev/pts
mount | grep $LFS/qlnx/proc    || mount -vt proc proc $LFS/qlnx/proc
mount | grep $LFS/qlnx/sys     || mount -vt sysfs sysfs $LFS/qlnx/sys
mount | grep $LFS/qlnx/run     || mount -vt tmpfs tmpfs $LFS/qlnx/run

chroot "$LFS" /qlnx/bin/env -i \
    HOME=/home/admin \
    TERM="$TERM" \
    PS1='(qlinux chroot) \u:\w\$ ' \
    CC=musl-gcc \
    PATH=/exec:qlnx/bin:/plng/bin:/misc/bin:libs/bin \
    /qlnx/bin/bash --login +h

umount $LFS/qlnx/dev/pts
umount $LFS/qlnx/dev
umount $LFS/qlnx/proc
umount $LFS/qlnx/sys
umount $LFS/qlnx/run

Now the chroot should be easily entered with

$> sudo ~/dochroot

<< Prev
Temporary Tools (Part I)

        

Next >>
Temporary Tools (Part II)