Changes between Initial Version and Version 1 of Linux/MountQemuQcowImages


Ignore:
Timestamp:
06/02/09 22:31:02 (9 years ago)
Author:
tj
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Linux/MountQemuQcowImages

    v1 v1  
     1= Mount KVM/QEMU QCOW images = 
     2Since around kvm-77 the `qemu-nbd` program (known as kvm-nbd on Debian/Ubuntu)  has been available. It is a Network Block Device server that can mount a QCOW/QCOW2 disk image (created by `qemu-img`) on a host. 
     3 
     4This is really handy for preparing the contents of a disk image without starting a virtual machine guest, or to copy files to/from the disk image without starting the virtual machine guest and having to use some form of network protocol to do it. 
     5 
     6First, ensure the `nbd` kernel module is loaded: 
     7{{{ 
     8sudo modprobe nbd 
     9}}} 
     10Now create a local block device (the process is put into the background): 
     11{{{ 
     12sudo kvm-nbd -c /dev/nbd0 ubuntu-jaunty-desktop.qcow2 & 
     13NBD device /dev/nbd0 is now connected to file ubuntu-jaunty-desktop.qcow2}}} 
     14The block device is now found at `/dev/nbd0` so it can be treated like a physical disk. For example: 
     15{{{ 
     16sudo cfdisk -P s /dev/nbd0 
     17Partition Table for /dev/nbd0 
     18 
     19               First       Last 
     20 # Type       Sector      Sector   Offset    Length   Filesystem Type (ID) Flag 
     21-- ------- ----------- ----------- ------ ----------- -------------------- ---- 
     22 1 Primary           0      208844     63      208845 Unknown (27)         None 
     23 2 Primary      208845      803249      0      594405 HPFS/NTFS (07)       None 
     24 3 Primary      803250     1799279      0      996030 Linux swap / So (82) None 
     25 4 Primary     1799280    10474379      0     8675100 Extended (05)        None 
     26 5 Logical     1799280     2104514     63      305235 Linux (83)           None 
     27 6 Logical     2104515    10474379     63     8369865 Linux (83)           None 
     28}}} 
     29To disconnect the block device use `nbd-client`: 
     30You might need to install the package: 
     31{{{ 
     32sudo apt-get install nbd-client 
     33}}} 
     34To disconnect: 
     35{{{ 
     36sudo nbd-client -d /dev/nbd0 
     37}}}