Untuk CentOS/RHEL 7
Untuk mengakses citra disk qcow2 tamu pada host CentOS/RHEL 7 KVM, gunakan qemu-nbd atau libguestfs .
Menggunakan qemu-nbd
Ikuti langkah-langkah di bawah ini untuk memasang gambar qcow2 di CentOS/RHEL 7 menggunakan qemu-nbd.
1. Aktifkan driver kernel NBD pada host KVM.
# modprobe nbd
2. Hubungkan gambar qcow2 sebagai perangkat blok jaringan.
# qemu-nbd --connect=/dev/nbd0 olseven.qcow2 -f qcow2
3. Temukan partisi pada gambar menggunakan fdisk
# fdisk /dev/nbd0 -l Disk /dev/nbd0: 32.2 GB, 32212254720 bytes, 62914560 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: 0x0009e4c2 Device Boot Start End Blocks Id System /dev/nbd0p1 * 2048 2099199 1048576 83 Linux /dev/nbd0p2 2099200 62914559 30407680 8e Linux LVM
4. Perangkat /dev/nbd0p2, adalah LVM sehingga Anda perlu mencari PV/VG dan LV baru di mesin host KVM.
# pvscan PV /dev/sda3 VG ol_kvm lvm2 [<363.23 GiB / 8.00 MiB free] Total: 1 [<363.23 GiB] / in use: 1 [<363.23 GiB] / in no VG: 0 [0 ]
Segarkan cache volume fisik sehingga mesin host mengenali PV baru.
# pvscan --cache
# pvscan PV /dev/sda3 VG ol_kvm lvm2 [<363.23 GiB / 8.00 MiB free] PV /dev/nbd0p2 VG ol_guestol lvm2 [<29.00 GiB / 4.00 MiB free] >> Now its listed. Total: 2 [392.22 GiB] / in use: 2 [392.22 GiB] / in no VG: 0 [0 ]
# vgscan Reading volume groups from cache. Found volume group "ol_kvm" using metadata type lvm2 Found volume group "ol_guestol" using metadata type lvm2 >> The VG in the image.
# lvscan ACTIVE '/dev/ol_kvm/root' [<46.57 GiB] inherit ACTIVE '/dev/ol_kvm/home' [206.75 GiB] inherit ACTIVE '/dev/ol_kvm/var' [<102.45 GiB] inherit ACTIVE '/dev/ol_kvm/swap' [7.45 GiB] inherit inactive '/dev/ol_guestol/swap' [2.00 GiB] inherit >> LV in the image. inactive '/dev/ol_guestol/root' [26.99 GiB] inherit >> LV in the image.
5. Aktifkan VG OS tamu.
# vgchange -ay 4 logical volume(s) in volume group "ol_kvm" now active 2 logical volume(s) in volume group "ol_guestol" now active
# lvscan ACTIVE '/dev/ol_kvm/root' [<46.57 GiB] inherit ACTIVE '/dev/ol_kvm/home' [206.75 GiB] inherit ACTIVE '/dev/ol_kvm/var' [<102.45 GiB] inherit ACTIVE '/dev/ol_kvm/swap' [7.45 GiB] inherit ACTIVE '/dev/ol_guestol/swap' [2.00 GiB] inherit ACTIVE '/dev/ol_guestol/root' [26.99 GiB] inherit
6. Pasang partisi LVM
# mount /dev/mapper/ol_guestol-root /ol7/ # cd /ol7/ # ls bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys test tmp usr var
Setelah perubahan dibuat pada citra disk virtual dengan aman, putuskan sambungan disk virtual untuk menghindari masalah apa pun.
1. Lepas partisi LVM:
# umount /ol7/
2. Nonaktifkan grup volume.
# vgchange -an ol_guestol 0 logical volume(s) in volume group "ol_guestol" now active
3. Putuskan sambungan gambar dari NBD
# qemu-nbd --disconnect /dev/nbd0 /dev/nbd0 disconnected
4. Hapus driver kernel NBD
# rmmod nbd
Untuk CentOS/RHEL 6
qemu-image yang dikirimkan dengan CentOS/RHEL 6, tidak memiliki dukungan NBD. Jadi, untuk mengakses image disk virtual di host CentOS/RHEL 6 KVM gunakan libguestfs alat.
1. Instal alat libguestfs
# yum install libguestfs-tools
2. Jalankan shell sistem file tamu
# guestfish --rw -a /var/lib/libvirt/images/olseven.qcow2 Welcome to guestfish, the guest filesystem shell for editing virtual machine filesystems and disk images. Type: ‘help’ for help on commands ‘man’ to read the manual ‘quit’ to quit the shell [fs]
3. Luncurkan backend menggunakan perintah "jalankan".
[fs] run 100% ⟦#################################################################################⟧ 00:00
4. Buat daftar sistem file dalam gambar.
[fs] list-filesystems /dev/sda1: xfs /dev/ol_guestol/root: xfs /dev/ol_guestol/swap: swap
5. Keluar dari shell sistem file tamu dan pasang partisi yang terlihat pada gambar disk.
# guestmount -a /var/lib/libvirt/images/olseven.qcow2 -m /dev/ol_guestol/root /ol7/
# cd /ol7/ # ls bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys test tmp usr var
6. Setelah selesai membuat perubahan pada gambar, unmount.
# umount /ol7/