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