website annotate en/doc/handbook/hacking-livecd.html @ rev 344

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