7. Installing / (root) and /usr file systems

Contents of this section

7.1 Initializing filesystems on partitions

Now we need to create the filesystems on the partitions. In my case, the first partition (12MB) is determined to be the root device, the second (12MB) for swapping, the third (6MB) as /tmp, and the fourth as /usr.

Normally you create an ext2-filesystem on your partitions. I use the minix filesystem on my /tmp for easy data transfer between Linux and AmigaOS. To create the filesystems, you type (as root):


/sbin/mkfs -t <fs-type> <device-node> <size>

or


/sbin/mkfs.<fs-type> <device-node> <size>

In my case, that's


/sbin/mkfs -t ext2 /dev/sdb1 12348

or

/sbin/mkfs.ext2 /dev/sdb1 12348

for the first partition (root). For ext2 filesystems, you might even leave out the number determining the size of the partition because Linux can find that out itself with its ext2 filesystem tools. For minix or other filesystems, however, you will have to specify the size yourself.

The second partition is used for swapping and does not need a filesystem. The third is /tmp, with minix filesystem (in my case, but you can also use ext2):


/sbin/mkfs.minix /dev/sdb3 6223

And the fourth for /usr:


/sbin/mkfs.ext2 /dev/sdb4 71736

Remember: All these device nodes and block sizes are from Ingo's configuration, and are used here only as an example. You definitely will have to use different numbers for your setup.

If you want to make a break here, don't just switch off your Amiga. Type


/sbin/shutdown

and wait until it says that you may turn off the power.

7.2 Unpacking the filesystems

First we need a second mountpoint, so create a directory:


mkdir /mnt2

