Saturday, January 23, 2010

Discovering the wonders of fstab

I’ve recently had to format my Ubuntu partition because of a Kernel Panic. This happened when I hit the “suspend” button in Boxee. The OS freezed still (it didn’t suspend) and there was no way to resurrect it than resetting the system. When I rebooted the there came the Kernel Panic. During the brief unsuccessful efforts to fix the problem I checked the fstab file to see if Boxee did somehow mess with it. I did not know much about fstab so, now that my system is fresh again, I want to discuss the wonders of fstab, this tiny yet superimportant text file.
fstab stands for file system table and it’s basically a configuration file which gives the kernel all the necessary information to mount partitions (usually only the internal ones; external partitions like usb flash drives and similar are mounted via volume managers). Being a configuration file fstab is located under the /etc directory; to read it you can just locate and open it by the graphical interface, however only root can write to it so if you need to modify it you must access with su (super user) privileges.
Disclaimer: Critical system files in Linux can only be modified by ROOT and not by the user(s). The rationale behind this is to make the system more safe against security attacks and mishandling by users. Having said that, use super user privileges to access system files only if you fall into one of the following categories:
- You know exactly what you’re doing
- You’re in an experiment environment
- Your system is completely and –by your point of view- irrevocably compromised so you judge you have nothing to lose
To read-only your fstab gile in console type:
~$ cat /etc/fstab
To open the fstab file in write mode open a console and type:
~$ sudo gedit /etc/fstab
As I said before the information contained in fstab is plain text, organized in rows and columns and laid out as follows
[device] [mount point] [file system type] [options] [dump] [pass]


[device] > indicates the device or partition that contains the file system
Note for Ubuntu: Canonical’s distro now uses UUID (Universally Unique Identifier) by default to identify partitions. In order to listyour devices by UUID you can use ~$ sudo blkid

[file system types] > indicates the type of file system. On Ubuntu you will likely see ext3 or ext4 for the main partition where root resides. Depending on the type of partitions or devices in your computer you could encounter any of the following file system types:
  • ext2, ext3, ext4, reiserfs (don’t miss the macabre gossip related to this one http://en.wikipedia.org/wiki/Hans_Reiser), etc.
  • auto (commonly used for removable devices in order to try to detect the specific file system of the device)
  • vfat (identify FAT partitions)
  • ntfs (identify NTFS partitions)
  • udf,iso9660 (identify optical media -aka CD/DVD-)
  • swap (a hard disk partition where a page of memory is copied to free up that page of memory)
  • procfs (stands for process file system and it’s a pseudo file system (dynamically generated at boot) used to access process information from the kernel. The file system is often mounted at the /proc directory and occupies no storage space
[options] > there are several options which specify how the partition is handled and what can or cannot do. I’ll try to cover them briefly here and let you google for them if you need an in depth description.
  • auto / noauto specify if the partition has to be automatically mounted or not at boot or when mount –a command is executed. auto itself it’s almost useless because it’s the default behavior. noauto is more interesting as it blocks a partition to be mounted unless you manually mount it.
  • sync / async are for I/O to the file system and indicate whether it has to be done synchronously (at the same time a I/O operation is issued) or asyinchronously. The meaning of this gets more clear if you imagine to issue a command to execute data transfer to a floppy disk or rw optical media.
  • exec / noexec is meant either to allow or prevent execution of binaries within the partition. If you set you’re the partition where root dwells as noexec your system is screwed
  • dev / nodev interpret or not interpret character or block special devices on the file system
  • ro / rw is used to specify if the partition is read-only or read-write mounted
  • suid / nosuid allow or block operations of suid or sgid bits. Suid and sgid stand for set user id and set group id. When a suid or sgid file is executed, the process which runs it is granted access to system resources based on the user who owns the file and not the user who created the process.
  • user / nouser are used to specify the user related permissions to mount the file system. user means that all the users can mount the file system and by consequence of this the noexec, nosuid,nodev options are automatically implied. nouser means instead that only root can mount the file system and this is the default setting.
  • defaults uses the default settings which are rw, suid, dev, exec, auto, nouser, async.
  • _netdev is for a network device which has to be mounted after bringing up the network and it’s only valid for nfs (Network File System)
Note for Ubuntu: from the 8.04 release Ubuntu uses relatime as default for linux native file systems. This options replaces atime and it’s used to know when a file was last used. Read more about atime and relatime here.
[dump] > this field specifies if the backup utility dump is enabled -1- or not -0-. Dump is a application which backs up and restores file systems as a whole. This field is usually set to 0.
[pass] > this field is related to the fsck system utility. fsck, which stands for “file system check”, is a program which check the state of the file system. In case of a system crash or a forced shutdown fsck
should detect it and then proceed automatically or user guided to fix the damaged parts. The options are the following:
  • 0 -> don’t check
  • 1 -> check this partition first
  • 2 -> check this partition next

fsck checks the file system every 30 mount operations as default. It’s possible to modify this interval (mostly by using tune2fs)
Here belows my fstab file commented by the system. Try to read it and retrieve the various specifications and options described before. You will surely encounter elements not covered in my description of fstab – i.e. ‘sw’, ‘utf8’ ‘errors=remount-ro’, ecc..- as you possibly will by reading your own fstab. This is common because technologies are for their nature prone to rapid changes and, like systems, tends to accumulates details in times. We have caught a couple of them like relatime and UUID while for the few remaining others you can google them to find more information or issue the command ~$ man fstab in a terminal
# /etc/fstab: static file system information.
#
# Use 'vol_id --uuid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
proc /proc proc defaults 0 0
# / was on /dev/sda5 during installation
UUID=197ac49c-16f9-41a6-9c18-40e87231f4ba / ext3 relatime,errors=remount-ro 0 1
# swap was on /dev/sda6 during installation
UUID=84365e80-cbc7-495f-9e46-46a852bef3c2 none swap sw 0 0
/dev/scd0 /media/cdrom0 udf,iso9660 user,noauto,exec,utf8 0 0
/dev/fd0 /media/floppy0 auto rw,user,noauto,exec,utf8 0 0