0

I am trying to extend the disk space on an AlmaLinux server (running on a VM). The goal is to add unallocated 10.00 GiB to the root partition (dev/sda2). What is the best way to do this without losing any data?

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0   310G  0 disk
├─sda1   8:1    0   512M  0 part /boot
├─sda2   8:2    0     4G  0 part /
├─sda3   8:3    0     1G  0 part /tmp
├─sda4   8:4    0     1K  0 part
└─sda5   8:5    0 294.5G  0 part /var/lib/mysql
sdb      8:16   0   127G  0 disk
sr0     11:0    1  1024M  0 from

Model: Msft Virtual Disk (scsi) Disk /dev/sda: 333GB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags:

Number Start End Size Type File system Flags 1 1049kB 538MB 537MB primary ext4 boot 2 538MB 4833MB 4295MB primary xfs 3 4833MB 5907MB 1074MB primary xfs 4 5907MB 322GB 316GB extended 5 5908MB 322GB 316GB logical xfs

Number Start End Size Type File system Flags 32.3kB 1049kB 1016kB Free Space 1 1049kB 538MB 537MB primary ext4 boot 2 538MB 4833MB 4295MB primary xfs 3 4833MB 5907MB 1074MB primary xfs 4 5907MB 322GB 316GB extended 5 5908MB 322GB 316GB logical xfs 322GB 333GB 10.7GB Free Space

enter image description here

1 Answers1

3

The goal is to add unallocated 10.00 GiB to the root partition (dev/sda2). What is the best way to do this without losing any data?

Your problem is that the unallocated space is at the end of the drive, while your partition is in the middle. You can generally only ever expand a partition to unallocated space adjacent to the partition. To overcome this, you have to use something like LVM (or a filesystem with subvolumes such as BTRFS).

In your scenario the proper way to do it is to perform a full backup, re-partition, reinstall system, and restore from backup. You can try to move partitions in gparted from a live system, but it carries the risk of data loss.

vidarlo
  • 11,723