website view en/doc/handbook/hacking-livecd.html @ rev 65

Add apps to Handbook (en)
author Paul Issott <paul@slitaz.org>
date Sun Jun 08 21:59:02 2008 +0000 (2008-06-08)
parents e172c1d2ec01
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">
4 <head>
5 <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" />
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="web-server.html">Web server</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">Hacking SliTaz LiveCD</font></h2>
33 <ul>
34 <li><a href="#intro">Introduction.</a></li>
35 <li><a href="#pre">Organisation and preparation.</a></li>
36 <li><a href="#add-files">Add files to the ISO.</a></li>
37 <li><a href="#isolinux">Modify the isolinux configuration.</a></li>
38 <li><a href="#memtest">Install and use Memtest86.</a></li>
39 <li><a href="#rootfs">Manipulate the Live root system.</a></li>
40 <li><a href="#gen-iso">Generate a bootable ISO image with isolinux.</a></li>
41 </ul>
43 <a name="intro"></a>
44 <h3>Introduction</h3>
45 <p>
46 <em>Hacking SliTaz LiveCD</em> or how to have fun with the LiveCD ISO image. Note that you can also
47 <a href="gen-livecd.html">create a custom flavor with Tazlito</a>.
48 Creating your own bootable ISO image is easily achievable and the steps are carefully described here. The manipulation of a personal ISO image can add new files or modify existing
49 ones found on the Slitaz Live CD. The Slitaz ISO image is less than 30 MB and a CD-R or CD-RW provides around 700 MB,
50 so there's plenty of scope for expansion. For example, you could store your images and even provide a <em>live</em> slideshow
51 using GQview. The <em>hacking</em> of the ISO image allows you to modify boot loader configuration files
52 (<em>boot loader</em>), <em>splash</em> images and GRUB itself. You could also add the
53 Memtest86 utility (tool used to test system RAM). Using the same techniques it's even possible to
54 modify the filesystem - this does however require some extra manipulation and a bit more time.</p>
56 <a name="pre"></a>
57 <h3>Organisation and preparation</h3>
58 <p>
59 To begin, first we must define where we are going to work by creating a directory and several sub directories
60 to accomodate all the different files. The <em>hacking</em> of the ISO can be done from within a SliTaz system or any
61 other GNU/Linux distribution such as Debian, Fedora, PCLinuxOS etc. If you use SliTaz LiveCD mode
62 (where you can remove the CD once SliTaz has launched in RAM and burn your new ISO), It's advisible to use
63 USB media to carry on working, otherwise your work will be lost on shutdown. To begin you need to create a
64 <em>hacking</em> directory that you can use inside <code>/home/slitaz</code> within the
65 root of your user space. The use of a <code>/home/slitaz</code> directory enables you to store an original
66 ISO image and gives you the option to create a <code>src/</code> directory to download possible source packages.
67 All the various stages of <em>hacking</em> can be done on the command line via a X terminal (Xterm) or in console mode
68 on a Linux terminal. It's advisable to run all commands as <em>root</em> to avoid any permission problems.
69 To become the (<em>root</em>) adminsistrator, create a <code>/home/slitaz/hacked</code> directory and proceed
70 inside:
71 </p>
72 <pre> $ su
73 # mkdir -p /home/slitaz/hacked
74 (# mkdir -p /home/slitaz/src)
75 # cd /home/slitaz/hacked
76 </pre>
77 <h4>Getting the contents of the ISO</h4>
78 <p>
79 Now that you are in the working directory, we must create the root of the amended CD-ROM and retrieve the files contained on the original Slitaz ISO - namely, the Linux Kernel (<code>bzImage</code>), the compressed
80 filesystem (<code>rootfs.gz</code>) and the isolinux bootloader files. To recover these files you have two
81 options, either take them from a burnt CD or from an ISO image stored locally. To create the root of your CD
82 (<code>rootcd</code>) and copy files from the cdrom device <code>/dev/cdrom</code> mounted on
83 <code>/media/cdrom</code>:
84 </p>
85 <pre> # mount -t iso9660 /dev/cdrom /media/cdrom
86 # mkdir rootcd
87 # cp -a /media/cdrom/* rootcd
88 </pre>
89 <p>
90 To mount an ISO image using <em>loop</em> in the temporary directory <code>/tmp/loop</code>
91 (with the ISO image <code>slitaz-cooking.iso</code>), create the root of the CD
92 (<code>rootcd</code>), copy all the files and dismount the ISO image:
93 </p>
94 <pre> # mkdir /tmp/loop
95 # mount -o loop slitaz-cooking.iso /tmp/loop
96 # mkdir rootcd
97 # cp -a /tmp/loop/* rootcd
98 # umount /tmp/loop
99 </pre>
100 <p>
101 Voilą, all the necessary files should now be present in the <code>rootcd/</code> directory.
102 To be sure, you can list all of the files recursively with the <code>ls</code> command:
103 </p>
104 <pre> # ls -R rootcd
105 </pre>
107 <a name="add-files"></a>
108 <h3>Adding the files to the ISO</h3>
109 <p>
110 The addition of various files and directories to the ISO image simply consists of copying data to
111 the root of the cdrom (<code>rootcd/</code>) and generating a new image. The data may be classified
112 in one or two directories created in the root of the CD. Once the ISO image is burnt to a CD-R/CD-RW
113 you can use SliTaz as before, mounted on <code>/media/cdrom</code> and navigate through your data using
114 emelFM2, Clex or the command line. You data will also be legible from all GNU/Linux systems, BSD or even
115 ... Windows.
116 </p>
117 <h4>Create directories and copy data</h4>
118 <p>
119 To create and copy files, you can start by using the command line and then continue on graphically as a simple
120 user. We will create a <code>images/</code> directory as <em>root</em> and change the permissions so that all
121 users can have write access:
122 </p>
123 <pre> # mkdir rootcd/images
124 # chmod 777 rootcd/images
125 </pre>
126 <p>
127 Now that a directory exists that anybody can write to, you can start to fill it. Once you've finished
128 you can then <a href="#gen-iso">generate a bootable ISO image</a>.
129 </p>
131 <a name="isolinux"></a>
132 <h3>Modify the isolinux configuration</h3>
133 <p>
134 The modification of isolinux allows you to create custom entries with <em>pre-boot</em> parameters,
135 for example you can add a <code>label</code> launching SliTaz with the <code>lang=en</code>
136 and <code>kmap=en</code> options. At the design level you can easily change the <em>splash</em>
137 image displayed at startup. The <code>isolinux</code> application manages the starting of the
138 <em>boot loader</em> of the LiveCD and is provided by the Syslinux package. The source file of
139 Syslinux provides various applications whose role it is to start a GNU/Linux system. The binary
140 <code>isolinux.bin</code> controls the actual boot loading. The boot loader is simple, fast and easily
141 configured either graphically or using a text editor. The syntax of the configuration file
142 <code>isolinux.cfg</code> is easy to understand - to add new entries just copy and paste using the
143 original file. To edit the file graphically using Leafpad:
144 </p>
145 <pre> # leafpad rootcd/boot/isolinux/isolinux.cfg &amp;
146 </pre>
147 <h4>Configuration file isolinux.cfg</h4>
148 <p>
149 The <code>isolinux.cfg</code> file found on the standard LiveCD of
150 SliTaz, begins with the value <code>display</code>, this will either display
151 a text file or a (<code>isolinux.msg</code>) file using 24 ASCII characters and
152 a splash image. The <code>default</code> value defines the name of the <code>label</code>
153 started by default after the (<code>timeout</code>) waiting time. <em>Timeout</em> is the
154 number of seconds to wait before booting the system, you can make it 0 to start booting
155 immediately or choose a waiting time as long as 80s. Finally the <code>prompt</code> can be
156 deactivated using the value <code>0</code>, F1, F2, F3 display help files and F4 displays a text file:
157 </p>
158 <pre class="script">display isolinux.msg
159 default slitaz
160 label slitaz
161 kernel /boot/bzImage
162 append initrd=/boot/rootfs.gz rw root=/dev/null vga=788
163 implicit 0
164 prompt 1
165 timeout 80
166 F1 help.txt
167 F2 options.txt
168 F3 isolinux.msg
169 F4 display.txt
170 </pre>
171 <p>
172 Example of a label <code>slitazen</code> which you can add to the original
173 to directly configure the language of the system as English and use the UK keyboard:</p>
174 <pre class="script">label slitazen
175 kernel /boot/bzImage
176 append initrd=/boot/rootfs.gz rw root=/dev/null lang=en kmap=en</pre>
177 <p>
178 Once you've finished modifying the configuration file, don't forget to save your changes and
179 <a href="#gen-iso">generate a bootable ISO image</a> with isolinux.
180 </p>
182 <a name="memtest"></a>
183 <h3>Install and use Memtest86</h3>
184 <p>
185 The application memtest86 (92 kB) is a tool for testing your system memory (RAM).
186 Memtest86 performs in depth tests, that if failed, point heavily towards a hardware fault.
187 The tool resides in the <code>boot/</code> directory and can be launched directly by typing
188 <code>memtest</code> at the isolinux boot prompt. Navigate to <code>/home/slitaz/src</code>
189 (if the directory dosen't exist: <code>mkdir -p /home/slitaz/src</code>), download the source
190 and unpack:</p>
191 <pre> # cd /home/slitaz/src
192 # wget http://www.memtest86.com/memtest86-3.3.tar.gz
193 # tar xzf memtest86-3.3.tar.gz
194 </pre>
195 <p>
196 On unpacking the source of the memtest86 package you'll find a
197 <code>README</code> providing information about the tool. Now you can install
198 into the <em>root CD</em> of your ISO hacked. Based on the premise that you'll be
199 working with a <code>/home/slitaz/hacked</code> directory, we will copy the binary
200 you precompiled into the <code>boot/</code> directory of the root of the CD:
201 </p>
202 <pre> # cp memtest86-3.3/precomp.bin \
203 /home/slitaz/hacked/rootcd/boot/memtest
204 </pre>
205 <p>
206 Now that the binary is installed in the <em>root CD</em>, we can just add an entry for memtest86
207 to the isolinux configuration file and <a href="#gen-iso">generate a bootable ISO image</a>.
208 Navigate to <code>/home/slitaz/hacked</code> and edit <code>isolinux.cfg</code> using Leafpad:
209 </p>
210 <pre> # cd /home/slitaz/hacked
211 # leafpad rootcd/boot/isolinux/isolinux.cfg &amp;
212 </pre>
213 <pre class="script">label memtest
214 kernel /boot/memtest
215 </pre>
216 <p>
217 Official website of <a href="http://www.memtest86.com/">Memtest86</a>
218 </p>
220 <a name="rootfs"></a>
221 <h3>Manipulate the Live root system</h3>
222 <p>
223 Changes to the Live root system allow you for example, to add a new user and password, customize graphics or
224 execute commands automatically at boot time. The necessary operations for changing the root file system are:
225 extract the compressed file system <code>rootfs.gz</code>, modify, rebuild the image and generate the ISO.
226 Based on the assumption that you've <a href="#pre">prepared a working directory</a>, we begin by creating
227 a directory to contain the files on the changed system. Since the compressed root file system is named
228 <code>rootfs.gz</code>, we suggest you use <code>rootfs/</code> to extract to. Navigate to the <code>hacked/</code>
229 directory, create the root directory and copy the compressed file system from <code>rootcd/boot/</code>
230 (the root of the cdrom):
231 </p>
232 <pre> # cd /home/slitaz/hacked
233 # mkdir rootfs
234 # cp rootcd/boot/rootfs.gz rootfs
235 </pre>
236 <p>
237 Now that you have the compressed copy of the system, just unpack with <code>cpio</code>.
238 Technically <code>rootfs.gz</code> is a cpio file compressed with lzma or gzip. It's recognized like an
239 <code>initramfs</code> image by the Linux Kernel. At the start up of the machine, the Kernel is loaded into
240 memory, which then decompresses the system image and carries out the initialization scripts. </p>
241 <p>To extract the file system
242 into <code>rootfs/</code> and delete the unarchived copy (remember you can copy &amp; paste):
243 </p>
244 <pre> # cd rootfs
245 # (zcat rootfs.gz 2&gt;/dev/null || lzma d rootfs.gz -so) | cpio -id
246 # rm rootfs rootfs.gz
247 </pre>
248 <p>
249 The system is now ready to be hacked, you can list all files at the root of your system by using the
250 <code>ls</code> command.
251 </p>
252 <h4>Modify a file</h4>
253 <p>
254 To keep things simple and to help you understand the principle, we are going to change a script file in
255 order to execute some commands to be carried out automatically when the CD starts up. The target is
256 <code>etc/init.d/local.sh</code>, just open with your favorite text editor such as Geany:
257 </p>
258 <pre> # geany etc/init.d/local.sh &amp;
259 </pre>
260 <p>
261 We'll add a command displaying a message and letting the system sleep for 4 seconds. Example using local script:
262 </p>
263 <pre class="script">echo "* Hacked SliTaz version booting..."
264 sleep 4
265 </pre>
266 <h4>Rebuilding the image of the compressed system</h4>
267 <p>
268 Once the changes are completed, you can rebuild a compressed image of your system by using
269 <code>find</code> to find the files, <code>cpio</code> for archiving, <code>lzma</code> and
270 <code>gzip </code> for compression and the pipe <code>|</code> to connect
271 everything together. This command must be launched from the root system (<code>rootfs/</code>)
272 and creates a compressed file <code>rootfs.gz</code> in the preceding directory:
273 </p>
274 <pre> # find . -print | cpio -o -H newc | lzma e -si -so &gt; ../rootfs.gz
275 Or with gzip:
276 # find . -print | cpio -o -H newc | gzip -9 &gt; ../rootfs.gz
277 </pre>
278 <p>
279 Finally copy the compressed file system into the <code>boot/</code> directory at the root of the CD and
280 <a href="#gen-iso">generate a bootable ISO image</a> with isolinux. To copy the newly compressed
281 <em>rootfs</em> into the working directory:
282 </p>
283 <pre> # cd ../
284 # cp -a rootfs.gz rootcd/boot
285 </pre>
287 <a name="gen-iso"></a>
288 <h3>Generate a bootable ISO image</h3>
289 <p>
290 The following commands create an image with the
291 <em>boot loader</em> <code>isolinux</code>, using the
292 <code>genisoimage</code> application and a few options. The name of the ISO is
293 specified at the beginning, after the <code>-o</code> option and the root directory
294 (<code>rootcd/</code>) at the end, after the <code>-boot-info-table</code> option:
295 </p>
296 <pre> # genisoimage -R -o slitaz-hacked.iso -b boot/isolinux/isolinux.bin \
297 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
298 -V "SliTaz-Hacked" -input-charset iso8859-1 -boot-info-table rootcd
299 </pre>
300 <p>
301 If you want to check the contents of the ISO before burning, just mount the image in <code>loop</code>
302 and list the files. On SliTaz and most GNU/Linux systems, you can burn images in ISO format with the
303 <code>wodim</code> utility.
304 </p>
305 <h4>Generate a new ISO via a script</h4>
306 <p>
307 If you wish to test out a lot of new possibilities and generate a lot of ISO images, you may want to
308 semi-automate the process via a simple SHell script. This tiny script can be created on the command line
309 or edited graphically, but don't forget to make it executable. You can create the script with <code>cat</code>,
310 note that <code>EOF</code> signifies <em>End Of File</em>. To create the script <code>gen_hacked_iso.sh</code>
311 using two variables to change the name of the ISO image and the path to the root directory of the cdrom:
312 </p>
313 <pre> # cat &gt; gen_hacked_iso.sh &lt;&lt; "EOF"
314 </pre>
315 <pre class="script">#!/bin/sh
316 # Gen a new hacked ISO image.
317 #
318 ISO_NAME="slitaz-hacked.iso"
319 ROOTCD="rootcd"
321 genisoimage -R -o $ISO_NAME -b boot/isolinux/isolinux.bin \
322 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
323 -V "SliTaz-Hacked" -input-charset iso8859-1 -boot-info-table $ROOTCD
325 EOF
326 </pre>
327 <p>
328 To use the script, just make it executable and execute:
329 </p>
330 <pre> # chmod +x gen_hacked_iso.sh
331 # ./gen_hacked_iso.sh
332 </pre>
334 <!-- End of content -->
335 </div>
337 <!-- Footer. -->
338 <div id="footer">
339 <div class="footer-right"></div>
340 <a href="#top">Top of the page</a> |
341 <a href="http://www.slitaz.org/en/doc/handbook/index.html">Table of contents</a>
342 </div>
344 <div id="copy">
345 Copyright © 2008 <a href="http://www.slitaz.org/en/">SliTaz</a> -
346 <a href="http://www.gnu.org/licenses/gpl.html">GNU General Public License</a>;<br />
347 Documentation is under
348 <a href="http://www.gnu.org/copyleft/fdl.html">GNU Free Documentation License</a>
349 and code is <a href="http://validator.w3.org/">valid xHTML 1.0</a>.
350 </div>
352 </body></html>