stichl.at tech at work

11Mar/130

Resizing LVM Volumes

I need to search the Internet everytime I want to resize LVM Volumes... So enjoy this short howto 🙂

Most important point: Ensure the physical partition is large enough to hold the active logical volumes. If your logical volume is bigger than the physical volume you will not be able to mount or resize.

1. fdisk -u /dev/sdb then press p

Disk /dev/sdb: 429.5 GB, 429496729600 bytes
255 heads, 63 sectors/track, 52216 cylinders, total 838860800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0004bd1a

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1              63   838860799   419430368+  8e  Linux LVM

2. Press d to remove the partition

3. Press n then primary p start sector 63 last cylinder 838860799 to add the newly re-sized partition. WARNING: Make sure the old and new partition start at the same sector position, not doing so will destroy your data.

4. Press t partition 2 Hex code 8e

5. Press p

Disk /dev/sdb: 429.5 GB, 429496729600 bytes
255 heads, 63 sectors/track, 52216 cylinders, total 838860800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0004bd1a

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1              63   419430399   419430368+  8e  Linux LVM

6. Finally press w write table to disk and exit and reboot

7. Use vgdisplay, pvdisplay, or lvdisplay to show the current and later ending size of your LV

8. Run pvresize /dev/sda2 to expand the physical volume on /dev/sda2 after enlarging the partition with fdisk

9. You could also extend the volume group across disks and partitions: pvcreate /dev/hdb1; vgextend vgname /dev/hdb1; vgdisplay vgname. With this method use fdisk to create a new partition instead of recreating the original one. This is certainly safer since there is less risk to your existing data and it makes it easier to break up volume groups in the future.

10. Use vgdisplay to find the Free PE / Size

  --- Volume group ---
  VG Name               vgname
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  10
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               400.00 GiB
  PE Size               4.00 MiB
  Total PE              102399
  Alloc PE / Size       51199 / 200.00 GiB
  Free  PE / Size       51200 / 200.00 GiB
  VG UUID               A1d9KK-KzyZ-8eqa-dpmO-HpTB-YB3N-m5dUOE

11. Use lvdisplay to display current logical volumes

  --- Logical volume ---
  LV Name                /dev/vgname/volname
  VG Name                vgname
  LV UUID                lZ2gbv-xKNi-7Qxq-0fZV-67kB-3oR5-r7oUlA
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                200.00 GiB
  Current LE             51199
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           251:0

12. lvextend -l +51200 /dev/vgname/volname (you can use the following to reduce again lvreduce -l -51200 /dev/SystemVG/RootLV)

13. lvdisplay /dev/vgname/volname to see the result

  --- Logical volume ---
  LV Name                /dev/opsi1_data/data
  VG Name                opsi1_data
  LV UUID                lZ2gbv-xKNi-7Qxq-0fZV-67kB-3oR5-r7oUlA
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                400.00 GiB
  Current LE             102399
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           251:0

14. ext2online /dev/vgname/volname while the filesystem is mounted or to be safe use resize2fs /dev/vgname/volname while the filesystem is unmounted. Note: resize2fs may require running e2fsck -f /dev/vgname/volname first.

Filed under: Linux Leave comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

No trackbacks yet.