Saturday, June 13, 2009

Hard disk image in qemu

create/update image

Install a mini linux system in </sub-linux>. It is very easy to install debian inside another Linux.

Update image quickly

 qemu-img create -b <hd.img> -f qcow2 <hd.qcow2> 

Update image

 sudo genext2fs -d </sub-linux> -b 344800 <hd.img> chown <yourself>. <hd.img> 

If you use <hd.qcow2> in QEMU, <hd.img> will not changed for ordinary usage.

commit changes

You can explicitely commit changes to <hd.img> by qemu monitor command "commit".

access qcow2 image

 $ qemu-nbd [-p <port>] hd.qcow2 $ sudo modprobe nbd nbds_max=<2> $ sudo nbd-client localhost <port> /dev/nbd0 $ sudo mount /dev/nbd0 /mnt 

after using:

 $ sudo umount /mnt $ sudo nbd-client -d /dev/nbd0 

No comments: