Shrink/Compact BIGIP VE Virtual Disk
After running for a while, BIG-IP VE virtual disk size might grow much beyond the actual size of the contained files.
For lab environment VE 16.1, I see the used space for is 6.4 GB.
If the virtual disk size is more than 7.5 GB, that usually means there is physical space that can be saved.
Before running shrink command, the unused space of the virtual disk needs to be zeroed.
Best way of zeroing is mounting the partitions or logical volumes then run fstrim.
It finishes instantly and doesn't need to actually writes zero to the unused space.
It is better than "cat /dev/zero ..." or zerofill which actually needs to write zero and takes lots of time for large size.
Zeroing steps:
- BIG-IP VE uses old Linux distro release that doesn't have builtin fstrim.
Hence we need to attach the virtual disk to other Linux system that as fstrim. - Shutdown VW virtual machine, then attach the virtual disk file to other Linux machine.
If you don't have a Linux VM, you can create empty Linux VM and boot it using Linux iso.
I usually use system rescue iso from https://www.system-rescue.org/Download/. - BIG-IP VE use LVM volumes as seen in below fdisk output.
The /, /var & etc. are stored in LVM volumes.
vgscan command will automatically scan LVM volumes and create /dev/dm-*.
Device Boot Start End Sectors Size Id Type
/dev/sdb1 * 1 409599 409599 200M b W95 FAT32
/dev/sdb2 409600 442367 32768 16M 82 Linux swap / Solaris
/dev/sdb3 442368 171965455 171523088 81.8G 8e Linux LVM
- Run the following commands to do mounting and fstrim on VE virtual disk partitions and LVM volumes.
For subsequent usages, store it as file in the Linux VM, e.g. as /var/tmp/trimf5.sh
vgscan
###fstrim can't trim swap partition, so need to reformat swap volume as ext4.
swapuuid=`blkid /dev/vg-db-vda/dat.swapvol | awk -F "\"" '{print $2}'`
mkfs.ext4 -F /dev/vg-db-vda/dat.swapvol
for i in `ls -1 /dev/dm-*`
do
mkdir -p "/tempdir"$i
mount $i "/tempdir"$i
done
fstrim -avvv
sleep 2
###Second fstrim to confirm results of first fstrim.
fstrim -avvv
for i in `ls -1 /dev/dm-*`
do
umount $i
done
mkswap -U $swapuuid /dev/vg-db-vda/dat.swapvol
- Zeroing result:
[root@localhost tmp]# sh trimf5.sh
Found volume group "vg-db-vda" using metadata type lvm2
mke2fs 1.46.5 (30-Dec-2021)
/dev/vg-db-vda/dat.swapvol contains a swap file system
Discarding device blocks: done
Creating filesystem with 256000 4k blocks and 64000 inodes
Filesystem UUID: 5ae4f6eb-b9ea-41d4-b710-b582eb4a5fa6
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
/tempdir/dev/dm-8: 3.9 GiB (4180942848 bytes) trimmed on /dev/mapper/vg--db--vda-set.1._var
/tempdir/dev/dm-7: 2 GiB (2195013632 bytes) trimmed on /dev/mapper/vg--db--vda-set.1._config
/tempdir/dev/dm-6: 840.6 MiB (881397760 bytes) trimmed on /dev/mapper/vg--db--vda-set.1._usr
/tempdir/dev/dm-5: 323.9 MiB (339643392 bytes) trimmed on /dev/mapper/vg--db--vda-set.1.root
/tempdir/dev/dm-4: 965.8 MiB (1012744192 bytes) trimmed on /dev/mapper/vg--db--vda-dat.swapvol
/tempdir/dev/dm-3: 2.8 GiB (2958065664 bytes) trimmed on /dev/mapper/vg--db--vda-dat.log
/tempdir/dev/dm-2: 23.7 GiB (25492357120 bytes) trimmed on /dev/mapper/vg--db--vda-dat.appdata
/tempdir/dev/dm-1: 14.5 GiB (15615614976 bytes) trimmed on /dev/mapper/vg--db--vda-dat.share
/tempdir/dev/dm-0: 280.5 MiB (294090752 bytes) trimmed on /dev/mapper/vg--db--vda-dat.maint.1
/boot/efi: 493.4 MiB (517373952 bytes) trimmed on /dev/sda1
/: 31.8 GiB (34121232384 bytes) trimmed on /dev/sda2
/tempdir/dev/dm-8: 0 B (0 bytes) trimmed on /dev/mapper/vg--db--vda-set.1._var
/tempdir/dev/dm-7: 0 B (0 bytes) trimmed on /dev/mapper/vg--db--vda-set.1._config
/tempdir/dev/dm-6: 0 B (0 bytes) trimmed on /dev/mapper/vg--db--vda-set.1._usr
/tempdir/dev/dm-5: 0 B (0 bytes) trimmed on /dev/mapper/vg--db--vda-set.1.root
/tempdir/dev/dm-4: 0 B (0 bytes) trimmed on /dev/mapper/vg--db--vda-dat.swapvol
/tempdir/dev/dm-3: 0 B (0 bytes) trimmed on /dev/mapper/vg--db--vda-dat.log
/tempdir/dev/dm-2: 0 B (0 bytes) trimmed on /dev/mapper/vg--db--vda-dat.appdata
/tempdir/dev/dm-1: 0 B (0 bytes) trimmed on /dev/mapper/vg--db--vda-dat.share
/tempdir/dev/dm-0: 0 B (0 bytes) trimmed on /dev/mapper/vg--db--vda-dat.maint.1
/boot/efi: 493.4 MiB (517373952 bytes) trimmed on /dev/sda1
/: 0 B (0 bytes) trimmed on /dev/sda2
mkswap: /dev/vg-db-vda/dat.swapvol: warning: wiping old ext4 signature.
Setting up swapspace version 1, size = 1000 MiB (1048571904 bytes)
no label, UUID=6be1839d-eb37-4710-9687-833dd206b6f2
[root@localhost tmp]#
Compacting steps:
- Poweroff the Linux VM, then run VM host's shrink/compact procedure.
For Hyper-V, execute powershell command: Optimize-VHD -Path bigip161.vhdx -Mode Full.
Change the file name according to your virtual disk file name.
https://learn.microsoft.com/en-us/powershell/module/hyper-v/optimize-vhd
In my lab environment, compacting reduce the physical virtual disk to around 6.8 GB. - Hyper-V also provide GUI menu for compacting but doesn't show the used Mode.
VMware and KVM also provides GUI menu and command line for compacting virtual disk.
- Finally, reboot to run regular VE again.
Updated Feb 06, 2025
Version 2.0zamroni777
MVP
Joined November 17, 2023
No CommentsBe the first to comment