Tuesday, February 13, 2018

Resize encrypted CentOS7 PV volume


If you ticked the checkbox "encrypt volume" during CentOS7 installation, the Disk is encrypted on the LVM PV (Physical Volume) level by CentOS using LUKS.
Therefore you need to perform this steps to grow one of the LVM partitions:
  • Increase the Partition of the disk
  • Increase the PV (physical LVM Volume)
  • Increase the LV (logical LVM Volume) 
  • Increase the file system of the partition holding your data.
Steps (example using VMWare ESXi VM):
  1. Increase the disk size in vCenter / ESXi for the VM (e.g from 750 GB to 800 GB). This can be done while the VM machine is up.
  2. Create a snapshot of the VM
  3. Reboot the VM
  4. Resize the disk partition
    fdisk /dev/sda
    
    • Print the partition table:
      Command (m for help): p
      
      Disk /dev/sda: 859.0 GB, 858993459200 bytes, 1677721600 sectors <--size in GiB!
      
      Device  boot.     Start        End     Blocks   Id  System
      /dev/sda1   *        2048     2099199     1048576   83  Linux
      /dev/sda2         2099200  1572863999   785382400   83  Linux <-- Holds the LVM vols.
      
    • Now delete the partition (not kidding):
      Command (m for help): d
      Partition number (1,2, default 2): 2
      
    • Re-create the partion with larger size:
      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 (2099200-1677721599, default 2099200): [ENTER]
      Using default value 2099200
      Last sector, +sectors or +size{K,M,G} (2099200-1677721599, default 1677721599): [ENTER]
      Using default value 1677721599
      Partition 2 of type Linux and of size 799 GiB is set
      
    • Check the partition table:
      Command (m for help): p
      
      Disk /dev/sda: 859.0 GB, 858993459200 bytes, 1677721600 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 label type: dos
      Disk identifier: 0x000f06d8
      
         Device Boot      Start         End      Blocks   Id  System
      /dev/sda1   *        2048     2099199     1048576   83  Linux
      /dev/sda2         2099200  1677721599   837811200   83  Linux   <-- New size
      
    • Write the partition table and exit:
      Command (m for help): w
      
  5. reboot
  6. Resize the PV (LVM Physical Volume):
    • Display the PV volumes:
      [root@localhost]# pvdisplay
        --- Physical volume ---
        PV Name               /dev/mapper/luks-999a99b9-8a99-9abc-d999-b99bb9999bb9
        VG Name               cl
        PV Size               <749,00 GiB / not usable 0
        Allocatable           yes
        PE Size               4.00 MiB
        Total PE              191743
        Free PE               1
        Allocated PE          191742
        PV UUID               Zu21Ve-7mx5-v4p2-bxfa-ZH2N-EbWE-WeMk3T
      
    • Resize the PV (to the maximum available)
      [root@localhost]# pvresize /dev/mapper/luks-999a99b9-8a99-9abc-d999-b99bb9999bb9
      Physical volume "/dev/mapper/luks-999a99b9-8a99-9abc-d999-b99bb9999bb9" changed
      1 physical volume(s) resized / 0 physical volume(s) not resized
      
    • check the PV:
      [root@localhost]# pvdisplay
        --- Physical volume ---
        PV Name               /dev/mapper/luks-999a99b9-8a99-9abc-d999-b99bb9999bb9
        VG Name               cl
        PV Size               <799,00 GiB / not usable 1,00 MiB
        Allocatable           yes
        PE Size               4,00 MiB
        Total PE              204543
        Free PE               12801
        Allocated PE          191742
        PV UUID               Zu21Ve-7mx5-v4p2-bxfa-ZH2N-EbWE-WeMk3T
      
  7. Resize LV (logical volume):
    • Display the Logical volume(s):
      [root@localhost]# lvdisplay
       ...
       --- Logical volume ---
        LV Path                /dev/cl/DATA
        LV Name                DATA2
        VG Name                cl
        LV UUID                X8AAA-4aAa-Aaaa-8A8A-BbbB-bb8b-bbB8BB
        LV Write Access        read/write
        LV Creation host, time localhost.localdomain, 2018-02-02 09:50:26 +0400
        LV Status              available
        # open                 1
        LV Size                <411,12 GiB
        Current LE             105246
        Segments               1
        Allocation             inherit
        Read ahead sectors     auto
        - currently set to     8192
        Block device           253:8
      
    • Resize the LV:
      [root@localhost]# lvresize --size +50G /dev/cl/DATA
      Size of logical volume cl/DATA changed from <411,12 GiB (105246 extents) to <461,12 GiB (118046 extents).
      Logical volume cl/DATA successfully resized.
      
    • Check the LV partition:
      [root@localhost]# lvdisplay
        ...
        --- Logical volume ---
        LV Path                /dev/cl/DATA
        LV Name                DATA2
        VG Name                cl
        LV UUID                X8AAA-4aAa-Aaaa-8A8A-BbbB-bb8b-bbB8BB
        LV Write Access        read/write
        LV Creation host, time localhost.localdomain, 2018-02-02 09:50:26 +0400
        LV Status              available
        # open                 1
        LV Size                <461,12 GiB
        Current LE             118046
        Segments               1
        Allocation             inherit
        Read ahead sectors     auto
        - currently set to     8192
        Block device           253:8
      
  8. Resize file system (can be done on-the-fly without unmount if it is XFS):
    [root@localhost]# xfs_growfs /dev/cl/DATA
    meta-data=/dev/mapper/cl-DATA2   isize=512    agcount=4, agsize=26942976 blks
             =                       sectsz=512   attr=2, projid32bit=1
             =                       crc=1        finobt=0 spinodes=0
    data     =                       bsize=4096   blocks=107771904, imaxpct=25
             =                       sunit=0      swidth=0 blks
    naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
    log      =Intern                 bsize=4096   blocks=52623, version=2
             =                       sectsz=512   sunit=0 blks, lazy-count=1
    realtime =keine                  extsz=4096   blocks=0, rtextents=0
    Datablocks changed from 107771904 to 120879104.

No comments:

Post a Comment