Controlling Your Linux System With fstab
Understanding fstabThe /etc/fstab file gives you control over what filesystems are mounted at startup on your Linux system, including Windows partitions and network shares. You can also use it to control the mount points of removable storage devices like USB sticks and external hard disks. Akkana Peck shows us how.
/etc/fstab -- it's there on every Linux computer, controlling which filesystems get mounted where.
Its manual page, man fstab, begins with this snippet:
fstab is only read by programs, and not written; it is the duty of the system administrator to properly create and maintain this file.
Fortunately, they're fibbing. These days fstab is usually created for you by an installer or other program. So don't get too worried about your "duty".
However, if you want to delve into fstab, it's easy to understand and modify.
A typical fstab
The fstab file installed by most modern Linux distros looks a bit intimidating. Here's one from an Ubuntu system:
# /etc/fstab: static filesystem information. # # Use 'blkid -o value -s 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/sda6 during installation UUID=2ad9188b-9d1c-4102-bf24-4b5ad456a701 / ext3 errors=remount-ro 0 1 # /boot was on /dev/sda1 during installation UUID=3943c247-16e9-405b-9fda-87684b02cc4e /boot ext2 defaults 0 2 # swap was on /dev/sda7 during installation UUID=15825096-aef7-41d6-b53a-c86aec2ebde8 none swap sw 0 0 /dev/scd0 /media/cdrom0 udf,iso9660 user,noauto,exec,utf8 0 0
Bummer about none of those columns being lined up! Figure 1 shows the meanings of the columns.
Devices and UUIDs
Let's start with the device: UUID=2ad9188b-9d1c-4102-bf24-4b5ad456a701. What does that mean?
In the old days, the device field of fstab was much simpler, typically something like /dev/hda3 for the third partition on the first IDE disk.
But systems got more complicated. USB and SATA disks both use the sd disk driver, originally written for SCSI. But you can't always predict their order. If you have several SATA and USB disks, or if you frequently add and remove drives, you might find that your root filesystem appears on sda2 one day and sdc2 the next.
To get around this confusion, fstab can use a "Universally Unique IDentifier" that identifies each filesystem.
How do you find out which disk partition maps to which UUID? You might have noticed some comments in fstab:
# / was on /dev/sda6 during installation UUID=2ad9188b-9d1c-4102-bf24-4b5ad456a701 / ext3 errors=remount-ro 0 1
Don't trust those comments. Your / may have been on sda6 once, but that doesn't mean it's there now.
It's safer to check the current value with the blkid command:
$ blkid /dev/sda1: UUID="702be669-1Aee-4128-8c57-60b58bc91f59" TYPE="ext2" /dev/sda3: UUID="615aaed5-0dba-4204-9717-c9a00ff411ea" SEC_TYPE="ext2" TYPE="ext3" /dev/sda5: UUID="0c5121ff-331a-4ae2-b8be-e0b10bcae62f" SEC_TYPE="ext2" TYPE="ext3" /dev/sda6: UUID="d2a1e4aa-6589-4846-ba58-107d32a25375" SEC_TYPE="ext2" TYPE="ext3" /dev/sda7: UUID="1533cdc3-635f-4552-818b-1fadce9ea7f8" SEC_TYPE="ext2" TYPE="ext3" /dev/sda8: UUID="b24fd645-7c28-431b-883d-0a6cf03340ed" SEC_TYPE="ext2" TYPE="ext3" /dev/sda9: TYPE="swap" $ blkid -o value -s UUID /dev/sda8 b24fd645-7c28-431b-883d-0a6cf03340ed
You can also use /dev/disk/by-uuid:
$ ls -l /dev/disk/by-uuid lrwxrwxrwx 1 root root 10 2010-04-18 09:06 0c5121ff-331a-4ae2-b8be-e0b10bcae62f -> ../../sda5 lrwxrwxrwx 1 root root 10 2010-04-18 09:06 615aaed5-0dba-4204-9717-c9a00ff411ea -> ../../sda3 lrwxrwxrwx 1 root root 10 2010-04-18 09:06 1533cdc3-635f-4552-818b-1fadce9ea7f8 -> ../../sda7 lrwxrwxrwx 1 root root 10 2010-04-18 09:06 b24fd645-7c28-431b-883d-0a6cf03340ed -> ../../sda8 lrwxrwxrwx 1 root root 10 2010-04-18 09:06 ca8ec122-33c7-4765-bd65-78a15c58def3 -> ../../sda2 lrwxrwxrwx 1 root root 10 2010-04-18 09:06 d2a1e4aa-6589-4846-ba58-107d32a25375 -> ../../sda6 lrwxrwxrwx 1 root root 10 2010-04-18 09:06 702be669-1Aee-4128-8c57-60b58bc91f59 -> ../../sda1
Some distros, instead of using UUIDs, attach a label to each filesystem:
LABEL=/ / ext3 defaults 1 1
This is much easier to read, but can get confusing. If you install several Linux releases on different partitions, you could end up with several partitions that have the same label. Then how do you tell which one gets mounted?
Confused by all these UUIDs and labels? You don't have to use them. If you have a simple setup with just one disk, the simple syntax still works:
/dev/sda6 / ext3 errors=remount-ro 0 1
Solid state disks (SSDs) made a splash in consumer technology, and now the technology has its eyes on the enterprise storage market. Download this eBook to see what SSDs can do for your infrastructure and review the pros and cons of this potentially game-changing storage technology.