Key Concepts - UNIX Administration: Class 4

This class went into the general concepts of files systems, mounting disk partitions and NFS partitions.

  • A typical Linux installation will divide one or more hard drives into multiple partitions. Each disk is given its own device name:
  • A partition number is added to the device name: /dev/hdXY (Y is the partition number) for IDE disks and /dev/sdXY (Y is the partition number) for SCSI disks. For example, the first partition on the first IDE drive on a system would be /dev/hda1.

  • Each physical disk partition has filesystem name associated with it. If you remember, during installation, we created a series of partitions and assigned each of them a file system name like /home, /var, /boot, /, /usr etc. You can view a partitions associated file system name by using the df command. Here is a sample output of a df command:
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/hda2             972M  670M  251M  73% /
    /dev/hda4             2.6G  1.7G  774M  69% /usr
    /dev/hda5             1.9G   32M  1.8G   2% /home
    
    Note: the output above may differ depending on what UNIX distribution you are using

    This shows us that the the disk partition for /dev/hda2 is associated with the / (root) filesystem, the partition /dev/hda4 is associated with the /usr file system and a the partition /dev/hda4 is associated with the /home partition.

  • You can create, modify and delete partitions using the powerful fdisk command. You launch fdisk by specifying a disk device name as an argument. For example, here to perform fdisk associated activities on hda, you would use fdisk /dev/hda. This example shows how to launch fdisk, print the menu and then print the partitions associated with a particular disk:
    [root@doh /root]# fdisk hda 
    
    Unable to open hda
    [root@doh /root]# fdisk /dev/hda
    
    Command (m for help): m
    Command action
       a   toggle a bootable flag
       b   edit bsd disklabel
       c   toggle the dos compatibility flag
       d   delete a partition
       l   list known partition types
       m   print this menu
       n   add a new partition
       o   create a new empty DOS partition table
       p   print the partition table
       q   quit without saving changes
       s   create a new empty Sun disklabel
       t   change a partition's system id
       u   change display/entry units
       v   verify the partition table
       w   write table to disk and exit
       x   extra functionality (experts only)
    
    Command (m for help): p
    
    Disk /dev/hda: 255 heads, 63 sectors, 787 cylinders
    Units = cylinders of 16065 * 512 bytes
    
       Device Boot    Start       End    Blocks   Id  System
    /dev/hda1   *         1       255   2048256   85  Linux extended
    /dev/hda2           256       383   1028160   83  Linux
    /dev/hda3           384       434    409657+  82  Linux swap
    /dev/hda4           435       787   2835472+  83  Linux
    /dev/hda5             1       255   2048224+  83  Linux
    
    This shows that we currently have 5 partitions on this hard drive - 4 Linux partitions and 1 Linux Swap partition.

  • After installing a new hard drive, you use the fdisk utility to partition the hard drive. The first 4 partitions on a hard drive are knows as the primary partitions. All other partitions are knows as extended partitions. You are required to specify a file system type for each partition by using the "t" option in fdisk, which allows you to specify a file system id number for the partition. The id number is 83 for a regular Linux partition and 82 for a Linux Swap Partition.

  • After partitioning a hard disk, you need to format it. You can do this by usuing the /sbin/mke2fs utility on all Linux system, which will format a partition into the Linux ext2 standard file system format. (there is also a generic /sbin/mkfs utility on all UNIX systems, including Linux, that allows you to specify the type of file system you want to create, in addition to many other options.)

  • Partitions are mounted at boot time by several rc scripts. The configuration file for mounting partitions at boot is /etc/fstab. This is where you specify what partitions to mount at boot time.

  • You can also mount file systems by hand using the mount command. Use the mount command in this format:
    mount {options} device-name mount-point
    where: device-name is the partition you want to mount (e.g. /dev/hda3) and mount-point is the location where you want to mount the partition; {options} can be a series of options that tell the system what type of file system you are mounting, whether to mount it in read-only mode, etc. For example, if you issue the following command:
    mount –o rw –t ext2 /dev/hda10 /tmphome
    The system will mount the /dev/hda10 partition as a read-write file system (specified by the "-o rw" switch). The files contained on /dev/hda10 can now be accessed under the /tmphome directory structure.