General:
External:
Linux Filesystem and Recovery Diskettes
Here is a reasonable minimum set of directories for your root filesystem:
/dev -- Devices, required to perform I/O
/proc -- Directory stub required by the proc filesystem
/etc -- System configuration files
/sbin -- Critical system binaries
/bin -- Basic binaries considered part of the system
/lib -- Shared libraries to provide run-time support
/mnt -- A mount point for maintenance on other disks
/usr -- Additional utilities and applications
To create the special files in /dev:
Use mknod
There is a shortcut, though -- copy your existing /dev directory contents,
and delete the ones you don't want. The only requirement is that you copy
the device special files using -R option. This will copy the directory
without attempting to copy the contents of the files. Be sure to use an
upper case R. If you use the lower case switch -r, you will probably end
up copying the entire contents of all of your hard disks:
cp -dpR /dev /mnt
assuming that the diskette is mounted at /mnt. The dp switches ensure that
symbolic links are copied as links, rather than using the target file, and
that the original file attributes are preserved, thus preserving ownership
information.
#/etc
This directory must contain a number of configuration files. On most
systems, these can be divided into three groups:
1. Required at all times, e.g. rc, fstab, passwd.
2. May be required, but no-one is too sure.
Files which are not essential can be identified with the command:
ls -ltru
This lists files in reverse order of date last accessed, so if any files
are not being accessed, they can be omitted from a root diskette.
#/etc/rc.d/rc:
#!/bin/sh
/bin/mount -av
/bin/hostname spcsys.com
#/etc/fstab:
/dev/ram0 / ext2 defaults
/dev/fd0 / ext2 defaults
/proc /proc proc defaults
#/etc/inittab:
id:2:initdefault:
si::sysinit:/etc/rc
1:2345:respawn:/sbin/getty 9600 tty1
2:23:respawn:/sbin/getty 9600 tty2
#/bin and /sbin
The /bin directory is a convenient place for extra utilities you need to
perform basic operations, utilities such as ls, mv, cat and dd.
Make sure you include the following programs:
init, getty or equivalent, login, mount, some shell capable of
running your rc scripts, a link from sh to the shell.
#/lib
In /lib you place necessary shared libraries and loaders.
If the necessary libraries are not found in your /lib directory then
the system will be unable to boot. If you're lucky you may see an error
message telling you why.
Nearly every program requires at least the libc library, libc.so.N,
where N is the current version number. Check your /lib directory.
libc.so.N is usually a symlink to a filename with a complete version
number:
% ls -l /lib/libc*
-rwxr-xr-x 1 root root 4016683 Apr 16 18:48 libc-2.1.1.so*
lrwxrwxrwx 1 root root 13 Apr 10 12:25 libc.so.6 -> libc-2.1.1.so*
In this case, you want libc-2.1.1.so. To find other libraries you should
go through all the binaries you plan to include and check their
dependencies with the ldd command. For example:
% ldd /sbin/mke2fs
libext2fs.so.2 => /lib/libext2fs.so.2 (0x40014000)
libcom_err.so.2 => /lib/libcom_err.so.2 (0x40026000)
libuuid.so.1 => /lib/libuuid.so.1 (0x40028000)
libc.so.6 => /lib/libc.so.6 (0x4002c000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
Each file on the right-hand side is required.
The file may be a symbolic link.
In /lib you must also include a loader for the libraries. The loader will
be either ld.so (for a.out libraries) or ld-linux.so (for ELF libraries).
Newer versions of ldd tell you exactly which loader is needed, as in the
example above, but older versions may not. If you're unsure which you need,
run the file command on the library. For example:
% file/lib/libc.so.4.7.2 /lib/libc.so.5.4.33 /lib/libc-2.1.1.so
/lib/libc.so.4.7.2: Linux/i386 demand-paged executable (QMAGIC), stripped
/lib/libc.so.5.4.33: ELF 32-bit LSB shared object, Intel 80386, version 1, stripped
/lib/libc-2.1.1.so: ELF 32-bit LSB shared object, Intel 80386, version 1, not stripped
The QMAGIC indicates that 4.7.2 is for a.out libraries, and ELF
indicates that 5.4.33 and 2.1.1 are for ELF.
Copy the specific loader(s) you need to the root filesystem you're building.
Libraries and loaders should be checked carefully against the included
binaries. If the kernel cannot load a necessary library, the kernel will
usually hang with no error message.
# Final:
Some system programs, such as login, complain if the file /var/run/utmp
and the directory /var/log do not exist. So:
mkdir -p /mnt/var/{log,run}
touch /mnt/var/run/utmp
Finally, after you have set up all the libraries you need, run ldconfig
to remake /etc/ld.so.cache on the root filesystem. The cache tells the
loader where to find the libraries. To remake ld.so.cache, issue the
following commands:
chdir /mnt; chroot /mnt /sbin/ldconfig
The chroot is necessary because ldconfig always remakes the cache for the
root filesystem.
Once you have finished constructing the root filesystem, unmount it, copy
it to a file and compress it:
umount /mnt
dd if=DEVICE bs=1k | gzip -v9 > rootfs.gz