2. Sys Build II

This is the second sys-build section. It will be reorganised with the next restructure. That will be when the screens based browser appears, which will be some time.

2.1 DOS format needs fdisk info
2.2 Formatting The Disks ..
2.3 mke2fs - make ext2 file-system on partition
2.4 mkswap - prepare swap partition
2.5 How to boot with LOADLIN.EXE
2.6 Other BOOT options
2.7 Mounting disks
2.8 /sbin/e2fsck
2.9 /etc/inittab
2.10 /etc/fstab
2.11 /etc/exports
2.12 /etc/profile
2.13 ln -s ttyS0 mouse
2.14 ln -s cua2 modem
2.15 ln -s hdd cdrom


DOS format needs fdisk info

Relevent to DOS users: Linux-only disks can forget this.

To prevent DOS complaining, the fdisk info for a DOS partition, must be written into the DOS filesystem, as part of the format headers. Don't mess with a running system, but if initialising a new disk, you might have to null out a block using dd as described in the debian README.fdisk document. Basically, it says create the dos partition using the DOS fdisk, or at least try the null block trick and then do DOS fdisk. Test it early, so that you don't have to delete that primary partition inorder to add it again. You will have to run DOS format to create the DOS filesystem, to be sure that DOS will find what it expects later.


Formatting The Disks ..

DOS is fragile

DOS has been 'dog-trained' to be hostile to foreign OS's. It does conform to rules, but it prefers to create it's own partitions. Let it.

On a fresh disk, layout the table how you choose, using linux fdisk, then delete the (allocated but not yet used) DOS partition, and let DOS fdisk + DOS format create it for itself. DOS will write it's own markers in it's own headers. Test this first because it might not work.

For more information refer to the README.fdisk document, and then the LILO documents.

ASIDE: util-linux-2.6.lsm is also a good place to look if you want to "roll-your-own" distribution. It contains other essential packages, as well as fdisk.


You need a Linux partition, a swap partition, and probably a 10 MB boot partition (see the section on 1024 cylinders).

fdisk Splits the disk into (upto) four main partitions.

One of the 4 partitions can be an "extended" partition, divided into sub-partitions. NB "ext2" also uses the word "extended" - a coincidence. As long as DOS doesn't complain you will be OK, Linux is very flexible. That leaves you with 3 primary partitions and maybe 4 logical partitions in the extended partition.

The partition that is the extended partition, eg /dev/hda3, is a container for several logical partitions, and cannot itself be used. You can only have one such container per disk. the logical partitions inside get numbered /dev/hda5,6,7 ...

Limit yourself to 8 partitions (total, including the container), you may or may-not have to make the end of the disk a plain partition. I had problems with an extended partition at the end, but maybe that was the nineth, one day I'll try again.

If your disk already has data on it, save the partition table NOW. If fdisk messes up, you can immediately replace it, and be happy. If you didn't write it down, or copy it to floppy, you will never guess the exact sector boundries you used the first time!

dd if = /dev/hda of=/dos/a/bootsect.hda bs=512 count=1

+------------------------+  ^  ^
| boot code              |  |  |
|                        | 446 |
|                        |  |  |
|------------------------|  v  |
| fdisk table            |    512
|                        |     |
|------------------------|     |
| Magic number (0xAA55)  |     |
+------------------------+     v

Having saved the fdisk info, to a DOS floppy, you may later try to restore it. The trouble is, the boot code also gets saved and loaded, along with the fdisk info, but you might want to restore the boot code, but not the fdisk table, or restore the fdisk table and not the boot code!

To reload just the boot code without overwriting the (carefully edited) fdisk table, use the following command.

To restore the fdisk table only, you have to do a "towers of hanoi" where you save the boot code, restore the entire sector, then restore the saved boot code.

dd if=/dos/a/bootsect.hda of=/dev/hda bs=446 count=1

The FDISK information is written on sector 0, and no-where else on the disk. If you accidentally get it wrong, you can run fdisk again to redraw the partition boundary lines and get your original data back - PROVIDED YOU KNOW WHAT THE ORIGINAL VALUES WERE and HAVE NOT MODIFIED THE DISK IN ANY OTHER WAY.

