website view 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 |
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="secure-server.html">Secure SHell (SSH)</a> |
20 <a href="index.html">Table of contents</a>
21 </div>
22 <h1><font color="#3e1220">SliTaz Handbook (en)</font></h1>
23 </div>
25 <!-- Content. -->
26 <div id="content">
27 <div class="content-right"></div>
29 <h2><font color="#df8f06">Chroot environment</font></h2>
31 <p>
32 This document describes the necessary steps to create a chrooted environment, in order to change the root
33 of the system so that you can work. This makes it possible to compile, test and develop SliTaz without any risk to
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
35 such as Debian, Fedora, PCLinuxOS and so on. You can also create a chrooted environment in LiveCD mode
36 associated with USB media. The only prerequisite is to have a SliTaz ISO image available and a little
37 time. Note that all commands are carried out as system administrator (<em>root</em>).
38 </p>
39 <h3>Prepare the environment</h3>
40 <p>
41 To begin, we must extract the contents of the ISO image into the directory that will serve as our chroot.
42 The directory can be created any place you choose, we'll use a directory <code>/home/slitaz/chroot-env</code>.
43 To extract the contents of an ISO image, we must mount it in a <em>loop</em> directory and then copy the compressed
44 root filesystem (<code>rootfs.gz</code>) into the chroot directory. Assuming the ISO is in the current directory:
45 </p>
46 <pre> # mkdir /tmp/loop
47 # mount -o loop slitaz-cooking.iso /tmp/loop
48 # mkdir -p /home/slitaz/chroot-env
49 # cp /tmp/loop/boot/rootfs.gz \
50 /home/slitaz/chroot-env
51 # umount /tmp/loop
52 </pre>
53 <p>
54 Now we have a copy of the compressed filesystem, we must extract and unpack it (this is a <code>cpio</code>
55 archive compressed with either gzip or lzma). To complete this stage, we can remove the
56 <code>rootfs</code> which is no longer required:
57 </p>
58 <pre> # cd /home/slitaz/chroot-env
59 # (zcat rootfs.gz 2>/dev/null || lzma d rootfs.gz -so) | cpio -id
60 # rm rootfs rootfs.gz
61 </pre>
62 <p>
63 If the unpacking of the rootfs compressed with lzma fails; you can use the following method:
64 </p>
65 <pre> # unlzma rootfs.gz -S .gz
66 # cat rootfs | cpio -id
67 </pre>
69 <h3>Using the environment</h3>
70 <p>
71 To begin using the chrooted environment, you just need to mount some virtual filesystems and use the <code>chroot</code>
72 command. To simplify things, we can write a small script automating the process. Example using the
73 chroot directory <code>/home/slitaz/chroot-env</code> and creating a script
74 <code>chroot_in_env.sh</code> in <code>/home/slitaz</code>.
75 On any systems other than SliTaz you can uncomment the lines about <code>/dev</code> and
76 <code>/tmp</code> - <em>Note</em> to save typing you can copy and paste:
77 </p>
78 <pre> # cat > /home/slitaz/chroot_in_env.sh << "EOF"
79 </pre>
80 <pre class="script">#!/bin/sh
81 # Chroot in SliTaz to hack.
82 #
83 ROOTFS="/home/slitaz/chroot-env"
85 # Mount virtual Kernel file systems and chroot.
86 #
87 #mount --bind /dev $ROOTFS/dev
88 #mount --bind /tmp $ROOTFS/tmp
89 mount -t proc proc $ROOTFS/proc
90 mount -t sysfs sysfs $ROOTFS/sys
91 mount -t devpts devpts $ROOTFS/dev/pts
92 mount -t tmpfs shm $ROOTFS/dev/shm
94 echo "Chrooting in $ROOTFS... "
95 chroot $ROOTFS /bin/sh --login
97 # Unmount virtual Kernel file systems on exit.
98 #
99 umount $ROOTFS/dev/shm
100 umount $ROOTFS/dev/pts
101 umount $ROOTFS/sys
102 umount $ROOTFS/proc
103 #umount $ROOTFS/tmp
104 #umount $ROOTFS/dev
106 echo "Exiting of $ROOTFS chroot environment... "
108 EOF
109 </pre>
110 <p>
111 To finish and test the environment, you just make the script executable and run:
112 </p>
113 <pre> # chmod +x /home/slitaz/chroot_in_env.sh
114 # sh /home/slitaz/chroot_in_env.sh
115 </pre>
116 <h4>To activate the network</h4>
117 <p>
118 In order to have the network up to download and install some development packages, just start the
119 DHCP client on the correct interface. Example using <code>eth1</code>:
120 </p>
121 <pre> /# udhcpc -i eth1
122 </pre>
123 <h4>Installing packages</h4>
124 <p>
125 If the network is functional, just reload the list of packages and use <code>tazpkg get-install</code> to
126 install them. If a connection is not possible, you can download the packages from another system, copy them
127 to the chrooted environment and install them with the <code>tazpkg install</code> command. To install the basic
128 compilation tools:
129 </p>
130 <pre> /# tazpkg recharge
131 /# tazpkg get-install slitaz-toolchain
132 </pre>
133 <p>
134 Once the environment is configured, you can compile applications from source to create packages, test scripts etc.
135 The <a href="../cookbook/">Cookbook</a> should help you out here:
136 </p>
137 <h4>Exit the environment</h4>
138 <p>
139 To exit the chrooted environment, just type <code>exit</code>, the <code>chroot_in_env.sh</code> script will then end
140 by unmounting the virtual filesystems from the Linux Kernel:
141 </p>
142 <pre> /# exit
143 #
144 </pre>
146 <!-- End of content -->
147 </div>
149 <!-- Footer. -->
150 <div id="footer">
151 <div class="footer-right"></div>
152 <a href="#top">Top of the page</a> |
153 <a href="http://www.slitaz.org/en/doc/handbook/index.html">Table of contents</a>
154 </div>
156 <div id="copy">
157 Copyright © 2008 <a href="http://www.slitaz.org/en/">SliTaz</a> -
158 <a href="http://www.gnu.org/licenses/gpl.html">GNU General Public License</a>;<br />
159 Documentation is under
160 <a href="http://www.gnu.org/copyleft/fdl.html">GNU Free Documentation License</a>
161 and code is <a href="http://validator.w3.org/">valid xHTML 1.0</a>.
162 </div>
164 </body></html>