Вы находитесь на странице: 1из 11

SliTaz Scratchbook - Base System

http://www.slitaz.org/en/doc/scratchbook/base-sy...

Table of contents | Base apps

SliTaz Scratchbook

Base System
Build a SliTaz GNU/Linux distro running in RAM and using BusyBox. About. Wget src. Unpack and prepare the Linux kernel. Creation of the Root System, the root le System (rootfs). Congure the box. Generate the initramfs, compressed cpio archive. Construction of the root of the cdrom (rootcd), and the conguration les of Syslinux. Create an ISO image with genisoimage or mkisofs. Burn or test the ISO with Qemu.

About
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. The scripts and conguration les 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. 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.

Wget src
Create a src directory for downloading and compiling: # mkdir -p src # cd src Linux Kernel 2.6.20 (http://www.kernel.org/). # wget ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.20.tar.bz2 Busybox 1.2.2 (http://www.busybox.net/). # wget http://www.busybox.net/downloads/busybox-1.2.2.tar.bz2 Syslinux 3.35 (http://syslinux.zytor.com/). # wget ftp://ftp.kernel.org/pub/linux/boot/syslinux/syslinux-3.35.tar.gz SliTaz tools 1.1. Download SliTaz tools, unpack, save the le in src/ and that's it: # wget http://download.tuxfamily.org/slitaz/sources/tools/slitaz-tools-1.1.tar.gz

1 de 11

07-01-2014 09:47

SliTaz Scratchbook - Base System

http://www.slitaz.org/en/doc/scratchbook/base-sy...

# tar xzf slitaz-tools-1.1.tar.gz

Unpack and prepare the Linux Kernel


We will begin by compiling a Linux kernel, which may take a little time. Linux Kernel Your kernel must support the intramfs lesystem, otherwise the cdrom will not start. You can also install the modules in a directory so as not to touch the host system. The conguration 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 nd in SliTaz tools, Makeles for the various 2.6.xx kernels. A feature of the 2.6 kernels is that if we make menucong, xcong or cong for the rst time, the setup menu is displayed based on the conguration of our current kernel. 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. We start by changing into the sources, make mrproper to put things in order, then we start a conguration interface: gcong, xcong, menucong or oldcong: # tar xjf linux-2.6.20.tar.bz2 # cd linux-2.6.20 # make mrproper # cp ../slitaz-tools-1.1/Makefiles/linux-2.6.20-slitaz.config .config # make oldconfig (# make menuconfig) # make bzImage # make modules # make INSTALL_MOD_PATH=$PWD/_pkg modules_install # cd .. 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.

Creation of the root system (rootfs)


The next step will create a le named 'rootfs' - Root File System, in the working directory SliTaz/: # mkdir ../rootfs Install BusyBox BusyBox (www.busybox.net) is a single executable oering 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). # tar xjf busybox-1.2.2.tar.bz2 Congure and compile, remembering the dumpkmap options, init, etc - you can nd help in the Makele in SliTaz Busybox tools. Make install creates a _install directory in the current directory:

2 de 11

07-01-2014 09:47

SliTaz Scratchbook - Base System

http://www.slitaz.org/en/doc/scratchbook/base-sy...

# cd busybox-1.2.2 # cp ../slitaz-tools-1.1/Makefiles/busybox-1.2.2.config .config # make oldconfig (# make menuconfig) # make # make install # chmod 4755 _install/bin/busybox Copy les compiled by BusyBox in the directory _install to the root le system (rootfs): # cp -a _install/* ../../rootfs 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: # cd ../../rootfs # ls -CF bin/ linuxrc@ sbin/

usr/

# rm linuxrc # ln -s bin/busybox init ldd on BusyBox The ldd command can show any libraries used by a program. Libraries used by Busybox may dier 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. # mkdir lib SliTaz or another: # cp /lib/{libcrypt.so.1,libm.so.6,libc.so.6} lib # cp /lib/ld-linux.so.2 lib Example on Debian Etch: # cp /lib/tls/{libcrypt.so.1,libm.so.6,libc.so.6} lib # cp /lib/ld-linux.so.2 lib Cleanup libraries with strip: # strip -v lib/* Linux tree and conguration 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 le system and its contents, there is a File System Hierarchy Standard available in various formats at www.pathname.com/fhs/.

