To create a Btrfs partition inside a LUKS container on an external drive, follow these steps:
- First, you need to create a LUKS container on the external drive. You can do this using the following command:
cryptsetup -y create luks_container /dev/your_external_drive
Replace /dev/your_external_drive with the correct device name for your external drive (e.g., /dev/sdb, /dev/sdc, etc.). You will be prompted for a password for the LUKS container.
2. Next, open the LUKS container using the password you set earlier. You can do this with the following command:
cryptsetup open luks_container luks_opened
- Now, create a Btrfs filesystem inside the LUKS container. You can do this with the following command:
mkfs.btrfs -f /dev/mapper/luks_opened
Replace /dev/mapper/luks_opened with the correct device name for your LUKS container (e.g., /dev/mapper/luks-your_external_drive).
4. Create a mount point directory for the Btrfs partition. For example:
mkdir /mnt/btrfs_partition
- Now, you can mount the Btrfs partition using the following command:
mount /dev/mapper/luks_opened /mnt/btrfs_partition
Replace /dev/mapper/luks_opened with the correct device name for your LUKS container.
6. To make the Btrfs partition automatically mount with the correct permissions when the external drive is connected, you can add an entry to the /etc/fstab file. Use a text editor to open the /etc/fstab file and add the following line:
/dev/mapper/luks_opened /mnt/btrfs_partition btrfs defaults,_netdev 0 0
Replace /dev/mapper/luks_opened with the correct device name for your LUKS container and /mnt/btrfs_partition with the mount point directory you created earlier.
7. Save the changes to the /etc/fstab file and exit the text editor.
8. Finally, you can manually test the mount by running the following command:
mount -a
Now, when you connect the external drive to your machine and enter the LUKS password, the Btrfs partition will be automatically mounted with full permissions.