May 26, 2016

3 Resize & Extend LVM disk












Resize disk in Linux OS after changing it’s size in Vmware. Works also for VirtualBox & Hyper-V.
Resize disk in Linux OS after changing it’s size in Vmware. Works also for VirtualBox & Hyper-V.      Tested with Ubuntu 14.04.03 basic VM installation, using default LVM disk configuration.

·  Install parted. Will use later.
 sudo apt-get install parted

·  Check all partitions on system :
 ls -al /dev/sda*

·  Set LVM partition type with cfdisk :
Look for free space and no part type.
Set type , hex code : 8e
Write changes.

·  Update partition table without server restart :
 sudo partprobe /dev/sda

·  Check new created partition :
 sudo fdisk -l

  Disk /dev/sda: 52.4 GB,

  Device    Boot      Start         End               Blocks       Id    System
  /dev/sda1   *        2048          499711         248832         83   Linux
  /dev/sda2          501758         102399999    50949121      5     Extended
  /dev/sda5          501760         20969471     10233856       8e   Linux LVM
  /dev/sda6        20969535       102399999    40715232+     8e   Linux LVM

·  Create physical volume on new partition /dev/sda6:
 sudo pvcreate /dev/sda6

  Physical volume "/dev/sda6" successfully created
   "/dev/sda6" is a new physical volume of "38.83 GiB"
   --- NEW Physical volume ---
   PV Name               /dev/sda6
                   PV Size                  38.83 GiB

·  Check volume group name :
 sudo vgdisplay


  --- Volume group ---
  VG Name            box-vg
  VG Size               9.76 GiB

·  Extend volume group "box-vg" to /dev/sda6 partition :
 sudo vgextend box-vg /dev/sda6

·  Check volume group :
 sudo vgdisplay

  --- Volume group ---
  VG Name            box-vg
  VG Size              48.58 GiB

·  Check Logical volume :
 sudo lvdisplay

  --- Volume group ---
  LV Path              /dev/box-vg/root
  VG Name           box-vg
  LV Size              8.76 GiB

·  Finally extend logical volume to all free space available :
 sudo lvextend -l 100%FREE /dev/box-vg/root

·  Resize filesystem & write changes :
 sudo resize2fs /dev/box-vg/root

·  Check Logical volume :
 sudo lvdisplay

  --- Logical volume ---
  LV Path               /dev/box-vg/root
  LV Name             root
  VG Name            box-vg
  LV Size               38.82 GiB

·  Check free disk space :
 sudo df -h

It is :
  Filesystem                         Size  Used    Avail Use%  Mounted on
  /dev/mapper/box--vg-root     39G  771M   36G   3%       /

It was :
  Filesystem                           Size    Used     Avail   Use%  Mounted on
  /dev/mapper/box--vg-root      8.5G   764M    7.3G    10%      /

3 comments :

  1. Thank you for good manual.

    ReplyDelete
  2. If I have 8, 2Tb disks, will it work?

    ReplyDelete
  3. Hi. Yes it'll work. Only creation time will be ~10min, depending how much you have CPU and RAM.

    ReplyDelete

Comment: