If you use linux and have never come across this statement (or just realized this in the course of working with the OS), then let me be the first to tell you this critical truth…

Everything is a bloody file.”

While this holistic statement isn’t quite 100% true, it’s close enough that if you adopt it as your life verse and it becomes your “modus operandi” for working in Linux, you will go farther faster.

It is so ubiquitous there is a wikipedia page devoted to it.

This opens up some novel concepts… for example, because everything is represented by a file, it means almost anything can be easily scripted… hence part of the fun of Linux…

For all of you out there like me who came from the Windows world, “Everything is a File” can also be a keen point of frustration if no one has ever made this statement to you and explained some of the implications. I have done my service and made the statement, I will leave it up to you to research and discover the implications. Go forth and research and then come back and keep reading.

Now, I am going to move on and start my first article in the new “Everything is a File” series in which I am going to attempt to tackle some of the most common files found on Debian Linux variants and explain their usage. To kick things off, I am going to document a file that I have to look up commonly; FSTAB. (the whole point of my blog is to create a place that I can just search my own notes rather than Googling (and re-Googling 6 months later) for other peoples’ notes)



Linux File System / Storage Device Naming System
Before I can jump into discussing the FSTAB file though I am going to rabbit-trail briefly on how linux organizes its file system. I will do this as a list of statements… This is coming from a native Windows Admin’s perspective so Linux gurus forgive me if I make a hash of it… Much of this information was stolen from here: https://askubuntu.com/questions/56929/what-is-the-linux-drive-naming-scheme

  1. Linux does NOT use drive letters. Forget C:, and D:, and the rest of the alphabet
  2. Linux refers to physical storage devices using a common nomenclature…
    • sd = SATA/SCSI Disk – (Most common, used for USB Thumb drives as well…)
    • hd = IDE Disk
    • fd = Floppy Disk
  3. It appends a letter for each storage device after type… i.e.
    • sda = The FIRST, SATA/SCSI Disk in the system
    • sdb = The SECOND, SATA/SCSI Disk in the system
    • sdc = The THIRD, SATA/SCSI Disk in the system…
  4. Finally, it appends a number for each partition on each storage device… i.e.
    • sda1 = The FIRST partition on the FIRST SATA/SCSI Disk in the system
    • sda2 = The SECOND partition on the FIRST SATA/SCSI Disk in the system
    • sdc5 = The FIFTH partition, on the THIRD SATA/SCSI Disk in the system…
  5. Because everything is a file, your hardware storage device will be represented by… you guessed it… a file, located in the /dev/ directory. Hence you will reference /dev/sdc2 for the SECOND partition on the THIRD SATA storage device
  6. You only need to care about “sda5” and “hdb2” when formatting and setting up disks… what you really care about is the “mount point.” And herein lies the last statement… Linux does not use drive letters.
  7. Which means you can MOUNT the partition on sda1 (or any other partition) as your root file system… “which is indicated by a forwards slash ‘/’ and you can mount sdb2 somewhere else like “/users/kiloroot/mydata”
  8. What that means is that instead of using a drive letter… like “D:” for a secondary data drive, you specify a “mount point” and anything you place therein goes on that device and partition

Some common commands you can use to figure out “what is what”:

sudo fdisk -l

and… (my favorite because the output is easy to read and to the point)

lsblk

and…

sudo parted -l

and… (I frequently use this to see how much free space I have on my disks/partitions)

df -ha

and finally… (this gives you the universally unique identifier for each device)

ls -lha /dev/disk/by-uuid

I would encourage you to try out the above commands, examine the output, and get really comfortable identifying disks and “thinking Linux” – especially if you are used to the Microsoft world which does a great deal more hand-holding…


What is FSTAB?
Now that we have laid some very loose groundwork, let me talk about the FSTAB configuration file. When you plug a USB drive into your windows laptop, Microsoft generally does a kind thing on your behalf and just automatically mounts the thing (assuming it is formatted) and assigns a drive letter.

Depending on your Linux variant (Ubuntu for example), much the same thing will occur, the difference being (based on the groundwork laid above) that the OS will create a “Mount Point” off of root (‘/’) for you, i.e. something like

/media/username/SoMeDeVicEiDeNtIfiEr

Auto-mounting in linux variants like Ubuntu is quick, dirty, and handy… however it isn’t always desirable, especially for “fixed” disks. This came up recently when I was working with PLEX (a media streaming server app) and all of my media was stored on a secondary disk I popped into my system. I started out using the auto-mount method in Ubuntu but quickly ran into issues. What I needed was for this disk to always be mounted right at startup and for that I needed FSTAB.

FSTAB is a file located in the /etc/ directory. The /etc/ directory is a default location of sorts for configuration files for… 95% of things (Okay, so I made that up on the spot but my experience indicates it’s generally true). The FSTAB file defines a list of file systems (i.e. a formatted device partition… sdb3) and their mount points (one “device + mount point” per line). Anything in FSTAB gets mounted at startup.

An FSTAB entry follows this format:

<file system> <mount point> <type> <options> <dump> <pass>

Here is an example of an FSTAB entry using the UUID of a storage device/partition:

UUID=f92lkbi3-yadayada-yadayada-18bk4lkmn /boot ext4 noatime,errors=remount-ro 0 0

The last command I provided in the previous section can give you the UUID for each of your device partitions. The example entry is using the UUID of the device partition followed by the mount location (/boot), followed by the filesystem type (ext4), followed by some options (noatime,errors=remount-ro), the DUMP field (0) I am not going to discuss other than to state that I believe in 99% of modern use cases this will be set to zero, and finally the PASS field has to do with what order file system checks are performed. My root file system and /boot are both set to 0 on all of my systems, any other mounted devices should be 1 or higher. Let’s give a simpler example…

Here is an example of an FSTAB entry for a secondary data drive with one partition using the sdxx identifier…

/dev/sdb1 /home/username/datadrive ext4 defaults 0 1

This mounts the FIRST partition on the SECOND SATA drive in my system (/dev/sdb1) at the mount point of /home/username/datadrive and indicates that it is using an EXT4 filesystem (ext4) with the default options (defaults) with a zero (0) for DUMP, and lower priority/order number for file system checks (1).

Adding this to my FSTAB file as a new line and then rebooting my system resulted in a mount point being created at /home/username/datadrive for my new SATA Disk Drive (which I can now use like any other folder after setting permissions).

Once this is added and shows up then I jumped into a terminal to set ownership and permissions

sudo chown root:username /home/username/datadrive
sudo chmod -R 775 /home/username/datadrive



Finito
This article was longer than I intended but by no means exhaustive… But it should be enough to give you an idea of how to use the FSTAB file and get your hard drive mounted so you can use it. Granted, I didn’t talk about formatting your drive which would be a first step for using a brand new hard drive… but that is another article.


References:

1 of 1

This post has no comments. Be the first to leave one!

Join the discussion

Your email address will not be published. Required fields are marked *