3 de 11

07-01-2014 09:47

SliTaz Scratchbook - Base System

http://www.slitaz.org/en/doc/scratchbook/base-sy...

You are free to create your own directory tree. In traditional Unix systems, /usr usually contains les from the distribution, /dev contains devices (devices), /etc contains conguration les, /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. # mkdir -p dev etc root home proc media mnt sys tmp var # mkdir -p usr/{lib,local,games,share} \ var/{cache,lib,lock,log,games,run,spool} \ media/{cdrom,flash,usbdisk} Change permissions on the /tmp directory: # chmod 1777 tmp Setting up glibc - note /etc/ld.so.conf and /etc/rpc are not essential for a micro system: # touch etc/ld.so.conf # cp /etc/rpc etc Create the devices in /dev 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: # cp ../src/slitaz-tools-1.1/utils/mktazdevs.sh bin # ./bin/mktazdevs.sh dev or: # cp ../src/busybox-1.2.2/examples/bootfloppy/mkdevs.sh bin # ./bin/mkdevs.sh dev # mkdir -p dev/{pts,input,shm,net,usb} Note that we start mdev-s with the rcS script to create devices dynamically at boot. Support for the resolution of hostnames (DNS) Copy the libraries libnss_* of the host system into our SliTaz system. These libraries are used for name resolution and are cleaned with strip: # cp /lib/{libnss_dns.so.2,libnss_files.so.2} lib # cp /lib/libresolv.so.2 lib # strip -v lib/*.so*

Conguration of your box


Create the necessary les in /etc. For more info, just look at the contents of the les. We start by creating some les relevant to the core operating system. Network Create basic les used to congure the network: # echo "127.0.0.1 localhost" > etc/hosts # echo "localnet 127.0.0.1" > etc/networks # echo "slitaz" > etc/hostname

4 de 11

07-01-2014 09:47

SliTaz Scratchbook - Base System


# echo "order hosts,bind" > etc/host.conf # echo "multi on" >> etc/host.conf /etc/nsswitch.conf Conguration les used to resolve names: # nano etc/nsswitch.conf

http://www.slitaz.org/en/doc/scratchbook/base-sy...

# /etc/nsswitch.conf: GNU Name Service Switch config. # passwd: group: shadow: hosts: networks: files files files files dns files

/etc/securetty /etc/securetty lists terminals that can connect to root: # nano etc/securetty # /etc/securetty: List of terminals on which root is allowed to login. # console # For people with serial port consoles ttyS0 # Standard consoles tty1 tty2 tty3 tty4 tty5 tty6 tty7

/etc/shells /etc/shells, a shells list of valid connections. This le is used by the SSH server (Dropbear): # nano etc/shells # /etc/shells: valid login shells. /bin/sh /bin/ash /bin/hush

5 de 11

07-01-2014 09:47

SliTaz Scratchbook - Base System

http://www.slitaz.org/en/doc/scratchbook/base-sy...

/etc/issue and /etc/motd /etc/issue is displayed at the end of boot and the message of the day is displayed after logging in: # echo "SliTaz GNU/Linux 1.0 Kernel \r \l" > etc/issue # echo "" >> etc/issue # nano etc/motd (- { Get documentation in: /usr/share/doc. //\ Use: 'less' or 'more' to read files, 'su' to be root. } v_/_ SliTaz is distributed in the hope that it will be useful, but with ABSOLUTELY NO WARRANTY.

/etc/busybox.conf The conguration le for BusyBox, it can set duties on BusyBox applications. For more information, you can read the security page in the Handbook. BusyBox.conf le: # nano etc/busybox.conf # /etc/busybox.conf: SliTaz GNU/linux Busybox configuration. # [SUID] # Allow command to be run by anyone. su = ssx root.root passwd = ssx root.root loadkmap = ssx root.root mount = ssx root.root reboot = ssx root.root halt = ssx root.root

