Home Network Disk Configurations

Planning a disk configuration for your computer can save you a lot of effort later. Now many of you already have a configuration up and running, so you are thinking I am stuck with my hard disk configuration. Well, this is Linux, so the answer is not really, there is a lot you can do without reinstalling.

Mount a partition

One of the key concepts in Unix/Linux is the idea of a directory tree. We all know how the tree begins with the root directory “/” and has sub directories for specific uses, /bin, /usr, /home, /etc, and others. The system is designed so there are no drive letters as you would have in Dos/Window, so how do we deal with more than one disk/partition? The answer is the mount command. But first lets look at hard disk partitioning.

Hard Disk Partitions

Lets start by looking at the partitioning on this laptop. Here is the output of the fdisk command. The -l option tells it to list the partitions and not enter interactive mode. This is a good way to view the partition table since you can not edit it this way.

You need to look at the Start and end cylinders to understand the order of the partitions on the disk. Partition /dev/hda3 is the first partition. This can be referred to simply as partition 3 for convenience. The first 4 partitions on this hard drive are primary partitions. Most hard disks are only allowed 4 primary partitions. You will notice the 4th partition is listed as extended. This means that it can be subdivided again.

     # fdisk -l /dev/hda

    Disk /dev/hda: 240 heads, 63 sectors, 1299 cylinders
    Units = cylinders of 15120 * 512 bytes

       Device Boot    Start       End    Blocks   Id  System
    /dev/hda1           571      1299   5511240    5  Extended
    /dev/hda2   *       300       570   2048760   83  Linux
    /dev/hda3             1        28    211648+   6  FAT16
    /dev/hda4            29       299   2048760    6  FAT16
    /dev/hda5           571       841   2048728+   6  FAT16
    /dev/hda6           842      1112   2048728+  83  Linux
    /dev/hda7          1113      1258   1103728+  83  Linux
    /dev/hda8          1259      1299    309928+  82  Linux swap

    Partition table entries are not in disk order

The mount command associates a partition to a location in the directory tree. If I run the mount command on this laptop it reports the following:

     # mount
    /dev/hda2 on / type ext2 (rw)
    none on /proc type proc (rw)
    usbdevfs on /proc/bus/usb type usbdevfs (rw)
    none on /dev/pts type devpts (rw,gid=5,mode=620)
    none on /dev/shm type tmpfs (rw)
    /dev/hda3 on /dosc type vfat (rw,uid=421,group=10,mask=000)
    /dev/hda4 on /win98 type vfat (rw,uid=421,group=10,mask=000)
    /dev/hda5 on /dosd type vfat (rw,uid=421,group=10,mask=000)
    /dev/hda7 on /opt type ext2 (rw)
    /dev/hda6 on /home type ext2 (rw)
    /dev/hdc4 on /zip type vfat (rw,uid=421,gid=100,umask=000)

If you look at the two tables above you will notice the three partitions with a type of FAT16 are associated with partitions 3, 4, and 5. But these are Dos/Windows partitions. Yes that is true, so when I mount them I identify them as vfat partitions, meaning that they are Dos formated for the long file names.

So, how do I take a Dos partition and mount it on top of Linux. The steps are simple:

  1. Create a directory to mount the partition onto. Lets say /dosc.
  2. Next, as root, we issue the command: mount -t vfat /dev/hda3 /dosc .

That will attach the Dos partition in /dev/hda3 to the directory /dosc. You will then be able to read and write the directories as though they were part of Linux.

While we are discussing partitions, there are three interesting partitions listed above. The first one is the /proc partition. This partition is a view into the kernal memory. Here is Rute has to say about this partition The proc filesystem is the de-facto standard Linux method for handling process and system information, rather than /dev/kmem and other similar methods.

The next interesting mount point is usbdevfs. This is the point where USB devices appear when installed.

The last of the interesting partition is /dev/shm. The Redhat Admin guide defines this as: In the list of partitions, there is an entry for /dev/shm. This entry represents the system’s virtual memory file system.

So the question remains how are the mounts handled at system boot? This is done by the file /etc/fstab. Here is the one from this laptop:

    LABEL=/        /            ext2    defaults                    1 1
    none           /dev/pts     devpts  gid=5,mode=620              0 0
    none           /proc        proc    defaults                    0 0
    none           /dev/shm     tmpfs   defaults                    0 0
    /dev/hda8      swap         swap    defaults                    0 0
    /dev/hda3      /dosc        vfat    uid=421,group=10,mask=000   0 0
    /dev/hda4      /win98       vfat    uid=421,group=10,mask=000   0 0
    /dev/hda5      /dosd        vfat    uid=421,group=10,mask=000   0 0
    /dev/hda7      /opt         ext2    defaults                    0 0
    /dev/hda6      /home        ext2    defaults                    0 0

