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. ๐๐
About this post
- Posted
- Archived
- Score
- 74 ยท 94% up
- Kind
- Text
- ID
- gd79ca
51 comments
Yeah,
fstabis 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 addnofailmount option, so that if you ever remove the drive or the partitions turn unmountable/missing or something, the system will still start up normally.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.
As far as I know,
systemd-mountby default just usesfstabto 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
udisksprovides daemonudisksd, 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 tofstabandsystemd-mountwhich 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.
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.
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.
K
aight
I needed this info thanks
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
https://www.freedesktop.org/software/systemd/man/systemd.mount.html#fstab
systemd themselves prefer fstab
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.
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?
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 issuemount /dev/sdxcommand 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
nofailAh 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!
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:
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?
My guess is that the wireless connection is not up when the filesystems get mounted.
Yeah that makes sense... How would I rectify this issue?
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=30minNote the idle-timeout on the end, perfect for spinning down your mechanical drives when not in use.
Another question: what's the difference between
autoandnoauto,x-systemd.automount?'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.
Nice, thanks for that example line!
Although I'm wondering about the idle timeout option: the documentation says this:
Are you sure that's what we want? Will it re-mount when a program attempts to access the drive?
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.
Deleted before we saved it.
I use fstab but instead of UUIDs I use partition labels. (LABEL=[...] in fstab)
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!
Deleted before we saved it.
There is no comparison between them. all of them should do the work correctly.
I'm sorry, I don't follow you here. No comparison? Are you saying they all have the same features to accomplish this?
r/emojipolice
You really feel that this qualifies? Yeesh.
He just kidding, yo!
Just the mandatory comment ;)
Never heard of r/emojipolice. I looked at the feed and it made my day ;)
Use Disk GUI application it makes your work easy .
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?