Ben's notes

Linux, Unix, network, radio...

User Tools

Site Tools


kvm_grow_pv

KVM grow PV

  • Current partition table:
    # fdisk -l /dev/sda
    
    Disk /dev/sda: 2000.3 GB, 2000341917696 bytes, 3906917808 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 262144 bytes / 524288 bytes
    Disk label type: dos
    Disk identifier: 0x000b9cd2
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048     1026047      512000   83  Linux
    /dev/sda2         1026048   592416767   295695360   8e  Linux LVM
  • Remove /dev/sda2 partition and create a new bigger one:
    # fdisk /dev/sda
    Welcome to fdisk (util-linux 2.23.2).
    
    Changes will remain in memory only, until you decide to write them.
    Be careful before using the write command.
    
    
    Command (m for help): d
    Partition number (1,2, default 2): 2
    Partition 2 is deleted
    
    Command (m for help): n
    Partition type:
       p   primary (1 primary, 0 extended, 3 free)
       e   extended
    Select (default p): p
    Partition number (2-4, default 2): 2
    First sector (1026048-3906917807, default 1026048): 
    Using default value 1026048
    Last sector, +sectors or +size{K,M,G} (1026048-3906917807, default 3906917807): +512G
    Partition 2 of type Linux and of size 512 GiB is set
    
    Command (m for help): p
    
    Disk /dev/sda: 2000.3 GB, 2000341917696 bytes, 3906917808 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 262144 bytes / 524288 bytes
    Disk label type: dos
    Disk identifier: 0x000b9cd2
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048     1026047      512000   83  Linux
    /dev/sda2         1026048  1074767871   536870912   83  Linux
    
    Command (m for help): w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    
    WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
    The kernel still uses the old table. The new table will be used at
    the next reboot or after you run partprobe(8) or kpartx(8)
    Syncing disks.
  • If disk is in use, reboot. Else try partprobe or kpartx.
  • Resize PV:
    # pvresize /dev/sda2
      Physical volume "/dev/sda2" changed
      1 physical volume(s) resized / 0 physical volume(s) not resized
  • Verify new size:
    [root@srv2 ~]# pvs
      PV         VG     Fmt  Attr PSize   PFree  
      /dev/sda2  centos lvm2 a--  512.00g 230.00g
kvm_grow_pv.txt · Last modified: 2021/10/09 15:14 by 127.0.0.1