website annotate en/doc/handbook/chroot-env.html @ rev 63

Add Apps to Handbook (en) and typos
author Paul Issott <paul@slitaz.org>
date Thu Jun 05 22:18:23 2008 +0000 (2008-06-05)
parents b7363623c8eb
children f0c0c73578c0
rev   line source
paul@41 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
paul@41 2 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><title>SliTaz Handbook (en) - Template</title>
paul@41 3
paul@41 4
paul@41 5
paul@41 6 <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />
paul@41 7 <meta name="description" content="slitaz English handbook" />
paul@41 8 <meta name="expires" content="never" />
paul@41 9 <meta name="modified" content="2008-02-26 18:30:00" />
paul@41 10 <meta name="publisher" content="www.slitaz.org" />
paul@41 11 <meta name="author" content="Christophe Lincoln" />
paul@41 12 <link rel="shortcut icon" href="favicon.ico" />
paul@41 13 <link rel="stylesheet" type="text/css" href="book.css" /></head><body bgcolor="#ffffff">
paul@41 14
paul@41 15 <!-- Header and quick navigation -->
paul@41 16 <div id="header">
paul@41 17 <div id="quicknav" align="right">
paul@41 18 <a name="top"></a>
paul@42 19 <a href="secure-server.html">Secure SHell (SSH)</a> |
paul@41 20 <a href="index.html">Table of contents</a>
paul@41 21 </div>
paul@41 22 <h1><font color="#3e1220">SliTaz Handbook (en)</font></h1>
paul@41 23 </div>
paul@41 24
paul@41 25 <!-- Content. -->
paul@41 26 <div id="content">
paul@41 27 <div class="content-right"></div>
paul@41 28
paul@41 29 <h2><font color="#df8f06">Chroot environment</font></h2>
paul@41 30
paul@41 31 <p>
paul@41 32 This document describes the necessary steps to create a chrooted environment, in order to change the root
paul@41 33 of the system so that you can work. This makes it possible to compile, test and develop SliTaz without any risk to
paul@41 34 the host system you're working on. The host system can be SliTaz installed to a hard drive or any other GNU/Linux system
paul@41 35 such as Debian, Fedora, PCLinuxOS and so on. You can also create a chrooted environment in LiveCD mode
paul@41 36 associated with USB media. The only prerequisite is to have a SliTaz ISO image available and a little
paul@41 37 time. Note that all commands are carried out as system administrator (<em>root</em>).
paul@41 38 </p>
paul@41 39 <h3>Prepare the environment</h3>
paul@41 40 <p>
paul@41 41 To begin, we must extract the contents of the ISO image into the directory that will serve as our chroot.
paul@41 42 The directory can be created any place you choose, we'll use a directory <code>/home/slitaz/chroot-env</code>.
paul@41 43 To extract the contents of an ISO image, we must mount it in a <em>loop</em> directory and then copy the compressed
paul@41 44 root filesystem (<code>rootfs.gz</code>) into the chroot directory. Assuming the ISO is in the current directory:
paul@41 45 </p>
paul@41 46 <pre> # mkdir /tmp/loop
paul@41 47 # mount -o loop slitaz-cooking.iso /tmp/loop
paul@41 48 # mkdir -p /home/slitaz/chroot-env
paul@41 49 # cp /tmp/loop/boot/rootfs.gz \
paul@41 50 /home/slitaz/chroot-env
paul@41 51 # umount /tmp/loop
paul@41 52 </pre>
paul@41 53 <p>
paul@41 54 Now we have a copy of the compressed filesystem, we must extract and unpack it (this is a <code>cpio</code>
paul@41 55 archive compressed with either gzip or lzma). To complete this stage, we can remove the
paul@41 56 <code>rootfs</code> which is no longer required:
paul@41 57 </p>
paul@41 58 <pre> # cd /home/slitaz/chroot-env
paul@41 59 # (zcat rootfs.gz 2&gt;/dev/null || lzma d rootfs.gz -so) | cpio -id
paul@41 60 # rm rootfs rootfs.gz
paul@41 61 </pre>
paul@41 62 <p>
paul@41 63 If the unpacking of the rootfs compressed with lzma fails; you can use the following method:
paul@41 64 </p>
paul@41 65 <pre> # unlzma rootfs.gz -S .gz
paul@41 66 # cat rootfs | cpio -id
paul@41 67 </pre>
paul@41 68
paul@41 69 <h3>Using the environment</h3>
paul@41 70 <p>
paul@41 71 To begin using the chrooted environment, you just need to mount some virtual filesystems and use the <code>chroot</code>
paul@41 72 command. To simplify things, we can write a small script automating the process. Example using the
paul@41 73 chroot directory <code>/home/slitaz/chroot-env</code> and creating a script
paul@41 74 <code>chroot_in_env.sh</code> in <code>/home/slitaz</code>.
paul@41 75 On any systems other than SliTaz you can uncomment the lines about <code>/dev</code> and
paul@41 76 <code>/tmp</code> - <em>Note</em> to save typing you can copy and paste:
paul@41 77 </p>
paul@41 78 <pre> # cat &gt; /home/slitaz/chroot_in_env.sh &lt;&lt; "EOF"
paul@41 79 </pre>
paul@41 80 <pre class="script">#!/bin/sh
paul@41 81 # Chroot in SliTaz to hack.
paul@41 82 #
paul@41 83 ROOTFS="/home/slitaz/chroot-env"
paul@41 84
paul@41 85 # Mount virtual Kernel file systems and chroot.
paul@41 86 #
paul@41 87 #mount --bind /dev $ROOTFS/dev
paul@41 88 #mount --bind /tmp $ROOTFS/tmp
paul@41 89 mount -t proc proc $ROOTFS/proc
paul@41 90 mount -t sysfs sysfs $ROOTFS/sys
paul@41 91 mount -t devpts devpts $ROOTFS/dev/pts
paul@41 92 mount -t tmpfs shm $ROOTFS/dev/shm
paul@41 93
paul@41 94 echo "Chrooting in $ROOTFS... "
paul@41 95 chroot $ROOTFS /bin/sh --login
paul@41 96
paul@41 97 # Unmount virtual Kernel file systems on exit.
paul@41 98 #
paul@41 99 umount $ROOTFS/dev/shm
paul@41 100 umount $ROOTFS/dev/pts
paul@41 101 umount $ROOTFS/sys
paul@41 102 umount $ROOTFS/proc
paul@41 103 #umount $ROOTFS/tmp
paul@41 104 #umount $ROOTFS/dev
paul@41 105
paul@41 106 echo "Exiting of $ROOTFS chroot environment... "
paul@41 107
paul@41 108 EOF
paul@41 109 </pre>
paul@41 110 <p>
paul@41 111 To finish and test the environment, you just make the script executable and run:
paul@41 112 </p>
paul@41 113 <pre> # chmod +x /home/slitaz/chroot_in_env.sh
paul@41 114 # sh /home/slitaz/chroot_in_env.sh
paul@41 115 </pre>
paul@41 116 <h4>To activate the network</h4>
paul@41 117 <p>
paul@41 118 In order to have the network up to download and install some development packages, just start the
paul@41 119 DHCP client on the correct interface. Example using <code>eth1</code>:
paul@41 120 </p>
paul@41 121 <pre> /# udhcpc -i eth1
paul@41 122 </pre>
paul@41 123 <h4>Installing packages</h4>
paul@41 124 <p>
paul@41 125 If the network is functional, just reload the list of packages and use <code>tazpkg get-install</code> to
paul@41 126 install them. If a connection is not possible, you can download the packages from another system, copy them
paul@41 127 to the chrooted environment and install them with the <code>tazpkg install</code> command. To install the basic
paul@41 128 compilation tools:
paul@41 129 </p>
paul@41 130 <pre> /# tazpkg recharge
paul@41 131 /# tazpkg get-install slitaz-toolchain
paul@41 132 </pre>
paul@41 133 <p>
paul@41 134 Once the environment is configured, you can compile applications from source to create packages, test scripts etc.
paul@41 135 The <a href="../cookbook/">Cookbook</a> should help you out here:
paul@41 136 </p>
paul@41 137 <h4>Exit the environment</h4>
paul@41 138 <p>
paul@41 139 To exit the chrooted environment, just type <code>exit</code>, the <code>chroot_in_env.sh</code> script will then end
paul@41 140 by unmounting the virtual filesystems from the Linux Kernel:
paul@41 141 </p>
paul@41 142 <pre> /# exit
paul@41 143 #
paul@41 144 </pre>
paul@41 145
paul@41 146 <!-- End of content -->
paul@41 147 </div>
paul@41 148
paul@41 149 <!-- Footer. -->
paul@41 150 <div id="footer">
paul@41 151 <div class="footer-right"></div>
paul@41 152 <a href="#top">Top of the page</a> |
paul@41 153 <a href="http://www.slitaz.org/en/doc/handbook/index.html">Table of contents</a>
paul@41 154 </div>
paul@41 155
paul@41 156 <div id="copy">
paul@41 157 Copyright © 2008 <a href="http://www.slitaz.org/en/">SliTaz</a> -
paul@41 158 <a href="http://www.gnu.org/licenses/gpl.html">GNU General Public License</a>;<br />
paul@41 159 Documentation is under
paul@41 160 <a href="http://www.gnu.org/copyleft/fdl.html">GNU Free Documentation License</a>
paul@41 161 and code is <a href="http://validator.w3.org/">valid xHTML 1.0</a>.
paul@41 162 </div>
paul@41 163
paul@41 164 </body></html>
paul@41 165