Mounting external LUKS encrypted drive via /etc/fstab

Quick to answer questions about finding your way around Linux Mint as a new user.
Forum rules
There are no such things as "stupid" questions. However if you think your question is a bit stupid, then this is the right place for you to post it. Stick to easy to-the-point questions that you feel people can answer fast. For long and complicated questions use the other forums in the support section.
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
rollingthunder
Level 1
Level 1
Posts: 8
Joined: Sun May 22, 2022 6:47 pm

Mounting external LUKS encrypted drive via /etc/fstab

Post by rollingthunder »

Hi all,

I'm trying add my external LUKS encrypted SSD drive to fstab, to persist the mount point to '/mnt/backup', so that timeshift and backintime can always find the drive. But it keeps mounting at '/media/username/Backup' and sometimes at 'media/username/Backup1'.

I only connect the drive when I'm doing backups, therefore it's not present at boot and I'm not trying to make it mount automatically at boot.

I've made an fstab entry, but it's failing to mount at the specified mountpoint.

Here's what lsblk gives when the drive is mounted. The drive in question is 'sda'.

Code: Select all

NAME                                        MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
sda                                           8:0    0 931.5G  0 disk  
└─luks-68c8eb91-29f6-44c3-83bb-c026217014f9 253:3    0 931.5G  0 crypt /media/username/Backup
nvme0n1                                     259:0    0 238.5G  0 disk  
├─nvme0n1p1                                 259:1    0   512M  0 part  /boot/efi
├─nvme0n1p2                                 259:2    0   732M  0 part  /boot
└─nvme0n1p3                                 259:3    0 237.3G  0 part  
  └─nvme0n1p3_crypt                         253:0    0 237.2G  0 crypt 
    ├─vgmint-root                           253:1    0 236.3G  0 lvm   /
    └─vgmint-swap_1                         253:2    0   976M  0 lvm   [SWAP]
And here it's entry in fdisk -l:

Code: Select all

Disk /dev/mapper/luks-68c8eb91-29f6-44c3-83bb-c026217014f9: 931.49 GiB, 1000171332096 bytes, 1953459633 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 33553920 bytes
And here is my etc/fstab:

Code: Select all

UUID=a6ae1c7f-98c3-4ae9-b181-28af8491394a       /       ext4    errors=remount-ro       0       1
UUID=79ad76b0-0518-4f88-a9d8-53192af6075f       /boot   ext4    defaults        0       2
UUID=D98E-4F8E  /boot/efi       vfat    umask=0077      0       1
/dev/mapper/vgmint-swap_1       none    swap    sw      0       0
/dev/mapper/Backup      /mnt/backup     ext4    noauto,noexec,rw,sync,user      0 0
In the /etc/fstab I've tried replacing '/dev/mapper/Backup' with the following, all to no avail:
  • /dev/mapper/luks-68c8eb91-29f6-44c3-83bb-c026217014f9
  • UUID of 'sda'
  • UUID of 'luks-68c8eb91-29f6-44c3-83bb-c026217014f9'
I'm running out of ideas and would really appreciate your help in finding my mental error.

PS, I didn't reboot each time I made edits to fstab and retrying to mount. Let me know if that's required.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
dave0808
Level 5
Level 5
Posts: 987
Joined: Sat May 16, 2015 1:02 pm

Re: Mounting external LUKS encrypted drive via /etc/fstab

Post by dave0808 »

Your entry in /etc/fstab needs to match the name given in the first column of the corresponding row in /etc/crypttab. So you probably have a line that starts with Backup, which would mean that /dev/mapper/Backup is correct in fstab.

I doubt that that is the issue with mounting though. I would imagine that the "hot plug" manager is taking control and is mounting it where it sees fit, as in, within /media/$USER. Someone else will know how to exclude this partition.
rollingthunder
Level 1
Level 1
Posts: 8
Joined: Sun May 22, 2022 6:47 pm

Re: Mounting external LUKS encrypted drive via /etc/fstab

Post by rollingthunder »

Yes I think that's what's happening. The drive always gets mounted in /media/$USER. I thought that adding an entry in /etc/fstab would override that behaviour.

So any insight on how to disable that behaviour is welcome.

Do I need an entry in /etc/crypttab? I had tried that but somehow thought that an entry there is only needed if I wanted the drive to mount automatically during boot.
djph
Level 7
Level 7
Posts: 1960
Joined: Thu Jun 27, 2019 5:43 am
Location: ::1

Re: Mounting external LUKS encrypted drive via /etc/fstab

Post by djph »

rollingthunder wrote: Mon May 23, 2022 5:55 pm Do I need an entry in /etc/crypttab? I had tried that but somehow thought that an entry there is only needed if I wanted the drive to mount automatically during boot.
yes, /etc/crypttab controls how the /dev/mapper/xyzzy device is setup. You need that in order for an entry in /etc/fstab to be able to work with the LUKS device.

If you don't want the drive to be automounted at boot, include the option noauto in /etc/fstab.
rollingthunder
Level 1
Level 1
Posts: 8
Joined: Sun May 22, 2022 6:47 pm

Re: Mounting external LUKS encrypted drive via /etc/fstab

Post by rollingthunder »

Thanks. I've edited my /etc/crypttab entry to match /etc/fstab, but still no luck.

Can anybody show me how I can prevent the system from automatically mounting my specific drive when it's connected?
djph
Level 7
Level 7
Posts: 1960
Joined: Thu Jun 27, 2019 5:43 am
Location: ::1

Re: Mounting external LUKS encrypted drive via /etc/fstab

Post by djph »

rollingthunder wrote: Mon May 30, 2022 2:54 pm Thanks. I've edited my /etc/crypttab entry to match /etc/fstab, but still no luck.

Can anybody show me how I can prevent the system from automatically mounting my specific drive when it's connected?
what do the two files have now?
rollingthunder
Level 1
Level 1
Posts: 8
Joined: Sun May 22, 2022 6:47 pm

Re: Mounting external LUKS encrypted drive via /etc/fstab

Post by rollingthunder »

/etc/crypttab

Code: Select all

nvme0n1p3_crypt	UUID=21ebf90c-d74e-4a3d-a6d0-f2ebd9c3230a	none	luks,discard
dev/mapper/Backup	none

/etc/fstab

Code: Select all

# <file system> <mount point> <type> <options> <dump> <pass>

UUID=a6ae1c7f-98c3-4ae9-b181-28af8491394a	/	ext4	errors=remount-ro	0	1
UUID=79ad76b0-0518-4f88-a9d8-53192af6075f	/boot	ext4	defaults	02
UUID=D98E-4F8E	/boot/efi	vfat	umask=0077	0	1
/dev/mapper/vgmint-swap_1	none	swap	sw	0	0
/dev/mapper/Backup	/mnt/backup	ext4	noauto,noexec,rw,sync,user	0 0

djph
Level 7
Level 7
Posts: 1960
Joined: Thu Jun 27, 2019 5:43 am
Location: ::1

Re: Mounting external LUKS encrypted drive via /etc/fstab

Post by djph »

well, the second line in /etc/crypttab is wrong.

it should be something like
Backup UUID=[LUKSUUID] none luks,discard

alternatively, if you wanted to use a keyfile, replace none with the absolute path to the keyfile.

To get the LUKS UUID, I believe it'll be in the output of blkid.

/etc/fstab looks alright.
Locked

Return to “Beginner Questions”