return to first page linux journal archive
keywordscontents

Linux System Administration

Adding a New Disk to a Linux System

by Æleen Frisch

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:

Making a New Disk Available to Linux

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:
ActionSubcommand
fdiskcfdisk
Create new partitionnn
Change partition typett
Make partition active/bootableab
Write partition table to diskwW
Change size unitsuu
Display partition tablepN/A

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:

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.

The Filesystem Configuration File: /etc/fstab

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:

rwRead-write filesystem
roRead-only filesystem
suidThe SUID access mode is permitted (default)
nosuidThe SUID access mode is not permitted
noautoDon't automatically mount this filesystem
usrquotaUser quotas may be placed in effect
grpquotaGroup quotas may be placed in effect

Viewing and Modifying the Superblock

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.

Hints for Splitting Linux Across Two Disks

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:

# cd /d2
# tar -cvf - -C /usr/lib terminfo | tar -xvpf -
# rm -rf /usr/lib/terminfo
# ln -s /d2/terminfo /usr/lib/terminfo

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 aefrisch@lorentzian.com.

  Previous    Next