TOPIC 3

Date: 6/3/2019
Server virtualization with KVM
Linux System Administration


Exercise: Accessing the virtual drive of a VM


If a VM fails to boot for some reason, you may need to access the virtual drive, analyse the system logs, and fix the configuration.
Below is the procedure how to mount the qcow2 disk image.

  • Shutdown kvm3
    
    virsh shutdown kvm3 
    

  • Load nbd kernel module for two partitions. It allows to create a mountable block device from the qcow2 file:
    
    sudo -s
    modprobe nbd max_part=2
    qemu-nbd --connect=/dev/nbd0 kvm3.qcow2
    

  • Create a mounting point, /mnt/vm, and mount the root partition of the drive:
    
    mkdir -p /mnt/vm
    cd KVM
    fdisk /dev/nbd0 -l 
    mount /dev/nbd0p1 /mnt/vm
    

  • Now you should be able to access the virtual drive content in directory /mnt/vm
    
    cd /mnt/vm
    ls 
    cat etc/hostname
    

  • Unmount and disconnect the drive:
    
    cd
    umount /mnt/vm
    qemu-nbd --disconnect /dev/nbd0 
    



  • Take me to the Course Website