There are upcoming maintenance events which may impact our services. Daha çox öyrən

Resizing Partition After Storage Upgrade Çap et

  • 0

Situation

  1. After a storage upgrade on a cloud/virtual server, the volume size allocated will be larger than the current partition size.
  2. Need to resize the partition to make sue of the upgraded space.

Procedure

  1. SSH to the newly created instance/VM and check current disk usage. You will see that regardless how much volume size upgraded earlier, total space will still follow the original size. In this example:-
    • Current storage size: 9GB
    • Upgraded storage size allocated to instance: 20GB
  2. You will need to resize this partition to fully utilize the whole allocated volume size.
    df -h

    Sample output:-

    Filesystem               Size  Used Avail Use% Mounted on
    /dev/mapper/centos-root  8.5G  5.7G  2.8G  68% / <----------------- Total Disk Space only 8.5GB
    devtmpfs                 1.9G     0  1.9G   0% /dev
    tmpfs                    1.9G     0  1.9G   0% /dev/shm
    tmpfs                    1.9G  8.6M  1.9G   1% /run
    tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
    /dev/vda1                497M  169M  329M  34% /boot
    tmpfs                    380M     0  380M   0% /run/user/0
    /dev/loop0               477M  2.4M  449M   1% /tmp
  3. Check current VM ROOT volume partition layout:-
    fdisk /dev/vda

    Sample output:-

    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): p
    
    Disk /dev/vda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x000eb263
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/vda1   *        2048     1026047      512000   83  Linux
    /dev/vda2         1026048    20971519     9972736   8e  Linux LVM <----- Needs to be resized
  4. First, we delete (yes, delete) the current Linux LVM partition.
    Command (m for help): d
    Partition number (1,2, default 2):
    Partition 2 is deleted
  5. Next, we create a new primary partition with full volume size allocated to it (In this example, total volume size is 19.5GB):-
    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-41943039, default 1026048):
    Using default value 1026048
    Last sector, +sectors or +size{K,M,G} (1026048-41943039, default 41943039):
    Using default value 41943039
    Partition 2 of type Linux and of size 19.5 GiB is set
  6. We need to set this new partition type to Linux LVM, just as before.
    Command (m for help): t
    Partition number (1,2, default 2):
    Hex code (type L to list all codes): 8e
    Changed type of partition 'Linux' to 'Linux LVM'
  7. Now, view the partition summary again, to verify that the size of the new Linux LVM partition now maximizes the available volume space:-
    Command (m for help): p
    
    Disk /dev/vda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x000eb263
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/vda1   *        2048     1026047      512000   83  Linux
    /dev/vda2         1026048    41943039    20458496   8e  Linux LVM
  8. If all OK, write changes to disk.
    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.
  9. Rescan the partitions to update the environment on this new size.
    partprobe -s

    Example output:-

    Error: Partition(s) 2 on /dev/vda have been written, but we have been unable to inform the kernel of the change, probably because it/they are in use.  As a result, the old partition(s) will remain in use.  You should reboot now before making further changes.
  10. Reboot the VM to activate the new sizing:-
    shutdown -r now
  11. After it reboots, check PV size:-
    pvs

    Sample output:-

      PV         VG     Fmt  Attr PSize PFree
      /dev/vda2  centos lvm2 a--  9.51g 40.00m

    You will see that the PV size is still the same as the old volume size (in this example, 9.51GB).

  12. Resize this partition:-
    pvresize /dev/vda2

    Sample output:-

      Physical volume "/dev/vda2" changed
      1 physical volume(s) resized / 0 physical volume(s) not resized
  13. Now check PV size after resizing, should be utilizing whole volume space:-
    pvs

    Sample output:-

      PV         VG     Fmt  Attr PSize  PFree
      /dev/vda2  centos lvm2 a--  19.51g 10.04g
  14. Next, check Volume Group (VG) size:-
    vgs

    Sample output:-

      VG     #PV #LV #SN Attr   VSize  VFree
      centos   1   2   0 wz--n- 19.51g 10.04g
  15. Looks OK already (utilizing whole space). Next is to check LV:-
    lvs

    Sample output:-

      LV   VG     Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
      root centos -wi-ao---- 8.47g                                                  
      swap centos -wi-ao---- 1.00g                                                  

    Ok LV still occupying old amount of space. Need to extend as follows:-

    lvextend -l +100%FREE centos/root

    Sample output:-

      Size of logical volume centos/root changed from 8.47 GiB (2168 extents) to 18.51 GiB (4738 extents).
      Logical volume centos/root successfully resized.
  16. Check LV again:-
    lvs

    Sample output (verify LSize now fills up maximum volume size):-

      LV   VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
      root centos -wi-ao---- 18.51g                                                 
      swap centos -wi-ao----  1.00g                                                 
  17. Now grow the filesystem in order to follow the new volume size. Find out the filesystem of the partition to be resized:-
    mount

    Sample output:-

    ....
    /dev/mapper/vg_centos6template-lv_root on / type ext4 (rw)
    ....
  18. Resize the filesystem according to its type:-
    • For xfs filesystem, use xfs_growfs, for example:-
      xfs_growfs /dev/mapper/centos-root

      Sample output:-

      meta-data=/dev/mapper/centos-root isize=256    agcount=4, agsize=555008 blks
               =                       sectsz=512   attr=2, projid32bit=1
               =                       crc=0        finobt=0 spinodes=0
      data     =                       bsize=4096   blocks=2220032, imaxpct=25
               =                       sunit=0      swidth=0 blks
      naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
      log      =internal               bsize=4096   blocks=2560, version=2
               =                       sectsz=512   sunit=0 blks, lazy-count=1
      realtime =none                   extsz=4096   blocks=0, rtextents=0
      data blocks changed from 2220032 to 4851712
    • For ext4 filesystem, use resize2fs, for example:-
      resize2fs /dev/mapper/vg_centos6template-lv_root

      Sample output:-

      resize2fs 1.41.12 (17-May-2010)
      Filesystem at /dev/mapper/vg_centos6template-lv_root is mounted on /; on-line resizing required
      old desc_blocks = 1, new_desc_blocks = 2
      Performing an on-line resize of /dev/mapper/vg_centos6template-lv_root to 7683072 (4k) blocks.
      The filesystem on /dev/mapper/vg_centos6template-lv_root is now 7683072 blocks long.
  19. Check df -h again to reconfirm:-
    df -h

    Sample output:-

    Filesystem               Size  Used Avail Use% Mounted on
    /dev/mapper/centos-root   19G  5.7G   13G  31% /
    devtmpfs                 5.8G     0  5.8G   0% /dev
    tmpfs                    5.8G     0  5.8G   0% /dev/shm
    tmpfs                    5.8G  8.6M  5.8G   1% /run
    tmpfs                    5.8G     0  5.8G   0% /sys/fs/cgroup
    /dev/vda1                497M  169M  329M  34% /boot
    /dev/loop0               477M  2.4M  449M   1% /tmp
    tmpfs                    1.2G     0  1.2G   0% /run/user/0
  20. Resizing complete. Continue the rest of the tasks you were working on.

Bu cavab sizə kömək etdi?

<< Geri