NetBSD LVM disk extend

NetBSD LVM disk extend

Recently I filled up all space for mails placed in LVM on NetBSD VM running in Xen (XCP-ng) environment.

Filesystem                            Size       Used Avail %Cap Mounted on 
/dev/mapper/varmailvg-virtuallv       984G       860G 74G  92% /var/mail/virtual 
There is still some free space, but this FS already started sending alerts.

Xen uses LVM also under the hood, so resizing disk its trivial. Here are the steps:

  1. Power off your machine
  2. Locate disk in XenOrchestra
  3. Expand it to new size (2TB limit) by clicking its size, then entering new one
XenOrchestra Storage view

4. Start machine and run dmesg to check how many sectors your expanded disk now have

xbd3 at xenbus0 id 51776: Xen Virtual Block Device Interface
xbd3: using event channel 23
xbd3: 2000 GB, 512 bytes/sect x 4194304000 sectors

5. Enter new value of total sectors and partitions in disklabel -e /dev/xbd3

Disklabel of disk

Total sectors = dmesg reported sectors

Partition d = whole disk, which is equal to total sectors

Partition a = slice for BSD file system - You need to tweak this accordingly. If you have only one partition which you probably have when using LVM put there total sectors minus offset

Save new disklabel

6. Resize physical disk in lvm

lvm pvresize /dev/rxbd3a 

7. Extend logical volume with now new free space available on physical disk

lvm lvextend -L+1000G /dev/mapper/varmailvg-virtuallv

8. Umount resized FS and run fsck as lvm sugesst

umount /var/mail/virtual/
fsck -y /dev/mapper/varmailvg-virtuallv

9. Resize actual FS

resize_ffs /dev/mapper/varmailvg-virtuallv

10. Remount resized volume on previous mount point

mount /dev/mapper/varmailvg-virtuallv /var/mail/virtual/

Results:

Filesystem                            Size       Used      Avail %Cap Mounted on
/dev/mapper/varmailvg-virtuallv       1.9T       915G       954G  48% /var/mail/virtual

Read more