NEXT UP previous
Next: Kernel Build

Setting Linux Up

During the installation and configuration of your Linux system it is a good idea to write a log which records everything you did. In particular, you need to record the choices that you made whenever you needed to make a decision. You are bound to make some choices, which, when you appreciate all their implications, will turn out to have been the wrong ones. There are so many choices that you need to make, some of which will be quite arbitrary, that it is not always easy, when you repeat the exercise, to work out what selections you actually made - unless you write them down.

Once you have your distribution, the next step is to plan its installation. This is especially important if you expect Linux to coexist with another operating system on the same machine DOS for example. The biggest problem is going to be to decide how much of your disk space to set aside for each system. If you get this wrong then it can only really be solved by taking all the software off the machine, so that you can move the boundary between the two systems, and then reinstalling it all again, with the new disk space sizes. Either that, or you will need to add an extra disk drive to cope with the overflow.

Disk Partitions

Assuming that you want DOS and Linux to coexist on your machine when it is finished, the best starting point is from a machine with empty disks. If the machine is already given over entirely to DOS, then this will mean making a backup (surely you do this already???) of everything you can't replace from master disks, so that you can re-partition the hard disk space to make room for the Linux software.

Under DOS, each disk can be split up into partitions. Up to four primary partitions can be created on each drive. For a simple installation on a single hard disk, this will usually be enough. For example, with a single 320 Mb disk, you might partition the space into three pieces, as in Figure 1.

Here, the first partition has been set aside for DOS use as the C: drive, the second partition will be used as swap space under Linux and the third partition will be used to hold the Linux root filesystem. Each separate filesystem under Linux will have its own disk partition.

Sometimes you will want to use more than four partitions on a hard drive, especially if it is a rather large drive. In this case, one of the four primary disk partitions can be used as an extended partition. The extended partition is then used like a container to hold a set of logical disk partitions (up to 23 of them under DOS).

