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

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