Understanding /etc/fstab
From Initq
fstab is a configuration file that contains information of all the partitions and storage devices in your computer. The file is located under /etc, so the full path to this file is /etc/fstab.
/etc/fstab contains information of where your partitions and storage devices should be mounted and how. If you can't access your Windows partition from Linux, aren't able to mount your CD or write to your floppy as a normal user, or have problems with your CD-RW, you probably have a misconfigured /etc/fstab file. So, you can usually fix your mounting problems by editing your fstab file.
/etc/fstab is just a plain text file, so you can open and edit it with any text editor you're familiar with. However, note that you must have the root privileges before editing fstab. So, in order to edit the file, you must either log in as root or use the su command to become root.
Contents |
/etc/fstab file
/dev/hda2 / ext2 defaults 1 1 /dev/hdb1 /home ext2 defaults 1 2 /dev/cdrom /media/cdrom auto ro,noauto,user,exec 0 0 /dev/fd0 /media/floppy auto rw,noauto,user,sync 0 0 proc /proc proc defaults 0 0 /dev/hda1 swap swap pri=42 0 0
1st and 2nd columns: Device and default mount point
3rd column: Filesystem type
4th column: Mount options
5th and 6th columns: Dump and fsck options
Command line examples
UUID mount point
Mount with device path has problems when you have multiple hard disk, and the order of hard disk changed may cause the file system failed to mount. Therefore later days of fstab entries has been modified to identify by uuid, UUID stands for Universally Unique Identifier, it gives each filesystem a unique identifier. With uuid, you no need to worry about the reordering of hard disk anymore.
root@initq:~# ls -la /dev/disk/ total 0 drwxr-xr-x 5 root root 100 2011-10-14 20:33 . drwxr-xr-x 16 root root 4440 2011-10-15 08:34 .. drwxr-xr-x 2 root root 120 2011-10-14 20:33 by-id drwxr-xr-x 2 root root 160 2011-10-14 20:33 by-path drwxr-xr-x 2 root root 80 2011-10-14 20:33 by-uuid root@initq:~# ls -la /dev/disk/by-path/ total 0 drwxr-xr-x 2 root root 160 2011-10-14 20:33 . drwxr-xr-x 5 root root 100 2011-10-14 20:33 .. lrwxrwxrwx 1 root root 9 2011-10-14 20:34 pci-0000:00:11.0-scsi-1:0:0:0 -> ../../sr0 lrwxrwxrwx 1 root root 9 2011-10-14 20:34 pci-0000:00:14.1-scsi-0:0:1:0 -> ../../sda lrwxrwxrwx 1 root root 9 2011-10-14 20:34 pci-0000:03:06.0-scsi-0:0:0:0 -> ../../sdb lrwxrwxrwx 1 root root 10 2011-10-14 20:34 pci-0000:03:06.0-scsi-0:0:0:0-part1 -> ../../sdb1 lrwxrwxrwx 1 root root 10 2011-10-14 20:34 pci-0000:03:06.0-scsi-0:0:0:0-part2 -> ../../sdb2 lrwxrwxrwx 1 root root 10 2011-10-14 20:34 pci-0000:03:06.0-scsi-0:0:0:0-part5 -> ../../sdb5 root@initq:~# ls -la /dev/disk/by-uuid/ total 0 drwxr-xr-x 2 root root 80 2011-10-14 20:33 . drwxr-xr-x 5 root root 100 2011-10-14 20:33 .. lrwxrwxrwx 1 root root 10 2011-10-14 20:34 48533b64-9f4d-4552-8e8e-7586314bac26 -> ../../sdb1 lrwxrwxrwx 1 root root 10 2011-10-14 20:34 d9f85a07-1bd3-492f-95d5-df2725de0a3f -> ../../sdb5 root@initq:~# ls -la /dev/disk/by-id/ total 0 drwxr-xr-x 2 root root 120 2011-10-14 20:33 . drwxr-xr-x 5 root root 100 2011-10-14 20:33 .. lrwxrwxrwx 1 root root 9 2011-10-14 20:34 ata-ST32000542AS_6XW032LS -> ../../sda lrwxrwxrwx 1 root root 9 2011-10-14 20:34 ata-TSSTcorp_CDDVDW_SH-S243N_0Qy3456789NLMNOP -> ../../sr0 lrwxrwxrwx 1 root root 9 2011-10-14 20:34 scsi-SATA_ST32000542AS_6XW032LS -> ../../sda lrwxrwxrwx 1 root root 9 2011-10-14 20:34 wwn-0x5000c50016330a40 -> ../../sda
You can also get the numbers with blkid utility. You can only run this as root.
[root@localhost ~]# blkid /dev/sda1: UUID="4e44b000-9e1e-45e7-b43f-02ae3293072b" TYPE="ext4" /dev/sda2: UUID="p3dxUz-ZaAT-B61N-0sXZ-Xtq6-uCp2-QvNoxM" TYPE="LVM2_member" /dev/mapper/VolGroup-lv_root: UUID="7dd04d07-6812-4e2e-8a9d-5678031218a9" TYPE="ext4" /dev/mapper/VolGroup-lv_swap: UUID="14fde53a-9431-4e1f-8027-225b9d164e2c" TYPE="swap" [root@localhost ~]# blkid /dev/sda1 /dev/sda1: UUID="4e44b000-9e1e-45e7-b43f-02ae3293072b" TYPE="ext4"