The process to expand an encrypted disk on Ubuntu Linux can be a complex process if not done correctly. W may need to take these steps because encrypted Disk on Ubuntu Linux can sometimes show smaller disk size compared to the disk capacity. I asked Mixtral LeChat, what this problem was and how to fix the issue.

Summary

The process to expand an encrypted disk on Linux involves resizing the physical volume, logical volume, and filesystem. By following the steps outlined in this guide, you can successfully expand your disk and utilize the additional space.

लिनक्स पर एक एन्क्रिप्टेड डिस्क का विस्तार करने में भौतिक वॉल्यूम, तार्किक वॉल्यूम और फाइलसिस्टम का आकार बदलना शामिल है। इस गाइड में बताए गए चरणों का पालन करके, आप सफलतापूर्वक अपनी डिस्क का विस्तार कर सकते हैं और अतिरिक्त स्थान का उपयोग कर सकते हैं।

Problem Statement

How to expand the encrypted disk, when the disk size in Ubuntu shows up much smaller than the actual disk capacity?

disk is 120 gb. lsblk shows:
vda3                      253:3    0  118G  0 part
  └─dm_crypt-0              252:0    0  118G  0 crypt
    └─ubuntu--vg-ubuntu--lv 252:1    0   59G  0 lvm   /

Expand Encrypted Disk on Ubuntu Linux. Blog by Amar Vyas

Why This Happens

As you use your system, the amount of data stored on your disk increases. Over time, you may find that your disk space is no longer sufficient. This is particularly true for encrypted disks, where the encryption layer adds an additional complexity to the resizing process.

How to Detect

To detect if you are running out of disk space, you can use the following commands:

$ lsblk
$ df -h
$ sudo pvdisplay
$ sudo vgdisplay
$ sudo lvdisplay

These commands will give you an overview of your disk usage and help you identify if you need to expand your disk.

Commands to Expand Encrypted Disk on Ubuntu Linux

Here are the key commands you will need to use to expand your encrypted disk:

$ sudo cryptsetup resize dm_crypt-0
$ sudo pvresize /dev/mapper/dm_crypt-0
$ sudo lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv
$ sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv  # For ext4
$ sudo xfs_growfs /  # For xfs

Steps to Follow

Step 1: Check Current Disk Usage and Layout

First, check the current disk usage and layout using the following commands:

$ lsblk
$ df -h
$ sudo pvdisplay
$ sudo vgdisplay
$ sudo lvdisplay

Step 2: Resize the Physical Volume

Since your disk is encrypted, you need to resize the encrypted physical volume first.

  1. Resize the LUKS Partition:
    $ sudo cryptsetup resize dm_crypt-0
  2. Resize the Physical Volume:
    $ sudo pvresize /dev/mapper/dm_crypt-0

Expand Encrypted Disk on Ubuntu Linux

Step 3: Resize the Logical Volume

Next, you need to resize the logical volume to use the additional space.

  1. Check the Volume Group:
    $ sudo vgdisplay
  2. Extend the Logical Volume:
    $ sudo lvextend -l +100%FREE /dev/mapper/ubuntu--vg-ubuntu--lv

Step 4: Resize the Filesystem

Finally, you need to resize the filesystem to use the new space.

  1. Check the Filesystem Type:
    $ df -Th
  2. Resize the Filesystem:For ext4:
    <$ sudo resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv

    For xfs:

    $ sudo xfs_growfs /

Step 5: Verify the Changes

Check the disk usage and layout again to ensure that the changes have been applied correctly.

$lsblk
$ df -h
$ sudo pvdisplay
$ sudo vgdisplay
$ sudo lvdisplay

Disk Sizes - after expansion

$ sudo vgdisplay
 VG Size               117.98 GiB
  PE Size               4.00 MiB
  Total PE              30203
$ sudo pvdisplay
PV Name               /dev/mapper/dm_crypt-0
  VG Name               ubuntu-vg
  PV Size               117.98 GiB / not usable 1.00 MiB
$ df -h

/dev/mapper/ubuntu--vg-ubuntu--lv  116G  9.9G  101G   9% /
$ lsblk #after

└─vda3                      253:3    0  118G  0 part
  └─dm_crypt-0              252:0    0  118G  0 crypt
    └─ubuntu--vg-ubuntu--lv 252:1    0  118G  0 lvm   /

Do's and Don'ts : Expand Encrypted Disk on Ubuntu Linux

Do's

  • Backup Your Data: Always back up your data before making any changes to your disk layout.
  • Check Disk Usage: Regularly check your disk usage to avoid running out of space.
  • Follow Steps Carefully: Follow the steps carefully to avoid any mistakes.

Don'ts

  • Don't Skip Backups: Never skip backing up your data.
  • Don't Rush: Take your time to ensure each step is completed correctly.
  • Don't Ignore Errors: If you encounter any errors, stop and troubleshoot before proceeding.
Expand Encrypted Disk on Ubuntu Linux
display from df-h on linux

This blog post was partly compiled and formatted using Mixtral Lechat AI or LLM tool.