My Wiki!

Packer Auto Installation Image

Resize partition

LVM

Required package

  apt install gdisk
  

Original partitioning:

fdisk -l

Disk /dev/sda: 146.5 GiB, 157286400000 bytes, 307200000 sectors      <----------- available space
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x7a3286e

Device     Boot   Start      End  Sectors  Size Id Type
/dev/sda1  *       2048  1499135  1497088  731M 83 Linux
/dev/sda2       1501182 20477951 18976770  9.1G  5 Extended           <--------- 9G
/dev/sda5       1501184 20477951 18976768  9.1G 8e Linux LVM          <-------- all partition are contained in Extended volum /dev/sda2


stack@xubuntu:/opt/devstack$ sudo su
root@xubuntu:/opt/devstack# pvdisplay 

  --- Physical volume ---
  PV Name               /dev/sda5
  VG Name               xubuntu-vg
  PV Size               9.05 GiB / not usable 2.00 MiB
  Allocatable           yes (but full)
  PE Size               4.00 MiB
  Total PE              2316
  Free PE               0
  Allocated PE          2316
  PV UUID               UXlLgE-xCum-rxae-DgVx-uv0z-fM6H-bNYUw2
   
root@xubuntu:/opt/devstack# vgdisplay 

  --- Volume group ---
  VG Name               xubuntu-vg
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               9.05 GiB
  PE Size               4.00 MiB
  Total PE              2316
  Alloc PE / Size       2316 / 9.05 GiB
  Free  PE / Size       0 / 0   
  VG UUID               CNAZ0a-XQ37-B9DT-0MGX-dzud-Io11-0oL2q7
   
root@xubuntu:/opt/devstack# lvdisplay 

  --- Logical volume ---
  LV Path                /dev/xubuntu-vg/root
  LV Name                root
  VG Name                xubuntu-vg
  LV UUID                H35cQ9-oRmE-IOMs-2zKi-LKuK-BjLl-UmUJV2
  LV Write Access        read/write
  LV Creation host, time xubuntu, 2019-01-29 20:20:36 +0000
  LV Status              available
  # open                 1
  LV Size                8.55 GiB
  Current LE             2188
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:0
   
  --- Logical volume ---
  LV Path                /dev/xubuntu-vg/swap_1
  LV Name                swap_1
  VG Name                xubuntu-vg
  LV UUID                NM64IR-S9D3-WXGK-vrr9-P5JI-v9wO-6933pE
  LV Write Access        read/write
  LV Creation host, time xubuntu, 2019-01-29 20:20:36 +0000
  LV Status              available
  # open                 2
  LV Size                512.00 MiB
  Current LE             128
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           252:1


###### Grow part

  root@xubuntu:/opt/devstack# growpart /dev/sda 2
  CHANGED: partition=2 start=1501182 old: size=18976770 end=20477952 new: size=305698785,end=307199967
 
  root@xubuntu:/opt/devstack# fdisk -l
  Disk /dev/sda: 146.5 GiB, 157286400000 bytes, 307200000 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
Disklabel type: dos
Disk identifier: 0x7a3286e9

Device     Boot   Start       End   Sectors   Size Id Type
/dev/sda1  *       2048   1499135   1497088   731M 83 Linux
/dev/sda2       1501182 307199966 305698785 145.8G  5 Extended
/dev/sda5       1501184  20477951  18976768   9.1G 8e Linux LVM

  root@xubuntu:/opt/devstack# growpart /dev/sda 5
  CHANGED: partition=5 start=1501184 old: size=18976768 end=20477952 new: size=305698783,end=307199967

root@xubuntu:/opt/devstack# fdisk -l

Disk /dev/sda: 146.5 GiB, 157286400000 bytes, 307200000 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
Disklabel type: dos
Disk identifier: 0x7a3286e9

Device     Boot   Start       End   Sectors   Size Id Type
/dev/sda1  *       2048   1499135   1497088   731M 83 Linux
/dev/sda2       1501182 307199966 305698785 145.8G  5 Extended    <-----
/dev/sda5       1501184 307199966 305698783 145.8G 8e Linux LVM   <-----

root@xubuntu:/opt/devstack# partprobe

## may have to deactivate lv. Works without for me!

root@xubuntu:/opt/devstack# pvresize /dev/sda5
  Physical volume "/dev/sda5" changed
  1 physical volume(s) resized / 0 physical volume(s) not resized

root@xubuntu:/opt/devstack# pvdisplay 
  --- Physical volume ---
  PV Name               /dev/sda5
  VG Name               xubuntu-vg
  PV Size               145.77 GiB / not usable 1.98 MiB      <------------
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              37316
  Free PE               35000
  Allocated PE          2316
  PV UUID               UXlLgE-xCum-rxae-DgVx-uv0z-fM6H-bNYUw2
   
root@xubuntu:/opt/devstack# lvresize -L +120G /dev/xubuntu-vg/root 
  Size of logical volume xubuntu-vg/root changed from 8.55 GiB (2188 extents) to 128.55 GiB (32908 extents).
  Logical volume root successfully resized.

root@xubuntu:/opt/devstack# resize2fs /dev/mapper/xubuntu--vg-root
resize2fs 1.42.13 (17-May-2015)
Filesystem at /dev/mapper/xubuntu--vg-root is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 9
The filesystem on /dev/mapper/xubuntu--vg-root is now 33697792 (4k) blocks long.

root@xubuntu:/opt/devstack# df -h
Filesystem                    Size  Used Avail Use% Mounted on
udev                          3.9G     0  3.9G   0% /dev
tmpfs                         799M   72M  727M  10% /run
/dev/mapper/xubuntu--vg-root  127G  7.2G  115G   6% /
tmpfs                         3.9G  144K  3.9G   1% /dev/shm
tmpfs                         5.0M  4.0K  5.0M   1% /run/lock
tmpfs                         3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda1                     720M  113M  571M  17% /boot
tmpfs                         799M   32K  799M   1% /run/user/1000
/dev/loop0                    6.0G  328M  5.7G   6% /opt/stack/data/swift/drives/sdb1

Headline


Navigation