April 22, 2019

Tutorial: Adding Additional Hard Drives in Linux - page 4

The Theory Behind Hard Drive Management

  • June 3, 2002
  • By Alexander Prohorenko

The type of the newly created partition on a new hard drive will always be set to 83 (Linux type). The 'fdisk' utility supports control and creation of numerous partition types, though. We can get a list of them using the command 'l'. We also can change the type of partition using the command 't'. I absolutely do not recommend beginners should use this ability in a Linux system; better they should use only two types -- 83 (Linux) and 82 (Linux swap).

After all manipulations with 'fdisk,' we will get needed configuration. Now we should quit 'fdisk' and save all results using the command 'w'.

We do not need to reboot our PC. Sometimes, to tell the truth, 'fdisk' is unable to update the table of partitions in memory (such as in, for example, the latest versions of Red Hat Linux), but it will report about such problem. If this happens, then you will have to reboot the PC.

Of course, before using a partition, you need to format it. Keep in mind that, since we need to work with partitions on hard disk, we be working with with the device /dev/hdc, but we will format the partition /dev/hdc1.

We can accomplish this formatting with the 'mkfs' utility. Usually for Linux partitions, we will use one of three file systems: ext2, ext3, or reiserfs. We

also have the option to use several others, like ext, XFS, JFS. But ext is too old, and is not in much use anymore, and XFS and JFS installation requires deep knowledge of setup and configuring the Linux operation system.

We can execute the following command to format the partition with the ext2 file system:

        # mkfs -t ext2 /dev/hdc1

(key '-t' points to the type of file system). To format as ext3:

        # mkfs -t ext2 -j /dev/hdc1

This is not a typo, by the way. We are setting the type to ext2. But since ext3 is an updated "child" of ext2, it has forward and backward compatibility with its "parent".

To format a partition with ReiserFS:

        # mkfs -t reiserfs /dev/hdc1

Once 'mkfs' has finished its work, our partition is ready to be mounted.

All of the methods described above have one rather unfortunate drawback: after each reboot of the system, you need manually mount partitions again as root. Ideally, you will want automated mounting on PC startup.

This is easily done. In the system configuration directory /etc there is a file named 'fstab'. Inside this file is a list of connected partitions, which looks something like this:

        # cat /etc/fstab

        /dev/hda1 / reiserfs notail,usrquota,grpquota 1 1
        none /dev/pts devpts mode=0620 0 0
        none /dev/shm tmpfs defaults 0 0
        /dev/hdb /mnt/cdrom auto user,iocharset=koi8-r,umask=0,exec,codepage=866,ro,noauto 0 0
        /dev/fd0 /mnt/floppy auto user,iocharset=koi8-r,umask=0,sync,exec,codepage=866,noauto 0 0
        none /proc proc defaults 0 0
        /dev/hda5 swap swap defaults 0 0

Each string of this file keeps a description of each partition for mounting and has six columns (fields):

  • Name of device
  • Mount point
  • Type of file system
  • Additional arguments of mount. Some of them are common for everything, some of them are specific for this or that file system
  • ID number in query to checkup of integrity of file system on PC startup. Such checking works periodicaly. If this id number is 0, no checking will be done
  • Backup value (0 or 1). This argument is used by some backup software utilities.

Let's come back to our example. Specifically, partition hdc1 was formatted as ext3 and it needs to be mounted on the /mnt/hdc1 mount point during PC startup. To accomplish this, we will add the following string to the end of the file /etc/fstab:

        /dev/hdc1  /mnt/hdc1  ext3  default 2 1

This is very important: do not forget to add a "carrier return" (break line, enter, etc.) at the end of /etc/fstab file. Otherwise, the last string in the file will be ignored! (Actually, this doesn't matter in the latest versions of Linux. But get in the habit anyway, to avoid problems on PCs with other Unix software or older versions of Linux).

Now, we need make sure: did we edit everything right in fstab?

        # mount /mnt/hdc1

If we don't get any error messages that means this partition will be automatically mounted upon every startup.

Notice, by the way, this other (short) syntax of the 'mount' command. When we are using only one argument (mount point) all the needed information for 'mount' was derived from /etc/fstab.

In this article, we examined a few variations and rules for connecting new hard drives in Linux. Note that we did not cover a lot of the specialized fine-tuning that can be done in some of the more advanced operations, such as tuning file systems with log support, defining access rights to mounted partitions, and the like. Hopefully you will take from this article is a clearer understanding of the principles behind adding a hard drive to a Linux system.

Most Popular LinuxPlanet Stories