For added security, change the permissions on the le: # chmod 600 etc/busybox.conf /etc/inittab Minimal conguration le for init. It helps to have a root console without having to go through the login and a console on tty2. # nano etc/inittab # /etc/inittab: init configuration for SliTaz GNU/Linux.

6 de 11

07-01-2014 09:47

SliTaz Scratchbook - Base System


::sysinit:/etc/init.d/rcS ::respawn:-/bin/sh tty2::askfirst:-/bin/sh ::ctrlaltdel:/bin/umount -a -r ::ctrlaltdel:/sbin/reboot

http://www.slitaz.org/en/doc/scratchbook/base-sy...

You will also nd a wider example of an inittab le in the archive of BusyBox. /etc/prole This le is read at each login and aects all users. We must use the ./prole cong le for each individual user: # nano etc/profile # /etc/profile: system-wide .profile file for the Bourne shells PATH="/usr/sbin:/usr/bin:/sbin:/bin:/usr/games" LD_LIBRARY_PATH="/usr/lib:/lib" if [ "`id -u`" -eq 0 ]; then PS1='\e[1m\u@\h:\w\#\e[m ' else PS1='\e[1m\u@\h:\w\$\e[m ' fi DISPLAY=:0.0 export PATH LD_LIBRARY_PATH PS1 DISPLAY ignoreeof umask 022

Users, groups and passwords Create conguration les of users, groups and passwords in /etc/ {passwd, shadow, group, gshadow}, and adjust permissions: # # # # # # echo "root:x:0:0:root:/root:/bin/sh" > etc/passwd echo "root::13525:0:99999:7:::" > etc/shadow echo "root:x:0:" > etc/group echo "root:*::" > etc/gshadow chmod 640 etc/shadow chmod 640 etc/gshadow

You can add other users, like hacker is used by the LiveCD mode. You can also congure 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 oer all of the options provided by the original program. /etc/fstab or /etc/mtab List lesystems to be mounted: # nano etc/fstab

7 de 11

07-01-2014 09:47

SliTaz Scratchbook - Base System

http://www.slitaz.org/en/doc/scratchbook/base-sy...

# /etc/fstab: information about static file system. # proc /proc proc defaults sysfs /sys sysfs defaults devpts /dev/pts devpts defaults tmpfs /dev/shm tmpfs defaults

0 0 0 0

0 0 0 0

/etc/mtab is used by other mkfs*, for listing the mounted partitions. It needs /proc because there is a link on /proc/mounts: # chroot . /bin/ash /# ln -s /proc/mounts /etc/mtab Keyboard You can create a kmap le specic to your keyboard with the dumpkmap command provided by BusyBox. You can nd some kmap les in SliTaz tools. To create a fr_CH kmap le: /# mkdir /usr/share/kmap /# /bin/busybox dumpkmap > /usr/share/kmap/fr_CH.kmap /# exit Once this is done, you can automatically load your keyboard with loadkmap in a /etc/init.d/rcS script: /usr/share/doc You can also add various documents, such as a SliTaz user manual, which you can download as a tar.gz from the website: # mkdir -p usr/share/doc Installing the udhcpc script 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 conguration le /etc/network.conf: # mkdir usr/share/udhcpc # cp ../src/busybox-1.2.2/examples/udhcp/simple.script \ usr/share/udhcpc/default.script # chmod +x usr/share/udhcpc/default.script /etc/init.d/rcS To nish o this draft, you must create the init script /etc/init.d/rcS to mount the lesystems and run some commands. For more information, you can look at the boot scripts page. You can change the value of the variable KMAP= for the keyboard: # mkdir etc/init.d # nano etc/init.d/rcS

8 de 11

07-01-2014 09:47

SliTaz Scratchbook - Base System

