slitaz-doc-wiki-data diff pages/en/handbook/chroot.txt @ rev 7

Add pages/en folder.
author Christopher Rogers <slaxemulator@gmail.com>
date Sat Feb 26 12:17:18 2011 +0000 (2011-02-26)
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/pages/en/handbook/chroot.txt	Sat Feb 26 12:17:18 2011 +0000
     1.3 @@ -0,0 +1,100 @@
     1.4 +====== Chroot environment ======
     1.5 +
     1.6 +This document describes the necessary steps to create a chrooted environment, in order to change the root of the system so that you can work. This makes it possible to compile, test and develop SliTaz without any risk to the host system you're working on. The host system can be SliTaz installed to a hard drive or any other GNU/Linux system such as Debian, Fedora, PCLinuxOS and so on. You can also create a chrooted environment in LiveCD mode associated with USB media. The only prerequisite is to have a SliTaz ISO image available and a little time. Note that all commands are carried out as system administrator (root).
     1.7 +
     1.8 +===== Prepare the environment =====
     1.9 +
    1.10 +To begin, we must extract the contents of the ISO image into the directory that will serve as our chroot. The directory can be created any place you choose, we'll use a directory ///home/slitaz/chroot-env//. To extract the contents of an ISO image, we must mount it in a loop directory and then copy the compressed root filesystem (rootfs.gz) into the chroot directory. Assuming the ISO is in the current directory:
    1.11 +
    1.12 +<code>
    1.13 + # mkdir /tmp/loop
    1.14 + # mount -o loop slitaz-cooking.iso /tmp/loop
    1.15 + # mkdir -p /home/slitaz/chroot-env
    1.16 + # cp /tmp/loop/boot/rootfs.gz \
    1.17 +   /home/slitaz/chroot-env
    1.18 + # umount /tmp/loop
    1.19 +</code>
    1.20 +
    1.21 +Now we have a copy of the compressed filesystem, we must extract and unpack it (this is a cpio archive compressed with either gzip or lzma). To complete this stage, we can remove the rootfs which is no longer required:
    1.22 +
    1.23 +<code>
    1.24 + # cd /home/slitaz/chroot-env
    1.25 + # (zcat rootfs.gz 2>/dev/null || lzma d rootfs.gz -so) | cpio -id
    1.26 + # rm rootfs rootfs.gz
    1.27 +</code>
    1.28 +
    1.29 +If the unpacking of the rootfs compressed with lzma fails; you can use the following method:
    1.30 +
    1.31 +<code>
    1.32 + # unlzma rootfs.gz -S .gz 
    1.33 + # cat rootfs | cpio -id
    1.34 +</code>
    1.35 +
    1.36 +===== Using the environment =====
    1.37 +
    1.38 +To begin using the chrooted environment, you just need to mount some virtual filesystems and use the chroot command. To simplify things, we can write a small script automating the process. Example using the chroot directory ///home/slitaz/chroot-env// and creating a script chroot_in_env.sh in ///home/slitaz//. On any systems other than SliTaz you can uncomment the lines about ///dev// and ///tmp// - Note to save typing you can copy and paste:
    1.39 +
    1.40 +<code> # cat > /home/slitaz/chroot_in_env.sh << "EOF" </code>
    1.41 +
    1.42 +<file>
    1.43 +#!/bin/sh
    1.44 +# Chroot in SliTaz to hack.
    1.45 +#
    1.46 +ROOTFS="/home/slitaz/chroot-env"
    1.47 +
    1.48 +# Mount virtual Kernel file systems and chroot.
    1.49 +#
    1.50 +#mount --bind /dev $ROOTFS/dev
    1.51 +#mount --bind /tmp $ROOTFS/tmp
    1.52 +mount -t proc proc $ROOTFS/proc
    1.53 +mount -t sysfs sysfs $ROOTFS/sys
    1.54 +mount -t devpts devpts $ROOTFS/dev/pts
    1.55 +mount -t tmpfs shm $ROOTFS/dev/shm
    1.56 +
    1.57 +echo "Chrooting into $ROOTFS... "
    1.58 +chroot $ROOTFS /bin/sh --login
    1.59 +
    1.60 +# Unmount virtual Kernel file systems on exit.
    1.61 +#
    1.62 +umount $ROOTFS/dev/shm
    1.63 +umount $ROOTFS/dev/pts
    1.64 +umount $ROOTFS/sys
    1.65 +umount $ROOTFS/proc
    1.66 +#umount $ROOTFS/tmp
    1.67 +#umount $ROOTFS/dev
    1.68 +
    1.69 +echo "Exiting $ROOTFS chroot environment... "
    1.70 +
    1.71 +EOF
    1.72 +</file>
    1.73 +
    1.74 +To finish and test the environment, you just make the script executable and run:
    1.75 +
    1.76 +<code>
    1.77 + # chmod +x /home/slitaz/chroot_in_env.sh
    1.78 + # sh /home/slitaz/chroot_in_env.sh
    1.79 +</code>
    1.80 +
    1.81 +=== To activate the network ===
    1.82 +
    1.83 +In order to have the network up to download and install some development packages, just start the DHCP client on the correct interface. Example using eth1:
    1.84 +
    1.85 + <code> # udhcpc -i eth1 </code>
    1.86 +
    1.87 +=== Installing packages ===
    1.88 +
    1.89 +If the network is functional, just reload the list of packages and use tazpkg get-install to install them. If a connection is not possible, you can download the packages from another system, copy them to the chrooted environment and install them with the tazpkg install command. To install the basic compilation tools:
    1.90 +
    1.91 + <code> # tazpkg recharge
    1.92 + # tazpkg get-install slitaz-toolchain </code>
    1.93 +
    1.94 +Once the environment is configured, you can compile applications from source to create packages, test scripts, etc. The Cookbook should help you out here:
    1.95 +
    1.96 +=== Exit the environment ===
    1.97 +
    1.98 +To exit the chrooted environment, just type exit, the //chroot_in_env.sh// script will then end by unmounting the virtual filesystems from the Linux Kernel:
    1.99 +
   1.100 +<code>
   1.101 + # exit
   1.102 + #
   1.103 +</code>