'Qemu'에 해당되는 글 3건

  1. 2013.09.28 Resize qcow2 image
  2. 2012.06.22 KVM/QEMU Guide #1 (Intro & Basic)
  3. 2012.05.13 KVM/QEMU - How to Migration(include LIve)

Resize qcow2 image

Cloud/KVM 2013. 9. 28. 23:07
[Info]
  • e.g.) Default 8GB(orig.img) -> 20GB(test.img) any..
  • Both Single-Image and BackingType-Image 
  • Test format: qcow2
  • Tools: parted, qemu-img, qemu-nbd
  • Test Platform: Ubuntu 13.04 x86_64


[Start]


- Check Image

# qemu-img info orig.img 

image: orig.img

file format: qcow2

virtual size: 8.0G (8589934592 bytes)

disk size: 883M

cluster_size: 65536

# qemu-img create -b /home/orig.img -f qcow2 test.img

# qemu-img info test.img

image: test.img

file format: qcow2

virtual size: 8.0G (8589934592 bytes)

disk size: 196K

cluster_size: 65536

backing file: /home/orig.img


- Connect NBD & Check partitions

# modprobe nbd

# qemu-nbd -c /dev/nbd0 /home/test.img

# ls -al /dev/nbd0*

brw-rw---- 1 root disk 43, 0 Sep 28 23:18 /dev/nbd0

brw-rw---- 1 root disk 43, 1 Sep 28 23:18 /dev/nbd0p1

# parted /dev/nbd0 --script print free

Model: Unknown (unknown)

Disk /dev/nbd0: 8590MB

Sector size (logical/physical): 512B/512B

Partition Table: msdos


Number  Start   End     Size    Type     File system  Flags

        32.3kB  1049kB  1016kB           Free Space

 1      1049kB  8589MB  8588MB  primary  ext4         boot

        8589MB  8590MB  1049kB           Free Space

- Disconnect NBD & Resize image

# qemu-nbd -d /dev/nbd0

/dev/nbd0 disconnected

# qemu-img resize test.img 20G

Image resized.


- Check image

# qemu-img info test.img

image: test.img

file format: qcow2

virtual size: 20G (21474836480 bytes)

disk size: 200K

cluster_size: 65536

backing file: /home/orig.img


Connect NBD & Check partitions

qemu-nbd -c /dev/nbd0 /home/test.img

parted /dev/nbd0 --script print free

Model: Unknown (unknown)

Disk /dev/nbd0: 21.5GB

Sector size (logical/physical): 512B/512B

Partition Table: msdos


Number  Start   End     Size    Type     File system  Flags

        32.3kB  1049kB  1016kB           Free Space

 1      1049kB  8589MB  8588MB  primary  ext4         boot

        8589MB  21.5GB  12.9GB           Free Space


- Re-Partitioning (Remove Partition and Create Partition) ("1" is partition-number)

# parted /dev/nbd0 --script rm 1

# parted /dev/nbd0 --script print free

Model: Unknown (unknown)

Disk /dev/nbd0: 21.5GB

Sector size (logical/physical): 512B/512B

Partition Table: msdos


Number  Start   End     Size    Type  File system  Flags

        32.3kB  21.5GB  21.5GB        Free Space


# parted -a optimal /dev/nbd0 --script mkpart primary ext4 0% 100%

# parted /dev/nbd0 --script print free

Model: Unknown (unknown)

Disk /dev/nbd0: 21.5GB

Sector size (logical/physical): 512B/512B

Partition Table: msdos


Number  Start   End     Size    Type     File system  Flags

        32.3kB  1049kB  1016kB           Free Space

 1      1049kB  21.5GB  21.5GB  primary  ext4


- Mount image's Partition (to edit boot-script :: rc.local)

# kpartx -a /dev/nbd0

# mount /dev/mapper/nbd0p1 /mnt/


- Apply Parition to VM (by resize2fs)

# echo 'resize2fs /dev/vda1; sed -i \"/resize2fs/d\" /etc/rc.local' >> /mnt/etc/rc.local


[End]

Booting VM with new image




[Appendix]

- Disconnect kpartx & NBD

# umount /mnt

# kpartx -d /dev/nbd0

# qemu-nbd -d /dev/nbd0


Posted by 사랑줍는거지
,

Qemu & kvm guide #1 (intro & basic)

View more documents from JungIn Jung


Posted by 사랑줍는거지
,





Migration

Introduction

KVM currently supports savevm/loadvm and offline or live migration Migration commands are given when in qemu-monitor (Alt-Ctrl-2). Upon successful completion, the migrated VM continues to run on the destination host.

Note

You can migrate a guest between an AMD host to an Intel host and back. Naturally, a 64-bit guest can only be migrated to a 64-bit host, but a 32-bit guest can be migrated at will.

