Linux System Administration
The steps required to add an additional disk drive to a microcomputer system are somewhat more tedious than those needed for larger systems. Most of the complexity comes from the fact that disks can be shared by distinct operating systems on microcomputers.
The terminology related to disk partitions varies somewhat between UNIX and other microcomputer operating systems. For example, DOS distinguishes between the primary partition (the principal, bootable DOS partition) and other extended partitions on the same hard disk; a UNIX disk partition is simply a separately accessible portion of a disk. DOS allows for a maximum of four physical partitions per disk. Under DOS, a physical disk partition can be further subdivided into multiple parts, known as logical drives. The first step in adding a disk to a microcomputer system is to decide how the drive will be split between DOS and UNIX (if applicable). The fdisk utility is used to create physical disk partitions on microcomputer systems (DOS also provides an fdisk utility). The cfdisk utility, a screen-based version of fdisk, is also available under Linux. The following considerations apply to the myriad of fdisk versions that you may encounter:
The conventional wisdom is to use the native version of fdisk to create and operate on the disk partitions for each operating system. In other words, use the DOS version for the DOS partitions, and the UNIX version for the UNIX partitions. In practice, you can often get away with using a different version. Things generally work fine, except when they don't.
Keep records of the partition numbers, starting and ending blocks, total sizes, partition type, and other data for each disk partition table as it is displayed by every version of fdisk that you have. An easy way to do this is to print the partition table from each version. If the table is ever damaged—and this does happen from time to time—you will probably need the information to recreate it and recover your data. Having the data from all the versions ensures that you can redefine partitions following the same alignment patterns and requirements as observed by the various operating systems when they created the partitions initially.
We'll look at the process of attaching a new SCSI disk to a Linux system in detail. The process would be the same for other disk types (for example, IDE), although the special files used to access the device would be different (for example, /dev/hdb).
After attaching the disk to the system, it should be detected when the system is booted. You can use the dmesg command to display boot messages or check /etc/boot.log if you're using the sysvinit facility:
scsi0 : at 0x0388 irq 10 options CAN_QUEUE=32 ... scsi0 : Pro Audio Spectrum-16 SCSI scsi : 1 host. Detected scsi disk sda at scsi0, id 2, lun 0 scsi : detected 1 SCSI disk total.
If necessary, create the device special files for the disk (needed only when you have lots of disks). For example, this command creates the special files used to access the fifth SCSI disk:
# cd /dev; MAKEDEV sde
Note also that disk ordering happens at boot time, so adding a new SCSI disk with a lower SCSI ID than an existing disk will cause special files to be reassigned—and probably break your /etc/fstab setup.
Assuming we have our special files all in order, we will use fdisk or cfdisk (a screen-oriented version) to divide the disk into partitions (we'll be saving about a third of the disk for a DOS partition). The following commands will start these utilities for the first SCSI disk:
# fdisk /dev/sda # cfdisk /dev/sda
We'll need the following subcommands:
Create new partition
Change partition type
Make partition active/bootable
Write partition table to disk
Change size units
Display partition table
cfdisk is more convenient to use as the partition table is displayed continuously. A cfdisk subcommand always operates on the current partition (highlighted). Thus, in order to create a new partition, move the highlight to the line corresponding to Free Space, and then enter an n. cfdisk will prompt for the partition information:
Primary or logical [pl]: p Size (in MB): 110
If you'd rather enter the size in a different set of units, use the u subcommand (cycles among MB, sectors and cylinders).
We use the same procedure to create a second partition, and then activate the first partition with the b subcommand. Then, we use the t subcommand to change the partition types of the two partitions. The most commonly needed type codes are 6 for DOS, 82 for a Linux swap partition, and 83 for a regular Linux partition.
Here is the final partition table (output has been simplified): Don't put any hairspaces in between the dashes below, or they will blow up. They don't have to look separated.
cfdisk 0.8 BETA Disk Drive: /dev/sda Heads: 16 Sectors per Track: 63 Cylinders: 1023 Name Flags Part Type FS Type Size (MB) /dev/sda1 Boot Primary Linux 110.0 /dev/sda2 Primary DOS 52.5 Pri/Log Free Space 0.5
If you've changed the partition layout of the disk—in other words, done anything other than change the types assigned to the various partitions—reboot the system at this point.
Next, use the mkfs command to create a filesystem on the Linux partition. mkfs has been streamlined in the Linux version and requires little input:
# mkfs -t ext2 /dev/sda1
This command creates an ext2-type filesystem. If you want to customize mkfs's operation, the following options may be useful:
-b: Set filesystem block size in bytes (the default is 1024).
-f: Set filesystem fragment size in bytes (the default is 1024).
-c: Check the disk partition for bad blocks before making the filesystem.
-i: Specify bytes/inode value: create one inode for each chunk of this many bytes. The default value of 4096 usually creates more than you'll ever need, but probably isn't worth changing.
-m: Specify the percentage of filesystem space to reserve (accessible only by root). The default is 5% (half of what is typical on other UNIX systems). In these days of multigigabyte disks, even this percentage may be worth rethinking.
Once the filesystem is built, run fsck:
# fsck -f -y /dev/sda1
The -f option is necessary to force fsck to run even though the filesystem is clean. The new filesystem may now be mounted and entered into /etc/fstab, which is the subject of the next section.
Here are some sample entries from /etc/fstab from a Linux system:
# device mount type options dump fsck /dev/hda2 / ext2 defaults 1 1 /dev/hdb1 /aux msdos noauto 1 2 /dev/hda1 none swap sw 0 0 /dev/sda1 /chem ext2 defaults 1 1
The general format for an entry is:
special-file loc type opts dump-freq pass-number
The fields have the following meanings:
special-file: The name of the special file on which the filesystem resides. This must be a block device name.
loc: The directory at which to mount the filesystem. If the partition will be used for swapping, use none for this field.
type: The kind of partition the entry refers to. The value for local filesystems under Linux is ext2. Other common type values are nfs for volumes mounted remotely via NFS, and swap for swap partitions and ignore, which tells mount to ignore the entry.
opts: This field consists of one or more options, separated by commas. The type field, above, determines which options are allowed for any given kind of filesystem. For ignore type entries, this field is ignored. For local filesystems, the options field may include the following keywords, separated by commas:
The SUID access mode is permitted (default)
The SUID access mode is not permitted
Don't automatically mount this filesystem
User quotas may be placed in effect
Group quotas may be placed in effect
Multiple options are separated by commas, without intervening spaces. On many systems, the keyword defaults may be placed into this field if no options are needed.
If the filesystem type is nfs, many more options are supported (see Chapter 13).
dump-freq: A decimal number indicating the frequency with which this filesystem should be backed up by the dump utility. The dump utility is in alpha testing and is not available on most Linux systems, so unless you use dump, you can ignore this field.
pass-number: A decimal number indicating the order in which fsck should check the filesystems. A pass-number of 1 indicates that the filesystem should be checked first, 2 indicates that the filesystem should be checked second, and so on. The root filesystem must have a pass-number of 1. All other filesystems should have the same or higher pass numbers. For optimal performance, two filesystems that are on the same disk drive should have different pass numbers; however, filesystems on different drives may have the same pass number, letting fsck check the two filesystems in parallel. fsck will usually be fastest if all filesystems checked on the same pass have roughly the same size. This field should be 0 for swap devices (0 disables checking by fsck).
The tune2fs command may be used to list and alter fields within the superblock of an ext2 filesystem. Here is an example of its display-mode output:
# tune2fs -l /dev/hdb1 Filesystem magic number: 0xEF53 Filesystem state: clean Errors behavior: Continue Inode count: 13104 Block count: 52208 Reserved block count: 2610 Free blocks: 50528 Free inodes: 13093 First block: 1 Block size: 1024 Fragment size: 1024 Blocks per group: 8192 Fragments per group: 8192 Inodes per group: 1872 Last mount time: Wed Dec 31 19:00:00 1969 Last write time: Thu Mar 2 04:19:16 1995 Mount count: 6 Maximum mount count: 20 Last checked: Thu Mar 7 15:27:34 1996 Check interval: 2592000 Next check after: Fri Apr 5 16:27:34 1996
The final items in the list concern when fsck will check the filesystem, even if it is clean. The Linux version of fsck for ext2 filesystems will check the filesystem if either the maximum number of mounts without a check has been exceeded or the maximum time interval between checks has expired (20 times and 30 days in the preceding output; the check interval is given in seconds).
tune2fs's -i option may be used to specify the maximum time interval between checks in days, and the -c option may be used to specify the maximum number of mounts between checks. For example, the following command disables the time-between-checks function and sets the maximum number of mounts to 25:
# tune2fs -i 0 -c 25 /dev/hdb1 Setting maximal mount count to 25 Setting interval between check 0 seconds
Another useful option to tune2fs is -m, which allows you to change the percentage of filesystem space held in reserve dynamically.
UNIX versions designed for microcomputers tend to assume that such systems have a single disk large enough to accommodate all of the filesystems that it will use. If what you actually have is a smaller amount of space on each of two disks but not enough on either one to hold all of UNIX, there is usually no built-in way to install the operating system anyway. However, a procedure like the following will usually be successful:
Install a minimal operating system on the partition on the first disk.
Add the partition(s) from the second disk to the system.
The general strategy is to create symbolic links to the partition on the second disk to allow the operating system to be split across them. This can mean copying some directories to the second disk after installation and then creating links in the original location, as in this example (/d2 is the mount point for the partition from the second disk:
# cd /d2 # tar -cvf - -C /usr/lib terminfo | tar -xvpf - # rm -rf /usr/lib/terminfo # ln -s /d2/terminfo /usr/lib/terminfo
Alternatively, if you know or can determine the location for an operating system component before installing it, you can pre-set up the symbolic link, then install that component, and the files will be written to the right location to begin with. For example, the following commands will cause the manual pages to be written to the second disk:
# mkdir /d2/man # chown bin /d2/man; chgrp bin /d2/man # chmod 755 /d2/man # ln -s /d2/man /usr/man
When selecting components to move, avoid placing anything required to boot the system on the second disk.
Continue this process until everything you want is installed.
Reprinted with minor alterations by permission from Essential System Administration ---Edition 2, copyright (C) 1995, O'Reilly and Associates, Inc. For orders and information call 800-998-9938 or 707-829-0515.
Æleen Frisch manages a very heterogeneous network of Linux and other UNIX systems and PCs. After finally finishing the second edition of Essential System Administration, she has gone back to her true calling in life, pulling the string for her cats, Daphne and Sarah. She can be reached via e-mail at firstname.lastname@example.org.