Skip to content

Mounting internal hard drives: fstab? udev? systemd-mount?

Hey good folk! Question! ๐Ÿ™‚

I have two hard disk drives. One 4 TB and one 2 TB. I want to mount them both automatically on boot.

The way I've always done this is using UUIDs and fstab. But is there a more modern, perhaps Arch-specific or systemd-specific idiomatic way of doing this? Perhaps using systemd-mount, udisks, or writing udev rules? I get the feeling the purpose of messing with udev is for media that may come and go while the system is running, whereas these are internal drives meant to always stay in place.

I find that the wiki doesn't really take a stance on this in my opinion. And maybe there is no stance regarding this scenario (only fstab is the true alternative? ๐Ÿคทโ€โ™‚๏ธ).

I would really appreciate some help on this. ๐Ÿ™‚๐Ÿ™

74 points47 comments
Open on Reddit
About this post
Posted
Archived
Score
74 ยท 94% up
Kind
Text
ID
gd79ca

Author

11
posts
1.1k
comments
2
media
View profile

51 comments

Yeah, fstab is the old but gold stable recommended approach that seems to work for everyone who uses it. One random suggestion though, for all partitions on the "secondary" drive (or, really, all unimportant partitions), you can add nofail mount option, so that if you ever remove the drive or the partitions turn unmountable/missing or something, the system will still start up normally.

65 points

Cool, good advice! Thanks!

So if fstab is the preferred way, what is the actual utility/purpose of udisks and systemd-mount, respectively? I don't think I get that.

14 points

As far as I know, systemd-mount by default just uses fstab to generate mount units. However, you can also use it to do some more granular mounting parameters, like "mount this partition only after this service has started, and give 5 seconds to the mounting process otherwise abort, and as this partition is mounted start this service".

In other words, it allows you to manage mounting actions as other systemd units. In most cases that kind of refining isn't needed though, so unless you know you need it you can just stick to fstab.

And udisks provides daemon udisksd, which is used to dynamically manage storage devices that can appear and disappear while the system is fully running, aswell as perform operations on demand of applications (in contrast to fstab and systemd-mount which are used to mount partitions before the system is fully up or depending on services).

You may need udisks to allow your file manager to show up USB/SD/CD/DVD media in the panel on the left, aswell as allow it to mount and unmount them as you click on them.

21 points

nofail

Also, I suggest chattr to make the directory unwriteable if it isn't mounted:

https://serverfault.com/questions/570255/prevent-the-possiblity-of-writing-data-to-an-unmounted-mount-point-directory

If you were to write something to an unmounted mount-point, you can't mount anything there until you clean it up.

4 points

In my experience you can still mount like that (actually just tried, works fine), obscuring the original files from the filesystem, but I don't know about how systemd mounts them.

4 points

Hey just wanted to apologize i definitely pocket k'd you at work today. Just now getting time to read the post. I work in a warehouse and move around a lot and have notifications turned on for archlinux. Now that I'm reading it though it sounds like a really practical idea

1 points
unknown author1 hidden

systemd auto-generates mounts from fstab already. I think making mount files is pretty simple and clean but for most usage won't be meaningfully different.

10 points

Okay, so what you mean is that the process which is doing the reading of /etc/fstab and performing the mounting is actually already systemd (or one or some its sub-tools)? Have I gotten that right?

1 points

I use UUID's (genfstab -U) to set up for the partitions I mount during the pre-install stage. For all my other volumes, i just use their /dev/sdx designations when I go to edit the fstab to add them. I liek the convenience of being able to just issue

mount /dev/sdx

command and letting fstab do the rest. it will only work if there is a valid entry for /dev/sdx in the fastab. Edit: +1 on nofail

3 points

Ah okay. Well, these drives must definitely not be confused with one another, as there are server daemons relying on correct files being the correct place. So files under /dev could be unreliable if I'm not mistaken. Also I won't ever mount it manually under normal circumstances.

Otherwise that's a convenient tip, and I thank you for it!

2 points

/dev could be unreliable if I'm not mistaken