There are some older Intel processors which don't support NX (or XD), which may cause problems in a cluster which includes NX-supporting hosts. To disable NX for a given guest, start it with such a parameter: -cpu qemu64,-nx

Requirements

  • The VM image is accessible on both source and destination hosts (located on a shared storage, e.g. using nfs).
  • It is recommended an images-directory would be found on the same path on both hosts (for migrations of a copy-on-write image -- an image created on top of a base-image using "qemu-image create -b ...")
  • The src and dst hosts must be on the same subnet (keeping guest's network when tap is used).
  • Do not use -snapshot qemu command line option.
  • For tcp: migration protocol
  • the guest on the destination must be started the same way it was started on the source.

highlights / merits

  • Almost unnoticeable guest down time
  • Guest is not involved (unique to KVM Live Migration [#1 1])
  • Capability to tunnel VM state through an external program (unique to KVM Live Migration [#1 1])
  • ssh/gzip/bzip2/gpg/your own
  • Upon success guest continues to run on destination host, upon failure guest continues to run on source host (with one exception)
  • Short and Simple
  • Easy to enhance
  • Hardware independence (almost).
  • Support for migration of stopped (paused) VMs.
  • Open

Anchor(1) 1 These features are unique to KVM Live Migration as far as I know. If you know of other hypervisor that support any of them please update this page or let me (Uri) know.

User Interface

The user interface is through the qemu monitor (alt-ctrl-2 on the SDL window)

Management

migrate [-d] <URI>
migrate_cancel    

The '-d' will let you query the status of the migration.

With no '-d' the monitor prompt returns when the migration completes. URI can be one of 'exec:<command>' or tcp:<ip:port>

Status

info migrate 

Migration Parameters

migrate_set_speed <speed>   set bandwidth control parameters (max transfer rate per second)

Example / HOWTO

A is the source host, B is the destination host:

TCP example:

1. Start the VM on B with the exact same parameters as the VM on A, in migration-listen mode:

B: <qemu-command-line> -incoming tcp:0:4444 (or other PORT))

2. Start the migration (always on the source host):

A: migrate -d tcp:B:4444 (or other PORT)

3. Check the status (on A only):

A: (qemu) info migrate                   

Offline example:

1. unlimit bandwidth used for migration:

A: migrate_set_speed 1g                

2. stop the guest:

A: stop                                

3. continue with either TCP or exec migration as described above.

Problems / Todo

  • TSC offset on the new host must be set in such a way that the guest sees a monotonically increasing TSC, otherwise the guest may hang indefinitely after migration.
  • usbdevice tablet complains after migration.
  • handle migration completion better (especially when network problems occur).
  • More informative status.
  • Migration does not work while CPU real-mode/protected mode are still changing.

savevm/loadvm to an external state file (using pseudo-migration)

  • To be supported directly by Migration Protocols, but until then...
  • Save VM state into a compressed file
    • Save
stop                                                               
migrate_set_speed 4095m                                            
migrate "exec:gzip -c > STATEFILE.gz"                              
    • Load
gzip -c -d STATEFILE.gz | <qemu-command-line> -incoming "exec: cat"   or
<qemu-command-line> -incoming "exec: gzip -c -d STATEFILE.gz"
  • Save VM State into an encrypted file (assumes KEY has already been generated)
    • Save
stop                                                                          
migrate_set_speed 4095m
migrate "exec:gpg -q -e -r KEY -o STATFILE.gpg"
  • Load VM state from an encrypted file
gpg -q -d -r KEY STATEFILE.gpg | <qemu-command-line> -incoming "exec:cat"

more exec: options

  • Send encrypted VM state from host A to host B (Note: ssh is probably better, this is just for show)
    • on host A
migrate "exec:gpg -q -e -r KEY | nc B 4444"
    • on host B
nc -l 4444 | gpg -q -d -r KEY | <qemu-command-line> -incoming "exec:cat"

Algorithm (the short version)

1. Setup

  • Start guest on destination, connect, enable dirty page logging and more

2. Transfer Memory

  • Guest continues to run
  • Bandwidth limitation (controlled by the user)
  • First transfer the whole memory
  • Iteratively transfer all dirty pages (pages that were written to by the guest).

3. Stop the guest

  • And sync VM image(s) (guest's hard drives).

4. Transfer State

  • As fast as possible (no bandwidth limitation)
  • All VM devices' state and dirty pages yet to be transferred

5. Continue the guest

  • On destination upon success
    • Broadcast "I'm over here" Ethernet packet to announce new location of NIC(s).
  • On source upon failure (with one exception).


Instructions for kvm-13 and below: MigrationQemu0.8.2.


Posted by 사랑줍는거지
,