We have touched on filesystem types. Here is a quick definition of what the file systems used here are:

  • devpts The devpts filesystem provides this auto-ownership feature for Unix98 ptys. For more information see: Linux Devfs (Device File System) FAQ
  • proc This is the filesystem to handle process and system information.
  • tmpfs this is a virtual filesystem.
  • swap this is a partition dedicated to providing swap space for the kernel.
  • ext2 This is the older style filesystem developed for Linux.
  • vfat This is the Linux version of the Extended Dos file system.

So to summarize, when the system boots it uses the file /etc/fstab to mount the partitions as directed.

Partition Strategy

The Linux filesystem has been defined by the Filesystem Hierarchy Standard for easy implementation across different distributions of Linux. Here is their definitions for the base directory structure:

“/” “the root directory”
bin Essential command binaries
boot Static files of the boot loader
dev Device files
etc Host-specific system configuration
lib Essential shared libraries and kernel modules
mnt Mount point for mounting a filesystem temporarily
opt Add-on application software packages
sbin Essential system binaries
tmp Temporary files
usr Secondary hierarchy
var Variable data

My strategy when I install a Linux system goes something like this:

  • Small partition near the top of the hard disk for /boot
  • Mid sized partition for root /
  • Large partition for /usr
  • Mid sized partition for /home

For me the advantages are that the boot partition is easily accessible at boot time. This is the only portion of the system than needs to be in the first 1024 sectors of a hard disk. This has started to change, but for now, this strategy works well. Next I have the /usr partition on a separate location so the working files have their own home. Lastly, I put /home on it’s own partition. This means that when I upgrade, I do not need to remove and reinstall the files in the home directories.

The way I do upgrades then, is to select three other partition to do the install in /, /boot, and /usr. I will then create a directory called something like /old, and mount the old partitions /, and /usr under /old. I can then refer to the previous configuration files while I configure the upgrade. But I continue to boot into the old configuration until I am satisfied with the configuration of the upgrade.

Maintaining your free space

To understand the flexibly of Linux lets walk through a scenario. Suppose you originally allocated only 500 meg for a home partition and you find that it is 90% full. What to do? The easiest way to handle this is to purchase another hard disk, and attach it to you computer. Now here are the steps to grow /home from 500 meg to 1 gig.

  1. As root, partition the new hard disk so you have a Linux partition of 1 gig. Fdisk can be used on the new drive while the system is running, you do not need to reboot for the partition table to take.
  2. Format the new partition with the following command, lets assume you new disk is hdb, and the partition you created is the first.

    mkfs -t ext2 /dev/hdb1

  3. Now mount the new partition into a temp location. Lets make the directory /mnt/home. Then use the command:

    mount -t ext2 /dev/hdb1 /mnt/home

  4. Copy all the files and directories from the current home to the new partition. First you change to the /home directory.

    find . -print | cpio -pv /mnt/home

    This will copy all the files from the old partition to the new partition. It is best to do this when no one but root is logged into the system.

  5. Unmount the two partitions and remount the new /home to it proper place. Here are the commands:

    umount /home /mnt/home

    mount -t ext2 /dev/hdb1 /home

    You now have a /home partition of 1 gig instead of 500 meg.

  6. The last step is to open the file /etc/fstab and change the mount point for /home to /dev/hdb1.

Your done. You have just increased the size of the /home partition without trying to resize a partition. Since all the users see a single directory tree, they will not know the difference.

OK, lets take a slightly more complex example now. Suppose you have been adding new programs to the /usr/local directory tree. You /usr partition is now showing 98% full. Lets assume that /usr/local is 250 meg in size, and you have added a hdb drive. Who thinks they can use the steps above to gain some more space for the /usr/local directory? Clue: this operation makes use of symbolic links.

Summary

We have seen how the mount command eliminates the idea of drive letters in Linux. This somewhat elegant solution gives flexibly not easily replicated in the Windows environment. We have seen how Linux deals with multiple file system types as opposed to window’s support for it’s own file systems only.

So we have seen how a file system is organized in Linux to make logical locations for the parts of the system. This organization makes it easier for developers and system designers to know where to place new items in the system.

We have seen how to grow and maintain disk space on a running Unix box by creating new partitions, moving data, and changing the mount points. This flexibly does mean some additional complexity for the superuser, but the results usually justify the work.



Written by John F. Moore

Last Revised: Tue Nov 1 20:43:39 EDT 2016

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
HTML5 Powered with CSS3 / Styling, and Semantics