Convert and install to LUKS Encrypted Drive Ubuntu 18.04 19.10 Linux Mint and Debian Based Linux

The reason for doing this is that the installer doesn't seem to work properly for LUKS and the server installer doesn't even support LUKS anymore.  When you use the GUI install on Desktop for LUKS it won't boot and will just hang after you enter your password.  So the only reliable way is to do it ourselves.

1.) Make a default minimal install of Ubuntu


2.) Have a secondary disk on the server or VM.

3.) Create the following on the secondary disk (we assume it is /dev/sdb)
/dev/sdb1 = /boot 1G
/dev/sdb2 = / (rest of free space)

Use fdisk or gdisk

4.) Create LUKS for root on /dev/sdb2

cryptsetup --verbose --verify-passphrase luksFormat /dev/sdb2

WARNING!
========
This will overwrite data on /dev/sdb2 irrevocably.

Are you sure? (Type uppercase yes): YES
Enter passphrase for /dev/sdb2:
Verify passphrase:
Command successful.


5.) Open your LUKS partition now


#note when we say LUKSroot below that becomes the LUKS device we can mount and use in /dev/mapper/LUKSroot (LUKSroot is the name that it will be given)

cryptsetup luksOpen /dev/sdb2 LUKSroot
Enter passphrase for /dev/sdb2:

6.) Create Partitions on your LUKS partition

mkfs.ext4 /dev/mapper/LUKSroot


#let's setup our boot as well while we're at it


mkfs.ext4 /dev/sdb1

7.) Let's prepare our target for migration (target is our new LUKS enabled drive)

mkdir /target
mount /dev/mapper/LUKSroot /target
mkdir /target/boot
mount /dev/sdb1 /target/boot

8.) rsync our current OS to the new LUKS partition (target)

rsync -Pha --exclude=/mnt/* --exclude=/media/* --exclude=/proc/* --exclude=/sys/* / /target
 

9.) Prepare to chroot into our new LUKS environment


for mount in dev proc sys; do
  mount -o bind /$mount /target/$mount
done


#enter our new LUKS environment
chroot /target
 

10.) Setup our LUKS environment to boot properly (update fstab, crypttab, initramfs and grub)

We need to update /etc/fstab with the new blkid's

# blkid /dev/sdb1
/dev/sdb1: UUID="e0e4d4b6-c45d-4749-81b9-a46bdc66f7c5" TYPE="ext4"


#blkid /dev/mapper/LUKSroot
/dev/mapper/LUKSroot: UUID="ba6af9a2-6ea1-49d9-95f1-df521cbd384b" TYPE="ext4"

#fstab should now look like this:

UUID=e0e4d4b6-c45d-4749-81b9-a46bdc66f7c5 /boot ext4 defaults 0 0
/dev/mapper/LUKSroot / ext4 defaults 0 0
/swap.img       none    swap    sw      0       0



#We need to also set /etc/crypttab
#it should be the UUID of /dev/sdb2

# blkid /dev/sdb2
/dev/sdb2: UUID="00321fcc-6ebc-4440-b62c-06b79f0aed96" TYPE="crypto_LUKS"

#crypttab should now look like this
LUKSroot UUID=00321fcc-6ebc-4440-b62c-06b79f0aed96 none luks,discard


#update our grub, initramfs and install grub to our secondary grub

update-grub
update-initramfs -k all -c
update-initramfs: Generating /boot/initrd.img-4.15.0-88-generic


grub-install /dev/sdb
#if your primary boot drive is /dev/sda you should install it into /dev/sda too
grub-install /dev/sda

#now reboot


Tags:

convert, install, luks, encrypted, ubuntu, linux, mint, debian, linuxthe, installer, doesn, server, gui, desktop, password, reliable, default, minimal, secondary, disk, vm, dev, sdb, fdisk, gdisk, cryptsetup, verbose, verify, passphrase, luksformat, overwrite, irrevocably, uppercase, partition, luksroot, mount, mapper, luksopen, partitions, mkfs, ext, migration, enabled, mkdir, rsync, os, pha, exclude, mnt, proc, sys, chroot, bind, update, fstab, crypttab, initramfs, grub, etc, blkid, uuid, quot, bdc, af, ea, df, cbd, defaults, swap, img, sw, fcc, ebc, aed, crypto_luks, discard, generating, initrd, generic, primary, sda, reboot,

Latest Articles

  • python mysql install error: /bin/sh: 1: mysql_config: not found /bin/sh: 1: mariadb_config: not found /bin/sh: 1: mysql_config: not found mysql_config --version
  • FreePBX 17 How To Add a Trunk
  • Docker Container Onboot Policy - How to make sure a container is always running
  • FreePBX 17 How To Add Phones / Extensions and Register
  • Warning: The driver descriptor says the physical block size is 2048 bytes, but Linux says it is 512 bytes. solution
  • Cisco How To Use a Third Party SIP Phone (eg. Avaya, 3CX)
  • Cisco Unified Communication Manager (CUCM) - How To Add Phones
  • pptp / pptpd not working in DD-WRT iptables / router
  • systemd-journald high memory usage solution
  • How to Install FreePBX 17 in Linux Debian Ubuntu Mint Guide
  • How To Install Cisco's CUCM (Cisco Unified Communication Manager) 12 Guide
  • Linux Ubuntu Redhat How To Extract Images from PDF
  • Linux and Windows Dual Boot Issue NIC Won't work After Booting Windows
  • Cisco CME How To Enable ACD hunt groups
  • How to install gns3 on Linux Ubuntu Mint
  • How to convert audio for Asterisk .wav format
  • Using Cisco CME Router with Asterisk as a dial-peer
  • Cisco CME How To Configure SIP Trunk VOIP
  • Virtualbox host Only Network Error Failed to save host network interface parameter - Cannot change gateway IP of host only network
  • Cisco CME and C7200 Router Testing and Learning Environment on Ubuntu 20+ Setup Tutorial Guide