Use fdisk to create your root, swap, dos and maybe boot partitions. Check that your system will boot from files below 1024 cylinders. Put the correct tag on the swap partition.

If you don't create a swap partition, you can create swap files. If you don't create either, your system will have less spare memory, and run slower.

The 4 partitions can have any numbers you choose, not just the sequence on the disk. That is how I created hda4 to boot from, which appears before hda1 (the main partition), but it doesn't matter as long as you use the correct number in the right places, and boot from below 1024.

There are two versions of fdisk (as well as the DOS versions). fdisk(8) and cfdisk(8). cfdisk is supposed to be more friendly (curses menu version), but it can actually be more confusing. The real difficulty with fdisk is knowing how big to make each partition (etc), not with the commands that make fdisk do it! Use fdisk, and accept that it is a boring TTY-text application with simple commands (new partition, delete partition, tag partition, x-tended commands / expert mode).

fdisk -l # lists all partitions on all drives.

Each partition has a partition TAG that tells Linux (and DOS) which operating system this partition is intended for, and whether it is a SWAP partition or a file system. fdisk has a list of tags to help you.

See the next chapter for more details on fdisk.


mke2fs - make ext2 file-system on partition

Creating the partitions, with fdisk(8), creates raw partitions areas. The information on them is random magnetic junk. A logically structured index of files needs to be written using the mke2fs(8) command. (Make file system). DOS uses the FORMAT command.

Linux understands a number of different fs layouts, the one used for hard disks is the ext2 fs, (they extending the Minix fs for bigger disks producing ext, then they extended the specification to a second version - ext2, you NEVER want plain ext).

