Created
June 10, 2016 14:05
-
-
Save mtsuszycki/70a3b960cf0a4ff2aed2283c3f1351c8 to your computer and use it in GitHub Desktop.
basic virsh commands, extending partition in guest OS etc.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Basic command to manage VMs | |
# list all defined domains (VMs) and their status (running, shut off etc.) | |
virsh list --all | |
# stop VM (named _myvm_) gracefully | |
virsh shutdown _myvm_ | |
# start VM | |
virsh start _myvm_ | |
# enter VM, you can exit from VM by ^] (control and then ']') | |
virsh console _myvm_ | |
# shutdown VM immediately, this is equivalent to pulling the plug off | |
virsh destroy _myvm_ | |
# mark VM to be started automatically | |
virsh autostart _myvm_ | |
# dump xml config (useful while cloning, renaming etc.) | |
virsh dumpxml _myvm_ > _myvm_.xml | |
# cloning | |
virt-clone -o centos6template -n _newvm_ -f /srv/vmstore/_newvm__.img | |
#### how to extend VM filesystem, | |
# In below example we will be extending logical volume named lv_root (/dev/mapper/vg_root-lv_root) | |
# that is created on volume group named vg_root | |
# 1. stop VM, this is important | |
virsh shutdown _myvm_ | |
# 2. resize qemu image, for example: add 2 gigabytes | |
cd /srv/vmstore/ && qemu-img resize _myvm_ +2GB | |
# 3. start VM and configure LVM: | |
virsh start _myvm_ | |
virsh console _myvm_ | |
# now insinde guest OS: | |
fdisk /dev/vda # add new partition that will be using added unused (yet) space | |
p | |
n | |
p (primary) | |
'partition number' | |
'First cylinder' number (see output from 'fdisk -l') | |
Last cylinder (+cylinders or +size{K,M,G}0 | |
w | |
reboot VM guest | |
# assuming new partition is vda4, add it to lvm: | |
pvcreate /dev/vda4 | |
# extend vg_root volume group | |
vgextend vg_root /dev/vda4 | |
# extend logical volume to use 100% available space: | |
lvextend -l +100%FREE /dev/mapper/vg_root-lv_root | |
# resize ext4: | |
resize2fs /dev/mapper/vg_root-lv_root | |
# done, no reboot necessary | |
# Extending _myvm_ memory to 4GB | |
# all commands to be issued on host OS | |
virsh shutdown _myvm_ | |
#command below will open text editor | |
# change <memory .. > value to 4194304 | |
# and also <currentMemory ..> value to 4194304 too | |
virsh edit _myvm_ | |
virsh setmaxmem _myvm_ 4194304 | |
virsh start _myvm_ | |
# all done, _myvm_ now has 4GB of ram | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment