Pour CentOS/RHEL 7
Pour accéder à l'image disque qcow2 de l'invité sur un hôte KVM CentOS/RHEL 7, utilisez soit qemu-nbd ou libguestfs .
Utiliser qemu-nbd
Suivez les étapes ci-dessous pour monter l'image qcow2 dans CentOS/RHEL 7 à l'aide de qemu-nbd.
1. Activez le pilote du noyau NBD sur l'hôte KVM.
# modprobe nbd
2. Connectez l'image qcow2 en tant que périphérique de bloc réseau.
# qemu-nbd --connect=/dev/nbd0 olseven.qcow2 -f qcow2
3. Trouvez les partitions dans l'image à l'aide de 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. Le périphérique /dev/nbd0p2 est LVM, vous devez donc localiser les nouveaux PV/VG et LV sur la machine hôte 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 ]
Actualisez le cache du volume physique afin que la machine hôte reconnaisse le nouveau PV.
# 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. Activez le VG du système d'exploitation invité.
# 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. Montez la partition 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
Une fois les modifications apportées à l'image du disque virtuel, déconnectez le disque virtuel en toute sécurité pour éviter tout problème.
1. Démontez la partition LVM :
# umount /ol7/
2. Désactivez le groupe de volumes.
# vgchange -an ol_guestol 0 logical volume(s) in volume group "ol_guestol" now active
3. Déconnectez l'image de NBD
# qemu-nbd --disconnect /dev/nbd0 /dev/nbd0 disconnected
4. Supprimez le pilote du noyau NBD
# rmmod nbd
Pour CentOS/RHEL 6
L'image qemu fournie avec CentOS/RHEL 6 ne prend pas en charge NBD. Ainsi, pour accéder à l'image du disque virtuel dans l'hôte KVM CentOS/RHEL 6, utilisez libguestfs outil.
1. Installez les outils libguestfs
# yum install libguestfs-tools
2. Exécutez le shell du système de fichiers invité
# 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. Lancez le backend à l'aide de la commande "exécuter".
[fs] run 100% ⟦#################################################################################⟧ 00:00
4. Répertoriez les systèmes de fichiers dans l'image.
[fs] list-filesystems /dev/sda1: xfs /dev/ol_guestol/root: xfs /dev/ol_guestol/swap: swap
5. Quittez le shell du système de fichiers invité et montez la partition visible dans l'image disque.
# 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. Une fois que vous avez terminé d'apporter des modifications à l'image, démontez-la.
# umount /ol7/