The partition device name is the partition number [1-4 on top of the disk device, eg /dev/hda4 on /dev/hda. The mke2fs program is intelligent enough to get the disk size correct, but proceeds IMMEDIATELY to initialise that partition, erasing any files that used to be there (note that the file data blocks are not actually overwritten, but the index is).

The 'superblock' is the root of the index, and you get a few 'backup' copies just in-case. The 'fsck' program knows where to find them. The inode table is the index of the disk. Linux-ext2 actually splits the partition into several zones, each with it's own inode tables - but you don't need to know that.

mke2fs /dev/hde3	# CHANGE THIS OR DIE

mke2fs won't ask for confirmation. Its effect is immediate (and devastating). Check your typing. It operates with extreme prejudice.


mkswap - prepare swap partition

Swap space is used as a virtual extension of memory. When running, pages of 4K bytes memory are swapped in and out of RAM to/from disk as needed (or not recently needed). If you don't have a swap partition you can use a plain file. See mkswap(8) and mkswap(8)

The swap partition will get overwritten (destroyed slowly) if it isn't really a swap partition. To prevent this, the swapon command checks for the 'signature' left by mkswap. The mkswap command is run once during installation, other than the device being CURRENTLY mounted, or nonexistent, mkswap won't check much. You can also create swap files, see the later secton.

mkswap /dev/hda5	# change this

free			# check that the swap section isn't yet used
swapon /dev/hda5	# if not in /etc/fstab
swapon -a		# loads those listed in fstab
free			# see the difference

Remember to edit /etc/fstab, otherwise the swap sections won't be loaded when you reboot. eg X11 will freeze mysteriously and totally. See fstab(5)

Remember that the /etc/fstab on the hard disk is not the same as the /etc/fstab on the RAM-disk!

You don't have to have any swap space, but you won't get any virtual memory. When real memory runs out, malloc and sbrk will return FAIL, and your applications will print error messages and fail gracefully.

Unfortunately XF86_SVGA the X11 server, does not program defensively against running out of memory, and will simply crash your session or entire machine. (Try connecting with TCP/IP or a second VDU).

(After some USENET discussions, it seems that there are other problems that make it difficult to correctly predict when FREE space is completely exhausted, but a program could still pre-reserve memory, and fail gracefully when it runs out. Personally, I hope things will get better.)

Without swap space, unused data pages remain in chip memory, reducing space to hold program pages. So program pages get dropped and reloaded more often, slowing down your system.

If your system seems slow, use the free(1) command to see how much free space you have, and how much swap space is available. If that seems ok, use the top(1) command to see if any processes are consuming 'too-much' CPU time (locked in a loop), and kill(1) them.


How to boot with LOADLIN.EXE

If you find yourself booting from the floppies a lot, you can save yourself some time by booting DOS and then use LOADLIN.EXE to boot Linux.

You can specify all those parameters that LILO allows, but they can appear one-on-a-line, (which is much neater than /etc/lilo.conf). Copy all the files onto c:/boot1 and create two files:


loadlin @kestrel.txt


This is a DOS text file, ie CR-LF, not just LF. Calling it .txt makes it easy to access. Commented-out lines are OK, as are multiple driver config lines

c:/boot/2-0-7.knl	# the kernel file on C:
# c:/boot/vmlinuz	# a different kernel
# root=/dev/fd0		# floppy disk
# ramdisk=1440		# loaded into RAM
root=/dev/sda4		# the root partition MUST be specified
sbpcd=0x320,LaserMate	# saves ages when groping
# aha1542=0x330,11,4,5	# sample parameters for a card
# buslogic=0		# bug # cannot diable !!

If you have DOS 6.0, you can edit config.sys to present you a menu of different boot profiles, including a range of Linux options. I don't have DOS 6. If you have System Commander or other, follow it's documentation. (I use LILO on the MBR and occasionally DOS 5 + WIN.311).


Other BOOT options

You have several BOOT options:

If something goes wrong, you can always re-create the BOOT+ROOT pair of diskettes from your CDROM, and repair your installation from there.

If you don't install LILO, or setup loadlin, you can create a BOOT-DISK (Slackware Setup will prompt you to do this). This is a special diskette with your selected kernel on it, along with the LILO loader, so that you can provide extra options.

Extra options to use when you boot, include root=/dev/hda1, which tells the kernel which partition to mount as the root disk, when looking for /etc and the rest. You can also provide other device driver control options such as hdc=cdrom. For more information, see the BOOT-HOWTO.

You can use a Slackware boot disk, to kick start a RedHat system, as long as the kernel versions make sense (etc).


Mounting disks

Creating disk file-systems does not bring them online. /etc/fstab makes it a lot easier, but you can issue the commands manually (as root), or even from a program.

mount				# see what was mounted before
mkdir /mnt			# usually already exists
mount -t ext2 /dev/hda4 /mnt	# bring the disk online 
mount				# see that is is mounted
df				# shows disk free space
umount /mnt			# 

other similar commands (examples). Note: for no real reason, boot disks tend to use /var/adm/mnt You don't have to.

mkdir -p /dos/c
mount -t msdos /dev/hda1 /dos/c

mkdir /cdrom
mount -t is09660 /dev/hdd /cdrom

mkdir -p /sparrow/cdrom
mount -t nfs sparrow:/cdrom /sparrow/cdrom # requires working TCP/IP

mount -t ext2 /dev/hda5 /mnt		# possibly a root disk
mount -t ext2 /dev/hda6 /mnt/boot	# boot partition

The /etc/fstab on the hard disk is not the fstab on the RAM-disk. This can cause confusion that wastes a lot of time! Slackware setup will help you setup a working /etc/fstab on your hard disk. Then you can use much simpler commands like:

mount /cdrom
mount /sparrow/cdrom
mount /hdc2		# I choose dir names similar to the device 

See the man pages for mount(8) and umount(8)



If an ext2 partition isn't umount'ed cleanly (eg you pressed reset mid-flight), you won't be able to mount the partition r/w until e2fsck(8) has had a look at it.

/sbin/e2fsck /dev/hda1

You should be able to mount the partition readonly, either by booting in single user mode, or from the BOOT+ROOT pair, using

mount -r -t ext2 /dev/hda1 /mnt

This is how the boot process runs e2fsck from the disk that is being checked! A risky thing to do, but for a list of reasons, it usually works! This is also an option if the disk or the interface is faulty, but if the card is 'badly seated' you may cause extensive damage, and it would be better to check the disk elsewhere.

If you did boot single user mode, and had to fsck the disk from itself, you can either reboot, or remount the partition (rw) with the command

mount -n -o remount,rw /



Normally when the system boots, you select the disk partition to boot as the 'root' partition '/' by configuring the LILO parameters (or LOADLIN.EXE). The kernel mounts the root partition read-only (initially) to prevent a sick system trashing the disk.

After loading and initialising, the kernel starts the one program it knows about: /etc/init, except nowadays it's /sbin/init. This must be on the root partition! /sbin/init then goes about it's job of bringing the system up. This includes mounting all the disks, and remounting the root partition (rw). /sbin/init is a program and not part of the kernel. It reads the parameters from the kernel and /etc/inittab, and decides what to do - ie run /etc/rc.d/rc.S, then /etc/rc.d/rc.M and the getty's. The files in /etc/rc.d are all shell scripts.

rc.S runs fsck on the root disk and remounts it writable (rw), and fsck's the other disks and mounts them - according to /etc/fstab. It also runs the swapon -a command, which reads /etc/fstab.

You do not need to edit /etc/inittab, except when you want to tell /etc/init to start a 'getty' on a serial line, or boot into a different run level (eg xdm).

If you need to add /sbin/kerneld to your rc.S file, add it before it is needed, eg just after the fsck part.



This file tells Unix what disk partitions to mount, and what partitions are easily available later. This is an example, you MUST tailor this to your system! You can use comment lines.

# ROOT #
/dev/hda1       /            ext2        defaults   1   1
# STD #
none            /proc        proc        defaults   1   0
/dev/cdrom	/cdrom	     iso9660	 defaults,noauto,ro,user 2 0
/dev/hda4       /hda4        ext2        defaults   1   2
/dev/hdb2       /hdb2        ext2        defaults   1   2
/dev/hdc2       /hdc2        ext2        defaults   1   2
# SWAP #
/dev/hdb1        swap        swap        defaults	0
/dev/hdc1        swap        swap        defaults	0
# NFS #
pigeon:/cdrom	/pigeon/cdrom nfs	 defaults,timeo=14,intr,noauto 0 0
crow:/		/crow	     nfs	timeo=14,intr,noauto
# DOS #
/dev/fd0    /dos/a   msdos defaults,noauto,noexec,user
/dev/hdb3   /dos/c   msdos defaults,umask=001,uid=1016,noexec	0 2
/dev/hdb3   /dos/x  umsdos defaults,umask=001,uid=1016,noexec,noauto	0 2

The root partition MUST have the correct /dev/hda1 device name. It will still work with the wrong value in /etc/fstab, because the actual value used is determined by LILO /root=/dev/hda1, but everyone gets confused if it's wrong, so make sure they agree.

/dev/hda1       /            ext2        defaults   1   1

The root partition MUST be first. Any lines before it won't get mounted properly (a bug maybe).

none            /proc        proc        defaults   1   0
/dev/cdrom	/cdrom	     iso9660	 defaults,noauto,ro,user 2 0

The standard entries are /proc and /cdrom. Note that /dev/cdrom is probably a symbolic link to /dev/hdd or something. You shouldn't need to touch /etc/fstab when you change your cdrom type. unless you're adding several online drives, or a jukebox. Instead you make /dev/cdrom point at the correct device.

/dev/hda4       /hda4        ext2        defaults   1   2
/dev/hdb2       /hdb2        ext2        defaults   1   2
/dev/hdc2       /hdc2        ext2        defaults   1   2

Then you list all the partitions, or each disk. If there are too many options, regroup the file by fs-type, sub-sorted by options.

/dev/hdb1        swap        swap        defaults	0
/dev/hdc1        swap        swap        defaults	0

Swap partitions must be listed in /etc/fstab. Then they will be found by swapon -a at boot time.

# DOS #
/dev/fd0    /dos/a   msdos defaults,noauto,noexec,user
/dev/hdb3   /dos/c   msdos defaults,umask=001,uid=1016,noexec	0 2
/dev/hdb3   /dos/x  umsdos defaults,umask=001,uid=1016,noexec,noauto	0 2

DOS partitions tand to have lots of options, so group them together. NFS also.

pigeon:/cdrom	/pigeon/cdrom nfs	 defaults,timeo=14,intr,noauto 0 0
crow:/		/crow	     nfs	timeo=14,intr,noauto

Did it work?

To see what is mounted, use df(1) or mount(8)

To see that the swap is being used, use top(1) or free(1). They will tell you the total memory, available and free, on swap and in core. dmesg(8) will tell you how it got there.

You can tell that it didn't happen, because your system slows down. If installing a new /etc/fstab, turns your machine into a dog, check that you haven't accidently trashed the swap line. Check with fdisk -l.

Swap space makes a lot of difference by increasing the cache size, decreasing the number of pages that have to be permamantly in core.

When the disk cache is smaller than the currently running CPU footprint, the CPU will keep bumping into an unloaded page, and have to wait for it to be loaded (and the rest of the queue).

The extreme limit, is where there is zero disk cache, and every time the CPU crosses a 4K boundry it has to wait for the disk queue. Ditto for every data file access, eg mmap'ed files.

If memory is that short, the system won't have enough virtual memory, and may crash inside X11 when running many windows.

The /cdrom line does not have to be there, and slackware works without it, by having a specific mount command in /etc/rc.d/somewhere. You should add it. You may also need to run a command like

ln -sf /dev/hdd /dev/cdrom # ie cdrom -> hdd

to indicate the real device for cdrom is the fourth ide disk. After that you won't need to reconfigure workman, workbone or /etc/fstab (unless you have more than one CDROM or a jukebox!)

When you have setup /etc/fstab and /dev/cdrom, you can change disks with:

umount /cdrom
mount /cdrom

provided, of course, that the disk is not is use, eg programs running from it, or pwd says that it is in use by the current shell (or on a different shell, different console, or parent shell!).

The lines like /hda4 use rather un-imaginative names for the mount points, but I like this scheme, since it is what it is. In practise each additional disk has several roles. When I want decent names I use symbolic links, eg:

/usr/andrew	-->	/hdc2/andrew	# shared by old+new
/usr/local	-->	/hdc2/local	# beware of tar, check the link 
/home/gps	-->	/hdc2/gps	# lots of ftp files there
/kernels	-->	/hda4/kernels	# < 1024 cylinders
/boot		-->	/hda4/boot	# < 1024 cylinders

/old		-->	/hdb2		# the 'old' booting system
/new		-->	/hda1 	# diff /old/etc/fstab /new/etc/fstab
/hda1		-->	/ 		# for regularity

Extra partitions don't have to be in /etc/fstab, you can use hte mount command manually, or from a script. It's just easier if they are.

pigeon is another host connected with ethernet. It has a file /etc/exports containing:

/cdrom  (ro)	# no host validation but probably secure ?

The defaults need investigating, as they are probably not secure enough, or configured ideally for your site, for normal use, but now I can say:

mount /pigeon/cdrom

The noauto parameter prevents those lines being mounted at boot time (a long timeout for NFS).

The parameters for the MSDOS partitions make it appear as if every file belonged to user 1016. The 'user' parameter makes it mountable by users without permission on the device, and every file then belongs to that user (for MSDOS, not for ext2). The umask should really be split into files and dirs (because of the 'x' bit), but the noexec makes it safer to navigate without running anything (or allowing suid programs in).

Those with sharp eyes will notice that /dos/c and /dos/x use the same device. This is OK because it can only be mounted once. Simply umount one, and mount the other. It is just a way of testing whether umsdos, with it's long file names are worth it or not.

My current opinion is not-really, but I'm not certain. There are parameters to mount (msdos) to control whether long file names generate errors. This needs further work, as a cp -p * /dos/a/safe_dir managed to overwrite file.name with file.name.bak. (Because file.name already had a dot in it!).



Note that NFS is not very secure. I had a host it refused to recognise, because I had mis-spelled lan68, and it refused my identity (quite properly). However it was quite happy to tell me whether directories existed or not! See exports(5)

# This file contains a list of all directories exported to other computers.
# It is used by rpc.nfsd and rpc.mountd.

# lan67 client #
#/              *.lan67.priv(rw)  # test only #
#/              *.lan67.priv(rw)  # test only #
#/hdc2          *.lan67.priv(rw)  # local LAN only #
/home           *.lan67.priv(rw)  # local LAN only #

# world #
/home/ftp       (ro)  
/cdrom          (ro)  

Note that the host name, is deduced from the calling IP address. If it isn't in /etc/hosts, the nameserver will get asked. The FQHN is the first name on the line in /etc/hosts.

If you don't run a nameserver and a host on lan67 doesn't have a entry in /etc/hosts, it won't be recognised as *.lan67.priv. It will be treated as as world-other.

This is some of the access-control or "fireproofing" applied to the Inet apps, including /etc/inetd.conf, /etc/hosts.allow, ftp.allow, and other files. It works by looking at the IP_ADDR of the calling host, and converting it to a host name, then allowing or denying access to that host, maybe readonly. By using /etc/hosts, to list your gateways and servers, you avoid needing a name server.



This is run by /bin/sh when you login. You may wish to make a few modifications. Test each modification before leaving them.

HINT: If you mess up badly, you won't be able to login. Keep a root login in a different window, that you can use. Also su - user goes through /etc/profile, whilst su user doesn't. If you can't login because you messed up /etc/profile, switch to the other virtual console (using ALT-F2), and fix it.


This makes it quicker if you use CTRL-D to exit a shell

export DISPLAY=${DISPLAY:-"0.0"}

This sets the default DISPLAY that X11 applications will use.

export MORE=${MORE:-less}

Selects the prefered pager. You might also want to run (once)

cd /usr/bin ; ln -s less pg


If you use such a directory.


Put this at the end of the file, after PS1 has been set, to tell you which user you are (as well as which host you are on). This makes it a lot less frustrating to work as a plain user. You should only run as root when doing root things like repartitioning disks.


ln -s ttyS0 mouse

If you have a serial mouse on ttyS0, you tell Linux apps where it is, (/dev/mouse --> /dev/ttyS0), and what it is (MouseSystems mode). using:

cd /dev
ln -s ttyS0 mouse

You also have to tell the two main Linux mouse apps, what type of mouse it is. With X11 (XFree86) you put a line in /etc/XF86Config

Section "Pointer"
	Protocol    "MouseSystems"
	Device      "/dev/mouse"

Text based apps, means the "gpm" program. You configure it with a a command line option, when you start gpm. Usually in /etc/rc.d/rc.local

# don't forget the ampersand
# it runs the command in the background
gpm -t msc & 	


ln -s cua2 modem

If you have a internal modem on ttyS2 which is the same as cua2 (but different), you tell Linux apps where it is using:

cd /dev
ln -s cua2 modem

From then on, you don't have to specify /dev/cua2, simply /dev/modem. Most comms programs have that as their default, so many things simply "fall into place".


ln -s hdd cdrom

First use ls -l cdrom, and substitute the right value. eg if you have an EIDE CDROM as the 4'th disk, it is hdd. If it is the Master then it's /dev/hdc.

cd /dev
ln -s hdd cdrom

If it isn't an EIDE drive, but has it's own card, then you need to know exactly what type it is, and also tell the kernel the IO_PORT parameters in either /etc/lilo.conf or /etc/conf.modules.

If it's "sound-blaster" it might be /dev/sbpcd. But you knew that already, but here is how you tell the system (as well as making sure that the driver code is included in the kernel).

You should also edit /etc/fstab.