KVM How-To
How-To
Disk Formatの確認
qemu-img info disk.img
Disk作成
qemu-img create -f qcow2 ${disk-name}.${qcow2} ${n}G
Disk Copy
cp –sparse=never olddisk.img newdisk.img
Disk Convert
qemu-img convert -O raw file.qcow2 file.img qemu-img convert -O qcow2 file.img file.qcow2
既存Disk ImageからDomainを追加
virt-manager
-
- 新しい仮想マシンの作成→名前つける→既存のディスクイメージをインポート→
- 既存のディスクイメージのパスを指定
command
virt-install -n ${vmname} -r 2048 --os-type=${os-type} --os-variant=${os-variant} --disk ${disk-path},device=disk,bus=virtio -w bridge=br0,model=virtio --vnc --noautoconsole --import
既存Domainのクローン,コピー
virt-manager
-
- domainを止める→cloneしたいdomainで右クリ→クローン→
- storageは勝手にcloneされるが,自分で作成したstorageの指定も可能
command
virt-clone --connect=qemu:///system -o srchost -n newhost -f /path/to/newhost.qcow2 [--force] # 既存のimgに上書きするには--force
command2 (これでもイケルはず)
virt-clone --connect=qemu+ssh://ubuntu@10.0.0.2/system -o srchost -n newhost -f /path/to/newhost.qcow2
Disk Attach
command
- general
virsh attach-disk ${domain} ${source} ${target}
- virtioでのhot attach
virsh attach-disk ${domain} ${source} vd{b, c, d, ...} --driver qemu \ --type disk --subdriver qcow2
- domain: domain name
- source: disk path
- target: vd{b, c, d, ...} # /devの下に作られる
Network Interface Attach
command
- hot attach
virsh attach-interface ${domain} ${type} ${source}
- domain: domain name
- type: brdige, network, etc
- source: interface name
os-variant一覧
virt-install --os-variant list
用語
Storage Pool
- vmを保存するdir, iSCSI, netfs, block device, LVM volumeなどの場所
- defaultは,/var/lib/libvirt/images
- /etc/libvirt/storage/${storage_pool_name}.xmlにpool単位で存在
- 変更
command
virsh pool-edit ${storage_pool_name}
virt-manager
接続→プラスボタン→名前を入力→ターゲットパスの入力
Disk format
- qcow2
- スナップショット取れる
- raw (sparse)
- スナップショット取れない
- raw
- スナップショット取れない
Tips
参考URLs
- https://help.ubuntu.com/community/KVM/
- https://help.ubuntu.com/community/KVM/CreateGuests
- http://d.hatena.ne.jp/kt_hiro/20120819/1345351773
- http://blog.allanglesit.com/2011/03/kvm-guests-using-virt-install-to-import-an-existing-disk-image/
- https://access.redhat.com/documentation/ja-JP/Red_Hat_Enterprise_Linux/6/html/Virtualization_Administration_Guide/index.html
- https://access.redhat.com/documentation/ja-JP/Red_Hat_Enterprise_Linux/6/html/Virtualization_Administration_Guide/sect-Virtualization-Virtualized_block_devices-Adding_storage_devices_to_guests.html