Expanding disk space in Linux virtual machines is a key aspect of server system management. In this article, we show how to effectively increase disk space using LVM and fdisk tools, based on real system data.
Preliminary Preparations
Before making changes to partitions and volumes, it is important to check the current state of the disks in the system. We will use the lsblk
command to identify available disks and partitions.
1 |
lsblk |
Here is an example of the lsblk
command output on a machine:
1 2 3 4 5 6 7 8 9 10 11 12 |
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT loop0 7:0 0 55.7M 1 loop /snap/core18/2829 sda 8:0 0 42G 0 disk ├─sda1 8:1 0 512M 0 part /boot/efi ├─sda2 8:2 0 1G 0 part /boot └─sda3 8:3 0 40.5G 0 part └─ubuntu--vg-ubuntu--lv 253:0 0 78.5G 0 lvm / sdb 8:16 0 350G 0 disk └─sdb1 8:17 0 60G 0 part └─ubuntu--vg-ubuntu--lv 253:0 0 78.5G 0 lvm / sr0 11:0 1 1024M 0 rom |
Creating Snapshots
Before making changes to disk configurations, it is advisable to create a snapshot of the LVM volumes to ensure data can be restored in case of unexpected issues.
1 |
lvcreate -L 20G -s -n my_snapshot /dev/ubuntu-vg/ubuntu-lv |
Modifying Partitions
Next, we proceed to modify the partitions using fdisk
. We remove the existing partition and then create a new one that utilizes the entire available space on disk sdb
.
1 |
fdisk /dev/sdb |
Saving Changes
After properly configuring the partitions, we use the w
command in fdisk
to save the changes and update the partition table.
1 |
Command (m for help): w |
Executing pvscan
After modifying the partitions, we execute the pvscan
command so the system can update information about available physical volumes.
1 |
pvscan |
Configuring LVM
After saving changes to the partition table, we need to update the LVM configuration to include the new disk space. We use the lvextend
command with automatic file system resizing.
1 |
lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv -r |
Summary
Expanding disk space on a Linux virtual machine enhances performance and the availability of storage space. Thanks to the steps described, managing disk space in systems using LVM becomes simpler and more efficient.