GNU/Linux >> Linux Esercitazione >  >> Cent OS

Come montare Guest Qcow2 Disco virtuale Immagine contenente LVM su macchina host KVM

Per CentOS/RHEL 7

Per accedere all'immagine del disco qcow2 del guest su un host KVM CentOS/RHEL 7, utilizzare qemu-nbd o libguestfs .

Utilizzo di qemu-nbd

Segui i passaggi seguenti per montare l'immagine qcow2 in CentOS/RHEL 7 usando qemu-nbd.

1. Abilita il driver del kernel NBD sull'host KVM.

# modprobe nbd

2. Collega l'immagine qcow2 come dispositivo di blocco di rete.

# qemu-nbd --connect=/dev/nbd0 olseven.qcow2 -f qcow2

3. Trova le partizioni nell'immagine usando 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. Il dispositivo /dev/nbd0p2 è LVM, quindi è necessario individuare i nuovi PV/VG e LV nella macchina 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 ]

Aggiorna la cache del volume fisico in modo che la macchina host riconosca il nuovo 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. Attiva il VG del SO guest.

# 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. Montare la partizione 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

Una volta apportate le modifiche all'immagine del disco virtuale, disconnetti in modo sicuro il disco virtuale per evitare problemi.

1. Smonta la partizione LVM:

# umount /ol7/

2. Disattiva il gruppo di volumi.

# vgchange -an ol_guestol
0 logical volume(s) in volume group "ol_guestol" now active

3. Scollegare l'immagine da NBD

# qemu-nbd --disconnect /dev/nbd0
/dev/nbd0 disconnected

4. Rimuovere il driver del kernel NBD

# rmmod nbd

Per CentOS/RHEL 6

L'immagine qemu fornita con CentOS/RHEL 6 non ha il supporto NBD. Quindi, per accedere all'immagine del disco virtuale nell'host KVM CentOS/RHEL 6, utilizzare libguestfs strumento.

1. Installa gli strumenti libguestfs

# yum install libguestfs-tools

2. Eseguire la shell del filesystem guest

# 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. Avvia il backend usando il comando "run".

[fs] run
100% ⟦#################################################################################⟧ 00:00

4. Elenca i filesystem nell'immagine.

[fs] list-filesystems
/dev/sda1: xfs
/dev/ol_guestol/root: xfs
/dev/ol_guestol/swap: swap

5. Esci dalla shell del filesystem guest e monta la partizione vista nell'immagine del disco.

# 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. Una volta terminate le modifiche all'immagine, smontala.

# umount /ol7/


Cent OS
  1. Come utilizzare gli strumenti libguestfs per modificare le immagini del disco della macchina virtuale (VM) in CentOS/RHEL/Fedora?

  2. Come aggiungere memoria, vCPU, disco rigido alla macchina virtuale KVM Linux

  3. Come montare un'immagine disco multi-partizione in Linux?

  4. Come posso montare un'immagine disco?

  5. Come inviare/caricare un file dal sistema operativo host al sistema operativo guest in KVM? (non condivisione di cartelle)

Come clonare la macchina virtuale in VirtualBox

Come installare le aggiunte guest di VirtualBox nella macchina virtuale Debian 9

Come montare il file del disco rigido virtuale (VHD) in Ubuntu Linux?

Come configurare un host virtuale Nginx

Come creare un modello di macchina virtuale KVM

Come creare macchine virtuali in KVM usando Virt-Manager