{"id":542,"date":"2012-12-03T12:20:19","date_gmt":"2012-12-03T12:20:19","guid":{"rendered":"http:\/\/www.wrigley.me.uk\/wp\/?p=542"},"modified":"2012-12-03T12:20:19","modified_gmt":"2012-12-03T12:20:19","slug":"automounting-usb-disk-on-boot-with-systemd-in-fedora","status":"publish","type":"post","link":"https:\/\/www.wrigley.me.uk\/2012\/12\/automounting-usb-disk-on-boot-with-systemd-in-fedora\/","title":{"rendered":"Automounting USB disk on boot with systemd in Fedora"},"content":{"rendered":"

I had a requirement to boot a USB disk (a Hitachi SimpleDrive) on a machine I rarely log into via the GUI. In the good old days, I’d hack up a udev script to do it.<\/p>\n

In Fedora, with the advent of systemd, I googled and quickly became horribly confused about how it should work.<\/p>\n

I found some stuff about systemd and automount, but the idea of a system.automount unit file scared me and I *really* didn’t want to have to learn too much more about systemd, just in order to mount a disk (I guess I’m putting off the inevitable since, professionally, I support Oracle Linux and I imagine it will eventually start to use systemd).<\/p>\n

I found the man page for systemd.mount(5) and read:<\/p>\n

Mount units may either be configured via unit files, or via \/etc\/fstab
\n (see fstab(5) for details).<\/p>\n

When reading \/etc\/fstab a few special mount options are understood by
\n systemd which influence how dependencies are created for mount points
\n from \/etc\/fstab. If comment=systemd.mount is specified as mount option,
\n then systemd will create a dependency of type Wants from either
\n local-fs.target or remote-fs.target, depending whether the file system
\n is local or remote. If comment=systemd.automount is set, an automount
\n unit will be created for the file system. See systemd.automount(5) for
\n details.<\/p><\/blockquote>\n

I obviously hadn’t drunk enough coffee, so I couldn’t seem to grok this, and had to read http:\/\/0pointer.de\/blog\/projects\/blame-game.html:<\/p>\n

Well, systemd possesses magic powers, in form of the comment=systemd.automount mount option in \/etc\/fstab. If you specify it, systemd will create an automount point at \/home and when at the time of the first access to the file system it still isn’t backed by a proper file system systemd will wait for the device, fsck and mount it.<\/p><\/blockquote>\n

I added:<\/p>\n

UUID=d0e1f72d-c56e-4239-ae79-277af99ada7a \/simpledrive\text4\tdefaults,comment=systemd.automount\t1 2
\n<\/code><\/p>\n

On reboot, I got dumped to a systemd console, and I thought maybe it was because the volume was being mounted before it was ready, so I added noauto, to let systemd pick it up later:<\/p>\n

UUID=d0e1f72d-c56e-4239-ae79-277af99ada7a \/simpledrive\text4\tnoauto,defaults,comment=systemd.automount\t1 2<\/code><\/p>\n

Still failed, but this time I got to see an error, and ran:<\/p>\n

# systemctl status automount.simpledrive
\n<\/code><\/p>\n

and it told me something about a resource. I figured out I’d misunderstood this line by Lennart:<\/p>\n

If you specify it, systemd will create an automount point<\/p><\/blockquote>\n

and that I needed to manually create \/simpledrive:<\/p>\n

# mkdir \/simpledrive
\n<\/code>
\nAfter that, <\/p>\n

# systemctl status simpledrive.automount
\nsimpledrive.automount
\n\t Loaded: loaded
\n\t Active: active (running) since Mon, 03 Dec 2012 10:25:00 +0000; 1h 51min ago
\n\t Where: \/simpledrive
\n<\/code><\/p>\n

and on reboot, the drive is mounted:<\/p>\n

systemd-1 on \/simpledrive type autofs (rw,relatime,fd=44,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)
\n\/dev\/sdd1 on \/simpledrive type ext4 (rw,relatime,data=ordered)
\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"

I had a requirement to boot a USB disk (a Hitachi SimpleDrive) on a machine I rarely log into via the GUI. In the good old days, I’d hack up a udev script to do it. In Fedora, with the advent of systemd, I googled and quickly became horribly confused about how it should work.\u2026 Read More »<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[8],"tags":[91,101,137,142],"class_list":["post-542","post","type-post","status-publish","format-standard","hentry","category-geek","tag-linux","tag-mount","tag-systemd","tag-usb"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p9qMPF-8K","jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.wrigley.me.uk\/wp-json\/wp\/v2\/posts\/542"}],"collection":[{"href":"https:\/\/www.wrigley.me.uk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wrigley.me.uk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wrigley.me.uk\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wrigley.me.uk\/wp-json\/wp\/v2\/comments?post=542"}],"version-history":[{"count":0,"href":"https:\/\/www.wrigley.me.uk\/wp-json\/wp\/v2\/posts\/542\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wrigley.me.uk\/wp-json\/wp\/v2\/media?parent=542"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wrigley.me.uk\/wp-json\/wp\/v2\/categories?post=542"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wrigley.me.uk\/wp-json\/wp\/v2\/tags?post=542"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}