Previous Page | Next Page

  1. Introduction
  2. Abbreviated Boot
  3. The Boot Process
  4. Startup and Run Levels
  5. Initialization Scripts
  6. Runlevel Scripts
  7. Login Process
  8. Bash Shell
  9. Filesystems
  10. LILO, Kernel and Root Filesystem
  11. The Kernel
  12. Passwords, Users, Groups, and Quotas
  13. The Environment
  14. The /etc/sysconfig directory
  15. The /proc filesystem
  16. Process Control
  17. Devices
  18. Daemons Services
  19. Inetd and Network Services
  20. Programs and Libraries
  21. Security and PAM
  22. The printer services
  23. Mouse support with gpm
  24. Mail
  25. News
  26. UUCP
  27. LDAP
  28. NFS and RPC
  29. Samba, NetBIOS, WINS, nmbd
  30. Identd (auth)
  31. Telnet and FTP
  32. Apache web server
  33. DNS and named
  34. How X Works
  35. X Scripts
  36. Support for Text
  37. Keymapping for Programs
  38. Keycode Table
  39. Example Keymap File
  40. Terminfo Commands
  41. VT100 ESC sequences
  42. Kernel Revisited
  43. Configuration Files
  44. Credits

Linux Filesystems

What happens with filesystems when the system starts

As discussed in previous sections, the LILO linux loader program will boot itself from the boot record of a hard drive, then look for the kernel in the location specified when it was installed. The kernel will load and decompress, then look for the root filesystem in a location specified by the user when they ran the rdev program on the kernel or specified it using LILO to pass the root location as a parameter to the kernel. The kernel will then normally mount the root filesystem in readonly mode, unless it has been programmed to do otherwise. Then the kernel will look for the init program and start it. The init program will run a series of script files which will:

  1. Use the program fsck to mount the /proc filesystem.
  2. It will start the swap device with the swapon command.
  3. Then it normally will do a filesystem check on the root filesystem with the program fsck. If the file /fastboot exists, filesystem checking will be skipped.
  4. then mount the root filesystem as read and write.
  5. Update (turn on) user quotas
  6. Update the /etc/mtab file with "mount -f /" and "mount -f /proc".
  7. The fsck program is used again with the -A option to check all filesystems listed in the /etc/fstab file.
  8. All other filesystems are mounted with the command "mount -a -t nonfs, smbfs, ncpfs, proc". These filesystems are not mounted when the system is booted to single user mode.

The fstab File

Located in "/etc/fstab", it is used to mount other partitions at startup. Each line in the file refers to a different filesystem. Fields are separated by whitespace. The primary filesystems must be mounted first, so they must be in correct order. Your native partition for the system you are running should be listed first.
The fields are as follows:

  1. The name of the device such as "/dev/hda1"
  2. The mount point. Use "/" for root. Other typical mount points are "/dos" for DOS, "swap" or "none" for the swap partition, and "/mnt/floppy" for "/dev/fd0" (the floppy drive).
  3. The type of filesystem. They are: mini, ext, ext2(linux native), xiafs, msdos, hpfs, ntfs, fat32, iso9660(CD-ROM), nfs, swap (for swap space)
  4. The mount options for use with the filesystem. Read the mount man page to see possible options. ro= read only, user- allows normal users to mount the device.
  5. The frequency the filesystem needs to be dumped by the dump command. For ext2, normally make it 1, for others make it 0. 0 or nothing means it is not dumped.
  6. A number telling the order in which the filesystems should be checked at reboot time by the fsck program. Your root should be 1, others are in ascending order or 0 to not be checked.

To determine your hard drive's partitions and see what each partition holds which operating system, you may use the fdisk program. Just make sure you don't change your disk information. You can use the 'p' command to see a list of current partitions, then you can add them to your fstab file.
Note: In order for the mount to succeed, you must have created the mount point subdirectory (except for root).

I like to install multiple copies of Linux on one computer for two reasons.

  1. The second copy can serve as a backup to the first. If I totally screw up one copy of Linux, by changing kernels, etc, I can still get to the filesystem from the other system and straighten out my problems.
  2. I can learn about other linux packages.

A typical /etc/fstab file:

/dev/hda2		/		ext2		defaults		1 1
/dev/hdb1		/data		auto		defaults		0 0
/dev/hda1		/dos		vfat		defaults		0 0
/dev/hda3		/slackw 	ext2		defaults 		1 2
/dev/hda4		swap		swap		defaults		0 0
/dev/cdrom		/mnt/cdrom	iso9660		noauto,owner,ro 	0 0
/dev/fd0		/mnt/floppy	ext2		noauto,owner		0 0
none			/proc		proc		defaults		0 0
none			/dev/pts	devpts		gid=5,mode=620 		0 0

The /proc filesystem is required for tracking processes in RAM (memory). The directories /data, /dos, and /slackw must exist or their mounts will fail. The entries for the floppy and cdrom allow them to be automatically dismounted if they are mounted during shutdown. The noauto option in their entries, keep these devices from being mounted at startup.

Note:
You can use the fdisk utility to toggle the bootable flag (change the boot partition). This can help if you install an OS over linux that wipes LILO. However the OS that wiped LILO must be able to toggle this partition to a Linux filesystem.