Mount the partition that is supposed to become your root filesystem (again, all device nodes are examples from Ingo's installation):


mount -t ext2 /dev/sdb1 /mnt

Now mount the CDROM or the AmigaOS partition where the root.tar.gz is located.

If you want to mount a CD, you will first have to create a device node for it in /dev (there is already one in the new-filesys filesystem, but it's wrong). Do this:


cd /dev
rm scd0
mknod scd0 b 11 0

Also, a convenient and usual point to mount a CD-ROM is /cdrom, so create that directory if it doesn't exist already:


cd /
mkdir cdrom

If you are mounting a harddisk partition, no further steps should be required to be able to mount it into Linux - unless the device nodes for your AmigaOS partitions have not yet been created. If that is the case, you will have to create them yourself using the mknod command. An example: If you have an AmigaOS partition on the second SCSI disk, 9th partition (which makes it sdb9 for Linux), you create it by typing:


mknod /dev/sdb9 b 8 25

The formula to determine the numbers is described below in the section "Creating the fstab file".

On Ingo's system, the first harddisk is used for AmigaOS, with 4 partitions, and the Linux archives are in Work:linux (Work: is the second partition on the first harddisk, so that's /dev/sda2 for Linux):

For CD-ROM:


mount -t iso9660 /dev/scd0 /cdrom

For an AmigaOS partition:


mount -t affs    /dev/sda2 /mnt2

Change to the new root:


cd /mnt

And extract the archive:

For CD:


gzip -c -d /cdrom/<path_to_files>/root.tar.gz | tar xvof -   

For AmigaOS partition:


gzip -c -d /mnt2/<path_to_files>/root.tar.gz | tar xvof - 

This will take some time...

Now for the /usr stuff. There is a slight problem here, since the filenames in the archive are relative to the parent of the usr directory: ./usr/*. Since the ramdisk filesystem already uses /usr, we create a new one (but first unmount the partition where you installed the root filesystem):


sync              ; this will write out all buffer data to disk
cd /              ; so we are not "in the way" of the partition
umount /dev/sdb1  ; to unmount the partition
mkdir /mnt/usr    ; new directory

Now we mount the usr partition under this directory:


mount -t ext2 /dev/sdb4 /mnt/usr

And extract the archive:

For CD:


gzip -c -d /cdrom/<path_to_files>/usr.tar.gz | tar xvof -   

For AmigaOS partition:


gzip -c -d /mnt2/<path_to_files>/usr.tar.gz | tar xvof - 

This will take even more time...

After that, unmount everything for a clean shutdown (this also implicitly performs the above mentioned sync command):


cd /
/sbin/shutdown

Now, hit CTRL-Amiga-Amiga to reboot into AmigaOS.

7.3 Creating the fstab file

Finally, you have to put together a list of filesystems that are to be mounted automatically when the system is coming up from harddisk.

This file is named /etc/fstab, and here is what it looks like on Frank's machine (yes, this file has been written by two persons, and we excuse for jumping from one's configuration to that of the other one of us all the time - we hope you still keep in mind at any time that all these are just examples of our personal setups, and will most probably have to be modified for your machine) :

# /etc/fstab
# static file system information, see fstab(5)
#
# This file is not used by the kernel, but rather by mount(8), umount(8),
# swapon(8) and swapoff(8).  (Some day fsck(8) will also use this file).
#
# Comment lines have "#" in the first column.  The device field is either
# the name of a block special file or a swap file.  The device and directory
# fields should be absolute pathnames (i.e. start with "/").  Entries that
# are to be ignored should have type "ignore".  Frequency and pass are numeric
# fields for dump(8) and fsck(8) that are not yet used in Linux.  You can
# leave them empty if you want.
#
# Since entries in this file are processed sequentially, file systems must
# appear after the file systems they are mounted on (/usr before /usr/spool).
#
# A sample fstab:
#
# device        directory       type    options
#
/dev/sda9       /               ext2    defaults
/proc           /proc           proc    defaults
#
/dev/sda8       /usr            ext2    defaults
/dev/sda10      /temp           msdos   defaults
/dev/sda7       /usr2           ext2    defaults
#/dev/sda11      none            swap    swap
#
# AmigaDOS affs partitions
/dev/sdb1       /ados/sys       affs    ro
/dev/sdb2       /ados/dh1       affs    ro
/dev/sdb3       /ados/dh2       affs    ro
/dev/sdb4       /ados/temp      affs    ro
/dev/sdb5       /ados/tmp2      affs    ro
/dev/sda1       /ados/fdh0      affs    ro
/dev/sda3       /ados/fdh1      affs    ro
/dev/sda6       /ados/fdh4      affs    ro
#
/dev/sda4       /mnt3           ext2    defaults
/dev/sda5       /mnt4           ext2    defaults

The lines starting with a # character are comment lines. All other lines denote what filesystems are to be mounted and where.

The structure of these lines is quite easy: The first column is the path to the device node. For SCSI harddisks, they start with /dev/sd.., for IDE harddisks use /dev/hd... The second column gives the mount point. In my case, /dev/sda9 is the root partition (/). The third column denotes the filesystem type - you should have learnt about that from the previous paragraphs. The options column can give a couple of arguments which are especially interesting for NFS mounted filesystems. All Amiga FFS partitions are mounted ro which means "read-only". Everything else (except the swap partition) is set to defaults.

The line with the /proc entry might look a bit strange. The /proc filesystem is a kernel-internal pseudo-filesystem for showing processes and their environment as files. This makes it easy for some tools to get ahold of kernel-related information. The /proc filesystem does not have a device node under /dev. Also, you cannot delete or rename files in /proc - they are just virtual files.

The line with the swap partition has been commented out right now because you have not yet set up a swap partition. We will do this as soon as the first version of your fstab file is working.

You will now have to create such an fstab file of your own. It might be a good idea to take the above excerpt and use it as a skeleton for your customized version. Comment out anything you do not have, and insert lines you need as required.

When you are done, put your fstab file on an AmigaOS partition, mount Linux again with a RAM filesystem as you have been doing before, mount the AmigaOS partition with the fstab on it under e.g. /mnt, mount your root partition e.g. under /mnt2 (you might have to do mkdir /mnt2 again, as the changes you have done last time have not been saved anywhere - remember this is only a RAM filesystem!) and copy the fstab file from the AmigaOS partition to the etc directory on your root partition (in our case, /mnt2/etc).

Important

The list of device nodes in /dev on your new root partition is not as complete as the list of nodes in /dev of the RAM filesystem. This means that you might not be able to access a couple of partitions if you do not extend the list of nodes in /dev on the root partition (e.g. it does not contain any nodes for IDE partitions (hda, hdb)). So you will have to create those nodes yourself.

Mount your root partition e.g. on /mnt and go to /mnt/dev (this is the dev/ directory of your root partition). Here, issue the mknod command with corresponding parameters. The mknod command is not on your RAM filesystem, so you will have to use the one on your root partition:


cd /mnt/dev
/mnt/bin/mknod <parameters>

Here are a few examples for nodes you might want to create if they do not yet exist:


/mnt/bin/mknod sda9  b 8 9   ; for a ninth partition on SCSI disk sda
/mnt/bin/mknod sda10 b 8 10  ; for a tenth partition on SCSI disk sda

(There is a limit of 15 partitions per harddisk, numbered 1...15).


/mnt/bin/mknod hda1 b 3 1  ; for the first IDE partition on hda
/mnt/bin/mknod hda2 b 3 2  ; for the first IDE partition on hda

The second parameter is the name of the node you want to create. The third is always "b" for a block special file (harddisks, CD-ROMs). The fourth is the major device number. For SCSI this is 8, for IDE 3. The last number is the minor number. It starts at 1 for the first partition on the first disk, with a maximum of 15 partitions per harddisk. So, SCSI partitions sda1...15 have a minor number of 1...15. The second harddisk starts with minor number 16. The formula to calculate minor numbers is thus:


partition number + (harddisk number * 16)

Ok, so you should now verify that all nodes required in /dev (on the root partition) are present, and if not, create them now. If you forget one or more, you will get strange error messages about "corrupt filesystems" or "invalid superblocks" the first time you try to start the kernel with a root filesystem on a harddisk partition.

After this, issue the cd /; /sbin/shutdown command again, and reboot once more when it has finished.

You are done !

So, here's the exciting moment: Boot Linux with your / and usr filesystems from harddisk. In Ingo's case, this is:


amiboot-<x.y> -k vmlinux-<version> root=/dev/sdb1 ro video=pal,inverse

You will have to replace the sdb1 with whatever is your root partition. Also, you might want to use another video mode (like video=ntsc,inverse or the like).

The ro argument tells Linux that the root filesystem should be mounted read-only for now. It is usually re-mounted read/write when the /etc/rc file is executed. Without this option, you will get a message like


warning: mounting unchecked file system

every time the system is started.

If everything goes well, the system should come up. If there are warnings about missing files or directories, ignore them for the moment.

You should be able to login as root (no password is set initially), look around in the filesystem, try a few programs, and execute the /sbin/shutdown when you want to turn off the power.

7.4 Setting up a swap partition

Ok, let's hope you managed to get everything running up to this point. Still missing is the creation of a swap partition. So that's what we'll do now.

You should have reserved a partition for swapping when you re-partitioned your harddisk, and you should already have created an entry in /dev for it. If not, read the previous section about creation of missing device nodes. E.g. if your swap partition is to be on the 11th partition on the first SCSI harddisk (as is the case for me), your command would be:


cd /dev
mknod sda11 b 8 11

Next, you need to initialize this partition - which is somewhat comparable to quick-formatting a partition under AmigaOS. Take the size of this partition from AmigaOS (you should have written it down), convert it to 1 KByte blocks (HDToolBox lists the size in 512 byte blocks, so divide the number by 2) and enter the command:


mkswap /dev/<device> <size_in_blocks>

In my case, this had been:


mkswap /dev/sda11 <size_in_blocks>

If you are uncertain about the size_in_blocks parameter, double-check it by looking into HDToolBox again. The parameter you give should be the size in KBytes, so if you have a 16 MByte swap partition, the value should be somewhere in the 16000 area.

If the mkswap command was successful, you can now remove the comment from the /etc/fstab file that shows the swap partition (don't forget to correct the device name here if it's not correct for your system).

Next, you can enable swapping by typing in:


swapon -a

This means "Enable Swapping on all partitions listed for swapping in the /etc/fstab file". If you should ever feel the need for several swap partitions, you can add them to the /etc/fstab file.

Alternatively, you can give the swapon command a device as parameter so that swapping is only started on this particular swap partition, like in:


swapon /dev/sda11

When swapping is to be turned off, the command to do that is swapoff. Its use is identical to swapon: Either use


swapoff -a

to stop swapping on all partitions, or give a device name like in


swapoff /dev/sda11

The swapon -a command should be executed automatically when your system is booting. Look into the system start file, /etc/rc, and search for such a line. If it's not yet there, add it somewhere at the top - swapping should be enabled as soon as possible.

Similarly, swapping should be automatically disabled when you want to bring down the system. Some init programs (SysV-init in particular) do this via a script file like /etc/rc.d/rc.halt. but the init you will probably be using (simpleinit) does not do that, so you might want to write a small script for shutting down which does just this.

A word of warning about swap partitions:

It is possible to use a swap partition under both AmigaOS (for instance with VMM) and Linux. I don't yet have any experience with VMM, but if you used a partition under AmigaOS (or NetBSD or whatever) and want to use it again for swapping under Linux, you will have to issue the mkswap command on that partition under Linux again. If you don't do that, Linux will complain with a message like


Unable to find swap signature

when trying to enable swapping. However, I have personally had a situation where this did not happen. Ok, I'll explain:

I wanted to use /dev/sda11 under AmigaOS for a small test. I re-enabled it using HDToolBox and quick-formatted it (I did not write anything else on that partition!). When I restarted Linux, it did not complain about not being able to find the swap signature - probably because it was not overwritten when quick-formatting. However, 2 days later I got very strange "SCSI I/O error on device 080b" messages on my console which made me believe my harddisk was going to die (imagine the panic!). But then I saw that in fact Linux tried to access blocks outside the partition - so the size information on the partition was somehow mangled. I did a new mkswap on the swap partition, and everything worked again. (People told me swap partitions should be at the beginning of a harddisk to make swapping as fast as possible, but in this case I was very happy that my swap partition was on the innermost cylinders - this way there was no other data behind the partition that might have become trashed).

Now you might think it could be a good idea to automatically do the mkswap each time the system is coming up - e.g. in the /etc/rc file. But this can also be dangerous: This way you have to keep both partition-dependent files in mind (/etc/rc and /etc/fstab). If you ever repartition the harddisk again so that the Linux partitions get shifted to new positions, you have to correct both files.

An example: For a long time, my root partition was on /dev/sda8 and the swap partition on /dev/sda9. Then I split a lower partition into two halves so that root was then on /dev/sda9 and swap on /dev/sda10. If I had the command mkswap /dev/sda9 <size_of_blocks> in my /etc/rc file, I would have destroyed my root partition on the next Linux boot. Be careful!


Next Chapter, Previous Chapter

Table of contents of this chapter, General table of contents

Top of the document, Beginning of this Chapter