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

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