website view en/doc/handbook/chroot-env.html @ rev 41

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