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

Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
jaymot

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

Post by jaymot »

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 LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
xenopeek
Level 25
Level 25
Posts: 29504
Joined: Wed Jul 06, 2011 3:58 am

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

Post by xenopeek »

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

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

Post by jaymot »

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.
jaymot

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

Post by jaymot »

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.
Locked

Return to “Storage”