vpsuefilvmdisk-partitioningalmalinux

Creating LVM Partitions for Web App, Database, Unused Space, and Swap on Almalinux 9.3


Struggling with LVM partitioning on Almalinux 9.3 GPT disk (sda), aiming to allocate space for a web app, database, unused storage, and a swap partition.

Currently, my Almalinux 9.3 system is configured with a GPT disk (/dev/sda) and four partitions, employing the XFS file system for the root, boot, and EFI partitions. The available space on the root partition (/dev/sda4) is 158GB. Below is the detailed output of 'lsblk -pf' and 'df -h' for a closer look at the current setup.

[root@vps-ad2 ~]# lsblk -pf
NAME        FSTYPE FSVER LABEL UUID                                 FSAVAIL FSUSE% MOUNTPOINTS
/dev/sda
├─/dev/sda1
├─/dev/sda2 vfat   FAT16       1D51-8780                             192.8M     4% /boot/efi
├─/dev/sda3 xfs                ef1aa53b-118d-7430-3c68-1766c214d407  246.3M    45% /boot
└─/dev/sda4 xfs                76dc2434-fac0-4605-9172-e8e2657dcdc5    157G     1% /
[root@vps-ad2 ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        4.0M     0  4.0M   0% /dev
tmpfs           3.7G     0  3.7G   0% /dev/shm
tmpfs           1.5G  144M  1.4G  10% /run
/dev/sda4       160G  2.2G  158G   2% /
/dev/sda3       448M  202M  247M  46% /boot
/dev/sda2       200M  7.1M  193M   4% /boot/efi
tmpfs           749M     0  749M   0% /run/user/1000
[root@vps-ad2 ~]# fdisk -l /dev/sda
Disk /dev/sda: 160 GiB, 171798691840 bytes, 335544320 sectors
Disk model: QEMU HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: E8AAFED4-5BC1-4ENB-ABCF-E86189F2CAEE

Device       Start       End   Sectors   Size Type
/dev/sda1     2048      4095      2048     1M BIOS boot
/dev/sda2     4096    413695    409600   200M EFI System
/dev/sda3   413696   1462271   1048576   512M Linux filesystem
/dev/sda4  1462272 335544286 334082015 159.3G Linux filesystem

In this configuration, I'm exploring the implementation of Logical Volume Management (LVM) to enhance flexibility and scalability. Specifically, I aim to create distinct logical volumes for a web application server, a database, a swap partition, and allocate space for future needs. The intention is to maintain adaptability by potentially resizing the future needs partition to accommodate the dynamic requirements of either the web server or the database LVM. Your insights and guidance on achieving this setup efficiently would be greatly appreciated


Solution

  • Short answer: you can't (easy)

    Long answer: There are two points which will stop you from migrate to LVM:

    1. You do not have free space to create new partition for LVM.
    2. You use xfs. One of the characteristics of this filesystem is you can't shrink it to free some space for creating LVM and migrating the programs and data.

    The simplest and fastest and probably the safest solution (for me) is to create new VM (with LVM), copy software/configurations and data to new VM and destroy the old one.

    Of course you can play by adding new disk for LVM, but if you do not have access to the VM console and the risk something bad happen (can be from single config mistake) is not small.