Resize Guest Disk Virtual Machine

Ringkasan langkah:

  1. Pastikan lokasi disk image yang akan diperbesar kapasitasnya
  2. Tentukan cara yang akan digunakan untuk memperbesar VM nya
    • Lihat informasi partisi pada disk image,
  3. Rename disk image lama, buat Disk image baru dengan ukuran yang diinginkan
  4. Buat disk baru
  5. Jalankan perintah virt-resize

1. Informasi tentang disk image

# virsh dumpxml <GuestName>

contoh:

# virsh dumpxml Digitos_U22_5
<domain type='kvm'>
  <name>Digitos_U22_5</name>
  <uuid>0d737f69-3200-440f-8117-8506bacde339</uuid>
  <metadata xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0" xmlns:cockpit_machines="https://github.com/cockpit-project/cockpit-machines">
    <libosinfo:libosinfo>
      <libosinfo:os id="http://ubuntu.com/ubuntu/22.04"/>
    </libosinfo:libosinfo>
    <cockpit_machines:data>
      <cockpit_machines:has_install_phase>false</cockpit_machines:has_install_phase>
      <cockpit_machines:install_source_type>file</cockpit_machines:install_source_type>
      <cockpit_machines:install_source>/server_images/ubuntu-22.04.3-live-server-amd64.iso</cockpit_machines:install_source>
      <cockpit_machines:os_variant>ubuntu22.04</cockpit_machines:os_variant>
    </cockpit_machines:data>
  </metadata>
  <memory unit='KiB'>2097152</memory>
  <currentMemory unit='KiB'>2097152</currentMemory>
  <vcpu placement='static'>2</vcpu>
  <os>
    <type arch='x86_64' machine='pc-q35-rhel8.6.0'>hvm</type>
  </os>
  <features>
    <acpi/>
    <apic/>
    <vmport state='off'/>
  </features>
  <cpu mode='host-model' check='partial'/>
  <clock offset='utc'>
    <timer name='rtc' tickpolicy='catchup'/>
    <timer name='pit' tickpolicy='delay'/>
    <timer name='hpet' present='no'/>
  </clock>
  <on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>
  <pm>
    <suspend-to-mem enabled='no'/>
    <suspend-to-disk enabled='no'/>
  </pm>
  <devices>
    <emulator>/usr/libexec/qemu-kvm</emulator>
    <disk type='block' device='disk'>
      <driver name='qemu' type='raw' cache='none' io='native'/>
      <source dev='/dev/vmdiskpool/vmdisk5'/>
      <target dev='vda' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x04' slot='0x00' function='0x0'/>
    </disk>
...

Terlihat bahwa disk image ada di : /dev/vmdiskpool/vmdisk5

2. Lihat informasi partisi pada disk image

# virt-df -h

Misalnya :

# virt-df -h -a /dev/vmdiskpool/vmdisk5 
Filesystem                                Size       Used  Available  Use%
vmdisk5-100g:/dev/sda2                    1.7G       130M       1.5G    8%
vmdisk5-100g:/dev/ubuntu-vg/ubuntu-lv
                                          8.0G       4.2G       3.4G   53%

3. Rename disk image

lvrename /dev/vmdiskpool/vmdisk5 /dev/vmdiskpool/vmdisk5.backup

4. Buat Disk baru

# lvcreate -L <new-size>G -n <nama-disk> <disk-pool>/dev/vg_guests

contoh:

# lvcreate -L 100G -n vmdisk5 /dev/vmdiskpool

5. Resize partisi (optional) dan salin partisi lama ke disk image baru

Bagi yang belum terinstall virt-resize, untuk pengguna Ubuntu, Debian dapat memasangnya sbb:

# apt-get install libguestfs-tools

Berikut penggunaannya:

# virt-resize /dev/vmdiskpool/vmdisk5-backup /dev/vmdiskpool/vmdisk5 --resize /dev/sda2=1.8G  --expand /dev/sda3 --LV-expand /dev/ubuntu-vg/ubuntu-lv

Output nya kira-kira akan seperti ini:

[   0.0] Examining /dev/vmdiskpool/vmdisk5-backup
**********

Summary of changes:

/dev/sda1: This partition will be left alone.

/dev/sda2: This partition will be resized from 1.8G to 1.8G.  The 
filesystem ext4 on /dev/sda2 will be expanded using the ‘resize2fs’ 
method.

/dev/sda3: This partition will be resized from 8.2G to 98.2G.  The LVM PV 
on /dev/sda3 will be expanded using the ‘pvresize’ method.

/dev/ubuntu-vg/ubuntu-lv: This logical volume will be expanded to maximum 
size.  The filesystem ext4 on /dev/ubuntu-vg/ubuntu-lv will be expanded 
using the ‘resize2fs’ method.

**********
[   3.7] Setting up initial partition table on /dev/vmdiskpool/vmdisk5
[  14.9] Copying /dev/sda1
[  14.9] Copying /dev/sda2
 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
[  18.7] Copying /dev/sda3
 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
[  46.2] Expanding /dev/sda2 using the ‘resize2fs’ method
[  46.3] Expanding /dev/sda3 using the ‘pvresize’ method
[  46.3] Expanding /dev/ubuntu-vg/ubuntu-lv using the ‘resize2fs’ method

Resize operation completed with no errors.  Before deleting the old disk, 
carefully check that the resized disk boots and works correctly.

Reference:

mysqldump in practice

Default

Kasus #1

# mysqldump --no-create-info --complete-insert --insert-ignore pintar_db > pintar_db-20230824-2208.insert-ignore.data

File backup yang dihasilkan:

  1. tidak memuat perintah CREATE [table “” not found /]
  2. kalau ada data yang akan di insert, ternyata sudah ada, maka proses insert record data terkait akan di lewatkan
  3. complete-insert …

Kasus #2 – replace

mysqldump --no-create-info --replace pintar_db > pintar_db-20230827-1554.replace.data

File backup yang dihasilkan:

  1. tidak memuat perintah CREATE [table “” not found /]
  2. kalau ada data yang akan di insert, ternyata sudah ada, maka data tersebut akan direplace oleh data yang baru datang

Kasus #3 – dump table tertentu

Jika Anda akan dumping tabel-tabel t1, t2, dan t3 dari mydb:

mysqldump -u... -p... mydb t1 t2 t3 > mydb_tables.sql

Sebaliknya, Jika Anda akan dumping semua tabel kecuali tabel-tabel t1, t2, dan t3 dari mydb:

DBTODUMP=mydb
SQL="SET group_concat_max_len = 10240;"
SQL="${SQL} SELECT GROUP_CONCAT(table_name separator ' ')"
SQL="${SQL} FROM information_schema.tables WHERE table_schema='${DBTODUMP}'"
SQL="${SQL} AND table_name NOT IN ('t1','t2','t3')"
TBLIST=`mysql -u... -p... -AN -e"${SQL}"`
mysqldump -u... -p... ${DBTODUMP} ${TBLIST} > mydb_tables.sql

Note: Anda dapat mengubah SQL="${SQL} AND table_name NOT IN ('t1','t2','t3')" to SQL="${SQL} AND table_name NOT LIKE 'foo\_%'". Anda juga dapat mengganti kondisi menjadi ‘%foo%’ untuk mendapatkan semua table yang menggandung kosa-kata ‘foo’ dalam nama tabelnya (termasuk didalamnya seperti: ‘food’, ‘fool’, dst).

Kasus #4 – ignore table(s)

Cara lain jika Anda akan dumping semua tabel kecuali tabel-tabel t1, t2, dan t3 dari mydb:

mysqldump -uusername -ppassword dbname \
  --ignore-table=schema.t1    \
  --ignore-table=schema.t2    \
  --ignore-table=schema.t3 > mysqldump.sql

File backup yang dihasilkan:

  1. Semua table di dump tapi tidak akan dumping table t1,t2 dan t3

References:

  1. https://man7.org/linux/man-pages/man1/mysqldump.1.html
  2. https://dba.stackexchange.com/questions/9306/how-do-you-mysqldump-specific-tables