Installing Ubuntu using Logical Volume Management (LVM) with encryption (LUKS)

To install Ubuntu using Logical Volume Management (LVM) with encryption (LUKS), follow these steps.

To install Ubuntu using Logical Volume Management (LVM) with encryption (LUKS), follow these steps. This guide assumes you are familiar with basic Linux commands and the Ubuntu installation process.

What you need

  • A bootable Ubuntu installation media (USB or DVD).
  • Backup any important data, especially if you plan to erase existing partitions.

To install Ubuntu using Logical Volume Management (LVM) with encryption (LUKS), follow these steps. This guide assumes you are familiar with basic Linux commands and the Ubuntu installation process.

Prerequisites

  • A bootable Ubuntu installation media (USB or DVD).
  • Backup any important data, especially if you plan to erase existing partitions.

Steps to Install Ubuntu with LVM and Encryption

1. Boot from Installation Media

  • Insert the bootable media and boot your computer.
  • Select “Try Ubuntu” to enter the live environment.

2. Prepare Disk for Installation

  • Open a terminal and identify your target disk using lsblk.
  • Create a new partition table on the disk (e.g., /dev/sda): bashsudo parted /dev/sda mklabel gpt

3. Create Partitions

  • Create two partitions:
    • One for /boot (e.g., 1 GB).
    • Another for the encrypted root partition (remaining space).

For example:

bashsudo parted /dev/sda mkpart primary ext4 1MiB 1024MiB   # /boot
sudo parted /dev/sda mkpart primary ext4 1025MiB 100%   # Encrypted root

4. Encrypt the Root Partition with LUKS

  • Initialize LUKS on the root partition: bashsudo cryptsetup luksFormat /dev/sda2
  • Open the LUKS volume: bashsudo cryptsetup open /dev/sda2 cryptroot

5. Set Up LVM

  • Create a physical volume on the opened LUKS device: bashsudo pvcreate /dev/mapper/cryptroot
  • Create a volume group: bashsudo vgcreate ubuntu-vg /dev/mapper/cryptroot
  • Create logical volumes (adjust sizes as needed): bashsudo lvcreate -L 32G -n lv_swap ubuntu-vg # Swap volume sudo lvcreate -L 40G -n lv_root ubuntu-vg # Root volume sudo lvcreate -l +100%FREE -n lv_home ubuntu-vg # Home volume

6. Format Partitions

  • Format the partitions:
bashsudo mkfs.ext4 /dev/sda1          # Format /boot
sudo mkfs.ext4 /dev/ubuntu-vg/lv_root   # Format root
sudo mkfs.ext4 /dev/ubuntu-vg/lv_home   # Format home
sudo mkswap /dev/ubuntu-vg/lv_swap      # Setup swap

7. Install Ubuntu

  • Start the installer by clicking on “Install Ubuntu”.
  • When prompted for installation type, select “Something else”.

Assign mount points:

  • /dev/sda1 to /boot
  • /dev/ubuntu-vg/lv_root to /
  • /dev/ubuntu-vg/lv_home to /home
  • Enable swap for /dev/ubuntu-vg/lv_swap.

Continue with the installation.

8. Post-installation Setup

After installation, do not reboot immediately. Instead, perform the following:

  1. Open a terminal in the live environment.
  2. Mount the installed system: bashsudo mount /dev/ubuntu-vg/lv_root /mnt sudo mount /dev/ubuntu-vg/lv_home /mnt/home sudo mount /dev/sda1 /mnt/boot
  3. Bind necessary directories: bashfor i in dev proc sys run; do sudo mount --bind /$i /mnt/$i; done
  4. Chroot into your installed system: bashsudo chroot /mnt
  5. Update initramfs and grub: bashupdate-initramfs -u update-grub
  6. Exit chroot and unmount everything: bashexit for i in dev proc sys run; do sudo umount /mnt/$i; done sudo umount /mnt/home sudo umount /mnt/boot sudo umount /mnt

9. Reboot

Now you can reboot your system, and it should boot into your newly installed Ubuntu with LVM and encryption.

More Information ℹ
Gabby
Gabby

Inspiring readers to expound the possibilities of the unfolding World

EGM