you're a little bit mistaken. I used to do them ALL with UUID under the impression that it was "more reliable." It turns out the reliability is a function of the mount point being mapped to a specific device UUID not a generic dev/sdx . Thats important for partitions needed to run the OS, obviously, but less so for other volumes. It's dangerous only if there's any chance that the drives connected to those ports will ever get changed w/o their entries in fstab as being changed as well. lets say you have /dev/sdb mounted to ~/Videos and /dev/sdc mounted to ~/Music. If for some weird reason, someone came along and swapped the drives themselves but didn't switch the fstab entry. Well, it'll suck because your videos will end up switched with your music when the drives mount from the fstab. Annoying, yes. But not super serious. If however, you did that with your / and /boot and mapped those to a device /dev/something instead of UUID.. that would be problematic in a serious way. Here's mine:

# <file system> <dir> <type> <options> <dump> <pass>
# /dev/sda3
UUID=2565b31a-93dc-4e92-8269-b01462a591d5 /    ext4 rw,relatime 0 1

# /dev/sda4
UUID=26fb42e9-a571-47de-8813-a0f23f62a735 /boot ext4 rw,relatime,stripe=4    0 2

# /dev/sda5
UUID=01fe6fdf-0cc1-49d2-a728-876cd8ca00ee /home ext4 rw,relatime 0 2

# /dev/sda2
UUID=0978721c-1aa1-44fd-8197-b78fd2e525aa  none swap defaults   0 0

## MY SHIT
/dev/sdd3  /home/lucifer/.storage       ext4  rw,relatime     0 2
/dev/sdb1  /home/lucifer/Games          ext4  rw,relatime     0 2
/dev/sdc1  /home/lucifer/Windows        ext4  rw,relatime     0 2
/dev/sdd1  /home/lucifer/Videos/Cinema  ext4  rw,relatime     0 2
/dev/sdd2  /home/lucifer/Videos/TV      ext4  rw,relatime     0 2
1 points

Just out of curiosity, I have 4 NFS shares that I have listed in fstab, but they only ever mount when the machine is on a wired connection... Fails every time on wireless... Has anyone experienced this?

3 points

My guess is that the wireless connection is not up when the filesystems get mounted.

1 points

I use/prefer systemd-mountd. I have an NTFS formatted USB drive that I like to share between Windows and Linux, so I do something like this in /etc/fstab:

UUID=1ec29cbd-ae2b-4257-924d-2059a905f2ac /mnt/usbdrive ntfs-3g users,noauto,uid=someuser,gid=somegroup,x-systemd.automount,x-systemd.idle-timeout=30min

Note the idle-timeout on the end, perfect for spinning down your mechanical drives when not in use.

2 points

Another question: what's the difference between auto and noauto,x-systemd.automount?

3 points

'auto' declares that you want to mount the drive at boot time. 'noauto' says not to mount at boot time, where systemd/automount takes care of automatically mounting the drive on access.

2 points

Nice, thanks for that example line!

Although I'm wondering about the idle timeout option: the documentation says this:

Once the mount has been idle for the specified time, systemd will attempt to unmount.

Are you sure that's what we want? Will it re-mount when a program attempts to access the drive?

2 points

Yes, automount will remount the drive whenever anyone tries to access it. It also won't cause any boot-time delay or hang if the external drive isn't ready yet. Mechanical drives sometimes take several seconds to wake from sleep mode, so you'll notice a pause when someone tries to access it and the drive has to spin back up and remount. Regardless, it works flawlessly and increases the lifespan of mechanical drives since they aren't up and spinning 24/7.

1 points
unknown author

Deleted before we saved it.

1 points

I use fstab but instead of UUIDs I use partition labels. (LABEL=[...] in fstab)

2 points

I guess that would be equally robust in my case. I'll keep the UUIDs though since it's already set up now. ๐Ÿ™‚ Thanks for the tip!

1 points
unknown author

Deleted before we saved it.

1 points

There is no comparison between them. all of them should do the work correctly.

0 points

I'm sorry, I don't follow you here. No comparison? Are you saying they all have the same features to accomplish this?

0 points

Use Disk GUI application it makes your work easy .

-14 points

What does that help me with if I'm already proficient with the command line? Just curious. This isn't going to me my "work", I expect this to be a one-time setup.

Also what package is that, specifically?

3 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

โ†orโ†’
Previous / next file
โ†‘orโ†“
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.