Chapter 3. The Linux Filesystem

Table of Contents

3.1. Operating the Linux Filesystem
3.1.1. Regular local filesystems
3.1.2. Swap Partions and SWAP files
3.2. Maintaining a Linux Filesystem
3.2.1. fsck
3.2.2. sync
3.2.3. hdparm
3.2.4. badblocks
3.2.5. mke2fs
3.2.6. dumpe2fs
3.2.7. debugfs
3.2.8. tune2fs
3.3. Configuring automount

This objective covers most points seen in LPI 101. Configuring automount is a new feature where special attention has to be paid to the syntax.

3.1. Operating the Linux Filesystem

When adding new filesystems to the existing root filesystem the key file involved is /etc/fstab which assigns a mount point, a mount order and global options per device.

Table 3.1. /etc/fstab options

ro or rwRead only or read write
noautoDo not respond to mount -a. Used for external devices CDROMs ...
noexecExecutables cannot be started from the device
nosuidIgnore SUID bit throughout the filesystem
nodevSpecial device files such as block or character devices are ignored
noatimeDo not update atimes (performance gain)
ownerThe device can be mounted only by it's owner
userImplies noexec, nosuid and nodev. A single user's name is added to mtab so that other users may not unmount the devices
usersSame as user but the device may be unmounted by any other user

mount will also keep track of mounted operations by updating /etc/mtab. The content of this file is similar to another table held by the kernel in /proc/mounts.

3.1.1. Regular local filesystems

When the system boots all local filesytems are mounted from the rc.sysinit script. The mount command will mount every thing in /etc/fstab that has not yet been mounted and that is not encrypted or networked:

mount -a -t nonfs,smbfs,ncpfs -o no_netdev,noloop,noencrypted

When shutting down, all filesystem are unmounted by the halt script by scanning the /proc/mounts file with the help of some awk commands!

3.1.2. Swap Partions and SWAP files

At boot time, swap partitions are activated in /etc/rc.d/rc.sysinit

swapon -a

Similarly when the system shuts down swap is turned off in the halt rc-script:

SWAPS=`awk '! /^Filename/ { print $1 }' /proc/swaps`
[ -n "$SWAPS" ] "" runcmd "Turning off swap: " swapoff $SWAPS

Example 3.1. Making a swap file of 10MB

  1. dd if=/dev/zero of=/tmp/SWAPFILE bs=1k count=10240
    
  2. mkswap /tmp/SWAPFILE
    
  3. swapon /tmp/SWAPFILE
    
  4. cat /proc/swaps
    Filename                  Type            Size    Used    Priority
    /dev/hda6                 partition       522072  39744   -1
    /tmp/SWAPFILE             file            10232   0       -2
    

Example 3.2. Making a swap partition of 16MB

  1. Make a new partition (e.g /dev/hda16) of type swap (82) and size 16MB. Reboot.

  2. Make a swap filesystem on the devices

    mkswap /dev/hda16
  3. Add the following to /etc/fstab

    /dev/hda16 swap swap  pri=-1 0 0
  4. Make the swap partition available with swapon -a

    Notice that if two swap partition are defined the kernel will automatically access them in stripedmode, provided they have been mounted with the same priority determined by the pri= option in /etc/fstab