http://www.slitaz.org/en/doc/scratchbook/base-sy...

#! /bin/sh # /etc/init.d/rcS: rcS initial script. # KMAP=fr_CH echo "Processing /etc/init.d/rcS... " /bin/mount proc /bin/mount -a /bin/hostname -F /etc/hostname /sbin/ifconfig lo 127.0.0.1 up /sbin/loadkmap < /usr/share/kmap/$KMAP.kmap

# chmod +x etc/init.d/rcS Note Note that you can still install the Tazpkg package manager (10 kb) that we created, you will nd information to install in the source tarball. You can also install various les from SliTaz tools, such as the licence.

Build an initramfs cpio archive


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 lesystem (also in RAM). To generate an initramfs archive, using the root directory of system les (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. 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 conguration le for isolinux: isolinux.cfg or the menu.lst for GRUB. Generation of the initramfs: # find . -print | cpio -o -H newc | gzip -9 > ../rootfs.gz You should now have a le rootfs.gz about 1 to 2MB in the working directory SliTaz/. 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.

Make rootcd les


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 les: # cd .. # mkdir -p rootcd/boot/isolinux Optionally, you can create some other directories in which to place various data, such as HTML

9 de 11

07-01-2014 09:47

SliTaz Scratchbook - Base System


documents or packages. Copy the kernel

http://www.slitaz.org/en/doc/scratchbook/base-sy...

Just copy the kernel previously compiled to rootcd/boot: # cp src/linux-2.6.20/arch/i386/boot/bzImage rootcd/boot Copy the initramfs into rootcd/boot 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 le system): # cp rootfs.gz rootcd/boot Install the isolinux bootloader The bootloader isolinux - simply copy the isolinux.bin from the source archive of Syslinux: # # # # cd src tar xzf syslinux-3.35.tar.gz cp syslinux-3.35/isolinux.bin ../rootcd/boot/isolinux cd ..

isolinux.cfg - Congure isolinux Here is an example of an isolinux.cfg le that should work well. You can change it if you wish: # nano rootcd/boot/isolinux/isolinux.cfg display display.txt default slitaz label slitaz kernel /boot/bzImage append initrd=/boot/rootfs.gz rw root=/dev/null vga=788 implicit 0 prompt 1 timeout 80

Here are some changes that you might like to make in isolinux.cfg: 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. prompt can be set to 0 to disable the 'boot:' prompt. You can add more lines to view the contents of several text les when the user presses F1, F2, F3, etc. display.txt A small welcome note, powered by isolinux, you can modify this le if you wish: # nano rootcd/boot/isolinux/display.txt

10 de 11

07-01-2014 09:47

SliTaz Scratchbook - Base System

http://www.slitaz.org/en/doc/scratchbook/base-sy...

/*

_\|/_ (o o) +----oOO-{_}-OOo---------------------------------------------------+ ____ _ _ _____ / ___|| (_)_ _|_ _ ____ \___ \| | | | |/ _` |_ / ___) | | | | | (_| |/ / |____/|_|_| |_|\__,_/___| SliTaz GNU/Linux - Temporary Autonomous Zone <ENTER> to boot. */

Create an ISO image with genisoimage or mkisofs


# genisoimage -R -o slitaz-cooking.iso -b boot/isolinux/isolinux.bin \ -c boot/isolinux/boot.cat -no-emul-boot -boot-load-size 4 \ -V "SliTaz" -input-charset iso8859-1 -boot-info-table rootcd For each change in the root of the box, you must create a new ISO image. 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.

Burn or test ISO image with Qemu


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: # wodim -v -speed=24 -data slitaz-cooking.iso Qemu 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: # qemu -cdrom slitaz-cooking.iso Following chapter The next chapter Base applications provides all the instructions to install and congure the basic applications and libraries.

Top of the page | Table of contents Copyright SliTaz - GNU General Public License; Documentation is under GNU Free Documentation License and code is valid xHTML 1.0.

11 de 11

07-01-2014 09:47

Вам также может понравиться