In addition to considering extended and logical disk partitions, for really large disk drives, a new problem pops into the frame. Due to a design oversight (the designers couldn't imagine hard drives becoming available that would be big enough to break their design limits...) you cannot generally boot a PC from a disk partition that uses disk cylinder numbers greater than 1023 (unless you have a modern motherboard whose BIOS supports large drives). For Linux, this means that its root filesystem must lie entirely in a partition under the 1024 cylinder boundary. Linux can hold data and programs in partitions above the boundary; you just can't boot Linux from these partitions. For an IDE disk, the 1024 cylinder limit comes at 504 Mb.

Suppose, then, that you have a 720 Mb IDE disk and you want to partition it to give a 150 Mb DOS C: drive, a 200 Mb DOS D: drive (probably to use as a compressed drive), a 16 Mb Linux swap partition and then the rest of the disk (354 Mb) for Linux filesystem space. Figure 2 shows one possible disk partitioning arrangement which takes all the constraints into account.

Notice that the Linux space has been split into two parts, so that the partition holding the root filesystem can fit below the 504 Mb boundary. This leaves the problem of where in the Linux directory tree the other Linux filesystem/partition can usefully be mounted. One obvious division, and the one shown here, is to split the Linux space into a system partition and a user partition. All of the Linux installation will then be made into the root partition, which leaves the other partition initially empty and allows it to be used as user home directory and working space, by mounting it as /home. Many other arrangements are possible and you may need to experiment until you find the one that suits your own particular circumstances best.

The program used to partition disks is called fdisk, both under DOS and under Linux. In general, you should only create the partitions to be used within a particular operating system using that system's own fdisk command. So the first task in our example is to install DOS from the master disks, using the DOS fdisk command to create just the required DOS partitions, leaving the rest of the disk space unallocated.

Most Linux distributions supply a one- or two-disk set, which you need to use to boot Linux on your machine initially. With the Slackware distribution there are two disks required, called the boot and root disks. In fact, there are several different versions of each of them, and you will need to select an appropriate one of each. The choice is based on what type of hard disk you will be installing to (SCSI or not) and what medium you will be using as the source of the files to install from (CD-ROM, floppy disk, hard disk or network).

You should consult the release notes supplied with your distribution (probably as a README file or a thin paper leaflet) to help you make the appropriate choice and to tell you how to create the boot and root disks from the files available.

For the rest of this section I shall assume that you have a 320 Mb IDE hard disk, partitioned as in the example in Figure 7.1, with the DOS partition already created and populated with your DOS software. I shall further assume that you wish to install the A, AP, D, K, N, F, X, XAP and Y software sets from the Slackware distribution and that your installation medium will be floppy disks (though the installation procedure is essentially the same from any other installation medium: CD-ROM, hard disk or network).

Once you have the boot and root disks prepared you should insert the boot disk and reboot the machine. Most distributions, Slackware included, provide a boot disk which will allow you to enter hardware configuration details after a prompt. This should only be necessary in the unlikely event that the boot disk kernel fails to detect, correctly identify or configure a particular hardware device.

Our example configuration should present no problems and so you would just press Enter or Return at the prompt to continue with the boot sequence. After a short time you will be prompted to remove the boot disk, replace it with the root disk and press Enter or Return to complete the initial boot sequence.

At this stage, you will have a minimal Linux system, running entirely in memory, using a ramdisk for its root filesystem and, if all has gone well, you should be looking at a Login: prompt. Now, login as root. There is no password set on the account, so you should be able to log straight in.

By convention (one which I shall follow in the examples in these tutorials) the system administrator or super-user is given a prompt which consists of, or at least ends in, a hash (#) symbol. It is a good idea, when used in a prompt, to keep the hash symbol exclusively for this purpose it will help to avoid confusion.

In order to set up the Linux partitions you need to run fdisk from the hash prompt, which gives an output as follows:

	# fdisk
	Using /dev/hda as default device!

	Command (m for help):

The file name /dev/hda is the device special file name corresponding to the whole of the first hard disk drive (/dev/sda for a SCSI disk). This is the drive that fdisk tries to work with by default. If you have a second hard drive, you can get fdisk to work with that instead by specifying the pathname to the device special file for the second drive (/dev/hdb or /dev/sdb) as a parameter to the command:

	# fdisk /dev/hdb

Under Linux, every disk drive and partition is given a name in /dev. These names appear as follows:

hdaentire hard drive 1;
sdaentire SCSI hard drive 1;
hdbentire hard drive 2;
sdbentire SCSI hard drive 2;
fd0entire floppy drive 0 (DOS A:);
fd1entire floppy drive 1 (DOS B:).

The partitions on any of the hard drives can be accessed just by adding the appropriate number to the name for the entire drive. The following table shows how to name the partitions on drive hda:

hdal hard drive 1, primary partition 1;
hda2 hard drive 1, primary partition 2;
hda3 hard drive 1, primary partition 3;
hda4 hard drive 1, primary partition 4;
hda5 hard drive 1, logical partition 1;
hda6 hard drive 1, logical partition 2;
hda7hard drive 1, logical partition 3, etc.

The Linux fdisk command looks different to the DOS equivalent, but they both perform similar functions. You can obtain a list of the functions by using the 'm' command once you have fdisk running:

	# fdisk
	Using /dev/hda as default device!

	Command (m for help): m Command action
	a	toggle a bootable flag
	c	toggle the dos compatibility flag
	d	delete a partition
	l	list known partition types
	m	print this menu
	n	add a new partition
	p	print the partition table
	q	quit without saving changes
	t	change a partition's system id
	u	change display/entry units
   	v	verify the partition table
  	w        write table to disk and exit
   	x	extra functionality (experts only)

A sensible thing to do at this point is to display the existing partition table, with the 'p' command, to check that the DOS partition has been set up properly:

	Command (m for help): p

	Disk /dev/hda: 16 heads, 40 sectors, 1024 cylinders Units = cylinders of 640 * 512 bytes

	     Device     Boot    Begin    Start     End     Blocks     Id     System
	/dev/hda1        *        1          1     511     163812+     6    DOS 16-bit >=32M

It has, so now you can set up the Linux partitions, starting with the swap space on /dev/hda2. You use the 'n' command to add a new partition, and then fdisk will ask you if you want to create a primary or extended partition. In our example, we want a primary partition, so you would answer 'p' to this prompt. You will then be asked which partition number to use and you would answer '2'. The next question from fdisk asks you to specify at which disk cylinder the new partition should start. In answer to this question, you should give the number of the next free cylinder, after the DOS partition. This will be 512 here. The last question asks you to specify where the new partition ends. This can be given as a cylinder number or you can just specify how big you want the partition in either bytes, kilo-bytes or mega-bytes. To specify a 16 Mb swap partition you would answer '+16M'. The whole sequence appears as:

	Command (m for help): n 
	Command action
		e    extended
                p    primary partition (1-4)
	p
	Partition number (1-4): 2
	First cylinder (512-1023): 512
	Last cylinder or +size or +sizeM or +sizeK (512-1023): +16M

Incidentally, there is nothing to stop you from having multiple swap partitions. If for instance you have more than one hard disk then this arrangement might be the most convenient.

After creating the partition to be used for swap space, a similar sequence can be followed for the Linux root partition on /dev/hda3:

	Command (m for help): n 
	Command action
	         e      extended
  		 p	primary partition (1-4)
	p
	Partition number (1-4): 3
	First cylinder (564-1023): 564
	Last cylinder or +size or +sizeM or +sizeK (512-1023): 1023

A 'p' command at the end of this sequence will confirm that all has gone according to plan:

	Command (m for help): 
	p

	Disk /dev/hda: 16 heads, 40 sectors, 1024 cylinders Units = cylinders of 640 * 512 bytes
	Device	   Boot Begin	Start	End	Blocks	Id	System
        /dev/hda1   *      1	   1 	511	163812+	 6	DOS 16-bit >=32M
	/dev/hda2 	 512	 512	563	16640	83	Linux native
	/dev/hda3	 564	 564   1023	147200	83	Linux native

This is looking good. However, there is just one more thing to do to finish it off. The system type for partition 2 is still flagged as Linux native when it should be Linux swap. This can be corrected with the 't' command to toggle the Id from 83 to 82. How do I know what the number should be? You can get fdisk to give you a list when you use the 't' command:

	Command (m for help): t
	Partition number (1-4): 2
	Hex code (type L to list codes): L

	1  DOS 12-bit FAT	8  AIX			75 PC/IX		b7 BSDI fs
	2  XENIX root		9  AIX bootable		80 Old MINIX		b8 BSDI swap
	3  XENIX usr		a  OS/2 Boot Man	81 Linux/MINIX		c7 Syrinx
	4  DOS 16-bit		40 Venix80286		82 Linux swap		db CP/M
	5  Extended		51 Novell?		83 Linux native		e1 DOS access
	6  DOS 16-bit		52 Microport		93 Amoeba		e3 DOS R/O
	7  OS/2 HPFS		63 GNU HURD		94 Amoeba BBT		f2 DOS sec
	9  AIX bootable		64 Novell		a5 BSD/386		ff BBT
	Hex code (type L to list codes): 82

And now, at last, the partition table should be set up as required. A final look just to make sure:

	Command (m for help): p

	Disk /dev/hda: 16 heads, 40 sectors, 1024 cylinders Units = cylinders of 640 * 512 bytes
	Device	       Boot   Begin	Start	   End	Blocks	Id	System
	/dev/hda1         *       1	   1	   511	163812+	 6	DOS 16-bit >=32M
	/dev/hda2	        512	 512	   563	 16640	82	Linux swap
	/dev/hda3	        564	 564	  1023	147200	83	Linux native

A good tip at this point is to make a note of the numbers of blocks in the Linux partitions for later operations (16640 and 147200 here). Using the 'w' command we will now write this new partition table back to the disk and then quit from fdisk. While using fdisk, if something should go horribly wrong, you can use the 'q' command to quit from the program without making any changes to the original partition table on disk.

To make sure that the changes to the partition table take effect with all versions of fdisk you should now reboot the machine with the boot and root disks again. Once you have done this and logged back in as root again, you are ready to continue.

Creating Filesystems

Having now created the partitions for Linux, the next task is to make the filesystem structures within those partitions. This is just the Linux equivalent of the DOS format operation. Working on the swap partition first, you use two commands: mkswap to prepare the partition and swapon to tell Linux to bring the partition into use:

	# mkswap -c /dev/hda2 16640 
	# swapon /dev/hda2

The -c switch to mkswap forces a check for bad data blocks in the partition. Obviously, if your swap partition is not hda2, then you would substitute the name of yours in the command. The number at the end of the line is just the block count of the swap partition, which you noted when you created the partitions. Again, you will substitute your own value in place of the 16640. The swapon command just takes a single parameter which is the name of the partition to use (hda2 here).

Before you can create the filesystems on the Linux native partitions, you have to choose which filesystem type to use. In fact, even though Linux supports several different filesystem structures, the best one all round is called the Second Extended Filesystem and it is the one to use. To make a second extended filesystem on a Linux native partition you use the mke2fs command:

	# mke2fs -c /dev/hda3 147200

The parameters specify the partition to use and its size in blocks. Again, the -c switch forces a bad block check. If you have more than one Linux native partition then you will need to use mke2fs on each of them.

Installing Packages

Having prepared the disk partitions, you are now ready to load the Linux software into them. Each different Linux distribution has a different method for performing this operation. But essentially what happens is that your Linux partitions are mounted under the root filesystem (which is still in RAM don't forget) and then the various software packages can be unpacked from floppy disk (or other installation medium) and copied into the appropriate places.

Some distributions require you to perform these operations manually, which is not a particularly difficult task, just a bit tedious. Other distributions, Slackware included, provide an installation script to automate the procedure. The installation script in the Slackware distribution is called setup:

	# setup

Running this command presents you with a menu which will guide you through the remaining steps of the installation. The various menu options are:

Booting Linux

Whatever Linux distribution you choose to install, it must provide you with some means of booting into Linux when you first switch the machine on. This can be as simple as supplying you with a floppy disk to boot from or you may get to use one of the Linux kernel loaders from your hard disk. The Slackware distribution allows you the opportunity of creating a boot floppy and also of installing the lilo boot loader. These things can be done from within the Configure option of the setup command.

In order to show how simple it is, we will create a boot floppy manually. This also gives you a spare boot floppy in case anything happens to the one you created at the end of setup. In fact, all that you need to do is just to copy the Linux kernel image from your hard disk to a floppy disk and it is automatically bootable.

Different Linux distributions store the kernel image file in different places. The most common places are:

	/vmlinuz
	/zImage 
	/etc/zImage

The Slackware distribution uses /vmlinuz by default. Once you have identified the location and name of your kernel image you will need to make sure that it is configured to run from floppy disk properly. To do this you use the rdev command. What rdev does is to allow you to modify some of the kernel's configuration details directly in the kernel file. What we need to do is to make sure that our kernel file has the name of the root partition set correctly and that initially the root partition is mounted read-only so that it can be checked. These operations are performed with the following two commands:

	# rdev /vmlinuz /dev/hda3 
	# rdev -R /vmlinuz 1

Obviously, if your kernel image name or your root partition name are different than those used in the example, you will need to substitute your own names into the commands.

All you need now is a blank disk to make the copy (a DOS formatted disk will do). If the disk needs to be formatted this can be done with the fdformat command. For example, to format a 1.44 Mb floppy disk in the A: drive (f dO):

	# fdformat /dev/fd0Hl44O

Notice the H1440 after the fd0 in the device special file name, this forces fdformat to treat the disk as high density and 1440 Kb in size (i.e. 1.44 Mb). There are other special files available which force the floppy disks to be treated as other standard sizes, as the following command shows:

	# ls /dev/fd0*
	/dev/fd0	/dev/fd0Hl440	/dev/fd0H72O	/dev/fd0h360
	/dev/fd0D36O	/dev/fd0H2880	/dev/fd0d36O	/dev/fd0h720
	/dev/fd0D72O	/dev/fd0H360	/dev/fd0h1200

Armed with the blank floppy disk and the name of the kernel image, all that remains is to perform the copy:

	# cp /vmlinuz /dev/fd0

You should now be able to boot the system with your new floppy in just the same way as you will with the floppy created during the setup procedure.

The Reboot Procedure

Unless you tried to install lilo during setup you will have to boot your Linux system from floppy disk for the time being. Having two boot floppy disks available, now is a good time to reboot your system to check that all is well - don't forget you are still running with the root filesystem on a RAM disk at the moment!

Reboot time is one of those particular times when you need to remember that Linux is a big-machine operating system. Under no normal circumstances should you shut down Linux by just switching the machine off or by pressing the reset switch - Linux needs to be shut down properly. Quite a lot of the work that Linux does is retained in memory for as long as possible rather than writing it to disk. The obvious reason for this is that accessing data in memory is orders of magnitude faster than accessing the same data on disk. One consequence of this, however, is that when you want to shut Linux down you need to give it advanced warning so that it has time to transfer all this memory resident data to disk before you pull the plug.

The safest way to shut Linux down is to use the shutdown command. The general form of this command is:

	shutdown flags time [message]

The shutdown command can only be executed by a user logged in as root and when it is given, message is sent to all users. If no message is specified then a default shutdown warning will be given. When shutdown time arrives a SIGTERM signal is sent to all processes to give them the opportunity to terminate cleanly, before the shutdown proper takes place.

The main flags are the command line switches: -h which means halt the machine after the shutdown and -r which means reboot the machine instead. The time parameter specifies when the shutdown should take place. It can be specified as an absolute time in the format hh : mm or it can be given as a number of minutes from the current time, in the format +mm. The word now can be used to mean +0 minutes.

During its operation, the shutdown command ensures that the disk data contents are synchronized with the data stored in memory so that no data will be lost. The following command will shut Linux down immediately and then halt the machine:

	# shutdown -h -t 0 now

It is also possible to configure the Linux kernel to reboot the machine when you press Ctrl-Alt-Del. This action can obviously be performed by anyone, at any time, whether they have a root login or not. On Linux machines for home and personal use this may not be a security issue. However, you may want to disable this feature on any machine whose main keyboard and screen are open to unauthorized access. You will see how to do this in the next page when we look at how to build a custom kernel.

Due to space restrictions on the RAM disk root filesystem, many Linux distributions do not supply the shutdown program on their setup disks. Therefore, you may need to use Ctrl-Alt-Del just for the first shutdown after initial installation.

lilo

Rebooting your Linux system from floppy disk should work fine; however, it is far more convenient if you can boot it directly from the hard disk, especially if you can have the choice of which operating system to boot, where there is more than one from which you might choose.

As I have mentioned briefly before, there is a program called lilo which can be used, along with a configuration file, to set the system up so that when the machine boots you can have exactly this choice.

If lilo is being used then at the start of the boot sequence the word:

	LILO

will appear on the screen followed by a short pause. If you do nothing during this pause then lilo will boot whichever operating system or kernel it has been set up to treat as its default system. If, instead, you press one of the keys: Shift, Ctrl or Alt during the pause, then you will be presented with a:

	boot:

prompt, at which you type in the name of the operating system or kernel you wish to boot. If you press the Tab key at the prompt then you will get a list of the names from which you may make your choice.

In order to set up lilo to give you these options, you just need to set up a configuration file, called:

	/etc/lilo.conf

with the required information about which operating systems or kernels you want to be able to boot, where they are on your hard disks and what names you want to give them, to use at the lilo boot: prompt, and then you just type in the following command to complete the installation:

	# lilo

The easiest way to appreciate what goes into the /etc/lilo.conf file is to take a look at one. The following is an example which could be used with our 320 Mb disk to boot DOS by default, but allow the choice of either dos or linux at the boot: prompt:

	# LILO configuration file
	# Global section
	boot = /dev/hda
	delay = 50

	# DOS bootable partition section other = /dev/hda1
	label = dos
	table = /dev/hda

	# Linux bootable partition section image = /vmlinuz
	root = /dev/hda3
	label = linux read-only

The configuration file is split up into sections: a global section to start, and then a further section for each operating system or kernel that you want to be able to choose at boot time. The first section after the global section gives the details of the operating system or kernel that lilo will boot by default.

In the example, the global section contains two lines: the first tells lilo from which hard drive it will be booting and, therefore, which disk's boot block it should modify when you install it; the second specifies the length of time (in tenths of a second) that lilo should pause before booting the default system.

Since DOS is to be the default operating system, the DOS section comes next in the configuration file. The three lines in the section specify: which partition holds DOS, the label you will type at the boot: prompt to run DOS and the location of the partition table.

The last section contains four lines of information about booting Linux: the full pathname of the bootable kernel image file, the name of the partition which holds the root filesystem, the label you will type at the boot: prompt to run Linux and a flag which specifies that initially, the root filesystem should be mounted read-only so that it can be checked for integrity by the filesystem check program.

If you want Linux to be the default operating system to boot rather than DOS then all you need to do is to swap over the DOS and Linux information so that the Linux information is given first.

Obviously, when you want to set up a lilo.conf file then you will substitute your own disk, partition, system label and kernel image names into the file in place of my examples.

You must remember that you need to run the lilo command every time you modify the configuration file and every time you change a kernel image file, whether you modify the configuration file or not. Even if you store a new kernel image in the same place as the old one, and with the same name, you must still run the lilo command to have the new kernel installed.


NEXT UP previous
Next: Kernel Build