Fstab

From 太極
Jump to navigation Jump to search
  • man fstab, man mount
  • https://help.ubuntu.com/community/Fstab
    • Format: [Device] [Mount Point] [File System Type] [Options] [Dump] [Pass]
    • Example: /dev/sdb1 /mnt/external vfat defaults 0 0
    • <File System Type>: ext2, ext3, ext4, msdos, vfat (for FAT32), ntfs, minix, hfs, xfs
    • <dump> Enable or disable backing up of the device/partition (the command dump). This field is usually set to 0, which disables it.
    • <pass> Controls the order in which fsck checks the device/partition for errors at boot time. A value of 0 means that the file system should not be checked by fsck. A value of 1 means that the file system should be checked first (like the "/" root file system), and a value of 2 or higher means that the file system should be checked after all file systems with a lower value have been checked. PS. However, running fsck on a file system can take some time, especially if the file system is large or contains a lot of data. This can increase the time it takes for your system to boot. If you are using an external drive for temporary storage or if you don’t mind waiting a bit longer for your system to boot, you may want to set the last field to 2. Otherwise, you may want to leave it set to 0 to skip the fsck check and speed up the boot process.
  • What Are UUIDs and Why Are They Useful
  • https://wiki.archlinux.org/title/Fstab
    • Noatime: – Do not update the file access times on the file system. This can help performance on old hardware.
    • Relatime: Update file access times relative to the file modified time.
    • nofail: Devices that are listed and not present will result in an error unless the nofail option is used.
  • External storage configuration from raspberrypi.org.
    UUID=5C24-1453 /mnt/mydisk fstype defaults,auto,users,rw,nofail 0 0
    UUID=5C24-1453 /mnt/mydisk ext4   defaults,noatime,nofail 0 2
    
  • https://wiki.archlinux.org/index.php/Fstab
    • Devices that are listed and not present will result in an error unless the nofail option is used. (good for external devices)
  • https://help.ubuntu.com/community/UsingUUID
  • Mount /tmp securely
  • http://www.thegeekstuff.com/2013/01/mount-umount-examples/
  • Graphical method using Disks
  • http://www.instructables.com/id/Using-a-USB-external-hard-drive-with-your-Raspberr/?ALLSTEPS Use UUID instead of /dev/sdXY to specify the partition in /etc/fstab to avoid any changes with /dev/sdXY. The UUID can be obtained using
    $ sudo blkid  #  list devices even not mounted yet
    

    and the result should be compared with

    $ sudo fdisk -l
    
  • Run sudo mount -a to remount /etc/fstab without reboot, except the partitions with noauto option. The following example shows a problem (as found from the output of df command) with </etc/fstab> where we use /dev/sdXY instead of UUID for specifying hard disks.
    $ sudo blkid
    /dev/sda1: LABEL="WD640" UUID="d3a0a512-bf96-4199-9674-f410f22f0a92" TYPE="ext4"
    /dev/sdb1: UUID="afaa4bde-1172-4c54-8b0a-a324ad855355" TYPE="ext4"
    /dev/sdb5: UUID="fb2a4ada-d80a-4e23-b4a2-67376b8b7e72" TYPE="swap"
    
    $ sudo fdisk -l
    Disk /dev/sda: 640.1 GB, 640135028736 bytes
    ...
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1            2048  1250263039   625130496   83  Linux
    
    Disk /dev/sdb: 640.1 GB, 640135028736 bytes
    ...
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1   *        2048  1217761279   608879616   83  Linux
    /dev/sdb2      1217763326  1250263039    16249857    5  Extended
    /dev/sdb5      1217763328  1250263039    16249856   82  Linux swap / Solaris
    
    $ cat /etc/fstab
    proc            /proc                                 proc    nodev,noexec,nosuid 0 0
    UUID=afaa4bde-1172-4c54-8b0a-a324ad855355 /           ext4    errors=remount-ro   0 1
    UUID=fb2a4ada-d80a-4e23-b4a2-67376b8b7e72 none        swap    sw                  0 0
    /dev/sdb1       /mnt/WD640                            ext4    rw,nosuid,nodev     0 2
    UUID=fb2a4ada-d80a-4e23-b4a2-67376b8b7e70 /mnt/extUSB auto nosuid,nodev,nofail 0 2
    UUID=2ab36808-038a-4dfa-ad52-c10944cf61f2 /mnt/hdd  ext4  defaults  0  2
    
    $ df -h
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/sdb1       572G  413G  130G  77% /
    ...
    /dev/sdb1       572G  413G  130G  77% /mnt/WD640
    

    To fix the error here, modify the line starting /dev/sdb1 in /etc/fstab and replace it with the UUID. Then run sudo umount /mnt/WD640 and sudo mount -a. Done!

  • Use defaults,ro if we don't want everyone to have the write access to a volume.
  • sudo mount /mnt/WD640 (no need to specify UUID, ...) will automatically mount a device according to the file /etc/fstab