slitaz-doc-wiki-data view pages/en/scratchbook/base-system.txt @ rev 45

Update pages/en folder.
author Christopher Rogers <slaxemulator@gmail.com>
date Sun May 01 07:41:07 2011 +0000 (2011-05-01)
parents
children 8147f4e1effb
line source
1 ====== Base System ======
3 Build a SliTaz GNU/Linux distro running in RAM and using BusyBox.
6 ===== About =====
8 This document describes the construction of the SliTaz base system and why we use a Linux Kernel, BusyBox and Syslinux to boot the system. SliTaz uses an initramfs archive unpacked in RAM by the kernel at boot. We will create a box to hold a root of 3 to 4MB and use strip on the libraries and binaries to save space.
10 The scripts and configuration files are created with GNU nano, using the keystroke <ctrl+x> to save and exit. But of course you are free to replace with your own text editor.
12 This document is based on a howto found in the archive of BusyBox, which is itself based on a paper presented by Erik Anderson in the Embedded Systems Conference in 2001.
14 ===== Wget src =====
16 Create a src directory for downloading and compiling:
18 # mkdir -p src
19 # cd src
21 * Linux Kernel 2.6.20 (http://www.kernel.org/).
23 # wget ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.20.tar.bz2
25 * Busybox 1.2.2 (http://www.busybox.net/).
27 # wget http://www.busybox.net/downloads/busybox-1.2.2.tar.bz2
29 * Syslinux 3.35 (http://syslinux.zytor.com/).
31 # wget ftp://ftp.kernel.org/pub/linux/boot/syslinux/syslinux-3.35.tar.gz
33 * SliTaz tools 1.1. Download SliTaz tools, unpack, save the file in src/ and that's it:
35 # wget http://download.tuxfamily.org/slitaz/sources/tools/slitaz-tools-1.1.tar.gz
36 # tar xzf slitaz-tools-1.1.tar.gz
38 ===== Unpack and prepare the Linux Kernel =====
40 We will begin by compiling a Linux kernel, which may take a little time.
42 ==== Linux Kernel ====
44 Your kernel must support the intramfs filesystem, otherwise the cdrom will not start. You can also install the modules in a directory so as not to touch the host system. The configuration of the Linux kernel sources is done by "make menuconfig" using ncurses or graphically with "make gconfig" or "make xconfig" using GTK development packages and/or QT respectively. You can find in [[http://doc.slitaz.org/en:cookbook:slitaztools|SliTaz tools]], Makefiles for the various 2.6.xx kernels.
46 A feature of the 2.6 kernels is that if we make menuconfig, xconfig or config for the first time, the setup menu is displayed based on the configuration of our current kernel.
48 The options depend on your needs, you can install module-init-tools to support compressed modules or for a minimal install, you can select only the vital options.
50 We start by changing into the sources, "make mrproper" to put things in order, then we start a configuration interface: gconfig, xconfig, menuconfig or oldconfig:
52 # tar xjf linux-2.6.20.tar.bz2
53 # cd linux-2.6.20
54 # make mrproper
55 # cp ../slitaz-tools-1.1/Makefiles/linux-2.6.20-slitaz.config .config
56 # make oldconfig
57 (# make menuconfig)
58 # make bzImage
59 # make modules
60 # make INSTALL_MOD_PATH=$PWD/_pkg modules_install
61 # cd ..
63 If you want more info on compiling kernels, there are many textbooks. Note that you can install the kernel and after rebooting, you can compile your own kernel following the same instructions.
65 ===== Creation of the root system (rootfs) =====
67 The next step will create a file named 'rootfs' - Root File System, in the working directory SliTaz/:
69 # mkdir ../rootfs
71 ==== Install BusyBox ====
73 BusyBox ([[http://www.busybox.net/|www.busybox.net]]) is a single executable offering versions of the main tools necessary to use a Linux kernel. It is (mainly) intended to be used embedded and can do almost anything. As well as proposing (coreutils) shell commands and a daemons system, it also provides a websever and client/server (DHCP, udhcpc).
75 # tar xjf busybox-1.2.2.tar.bz2
77 Configure and compile, remembering the dumpkmap options, init, etc - you can find help in the Makefile in SliTaz Busybox tools. Make install creates a _install directory in the current directory:
79 # cd busybox-1.2.2
80 # cp ../slitaz-tools-1.1/Makefiles/busybox-1.2.2.config .config
81 # make oldconfig
82 (# make menuconfig)
83 # make
84 # make install
85 # chmod 4755 _install/bin/busybox
87 Copy files compiled by BusyBox in the directory _install to the root file system (rootfs):
89 # cp -a _install/* ../../rootfs
91 The linuxrc link pointing to /bin/busybox, folders /bin, /lib and /sbin were added to the directory /rootfs - you can check this. It may be that the link isn't there if you didn't select the option initrd support in Busybox. We'll delete the linuxrc link and create a link for init that points to /bin/busybox:
93 # cd ../../rootfs
94 # ls -CF
95 bin/ linuxrc@ sbin/ usr/
97 # rm linuxrc
98 # ln -s bin/busybox init
100 ==== ldd on BusyBox ====
102 The ldd command can show any libraries used by a program. Libraries used by Busybox may differ depending on the host system. On Debian for example, copying the libraries in /lib/tls. The following commands are given using 'v' for verbose mode. To eliminate the symbols of executable binaries and shared libraries we can utilize strip. Note you may also use the mklibs or uClibc libraries.
104 # mkdir lib
106 SliTaz or another:
108 # cp /lib/{libcrypt.so.1,libm.so.6,libc.so.6} lib
109 # cp /lib/ld-linux.so.2 lib
111 Example on Debian Etch:
113 # cp /lib/tls/{libcrypt.so.1,libm.so.6,libc.so.6} lib
114 # cp /lib/ld-linux.so.2 lib
116 Cleanup libraries with strip:
118 # strip -v lib/*
120 ==== Linux tree and configuration ====
122 Make some directories for a classic Linux branch SliTaz installation. /dev for devices, /etc, /home, /usr, /proc, /root and co. To learn more about the hierarchy of a file system and its contents, there is a File System Hierarchy Standard available in various formats at [[http://www.pathname.com/fhs/|www.pathname.com/fhs/]].
124 You are free to create your own directory tree. In traditional Unix systems, /usr usually contains files from the distribution, /dev contains devices (devices), /etc contains configuration files, /lib libraries, /home for home users and /var for variable data. Note that we do not create /lib, /bin or /sbin - these are created when BusyBox is installed.
126 # mkdir -p dev etc root home proc media mnt sys tmp var
127 # mkdir -p usr/{lib,local,games,share} \
128 var/{cache,lib,lock,log,games,run,spool} \
129 media/{cdrom,flash,usbdisk}
131 Change permissions on the /tmp directory:
133 # chmod 1777 tmp
135 Setting up glibc - note /etc/ld.so.conf and /etc/rpc are not essential for a micro system:
137 # touch etc/ld.so.conf
138 # cp /etc/rpc etc
140 ==== Create the devices in /dev ====
142 This can be done with the script 'mkdevs.sh' found in BusyBox, or with our script 'mktazdevs.sh' in SliTaz tools. If you want more details, read the scripts. If you used the BusyBox version, we must still create the pts directory:
144 # cp ../src/slitaz-tools-1.1/utils/mktazdevs.sh bin
145 # ./bin/mktazdevs.sh dev
147 or:
149 # cp ../src/busybox-1.2.2/examples/bootfloppy/mkdevs.sh bin
150 # ./bin/mkdevs.sh dev
151 # mkdir -p dev/{pts,input,shm,net,usb}
153 Note that we start mdev-s with the rcS script to create devices dynamically at boot.
155 ==== Support for the resolution of hostnames (DNS) ====
157 Copy the libraries libnss_* of the host system into our SliTaz system. These libraries are used for name resolution and are cleaned with strip:
159 # cp /lib/{libnss_dns.so.2,libnss_files.so.2} lib
160 # cp /lib/libresolv.so.2 lib
161 # strip -v lib/*.so*
163 ===== Configuration of your box =====
165 Create the necessary files in /etc. For more info, just look at the contents of the files. We start by creating some files relevant to the core operating system.
167 ==== Configure network ====
169 Create basic files used to configure the network:
171 # echo "127.0.0.1 localhost" > etc/hosts
172 # echo "localnet 127.0.0.1" > etc/networks
173 # echo "slitaz" > etc/hostname
174 # echo "order hosts,bind" > etc/host.conf
175 # echo "multi on" >> etc/host.conf
177 ==== /etc/nsswitch.conf ====
179 Configuration files used to resolve names:
181 # nano etc/nsswitch.conf
182 <file>
183 # /etc/nsswitch.conf: GNU Name Service Switch config.
184 #
186 passwd: files
187 group: files
188 shadow: files
190 hosts: files dns
191 networks: files
192 </file>
193 ==== /etc/securetty ====
195 /etc/securetty lists terminals that can connect to root:
197 # nano etc/securetty
198 <file>
199 # /etc/securetty: List of terminals on which root is allowed to login.
200 #
201 console
203 # For people with serial port consoles
204 ttyS0
206 # Standard consoles
207 tty1
208 tty2
209 tty3
210 tty4
211 tty5
212 tty6
213 tty7
214 </file>
215 ==== /etc/shells ====
217 /etc/shells, a shells list of valid connections. This file is used by the SSH server (Dropbear):
219 # nano etc/shells
220 <file>
221 # /etc/shells: valid login shells.
222 /bin/sh
223 /bin/ash
224 /bin/hush
225 </file>
226 ==== /etc/issue and /etc/motd ====
228 /etc/issue is displayed at the end of boot and the message of the day is displayed after logging in:
230 # echo "SliTaz GNU/Linux 1.0 Kernel \r \l" > etc/issue
231 # echo "" >> etc/issue
232 # nano etc/motd
233 <file>
234 (°- { Get documentation in: /usr/share/doc.
235 //\ Use: 'less' or 'more' to read files, 'su' to be root. }
236 v_/_
238 SliTaz is distributed in the hope that it will be useful, but
239 with ABSOLUTELY NO WARRANTY.
240 </file>
241 ==== /etc/busybox.conf ====
243 The configuration file for BusyBox, it can set duties on BusyBox applications. For more information, you can read the [[http://doc.slitaz.org/en:handbook:security|security]] page in the Handbook. BusyBox.conf file:
245 # nano etc/busybox.conf
246 <file>
247 # /etc/busybox.conf: SliTaz GNU/linux Busybox configuration.
248 #
250 [SUID]
251 # Allow command to be run by anyone.
252 su = ssx root.root
253 passwd = ssx root.root
254 loadkmap = ssx root.root
255 mount = ssx root.root
256 reboot = ssx root.root
257 halt = ssx root.root
258 </file>
259 For added security, change the permissions on the file:
261 # chmod 600 etc/busybox.conf
263 ==== /etc/inittab ====
265 Minimal configuration file for init. It helps to have a root console without having to go through the login and a console on tty2.
267 # nano etc/inittab
268 <file>
269 # /etc/inittab: init configuration for SliTaz GNU/Linux.
271 ::sysinit:/etc/init.d/rcS
272 ::respawn:-/bin/sh
273 tty2::askfirst:-/bin/sh
274 ::ctrlaltdel:/bin/umount -a -r
275 ::ctrlaltdel:/sbin/reboot
276 </file>
277 You will also find a wider example of an inittab file in the archive of BusyBox.
279 ==== /etc/profile ====
281 This file is read at each login and affects all users. We must use the ./profile config file for each individual user:
283 # nano etc/profile
284 <file>
285 # /etc/profile: system-wide .profile file for the Bourne shells
287 PATH="/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
288 LD_LIBRARY_PATH="/usr/lib:/lib"
290 if [ "`id -u`" -eq 0 ]; then
291 PS1='\e[1m\u@\h:\w\#\e[m '
292 else
293 PS1='\e[1m\u@\h:\w\$\e[m '
294 fi
296 DISPLAY=:0.0
298 export PATH LD_LIBRARY_PATH PS1 DISPLAY ignoreeof
299 umask 022
300 </file>
301 ==== Users, groups and passwords ====
303 Create configuration files of users, groups and passwords in /etc/ {passwd, shadow, group, gshadow}, and adjust permissions:
305 # echo "root:x:0:0:root:/root:/bin/sh" > etc/passwd
306 # echo "root::13525:0:99999:7:::" > etc/shadow
307 # echo "root:x:0:" > etc/group
308 # echo "root:*::" > etc/gshadow
309 # chmod 640 etc/shadow
310 # chmod 640 etc/gshadow
312 You can add other users, like hacker is used by the LiveCD mode. You can also configure a password for the root user with the "passwd" command. To add an existing user to an existing group, you must edit /etc/group and /etc/gshadow because the applet "adduser" provided by BusyBox doesn't offer all of the options provided by the original program.
314 ==== /etc/fstab or /etc/mtab ====
316 List filesystems to be mounted:
318 # nano etc/fstab
319 <file>
320 # /etc/fstab: information about static file system.
321 #
322 proc /proc proc defaults 0 0
323 sysfs /sys sysfs defaults 0 0
324 devpts /dev/pts devpts defaults 0 0
325 tmpfs /dev/shm tmpfs defaults 0 0
326 </file>
327 /etc/mtab is used by other mkfs*, for listing the mounted partitions. It needs /proc because there is a link on /proc/mounts:
329 # chroot . /bin/ash
330 /# ln -s /proc/mounts /etc/mtab
332 ==== Keyboard ====
334 You can create a kmap file specific to your keyboard with the dumpkmap command provided by BusyBox. You can find some kmap files in SliTaz tools. To create a fr_CH kmap file:
336 /# mkdir /usr/share/kmap
337 /# /bin/busybox dumpkmap > /usr/share/kmap/fr_CH.kmap
338 /# exit
340 Once this is done, you can automatically load your keyboard with loadkmap in a /etc/init.d/rcS script:
342 ==== /usr/share/doc ====
344 You can also add various documents, such as a SliTaz user manual, which you can download as a tar.gz from the website:
346 # mkdir -p usr/share/doc
348 ==== Installing the udhcpc script ====
350 Udhcpc DHCP client supplied by Busybox is fast and stable, but is developed independently. Web site: http://udhcp.busybox.net/. You can use the default script found in the archive of BusyBox. This script goes into /usr/share/udhcpc/default.script, but this can be changed via the command line. On SliTaz, the client is started at boot by the script /etc/init.d/network.sh via the configuration file /etc/network.conf:
352 # mkdir usr/share/udhcpc
353 # cp ../src/busybox-1.2.2/examples/udhcp/simple.script \
354 usr/share/udhcpc/default.script
355 # chmod +x usr/share/udhcpc/default.script
357 ==== /etc/init.d/rcS ====
359 To finish off this draft, you must create the init script /etc/init.d/rcS to mount the filesystems and run some commands. For more information, you can look at the [[http://doc.slitaz.org/en:cookbook:bootscripts|boot scripts]] page. You can change the value of the variable KMAP= for the keyboard:
361 # mkdir etc/init.d
362 # nano etc/init.d/rcS
363 <file>
364 #! /bin/sh
365 # /etc/init.d/rcS: rcS initial script.
366 #
368 KMAP=fr_CH
370 echo "Processing /etc/init.d/rcS... "
372 /bin/mount proc
373 /bin/mount -a
374 /bin/hostname -F /etc/hostname
375 /sbin/ifconfig lo 127.0.0.1 up
376 /sbin/loadkmap < /usr/share/kmap/$KMAP.kmap
378 # chmod +x etc/init.d/rcS
379 </file>
380 ==== Note ====
382 Note that you can still install the Tazpkg package manager (10 kb) that we created, you will find information to install in the source tarball. You can also install various files from SliTaz tools, such as the licence.
384 ===== Build an initramfs cpio archive =====
386 The initramfs is a "cpio" archive generated from the root of the system, it is decompressed in RAM by the Linux kernel at boot to create the filesystem (also in RAM). To generate an initramfs archive, using the root directory of system files (rootfs), we facilitate a search with "find" and add some pipes "|". Then we create a cpio archive using "gzip" which we put in the working directory.
388 The SliTaz initramfs **rootfs.gz** is the root system, but with a ".gz" extension. If you want to change the name, you need to edit the configuration file for isolinux: isolinux.cfg or the menu.lst for GRUB.
390 Generation of the initramfs:
392 # find . -print | cpio -o -H newc | gzip -9 > ../rootfs.gz
394 You should now have a file rootfs.gz about 1 to 2MB in the working directory SliTaz/.
396 For a new image, when making changes in rootfs, simply copy the new rootfs.gz archive to rootcd/boot and create a new image with "genisoimage" or "mkisofs". For this you can also use **mktaziso** within SliTaz tools. This script will check if the directories are present, create a new compressed cpio archive and generate a new bootable ISO image.
398 ===== Make rootcd files =====
400 The following steps will help you create the root of the bootable CD-ROM. We begin by creating the rootcd, boot and isolinux directories for the cd-rom files:
402 # cd ..
403 # mkdir -p rootcd/boot/isolinux
405 Optionally, you can create some other directories in which to place various data, such as HTML documents or packages.
407 ==== Copy the kernel ====
409 Just copy the kernel previously compiled to rootcd/boot:
411 # cp src/linux-2.6.20/arch/i386/boot/bzImage rootcd/boot
413 ==== Copy the initramfs into rootcd/boot ====
415 Copy the rootfs.gz to rootcd/boot. We must not forget to generate a new initramfs archive for any changes made to the rootfs (root file system):
417 # cp rootfs.gz rootcd/boot
419 ==== Install the isolinux bootloader ====
421 The bootloader isolinux - simply copy the isolinux.bin from the source archive of Syslinux:
423 # cd src
424 # tar xzf syslinux-3.35.tar.gz
425 # cp syslinux-3.35/isolinux.bin ../rootcd/boot/isolinux
426 # cd ..
428 ==== isolinux.cfg - Configure isolinux ====
430 Here is an example of an isolinux.cfg file that should work well. You can change it if you wish:
432 # nano rootcd/boot/isolinux/isolinux.cfg
433 <file>
434 display display.txt
435 default slitaz
436 label slitaz
437 kernel /boot/bzImage
438 append initrd=/boot/rootfs.gz rw root=/dev/null vga=788
439 implicit 0
440 prompt 1
441 timeout 80
442 </file>
443 Here are some changes that you might like to make in isolinux.cfg:
445 * The timeout value is the number of seconds to wait before booting You can make it 0 or delete the line to start instantly, or choose to wait as long as 10s.
446 * prompt can be set to 0 to disable the 'boot:' prompt.
447 * You can add more lines to view the contents of several text files when the user presses F1, F2, F3, etc.
449 ==== display.txt ====
451 A small welcome note, powered by isolinux, you can modify this file if you wish:
453 # nano rootcd/boot/isolinux/display.txt
454 <file>
455 /* _\|/_
456 (o o)
457 +----oOO-{_}-OOo---------------------------------------------------+
458 ____ _ _ _____
459 / ___|| (_)_ _|_ _ ____
460 \___ \| | | | |/ _` |_ /
461 ___) | | | | | (_| |/ /
462 |____/|_|_| |_|\__,_/___|
464 SliTaz GNU/Linux - Temporary Autonomous Zone
466 <ENTER> to boot.
468 */
469 </file>
470 ===== Create an ISO image with genisoimage or mkisofs =====
472 # genisoimage -R -o slitaz-cooking.iso -b boot/isolinux/isolinux.bin \
473 -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \
474 -V "SliTaz" -input-charset iso8859-1 -boot-info-table rootcd
476 For each change in the root of the box, you must create a new ISO image.
478 You can create a small script that will generate a new compressed cpio archive and a new image, or use mktaziso within SliTaz tools. Note that you can also use GRUB to boot the box.
480 ===== Burn or test ISO image with Qemu =====
482 You can burn the ISO image with Graveman, k3b or wodim and boot it. Simple burning command using wodim (also valid for cdrecord), with a 2.6.XX. kernel:
484 # wodim -v -speed=24 -data slitaz-cooking.iso
486 ==== Qemu ====
488 Note that you can test the ISO image with the software emulator Qemu (On Debian # aptitude install qemu). To emulate the newly created ISO image, simply type:
490 # qemu -cdrom slitaz-cooking.iso
492 ==== Following chapter ====
494 The next chapter [[base-apps|Base applications]] provides all the instructions to install and configure the basic applications and libraries.