Meaning of <file system> when using fstab

Asellus

Honorable
Oct 25, 2013
21
0
10,510
Hi there,

I'm trying to automatically mount a disk at boot, using fstab. But for every tutorial I find, they seem to use a new string in the first column, which is the <file system> column (as far as I can figure out).
One that seems to work would be /dev/sda1 (for example), but here comes the next problem. Because commands like fdisk, lshw -class disk and fs, all gives different indications of the /dev/[hdname], so how do I know which to use? I could of course just try to reboot until it works, but at this is a rather critical server, I would prefer to minimize downtime. So I really hope you guys can help. Currently I'm using the following line in fstab:

Code:
Data   /media/Data   ext4   defaults   0   0

Is this even remotely correct? And if not, what should change?
 
Solution
You can get both /dev/sd?? label and UUID from sudo blkid. You can use either the /dev/sd?? label or the UUID but UUID is preferred because it will never change (for example, if you switch your cables around). If you use the UUID method, replace /dev/sd?? with UUID=12345678910. So the correct fstab would be:

UUID=1245678910 /media/data ext4 defaults 0 2

Just because the disk is mounting manually does not mean you have the correct file system type. Linux will mount all sorts of file systems. To get fstab correct you need to do sudo blkid to confirm you have the correct file type. If the HDD was pre-formatted it most likely is NOT ext4, because that is a Linux format. The only way it would be ext4 is if you formatted it yourself.
In your example the "file system" is ext4

What filesystem was created on "Data"?

If you will not know what file system will be mounted beforehand you can always use "auto" and let mount figure it out. However, mount can guess wrong and fail to mount the volume.

First column = What you want to mount. Could be a UUID, /dev/xxx, or other unique identifier.

Second column = Where you want to mount it. Be aware that what you mount here will overlay anything that may already exist that that point, rendering it inaccessible until you unmount.

Third column = What file system is on the volume being mounted.
 
The easiest way to do it is to put the device name in the first column. This will be /dev/sd??, where the two question marks are replaced with the appropriate letter and number. So the question is, what is the device you are trying to mount. Is it on the only hard disk, the second hard disk, or where? And which partition on that device is it? To help, have a look at what is already mounted; using just the "mount" command will tell you that. And have a look at the available devices; "ls /dev/sd??" will tell you that.

Then make the entry in fstab and test it. You don't need to reboot to do this. The command "mount /media/Data" will do the mount if your entry is correct. If not, try again. But the first step is to understand which device the filesystem resides on.
 

Aristotelian

Distinguished
Jun 21, 2012
579
0
19,160
Just to clarify...ext4 is correct if that is the file system of the drive you are trying to mount. Other options are ext3, vfat, etc. You can find the filesystem types, the location (dev/sd??), and UUID by typing in terminal:

sudo blkid

Also for the options at the end, for a data drive the recommendation is usually "defaults 0 2". The 2 ensures that it is one of the last drives to mount.

Following exbubble's instructions, the correct entry for /dev/sdb1 formatted as ext4 would be:

/dev/sdb1 /media/Data ext4 defaults 0 2

Note that you will need to create a folder within /media called "Data" prior to reboot.
 

I think you have a Catch-22 there. "blkid" only lists those details for mounted filesystems. The problem here seems to be in finding the correct details to mount the filesystem in the first place.
 

Aristotelian

Distinguished
Jun 21, 2012
579
0
19,160


No, blkid will work. When a drive is unmounted it is still detected by the system and blkid gives you all the essential info to edit fstab. I have used it hundreds of times.

 
Yes blkid directly detects block devices. In particular:
Code:
       When  device  is specified, tokens from only this device are displayed.
       It is possible to specify multiple  device  arguments  on  the  command
       line.   If  none is given, all devices which appear in /proc/partitions
       are shown, if they are recognized.
 

Asellus

Honorable
Oct 25, 2013
21
0
10,510


I thought the first column was called "file system" and was something like the dev/sd?? where the thing you are talking about (as I understand it) is what is called "fs type" in fstab?


Also, I'm pretty sure the correct "fs type" (or whatever it is called) is ext4. The disk has currently been mounted using the GUI, so it is possible to access it. I just need this process automated.

Finally, as mentioned, I have some issues figuring out what /dev/sd?? name the disk has. Different commands, seems to give different answers. Which one would be the correct?
 
you can use command "sudo parted -l" to see what disk has been assigned to a specific label /dev/sdX.
unfortunately the assignment is not guaranteed to be the same next time you reboot.
for this reason you should use UUID in your fstab and not /dev/sdX
 

Aristotelian

Distinguished
Jun 21, 2012
579
0
19,160
You can get both /dev/sd?? label and UUID from sudo blkid. You can use either the /dev/sd?? label or the UUID but UUID is preferred because it will never change (for example, if you switch your cables around). If you use the UUID method, replace /dev/sd?? with UUID=12345678910. So the correct fstab would be:

UUID=1245678910 /media/data ext4 defaults 0 2

Just because the disk is mounting manually does not mean you have the correct file system type. Linux will mount all sorts of file systems. To get fstab correct you need to do sudo blkid to confirm you have the correct file type. If the HDD was pre-formatted it most likely is NOT ext4, because that is a Linux format. The only way it would be ext4 is if you formatted it yourself.
 
Solution

Asellus

Honorable
Oct 25, 2013
21
0
10,510


Thanks for the hint, that might ease the testing a bit. However, the drive must be available at all time (as far as possible), so re-mounting is not possible right now.