[SOLVED] How do I automatically mount a LUKS partition using its UUID?

Forum rules
Before you post please read this
Post Reply
jaymot
Level 2
Level 2
Posts: 53
Joined: Thu Apr 12, 2018 11:22 pm

[SOLVED] How do I automatically mount a LUKS partition using its UUID?

Post by jaymot » Tue Apr 17, 2018 7:39 am

I need to set up Mint so a non-system LUKS-encrypted drive's partition is automatically mounted when the OS starts. I take it that if it were an unencrypted ext4 partition I would just add an entry to fstab, something like UUID=(the partition's UUID) /mnt/mountpoint ext4 defaults,nofail 0 0 but how do I do that for an encrypted drive? I see that besides fstab there's a crypttab in /etc. Would I edit that file instead, or do both crypttab and fstab need entries for the drive? What would the syntax be for the entry or entries?

I run a Synchronet BBS on that drive (which I'd encrypted a long time ago before I'd decided what to use it for) and need to start the bbs as a daemon when the computer boots, so the drive always has to be mounted at boot and be mounted in the same mount point for the daemon to work. The board's been down for a week and I really should get it running again, as now that I've finally got Mint installed and most of the bugs worked out of it that's the last thing I need to do to get everything working again the way it used to before my previous Linux installation soiled itself. :) I want to use the UUID in case Linux changes the device name from /dev/sdb1 to something else like /dev/sdc1, such as if I forget and leave an external drive connected when I boot up.

TIA
Last edited by jaymot on Tue Apr 17, 2018 11:59 pm, edited 1 time in total.
Mint 18.3 Sylvia Cinnamon, Asus Zenbook UX303UB, 12GiB 1.6GHz DDR3 RAM, 1TiB HD, Intel Skylake & GeForce 940M GPUs

User avatar
xenopeek
Level 24
Level 24
Posts: 22499
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: How do I automatically mount a LUKS partition using its UUID?

Post by xenopeek » Tue Apr 17, 2018 9:52 am

From your wording I'm assuming you've already created the LUKS partition and formatted it.

You set up a device mapper name for the LUKS partition in /etc/crypttab. Then you mount the LUKS partition by its device mapper name in /etc/fstab. systemd takes care of the rest and prompt for the mount passphrase during boot.

/etc/crypttab at minimum requires a device mapper name (first field), of your choice, and the partition id (second field):
mapname UUID=the partition's UUID

/etc/fstab then uses the device mapper name, which after the LUKS partition is unlocked will be found under /dev/mapper/:
/dev/mapper/mapname /path/to/mountpoint ext4 defaults,nofail 0 2
From your example I've replaced /mnt/mountpoint with /path/to/mountpoint. /mnt exists for temporarily mounted filesystems. You may confuse your file manager by setting up permanent mounts here. Suggest you find a better place to mount. Like /disk2 or /home/jaymot/disk2 or similar. I've also changed the last field from 0 to 2 as for ext4 you'll want fsck to run I think.

You can optionally set up /etc/crypttab so that it will use a keyfile to unlock the LUKS partition during boot. This only makes sense to do if you can store that keyfile on another encrypted partition. It's thus useful for people having an encrypted Linux Mint installation that want to add a second encrypted disk to their system but don't want to have to enter a mount passphrase twice.
Image

jaymot
Level 2
Level 2
Posts: 53
Joined: Thu Apr 12, 2018 11:22 pm

Re: How do I automatically mount a LUKS partition using its UUID?

Post by jaymot » Tue Apr 17, 2018 10:19 am

Thanks! I have a pretty good handle on how to do it now. I'll tackle it tomorrow after a night's sleep and some coffee.
Mint 18.3 Sylvia Cinnamon, Asus Zenbook UX303UB, 12GiB 1.6GHz DDR3 RAM, 1TiB HD, Intel Skylake & GeForce 940M GPUs

jaymot
Level 2
Level 2
Posts: 53
Joined: Thu Apr 12, 2018 11:22 pm

Re: How do I automatically mount a LUKS partition using its UUID?

Post by jaymot » Tue Apr 17, 2018 11:58 pm

Success! Thanks again, xenopeek.

FY other people's I I found some excellent instructions for doing this including creation of a keyfile at
https://www.howtoforge.com/automaticall ... -a-keyfile.
Mint 18.3 Sylvia Cinnamon, Asus Zenbook UX303UB, 12GiB 1.6GHz DDR3 RAM, 1TiB HD, Intel Skylake & GeForce 940M GPUs

Post Reply

Return to “Mounting Partitions”