Programs used to manage filesystems

  • badblocks(8) - Search a device for badblocks. The command "badblocks /dev/hda" will search the first partition of the first IDE hard drive for badblocks.
  • cfdisk(8) - A partition table manipulator used to create or delete disk partitions.
  • dosfsck(8) - Used to check a msdos filesystem.
  • dumpe2fs(8) - Lists the superblock and blocks group information on the device listed. Use with a command like "dumpe2fs /dev/hda2". The filesystem on the device must be a Linux filesystem for this to work.
  • fdformat(8) - Performs s lowlevel format on a floppy disk. Ex: "fdformat /dev/fd0H1440".
  • fdisk(8) - Used to add or remove partitions on a disk device. It modifies the partition table entries.
  • fsck(8) - Used to check and/or repair a Linux filesystem. This should only be used on systems that are not mounted.
  • hdparm(8) - Used to get or set the hard disk parameters.
  • mkdosfs(8) - Used to create a msdos filesystem.
  • mke2fs(8) - Create a Linux native filesystem which is called a second extended filesystem. This creates the current version of the Linux filesystem.
  • mkfs(8) - Used to make a Linux filesystem on a device. The command "mkfs /dev/hdb1" will create a Linux filesystem on the first partition of the second IDE drive.
  • mkswap(8) - Creates a Linux swap area on a device.
  • mount(8) - Used to mount a filesystem. It supports many types of filesystems.
  • stat(1u) - Used to print out inode information on a file. Usage: stat filename
  • swapoff(8) - Used to de-activate a swap partition.
  • swapon(8) - Used to activate a swap partition.
  • tune2fs(8) - Used to adjust filesystem parameters that are tunable on a Linux second extended filesystem. The filesystem must not be mounted write when this operation is performed. Can adjust maximum mount counts between filesystem checks, the time between filesystem checks, the amount of reserved blocks, and other parameters.
  • umount(8) - Unmount a filesystem.

The fsck Program

Fsck is used to check and optionally repair a damaged file system. Exit codes when all filesystems are checked using the ľA option are:

  • 0 - No errors
  • 1 - File system errors corrected
  • 2 - System should be rebooted
  • 4 - File system errors left uncorrected
  • 8 - Operational error
  • 16 - Usage or syntax error
  • 128 - Shared library error.

Options:

  • -A Check all filesystems listed in /etc/fstab in one run
  • -C Display completeness progress bars
  • -N Don't execute, show what would be done
  • -R Skip the root filesystem when checking all root filesystems
  • -a Automatically repair the filesystem
  • -r Interactively repair the filesystem

This program is actually a front end for the file system checkers fsck.ext2, fsck.minix, and fsck.msdos.

The mount and umount Command

Used to mount a filesystem. This program is used to attach a filesystem on some device to the Unix directory tree. The "umount" command is used to detach the filesystem. The mount command supports the filesystems listed below. One command syntax is:

mount [-fnrsvw] [-t fstype] [-o options] device dir

Where the device is the name of the device being mounted and dir is the name of the directory the device will be mounted to (mount point).

Some options:

  • -a - Mount all filesystems listed in the /etc/fstab file.
  • -F - Forks a new mount thread for each device. This option is used with the -a option.
  • -f - Fakes the mount since it does everything except the call to perform the mount. This option works to add entries in the /etc/mtab file.
  • -n - Does a mount without writing into the /etc/fstab file. This is needed to mount filesystems read only.
  • -r - Mount the device in read only mode.
  • -w - Mount the device in read/write mode. This is the default setting for the mount command.
  • -L label - Mount the filesystem with the label indicated.
  • -U uid - Mount the filesystem with the user ID indicated.
  • -t fstype - This option tells the mount command what type of filesystem is being mounted. The types are listed below. It the -t option is not used or the type is specified as auto, the superblock of the device will be probed to determine the type of filesystem. If this fails, the files /etc/filesystems or /proc/filesystems will be read and all filesystems listed there will be tried except for proc and nfs.

The -o option allows additional options to be listed in the mount command. Some of these options are:

  • auto - Mount the device in the auto mode as described above.
  • defaults - Use the default options of rw, suid, dev,exec,auto, nouser, and async.
  • dev - Interpret block or character special devices
  • exec - Allow execution of executable files
  • nouser - Don't allow a normal user to mount the filesystem.
  • rw - Allow reading and writing to/from the device.
  • suid - Allow set user identifier and set group identifier bits to have an effect.

See the mount(8) man page for more information.

Filesystems supported by mount

  • adfs
  • affs
  • autofs
  • coda
  • devpts - Linux swap
  • ext2 - Linux native partition
  • hfs
  • hpfs
  • iso9660 - Filesystem used on CDROM disks.
  • msdos - DOS based filesystem, Also called FAT or FAT16.
  • nfs - Network file sharing
  • ntfs - Filesystem for Windows NT and Windows 2000
  • proc - The virtual filesystem Linux uses to store parameters in memory.
  • qnx4
  • romfs
  • smbfs
  • sysv - UNIX filesystem
  • ufs
  • umsdos
  • vfat - Enhanced 32 bit filesystem used for Windows 95 and Windows 98. Sometimes called FAT32.

Files

  • /etc/fstab - The filesystem table defining devices to be mounted when the system starts.
  • /etc/mtab - The mount table for mounted devices.
  • /proc/mounts - Contains similar information as /etc/mtab.
  • /etc/filesystems - Can be used to set the filesystem probe order when filesystems are mounted with the auto option. The nodev parameter is specified for filesystems that are not really locally mounted systems such as proc, devpts, and nfs systems.
  • /proc/filesystems - The file used to detect filesystems if the /etc/filesystems does not exist. An example:
    	ext2
    nodev	proc
    	iso9660
    nodev	autofs
    nodev	devpts
    	vfat
    nodev	ncpfs