Reduce disk

Lars Jönsson 2019-11-26

Reducing a logical partition to be able to remove a physical partition.

Scenario

The root partition is located on a logical partition that include two physical partitions. The whole root partition fits inside the first physical partition and the other phycal partition can be removed.

Boot the Live CD

The instructions requires tha the system is booted with a Live CD. The partition to reduce cannot be mount when reducing the size.

Install system storage manager

The system storage manager (ssm) reduces the disk in one go. It can be done by using using the separated commands e2fsck, resize2fs and lvreduce, but ssm simplifies the task.

Install the system storage manager.

# dnf install system-storage-manager

Reduce the logical partition

Reduce the logical partition. Ensure that the new size is smaller than the size of the physical partition.

# ssm resize -s 9G /dev/fedora/root 

Remove the unused physical partition from the volume group.

# vgreduce fedora /dev/sda3 

Remove the physical partition from available physical volumes.

# pvremove /dev/sda3 

Optionally add the unused space in the fedora volume group (/dev/sda2) to the logical root partition.

# lvextend -l +100%FREE /dev/fedora/root

Remove the partition from the partition table

# parted /dev/sda print free
Number  Start   End     Size    Type     File system  Flags
        1024B   1049kB  1048kB           Free Space
 1      1049kB  1075MB  1074MB  primary  ext4         boot
 2      1075MB  12,9GB  11,8GB  primary               lvm
 3      12,9GB  32,2GB  19,3GB  primary               lvm

# parted /dev/sda rm 3

Use the freed up disk space (optional)

The disk space previuosly used by /dev/sda3 can be used to extend the physical partition /dev/sda2.

Extend /dev/sda2.

# parted /dev/sda resizepart 2 100%
# parted /dev/sda print free
Number  Start   End     Size    Type     File system  Flags
        1024B   1049kB  1048kB           Free Space
 1      1049kB  1075MB  1074MB  primary  ext4         boot
 2      1075MB  32,2GB  31,1GB  primary               lvm

Add the increased size of the physical partition to the physical volumes.

# pvresize /dev/sda2 

Extend the logical root partition.

# lvextend -l +100%FREE /dev/fedora/root
# resize2fs /dev/fedora/root 

Chack that the new space is available.

# mount /dev/fedora/root /mnt/
# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 963M     0  963M   0% /dev
tmpfs                    994M  4,0K  994M   1% /dev/shm
tmpfs                    994M  1,4M  992M   1% /run
/dev/sr0                 1,8G  1,8G     0 100% /run/initramfs/live
/dev/mapper/live-rw      6,4G  5,6G  790M  88% /
tmpfs                    994M   80K  994M   1% /tmp
vartmp                   994M     0  994M   0% /var/tmp
tmpfs                    199M  9,1M  190M   5% /run/user/1000
/dev/mapper/fedora-root   28G  8,2G   18G  32% /mnt
# umount /mnt