Virtualization
mount kvm disk qcow on linux
1 2 3 4 5 6 7 8 9 10 11 12 13 |
# Enabling mounting. sudo modprobe nbd max_part=8 sudo qemu-nbd --connect=/dev/nbd0 /mnt/kvm/wordpress-sites.qcow2 sudo fdisk /dev/nbd0 -l sudo mount /dev/nbd0p1 /mnt/somepoint/ sudo umount /mnt/somepoint/ sudo qemu-nbd --disconnect /dev/nbd0 |
Example 2:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
losetup /dev/loop0 raw-image-file.raw ## # kpartx: # Recognise and activate partitions in the image: kpartx -a /dev/loop0 ## # Check partitions available to this image under /dev/mapper/loop0* # ls /dev/mapper/loop0* /dev/mapper/loop0p1 /dev/mapper/loop0p2 /dev/mapper/loop0p3 /dev/mapper/loop0p4 /dev/mapper/loop0p5 /dev/mapper/loop0p6 ## # mount each partition to a mount point: mount /dev/mapper/loop0p1 /mnt ## # umount and delete created objects. umount /mnt kpartx -d /dev/loop0 losetup -d /dev/loop0 |
Virtual machine resize Disk Volume Group
KVM
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
root@server3.kutayzorlu.com:~# qemu-img resize vmdisk.img +100G # GPARTED and extend disk root@server3.kutayzorlu.com:~# lvdisplay --- Logical volume --- LV Path /dev/telekom_kutayzorlu_com-vg/root LV Name root VG Name telekom_kutayzorlu_com-vg LV UUID s4szbj-zgxD-jniW-j904-wEhe-CQSf-3D2CXW LV Write Access read/write LV Creation host, time telekom_kutayzorlu_com, 2015-05-26 16:44:59 -0500 LV Status available # open 1 LV Size 9.26 GiB Current LE 2370 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 252:0 --- Logical volume --- LV Path /dev/telekom_kutayzorlu_com-vg/swap_1 LV Name swap_1 VG Name telekom_kutayzorlu_com-vg LV UUID wcVWPh-kcec-0892-0hpj-wa34-l6eJ-VGnCp3 LV Write Access read/write LV Creation host, time telekom_kutayzorlu_com, 2015-05-26 16:44:59 -0500 LV Status available # open 2 LV Size 512.00 MiB Current LE 128 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 |
Important for us
1 2 |
LV Path /dev/telekom_kutayzorlu_com-vg/root LV Name root |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
root@server3.kutayzorlu.com:~# root@server3.kutayzorlu.com:~# vgdisplay --- Volume group --- VG Name telekom_kutayzorlu_com-vg System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size 29.76 GiB PE Size 4.00 MiB Total PE 7618 Alloc PE / Size 2498 / 9.76 GiB Free PE / Size 5120 / 20.00 GiB VG UUID 6OvM2c-4jFf-5Mqt-IbrF-8f5O-2hsh-EjVIGd |
**>> Free PE / Size 5120 / 20.00 GiB
So Firstly we are extending volume group
# lvextend -l +5120 /dev/telekom_kutayzorlu_com-vg/root
After Resize to see Action in Disk Size Now
# resize2fs /dev/telekom_kutayzorlu_com-vg/root
If you are using XFS file format it will give error so use that
# xfs_growfs /dev/telekom_kutayzorlu_com-vg/root
1 2 3 4 5 6 7 8 9 10 |
root@server3.kutayzorlu.com:~# df -h Filesystem Size Used Avail Use% Mounted on udev 990M 0 990M 0% /dev tmpfs 201M 4.7M 196M 3% /run /dev/mapper/telekom_kutayzorlu_com--vg-root 29G 2.8G 25G 10% / tmpfs 1001M 0 1001M 0% /dev/shm tmpfs 5.0M 4.0K 5.0M 1% /run/lock tmpfs 1001M 0 1001M 0% /sys/fs/cgroup /dev/sda1 236M 42M 182M 19% /boot tmpfs 201M 0 201M 0% /run/user/1000 |
how to increase virtual machine disk size
- stop the VM
- run $ qemu-img resize vmdisk.img +10G to increase image size by 10Gb
- start the VM, resize the partitions and LVM structure within it normall
- Boot your system with GPARTED
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
1 2 3 4 5 6 7 8 9 10 11 |
This one is also possible but , dont do that, # 1. stop the VM # 2. move the current image mv old_kutay_kvm.img old_kutay_kvm.img.bak # 3. create a new image qemu-img create -f raw addon.raw 30G # 4. concatenate the 2 images cat old_kutay_.img.bak addon.raw >> old_kutay_.img |
Xen Installation Step 1
.
1 2 3 4 5 6 7 8 9 10 11 12 |
wget http://au1.mirror.crc.id.au/repo/el6/x86_64/xen-4.2.5-9.el6.x86_64.rpm wget http://au1.mirror.crc.id.au/repo/el6/x86_64/xen-doc-4.2.5-9.el6.x86_64.rpm wget http://au1.mirror.crc.id.au/repo/el6/x86_64/xen-debuginfo-4.2.5-9.el6.x86_64.rpm wget http://au1.mirror.crc.id.au/repo/el6/x86_64/xen-devel-4.2.5-9.el6.x86_64.rpm wget http://au1.mirror.crc.id.au/repo/el6/x86_64/xen-hypervisor-4.2.5-9.el6.x86_64.rpm wget http://au1.mirror.crc.id.au/repo/el6/x86_64/xen-libs-4.2.5-9.el6.x86_64.rpm wget http://au1.mirror.crc.id.au/repo/el6/x86_64/xen-licenses-4.2.5-9.el6.x86_64.rpm wget http://au1.mirror.crc.id.au/repo/el6/x86_64/xen-ocaml-4.2.5-9.el6.x86_64.rpm wget http://au1.mirror.crc.id.au/repo/el6/x86_64/xen-ocaml-devel-4.2.5-9.el6.x86_64.rpm wget http://au1.mirror.crc.id.au/repo/el6/x86_64/xen-runtime-4.2.5-9.el6.x86_64.rpm wget http://au1.mirror.crc.id.au/repo/el6/x86_64/kernel-xen-3.14.33-1.el6xen.x86_64.rpm wget http://au1.mirror.crc.id.au/repo/el6/x86_64/kernel-xen-firmware-3.14.33-1.el6xen.x86_64.rpm |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
rpm -ivh --nodeps xen-4.2.5-9.el6.x86_64.rpm xen-doc-4.2.5-9.el6.x86_64.rpm xen-hypervisor-4.2.5-9.el6.x86_64.rpm xen-libs-4.2.5-9.el6.x86_64.rpm xen-licenses-4.2.5-9.el6.x86_64.rpm xen-runtime-4.2.5-9.el6.x86_64.rpm rpm -ivh --nodeps xen-debuginfo-4.2.5-9.el6.x86_64.rpm xen-devel-4.2.5-9.el6.x86_64.rpm xen-ocaml-4.2.5-9.el6.x86_64.rpm xen-ocaml-devel-4.2.5-9.el6.x86_64.rpm rpm -ivh --nodeps --force kernel-xen-3.14.33-1.el6xen.x86_64.rpm kernel-xen-firmware-3.14.33-1.el6xen.x86_64.rpm depmod: WARNING: could not open /lib/modules/3.14.33-1.el6xen.x86_64/modules.order: No such file or directory depmod: WARNING: could not open /lib/modules/3.14.33-1.el6xen.x86_64/modules.builtin: No such file or directory depmod: WARNING: could not open /var/tmp/initramfs.XexgLv/lib/modules/3.14.33-1.el6xen.x86_64/modules.order: No such file or directory depmod: WARNING: could not open /var/tmp/initramfs.XexgLv/lib/modules/3.14.33-1.el6xen.x86_64/modules.builtin: No such file or directory mv /usr/lib64/python2.6/site-packages/xen /usr/lib64/python2.7/site-packages mv /usr/lib64/python2.6/site-packages/xen-3.0-py2.6.egg-info /usr/lib64/python2.7/site-packages cd /usr/lib64 ln -s libpython2.7.so.1.0 libpython2.6.so.1.0 ln -s liblzma.so.5.0.99 liblzma.so.0 ln -s libgnutls.so.28.20.4 libgnutls.so.26 edit /etc/default/grub : GRUB_DEFAULT="CentOS Linux, with Xen hypervisor" grub2-mkconfig --output=/boot/grub2/grub.cfg chkconfig --level 2345 xend on systemctl stop NetworkManager systemctl disable NetworkManager Create a network initialization script (replacing eth0,a.b.c.d and e.f.g.h with your adapater,IP address and gateway address): ################################################# /etc/xen/scripts/xenbr0.sh #!/bin/bash brctl addbr xenbr0 ip addr flush eno1 ip addr add xx.210.xx.109/24 broadcast xx.xx.254.255 dev xenbr0 ifconfig xenbr0 up ip route add default via xx.xx.254.1 brctl addif xenbr0 eno1 ######################################################## yum install libvirt python-virtinst libvirt-daemon-xen ######################################################### vnc network giving error for the XEN network. 1. new virtual network created . 2. network interface came here than added (+) Bridge . em0 XENbridge clicked. |
Virtual network security configuration
Only local access VM network creating
ALL OF the interfaces, `ROUTED` not `NAT`
no internet only routed net.
NAT is unsecure network, because server can reachable from internet.
So the best one is the NOT _ NAT
Virtual machine disc conversion command line example
1 2 |
# Disk Conversion root@s:/backups/# qemu-img convert -O raw vm-102-disk-1.qcow2 test.img |