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

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