Elj Issue 0: Building Tiny Linux Systems with Busybox - Part Iposted On Tuesday, November 20, 2001 by Bruce Peens
Create a Busybox Single-Floppy Linux System That Includes a kernel, Command-Line Environment and your application.because Linux is small and easy to customize, it '
S a Fine Kernel for Embedded Systems. But What About All of The Other Programs That Are NEEDED for a MINIMUM FUNCTIONAL GNU / Linux SYSTEM?
The minimum system installed by the Debian or Red Hat set-up disks, exclusive of the kernel, is about 40 megabytes in size Busybox replaces the GNU / Linux distribution with a large set of command-line tools -. All that are needed to boot and run a practical Linux system with networking -. in a very small package The typical compiled size of Busybox on the i386 architecture is 256 to 500K total for all tools, depending on the C library used and how it is linked This makes. it easily possible to create a single-floppy Linux systems with a full-featured kernel, a command-line environment, plus your application. I originally wrote Busybox in 1996 for the Debian GNU / Linux setup disk. The goal was to put a complete bootable system on a single floppy that would be both a rescue disk and an installer for the Debian system. A rescue disk is used to repair a Linux system when that system has become unbootable. Thus, a rescue disk needs to be able to boot the System and mount the hard disk file syb stems, and it must provide the command-line tools needed to bring the hard-disk root file system back to a bootable state. The Debian installer at the time I wrote Busybox was a Bourne shell script using dialogto provide a simple graphical interface on an ANSI terminal or the Linux console. Since its creation, many people have added to and maintained Busybox, including members of the Debian Boot-floppies team, the Linux Router Project and Lineo Corporation, where Eric Anderson maintains Busybox today. In the tradition of Free Software Projects, Contributions by Other Authors Now Make Up The Majority of the Project.
Busybox is a part of almost every commercial embedded Linux offerings, and is found in such diverse projects as the Kerbango Internet Radio and the IBM Wristwatch that runs Linux. The name Busybox comes from a child's toy box with a telephone dial and anumber of knobs, buttons and other devices, all of which make noises when operated. This was called a busy boxin the past and is today commonly referred to as an activity center. The Busybox source code can be found at www.busybox.lineo.com. By default , the Makefile provided builds a dynamic-link executable using the default libc library on your system. However, it is easily adapted to cross-compilation, and one can select static linking and other, specialized libc libraries by editing Makefile variables. Before you exercise the Makefile options or embed Busybox, you should build and run it on your host system just so that you can get familiar with it. If you are on a Linux system with the development tools installed, simply typing mak e should build it. Once you build Busybox, it's time to learn about multi-call executable files. This is a trick we use to make Busybox small. There is one executable called busybox that is linked to 107 different names and provides the functions of 107 Different Programs. To Illustrate this, Run The Following Shell Commands: LN Busybox LS
Ln busybox uptime
Ln busybox whoami
Now, Run these Commands:
./ls
./uptime
./whoami
Be sure to type the leading "./" as illustrated above, or you will get the system version of these commands rather than the Busybox version. The lncommand is used to apply another name to a file. It does not copy the file. The ONLY SPACE ITES IN THE IS Necessary To Store A Name In A Directory. You Can Illustration Ls Command: Ls --il Busybox LS Uptime WhoAmi
Be sure to use the -il argument to ls as above. This causes ls to print the inode number, a unique number identifying each file in a file system, along with the usual long listing provided by the -l argument. Linux allows the same File to Have More Than One Name, But A File Only Has One Inode Number. You Should See Something Similar To Listing 1. 1849054 -RWXRWXR-X 4 Bruce Bruce 252956 Sep 7 08:22 BusyBox
1849054 -RWXRWXR-X 4 Bruce Bruce 252956 Sep 7 08:22 LS
1849054 -RWXRWXR-X 4 Bruce Bruce 252956 Sep 7 08:22 Uptime
1849054 -RWXRWXR-X 4 Bruce Bruce 252956 Sep 7 08:22 WhoAmi
Note that this is not a listing of four files. It is a listing of one file with four names, as indicated by the inode number in the first column and the link count in the third column. The link count reports how many names a file . has You'll notice that directories in the common Linux file systems always have a link count of two, because they have two names: ".". and ".." Most files, however, only have one name and their link count will be 1. Because there is a fixed overhead of several kilobytes for every executable program, compressing 107 commands into one file saves a significant amount of space. So, just as we have linked Busybox to four different names, we can link it to 107 . This provides us with a complete, bootable, runnable Linux system in a very small space. Even static-linking with GNU LIBC 6, which has become the standard for Linux systems, Busybox occupies only half a megabgyte. If you do not need The Internationalization of Libc 6, The Old Libc 5 IS Significantly Smalle r. A new library intended for embedded use, uC-Libc (www.opensource.lineo.com), is even smaller, but use caution if your application is proprietary. Like Busybox, uC-Libc is covered by the GNU GPL (General Public license), and can't be Linked to Proprietary Software. Gnu Libc 5 and 6, in Contrast, Are Under the LGPL (The Lesser General Public License) and can be linked to proPrietary Applications. So, Don't UC- Libc for the libc library of a non-free program. At this Writing, UC-Libc Doesn't Quite Provide All of the Functions Required by Busybox, But IT '
s only short a few and these may be provided by the time you read this article. Table 1. Tools Provided On the Debian install floppy, I linked Busybox dynamicaly, and then stripped down the shared libc library so that it only provided the functions necessary to support Busybox and the other executables on the floppy. This was the best way to provide a library shared by several different executables, since the floppy contained other programs besides Busybox. Stripping libc down to only the functions that actually were used cut its size by half. Rather than strip it by hand, I wrote a script that finds all of the library functions referenced by a set of dynamic executables, and then creates a library subset providing those functions (and the functions they depend on). This script has since BEEN Completely Replaced by a Version Written by Marcus Brinkmann, Which Can Be Found In The Debian Boot-Floppies Package Under Scripts / Rootdisk / Mklibs.sh. The Script and How IT Works Are Properly THE subject of another article the size of this one however, until that article is written, one can puzzle out how mklibs.sh works by installing the boot-floppies package on a Debian system, building the floppies and then reading the script carefully Warning.: Mklibs.sh Is Probably the Most Complex Shell Script You Will Ever Examine. So, Now That You Know How To Build And Run Busybox, How do you make a small linux system containing it? you '
ll need a few pieces: a static-linked Busybox executable, a skeleton root file system and / dev directory populated with the proper special files, and a Linux kernel with the features you need plus two features that will be used to boot and run a Small Linux System: Ram Disks and The Compressed Rom File System. [Look for the details on ~ Build A Small Linux System Containing Busybox in A FUTURE ISSUE - ED.] ------------- -------------------------------------------------- ---------------------------------
ELJ Issue 1: Building Tiny Linux Systems with Busybox, Part 2: Building the KernelPosted on Saturday, January 20, 2001 by Bruce Perens Let Bruce help you put the BusyBox to work.For this example I use Linux kernel version 2.2.17 The. 2.4.0-test8 kernel that I tried did not size the RAM disk for the root file system properly, leading to a `` not enough memory '' message at boot time. that bug will probably be repaired in the 2.4 series of kernels by the time you read this. We will build our example to run on an i386-architecture PC-compatible system with PC keyboard and VGA display, booting from a floppy disk and running the root file system entirely in RAM once the system is booted. This example should also boot from IDE disks and from FLASH EEPROM devices that masquerade as IDE disks. It can also be configured to boot from a CD-ROM. Build a bzImage-style kernel with all of the facilities needed for the application, plus these three :
RAM disk support (in the Block Devices menu) Initial RAM disk (initrd) support (also in the Block Devices menu) ROM file system support (in the File Systems menu) Do not use kernel modules, because this example system does not support them. do not put any facilities in the kernel that you do not need, as they will use up space that you need on the floppy disk. A kernel with the facilities you need should be around half a megabyte in size and should fit easily on a floppy along with the ROM root file system. A kernel with many unnecessary bells and whistles will be a megabyte or more and will not leave sufficient room for your ROM root file system. If you're not familiar with building and Installing kernels on a Normal Linux PC, You'll Need to Study Up on That. in Short, i Placed The Kernel Sources In / USR / SRC / Linux and Ran: Xhost Localhostsu
Make Xconfig
Make Dep
Make Bzimage
This created a compiled Linux kernel in / usr / src / linux / arch / i386 / boot / bzImage. Building a Static-Linked Busybox In the busybox source directory, edit the Makefile, changing the variable DOSTATIC from false to true. Then run make That Will Create a static-linked version of busybox. Confirm That it is static-linked by Running this Command: LDD BusyBox
This Should Print Something Like: StaticLinked (ELF)
It's important to get this right; if you install a dynamic-linked version of Busybox, your system will not run because we are not installing the runtime dynamic linker and its libraries on the floppy disk for this example Creating a ROM Root File. System We're going to go through all of the steps for creating a minimal root file system by hand so that you will understand just how little is necessary to boot your system rather than copying all of the files from the root of your Linux distribution and then being afraid to remove anything because you do not know whether it's necessary. you will need to become root (the superuser) to perform the following steps because the mknod command requires superuser privilege. Create the tiny-linux directory and change directory into it : mkdir tiny-linuxcd tiny-linux
Create The Standard Director In It: MKDir dev etc ETC / Init.d Bin Proc MNT TMP VAR VAR / SHM
CHMOD 755. DEV ETC ETC / INIT.D BIN Proc MNT TMP VAR VAR / SHM
Enter the tiny-linux / dev directory: CD DEV
Create The Generic Terminal Devices: MKNOD TTY C 5 0
MKNOD Console C 5 1
CHMOD 666 TTY Console
#Allow anyone to open and write.
Create the Virtual Terminal Device for the VGA Display: MKNOD TTY0 C 4 0
CHMOD 666 TTY0
Create The Ram Disk Device: MKNOD RAM0 B 1 0
CHMOD 600 RAM0
Create the Null Device, Used to Discard Unwanted Output: Mknod Null C 1 3
CHMOD 666 NULL
Change Directory to Tiny-Linux / etc / init.d, where startup scripts are stored: cd ../etc/init.d
Use an editor to create this shell script in tiny-linux / etc / init.d / rcs. It will be executed by system boots: #! / Bin / sh
Mount -a # mount the default file systems exercioned IN / etc / fstab.
Make The Script Executable: CHMOD 744 RCSChange Directory to Tiny-Linux / etc: CD ..
Use an editor to create the file tiny-linux / etc / fstab, Which sign what file systems shop be mounted at boot time: Proc / Proc Proc Defaults 0 0
None / Var / Shm SHM Defaults 0 0
Set the mode of tiny-linx / etc / fstab: chmod 644 fstab
Use an editor to create the file tiny-linux / etc / inittab, which tells / bin / init, the system startup program: :: sysinit: /etc/init.d/rcs
:: askfirst: / bin / sh
The Above Example Runs the script /etc/init.d/rcs at boot time and runs an interactive shell on the console device. Set the modes of tiny-linux / etc / inittab: chmod 644 inittab
That's Everything Necessary To Create Your Root File System, Except for the installation of the program. Change directory to tiny-linux / bin: cd ../bin
Copy Your Static-Linked Version of Busybox from Wherever You Built It Into Tiny-Linux / Bin / Busybox with a Command Similar To this ONE: CP ~ / Busybox-0.46 / Busybox BusyBox
Add Another Command Name Ls to Busybox Using The LN Command: LN Busybox LS
Run LS, AND The Result Should Look Like this: -rwxr-xr-x 2 root root 580424 Sep 12 15:17 busybox
-RWXR-XR-X 2 root root 580424 Sep 12 15:17 ls
Repeat The Above Ln Command for All of these names: [, Ar, BaseName, Cat, Chgrp, Chmod, Chown,
Chroot, CHVT, Clear, CP, CUT, DATE, DC, DD,
DEAALLOCVTDF, DIRNAME, DMESG, DU, DUMPKMAP DUTMP,
Echo, False, FBSET, FDFLUSH, FIND, FREE,
Freeramdisk, Fsck.minix, Grep, Gunzip, Gzip, Halt,
Head, Hostid, Hostname, ID, INIT, INSMOD, KILL,
Killall, Length, Linuxrc, LN, LoadAcm, LoadFont,
Loadkmap, Logger, LOGNAME, LSMOD, MAKEDEVS, MD5SUM,
Mkdir, MKFIFO, MKFS.MINIX, MKNOD, MKSWAP, MKTEMP, MOUNT, MT, MV, NC, NSLOOKUP, PING, POWEROFF,
Printf, PS, PWD, Reboot, RM, RMDIR, RMMOD, SED,
SetKeycoDes, SH, SLEEP, SORT, SWAPOFF, SWAPON, SYN, C
Syslogd, Tail, Tar, Tee, Telnet, Test, Touch, Tri,
True, TTY, Umount, Uname, UNIQ, Update, Uptime,
Usleep, Uudecode, Uuencode, WC, Which, Whoami, Yes,
zcat
? Are you tired yet Well, now is a good time to take a break -. You've finished creating your ROM root file system Generate the ROM Root File System Image You'll need the genromfs program to generate the ROM file system image . If you are using Debian or Red Hat, it's already packaged for you as part of the standard system; you'll just need to run the command to install it If your Linux distribution does not include a prepackaged version, at this writing. . the program can be found at ftp://ibiblio.org/pub/Linux/system/recovery/genromfs-0.3.tar.gz Install the program, change directory to the directory that contains tiny-linux and run these commands: genromfs -d tiny-linux -f fs
THIS CREATES The ROM FILE SYSTEM Image IN THE FILE FS. NOW, Compress The File System Image Using The Gzip Command: Gzip -9 FS
That will create the file fs.gz, which is about half the size of the uncompressed version Build the Floppy We'll need one more program to build our floppy:.. Syslinux This is an i386 bootstrap program that will load a kernel and a compressed root file system image from a floppy, hard disk or CD. Again, it's prepackaged with Debian or Red Hat and can be found, at this writing, at ftp://ibiblio.org/pub/Linux/system/boot/loaders /syslinux-1.48.tar.gz. Create an MS-DOS file system on a floppy by using the Linux mformat command (or by another means). Put the floppy in your drive but do not mount it, and install the syslinux bootstrap with this command: syslinux / dev / fd0That will copy a first-stage bootstrap onto the first block of the floppy and a second-stage bootstrap into the file lDLINUX.SYS in the MS-DOS file system of the floppy I'm assuming. You Have a Directory Called / MNT; Substitution Whate Directory You Usually Use for Mounting Floppy Disks in The Shell Commands Below. Now, IT's Time to Copy Our Kernel And Root File System ONTO THE FLOPPY: MOUNT - MSDOS / DEV / FD0 / MNT
CP fs.gz / mnt
CP / USR / SRC / Linux / Arch / I386 / Boot / BZIMAGE / MNT / Linux
Create the configuration file / mnt/syslinux.cfg with an editor: Timeout 20
DEFAULT Linux
Label Linux
Kernel Linux
Append root = / dev / ram0 initrd = fs.gz
This tells syslinux to wait for two seconds and then boot the default system. You can interrupt the default boot during those two seconds by pressing the shift key. Typing linux at the prompt will do the same thing as the default. The kernel is booted with the arguments root = / dev / ram0 and initrd = fs.gz. These arguments tell the kernel that the root is a RAM disk, and that the RAM disk is loaded from the compressed ROM file system image fs.gz. Although the `` ROM '' root file system is actually in RAM, it will not be writable because the Linux ROM file system driver used in this example is meant to work with real ROMs and thus does not support writing. The Smoke Test Configure an i386 PC to boot from the floppy. Note that this is a setting in the BIOS preferences of most new PCs, and they are often configured to boot from the hard disk without first looking for a bootstrap on the floppy. Place the floppy in the first floppy drive, And restart the system. You Should See Something Like To FOLLOWING: SYSLINUX 1.48 1999-09-26CopyRight (c) 1994-1999 H. Peter Anvin
Loading fs.gz .........
Loading Linux ...............
Uncompressing Linux, OK, Booting The Kernel
Tons of CyberCrud About Every Device Driver and facility in the Kernel Race By Too Rapidly to read ... ramdisk: Compressed Image Found At Block 0.
VFS: MOUNTED ROOT (ROMFS File System)
Please press console.
You'VE DONE IT! Press Enter and You Should See Something Like this: BusyBox V0.46 (2000-09-12-22: 16 0000) Built-in Shell
ENTER 'HELP' for a list of build-in commans.
/ # _
Pop out the floppy disk;... It's not being used any longer The root file system is entirely in RAM You should be able to look around the system and try out commands, but you will not have any writable storage This is the simplest , bootable-system, running busybox that I could think of, and thus I've left out the files in / dev that you'd need to mount writable RAM disks, floppies and hard disks. you now should be able to figure out what Those Devices Are, Add Them and Build A Tiny Linux System Specialized to your application. --------------------------------- -------------------------------------------------- --------
ELJ Issue 2: Building Tiny Linux Systems with BusyBox, Part 3Posted on Tuesday, March 20, 2001 by Bruce Perens Let's get smaller, writable and multiuser A new library, new kernel and other bells and whistles gives us more practice building a highly functional! linux system with a tiny footprint.This is the third article in the series `` Building Tiny linux Systems with BusyBox ''. You'll need to refer to my last article (part 2) on kernel building in the January / February 2001 issue Of Elj if you don't have it a paper copy of the previous ipsue on-line magazine archive at http://embedded.linuxjournal.com/magazine/issue01/4395/ [Part 1 Appeared in the ELJ supplement (November 2000) and is available at http://embedded.linuxjournal.com/magazine/issue00/4335/.] In this article, we'll add writable storage and a multiuser capability to your tiny Linux system, and When We're Done The System Will Be Much Smaller Than When We Started. Time Marches on Progress On Bu syBox and its friends has continued since I wrote the first two articles, largely due to the efforts of Erik Andersen, whose name I so horribly misspelled in the first article. Erik's work on BusyBox and associated programs is supported by Lineo and benefits the entire Embedded Linux community. Erik and his colleagues have continued to contribute to BusyBox using the original license I chose, the GPL, and they have made great contributions to other embedded programs under the GPL and LGPL. In my last article, we used the 2.2 kernel, Due to a bug in 2.4. That Has Now Been Repaired, and Since The 2.4 kernel Has Been released, let '
. S try it syslinux has also been updated to cope with the new kernel Software to Download We'll be using some new software:.. TinyLogin and uClibc, and new versions of BusyBox and syslinux Create a directory where you will work on this example And Change to That Directory. Download the 2.4 kernel source from http://www.kernel.org or any of its mirrors. Download all of the files from fp://ftp.peres.com/elj/3/. Read the README.txt file. Extract the compressed tar archives you've just downloaded. Do not run the shell script as_in_episode_2.sh yet. Build and install syslinux from the downloaded sources, replacing the old version if you've installed it on your system. Build BusyBox from the downloaded sources. Getting Comfortable with the 2.4 Kernel Take the time to install the 2.4 kernel on a BusyBox floppy, just to get comfortable with configuring and running it. We'll use some scripts in the elj-3 directory TO SPARE You Most of the Typing You Did in The Kernel Article. If You Still have the tiny Linux directory that we used in the second article, move it out of the way. We're about to create a new one. Extract the kernel source and configure it as we configured the kernel in my last article under the subhead ` `Build the Kernel '', but add two new features to the kernel if they are not already in it:. the DOS FAT filesystem and the VFAT (Windows 95) filesystem These are in the filesystems menu of the kernel configuration You will need. to use these filesystems on both your development system and your tiny Linux system, so you may end up building and installing two kernels. Remember, you need to keep the kernel on your tiny Linux system small, so it probably won '
. T be the same kernel you run on your development system Go to the BusyBox source directory and edit the Makefile, setting DOSTATIC to true to build a statically linked version of BusyBox Build BusyBox with the make command, and then run:. Make PREFIX = ../tiny-linux install-hardlinksThis will create the tiny Linux directory in the directory above the BusyBox directory and will create the bin, sbin and / usr / sbin directories within the tiny Linux directory. The Makefile will install BusyBox in that directory tree and will create all of the links for the various command names, automatically doing much of the work we performed manually in Part 2. It will not install scripts and files and will not create the / dev directory. One of the scripts you downloaded Will Do That. Change Directory to ../ELJ-3 and Run: SH -X as_in_episode_2.sh ../tiny-linux
That will create the contents of the / dev and / etc directories and anything else you need to make a ROM filesystem. Now, follow the instructions in my January / February 2001 article under the subheadings `` Generate the ROM Root Filesystem Image '' and `` Build the Floppy ''. Finally, boot the floppy to test it. Let's Get Small Another good thing Erik and others have been working on is uClibc, the free embedded C library. I had previously identified this library as being under the GPL license, but I was mistaken. uClibc is under the LGPL and is thus fine for linking with proprietary applications. You can now make BusyBox statically linked to run with uClibc rather than libc5 or libc6. The result is less than 300K in size, and of course, it gets even smaller when the ROM filesystem is compressed. In the uClibc source directory, edit the configuration file and change HAS_MMU to true, HAS_FLOATS to true and KERNEL_SOURCE to the location of your kernel source. Change the definition of the CC To be $ (cross) gcc -os to optimize for smaller code size. if you Version of GCC Does Not Support the --os flag, use -O2 instead. Run make to build the libc.a library. in this Article, Uclib Supports only static linking, but dynamic linking has just started to work. We'll give it a little time to stabilize and will cover it in the next issue. Now, go back to the BusyBox source, edit the Makefile and look for the lines that Say `` to compile vs. an alternative libc, you may need to use / adjust the folload line of source to meet your needs ''
. Below that section are lines that define LIBCDIR, LDFLAGS, LIBRARIES, CROSS_CFLAGS and GCCINCDIR. Most or all of these definitions are commented out. Uncomment the definitions to enable linking with uClibc. Change the definition of LIBCDIR to be the location of your uClibc source . Edit Config.h, and comment out the BB_GETOPT and BB_FEATURE_NFSMOUNT definitions to disable the getopt command and the ability to mount remote NFS filesystems with the mount command. As I write this, there's a bug preventing the BusyBox getopt command from working with uClibc, but that might be fixed by the time you read this article. uClibc does not currently include network support, although I'm sure that someone will add it eventually. Now, rebuild all of BusyBox with the make clean and make commands. On my system , the result is a statically linked executable of 297,620 bytes in size. remove the file tiny-linux / bin / getopt. That file Won't be my Turned Off The Definition of B . B_GETOPT If we do not remove it, we'll end up with two versions of BusyBox and a lot of wasted space Use the instructions above under `` Getting Comfortable with the 2.4 Kernel '', starting with the command:. Make PREFIX = .. / tiny-linux install-hardlinks
This generates another floppy. Boot the floppy to test it. Add Writable Storage Probably the biggest missing feature in your tiny Linux system so far is the lack of writable storage. Let's fix that now. We'll use a VFAT filesystem for the writable storage . This is an extension of the old DOS FAT filesystem to handle long and mixed-case filenames, introduced for Windows 95. Since your floppy already uses a DOS filesystem to hold the kernel and the compressed ROM image file, it's easiest to use VFAT to extend that filesystem for this example. Become root. Create a tiny var directory. This directory tree will hold files that will be writable on your tiny Linux system. You will copy it to the floppy later on, and it will be mounted on / floppy / Var when your tiny linux system boots. Move Your entire Tiny-Var / etc Directory to tiny-var / etc uYING THE COMMAND TINY-VARCREATE TWO Other Directories: tiny-var / shm and tiny-var / home. The first directory is buy by the mount co mmand as a placeholder when providing shared memory, and the second is used to hold home directories for users. Now we'll create symbolic links in tiny Linux to redirect some directories to / var so that you will have access to your writable storage and then REDIRECT / VAR TO / FLOPPY / VAR. We do the symbolic links in two levels here so that the location of all of the write online can be changing by replacing online
Rm -f -r var
Mkdir Floppy
ln -s floppy / var var
Ln -s var / etc ETC
ln -s var / home home
Create the shell script startup.sh as shown Below: #! / Bin / sh
/ BIN / MOUNT -T VFAT / DEV / FD0 / FLOPPY
EXEC / SBIN / INIT
This script will run when the system starts, instead of init, because we'll provide a special command-line argument to the kernel. It will mount the floppy so that the contents of / etc are correct before init starts. Note that exec / sbin / init is different from simply running / sbin / init. The exec command says to replace the shell with the given program, rather than run the program as a subprocess of the shell. Thus, init will run in the same process-ID as the shell, which in this case will be process-ID 1. This is important as the kernel gives process-ID 1 some special properties, and init will not run properly unless it's in process-ID 1. Change the mode of the script so that it is executable: chmod 744 startup.shChange directory up one level (cd ..): Use an editor to modify the file tiny-var / etc / inittab, which tells / bin / init, the system startup program, which processes to START. The entire contents of the file shouth::::::: in
:: askfirst: / bin / sh
:: Ctrlaltdel: / sbin / swapoff -a
:: CtrlalevDel: / bin / umount -a
We're adding lines here to cleanly unmount filesystems at shutdown time, so that the floppy filesystem containing the writable files will be unmounted Tasks on lines that start with :: ctrlaltdel:.. Will be executed just before the system halts We also turn off Any Swap Partitions That Are ActiVated, Just In Case The Live ON A Mounted FileSystem. Create The Special Device File Necessary To Mount The Floppy: MKNOD TINY-Linux / DEV / FD0 B 2 0
CHMOD 644 Tiny-Linux / DEV / FD0
Now, regenerate the ROM filesystem from the tiny Linux directory, using genromfs as before, and compress it using gzip to create a new fs.gz. Mount your floppy with this command: mount -t vfat / dev / fd0 / mntand copy the new Fs.gz to your tiny linux floppy, replacing the old rom filesystem. Copy The Tiny Var Directory Tree To your floppy with the commands: mkdir / mnt / var
Cp -R tiny-var / * / mnt / var
Tell the kernel to run /startup.sh instead of / sbin / init by editing the file / mnt/syslinux.cfg. Change the line That Says append root = / dev / ram0 initrd = fs.gz
To sign append root = / dev / ram0 initrd = fs.gz init = startup.sh
Change Directory to /, and unmount the floppy with this command umount / dev / fd0
You should now be able to boot the floppy, and the directories / var, / etc and / home should be writable. A Multiuser System on One Floppy Your tiny Linux system currently just logs you in as root. Let's make a more versatile system that supports user and group names, the login command, support for logins via the console, a modem or a serial line, and utilities to add and delete users. Let's also make the disk writable, unlike the system we made in the second article. Let's fit all of this, and our BusyBox toolkit of more than 100 general-purpose UNIX commands, on one floppy with room to spare! Go into the TinyLogin source directory and edit the Makefile. We'll be using uClibc to build TinyLogin, so set DOSTATIC to true, comment out the -lcrypt in the definition of LIBRARIES, and set USE_SYSTEM_PWD_GRP to true. Look in the Makefile for the lines that say `` to compile vs. an alternative libc, you may need to use / adjust the following lines To meet your needs. '' Change the Lines Below TH at in the same way that you changed the BusyBox Makefile to enable building with uClibc Warning:. if you ever link TinyLogin with a C library that uses the Name Service Switch (NSS), including GNU LIBC and probably the default libc on your development system , you must set USE_SYSTEM_PWD_GRP to false in the Makefile. that will replace the functions that read the / etc / passwd and / etc / group files, etc., with a version that does not use NSS. Our tiny Linux system does not provide The Files and Other Facilities Needed for nss to work, and thus tinylogin will fail when Built with it. this is the max-offen-repeorted `` bug ''
for TinyLogin, and its author is rather weary of explaining how NSS works to everyone who reports this `` bug ''. Build TinyLogin with the make command. The result should be about 58K in size. Install TinyLogin in your tiny Linux directory using make PREFIX = .. / tiny-linux install-hardlinksChange directory up one level (cd ..). Use an editor to modify the file tiny-var / etc / inittab, which tells / bin / init, the system startup program, which processes To start. the entire contents of the file shop LOKE this: :: sysinit: /etc/init.d/rcs
TTY1 :: askFirst: / bin / login
TTY2 :: askfirst: / bin / login
TTY3 :: askFirst: / bin / login
TTY4 :: askfirst: / bin / login
:: Respawn: / sbin / getty -l ttys0 9600
:: Respaw: / sbin / getty -l ttys1 9600
:: Ctrlaltdel: / sbin / swapoff -a
:: CtrlalevDel: / sbin / umount -a
This configures the system to offer a login on the first four console virtual terminals and on the first two serial ports at 9,600 baud Create the file tiny-var / etc / passwd containing this line:. Root :: 0: 0: Super User: /: / bin / sh
Create tiny-var / etc / group containing this line: root: x: 0:
Create The Terminal Devices: CD Tiny-Linux / Dev
MKNOD TTY0 C 4 0
MKNOD TTY1 C 4 1
MKNOD TTY2 C 4 2
MKNOD TTY3 C 4 3
MKNOD TTY4 C 4 4
MkNod TTYS0 C 4 64
MKNOD TTYS1 C 4 65
CHMOD 600 TTY0 TTY1 TTY2 TTY3 TTY4 TTYS0 TTYS1
Change directory up two levels (cd ../ ..) Regenerate the compressed ROM filesystem, and install it on the floppy, as you have done before Copy the new tiny var to the floppy using this command:.. Cp -R tiny- VAR / * / mNT / VAR
.. Unmount the floppy disk Boot the floppy to test it When the floppy boots, you will get a login prompt Use root as your login -.. There's no password (yet) You'll see some complaints about missing files Now,. you can experiment with the adduser and passwd commands. you should be able to add users and set their passwords. Once you've added some users, you can log them in. to visit one of the other console virtual terminals, type Ctrl Alt F2 through Ctrl Alt F4. Ctrl Alt F1 will get you back to the first virtual console. you should be able to log in a different user to each virtual terminal. If you can, connect two serial terminals, set to 9,600 baud, to the first two serial ports on the system. you should be able to have users on each terminal too. Feel free to add the missing files and test the other programs in the TinyLogin package. to have a fully functional system, you 'll nesed / etc / shadow, / etc / gshadow, / etc / securetty and the utmp file. The location of the utmp file is defined in /usr/include/paths.h on your development system. Security will be nonexistent because the VFAT filesystem does not support the ownership and mode information needed to provide security. You'll have to replace VFAT with another filesystem if you actually need this system to be secure. The USMSDOS filesystem is a good replacement for VFAT. Other filesystems are just a bit more complicated because they are not compatible with the MS-DOS FAT filesystem used by syslinux to load the kernel and the ROM filesystem image. You Could Replace The Fat FileSystem Extilele with The Minix or Ext2 FileSystems, But you '