Cara Extend Storage KVM

Setelah beli storage tambahan untuk VM (KVM), terkadang kapasitasnya tidak otomatis bertambah, meskipun VM sudah di stop dan distart kembali. Biasanya disebabkan adanya partisi swap yang menghalangi proses extendnya.

Skenario:
– Saya sudah punya VM dengan kapasitas storage 30G.
– Beli storage tambahan 90G.

– Tujuan akhir, storage total vm partisi “/” menjadi 120G.

Berikut adalah cara extend storage kvm secara manual:

  1. Kondisi semula, partisi /  ( 30G )
    bash-4.2# df -h
    Filesystem      Size  Used Avail Use% Mounted on
    devtmpfs        2.9G     0  2.9G   0% /dev
    tmpfs           2.9G  136K  2.9G   1% /dev/shm
    tmpfs           2.9G  8.5M  2.9G   1% /run
    tmpfs           2.9G     0  2.9G   0% /sys/fs/cgroup
    /dev/vda1       30G  5.0G  25G   17% /
  2. Cek partisi vm saat ini,  dari  contoh  ini  ada  dua  partisi  vda1  dan  vda2
    bash-4.2# fdisk -l
    
    Disk /dev/vda: 128.8 GB, 128849018880 bytes, 251658240 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: 0x000b136f
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/vda1   *        2048    81788928    40893440+  82  Linux swap / Solaris
    /dev/vda2        81788929    83886079     1048575+  82  Linux swap / Solaris
  3. Cek detailnya di fstab, vi /etc/fstab ternyata vda2 adalah swap, comment (#) swapnya
    # /etc/fstab
    # Created by anaconda on Mon May 14 08:32:03 2018
    #
    # Accessible filesystems, by reference, are maintained under '/dev/disk'
    # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
    #
    LABEL=root /                       ext4    defaults        1 1
    #/dev/vda2        swap       swap       defaults  
  4. Sementara swap kita off kan dulu
    bash-4.2# swapoff -v /dev/vda2
    
  5. Selanjutnya hapus partisi swapnya  menggunakan  “fdisk”
    bash-4.2# fdisk /dev/vda
    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): 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.
  6. Install growpart utility
    yum install cloud-utils-growpart
  7. Lakukan extend storage vda1, dengan perintah growpart dan resize2fs
    bash-4.2# growpart /dev/vda 1
    CHANGED: partition=1 start=2048 old: size=81786881 end=81788929 new: size=251656159 end=251658207
    bash-4.2# resize2fs /dev/vda1
    resize2fs 1.42.9 (28-Dec-2013)
    Filesystem at /dev/vda1 is mounted on /; on-line resizing required
    old_desc_blocks = 5, new_desc_blocks = 15
    The filesystem on /dev/vda1 is now 31457019 blocks long.
  8. Stop vm dari dasbor member area, lalu start lagi
  9. Cek ulang, dan storagenya sudah bertambah ( / partisi sebelumnya 30G sekarang jadi 120G – sesuai storage tambahan yang dibeli)
    bash-4.2# df -h
    Filesystem      Size  Used Avail Use% Mounted on
    devtmpfs        2.9G     0  2.9G   0% /dev
    tmpfs           2.9G  136K  2.9G   1% /dev/shm
    tmpfs           2.9G  8.5M  2.9G   1% /run
    tmpfs           2.9G     0  2.9G   0% /sys/fs/cgroup
    /dev/vda1       119G  5.0G  108G   5% /
  10. Kondisi terakhir swap di VM kamu tidak ada atau 0 , saran saya dibiarkan tetap begitu saja karena dampaknya tidak terlalu signifikan, justru kalo partisi swap sampai terpakai bisa membuat performa VM menjadi lambat. Kalaupun karena suatu hal kamu masih perlu swap, kamu bisa gunakan tutorial ini
Sprinter Asked on 14 July 2021 in VPS.
Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.