Saturday, July 2, 2011

Expanding a KVM guest disk image using virt-resize

Decide on how you wish to expand the guest. Run virt-df -h and virt-list-partitions -lh on the guest disk, as shown in the following output:

# virt-df -h /dev/vg_kvm/kvm7
Filesystem                                Size       Used  Available  Use%
/dev/vg_kvm/kvm7:/dev/sda1              484.2M      48.8M     410.4M   11%
/dev/vg_kvm/kvm7:/dev/sda3               2.5G       1.3G      25.4G    5%

# virt-list-partitions -lh  /dev/vg_kvm/kvm7
/dev/sda1 ext4 500.0M
/dev/sda2 swap 1.0G
/dev/sda3 ext4 2.5G

This example we will increase the size of /dev/sda3 to 30G

1. Shutdown guest

2. Rename the original disk for the backup purpose, for lvm use lvrename command, for file use 'mv' command

# lvrename /dev/vg_kvm/kvm7 /dev/vg_kvm/kvm7.backup
  Renamed "kvm7" to "kvm7.backup" in volume group "vg_kvm"

3. Create new disk
# lvcreate -L 30G -n kvm7 vg_kvm
Logical volume "kvm7" created

4. Now resize the /dev/sda3, refer to virt-resize man for detail.

# virt-resize \
       /dev/vg_kvm/kvm7.backup /dev/vg_kvm/kvm7 \
       --expand /dev/sda3
Summary of changes:
/dev/sda1: partition will be left alone
/dev/sda2: partition will be left alone
/dev/sda3: partition will be resized from 2.5G to 28.5G
Copying /dev/sda1 ... done
Copying /dev/sda2 ... done
Copying /dev/sda3 ... done

Parition /dev/sda3 contains a filesystem or LVM PV, then this content is not automatically resized.  You can resize it afterwards either using guestfish(1) (offline) or using commands inside the guest (online resizing).

Here we resize the filesystem using guestfish

[root@kvm ~]# guestfish -a /dev/vg_kvm/kvm7

Welcome to guestfish, the libguestfs filesystem interactive shell for
editing virtual machine filesystems.

Type: 'help' for help with commands
      'quit' to quit the shell

> run
> resize2fs /dev/sda3
libguestfs: error: resize2fs: resize2fs 1.41.12 (17-May-2010)
Please run 'e2fsck -f /dev/vda3' first.
> e2fsck-f /dev/sda3
> resize2fs /dev/sda3
> exit

[root@kvm ~]# virt-df -h sl6-5
Filesystem                                Size       Used  Available  Use%
sl6-5:/dev/sda1                         484.2M      48.8M     410.4M   11%
sl6-5:/dev/sda3                          28.1G       1.3G      25.4G    5%


Try to boot the virtual machine. If it works you can delete the backup disk.

# lvchange -an vg_kvm/kvm7.backup

# lvremove vg_kvm/kvm7.backup
  Logical volume "kvm7.backup" successfully removed

Clone KVM with virt-clone

virt-clone is a command line tool for cloning existing virtual machine images using the "libvirt" hypervisor management library. It will copy the disk images of any existing virtual machine, and define a new guest with an identical virtual hardware configuration. Elements which require uniqueness will be updated to avoid a clash between old and new guests

virt-clone of python-virtinst package is a great tool for creating cloned KVM virtual machine quickly. 

Example:  LVM based kvm

# virt-clone --original sl6-3  \
             --name sl6-4 \
              --file /dev/mapper/vg_kvm-kvm6 --prompt


In the above example /dev/mapper/vg_kvm-kvm6 LVM should be created before executing the virt-clone command.

Creating LVM
# lvcreate -L 4G -n kvm6 vg_kvm

Example file based storage
virt-clone \
              --original ubuntu11 \
              --name ubuntu-2 \
              --file /var/lib/libvirt/images/ubuntu-2.img

--original sl6-3 = name of the existing KVM (make sure the original KVM is shutdown before creating clone out of it)

--name se6-4 = Name of the New KVM (cloned)
--file = In LVM case path to the existing storage, in file based storage the file will be automatically created by virt-clone

Troubleshooting Network issue
Upon booting the new cloned KVM VM I encounter with problem of not showing any network interface. After digging more it appears that udev on virtual machine changed the eth0 interface with eth1 due to change in MAC of the interface. Quick search on Google suggested the following solution to get back the 'eth0' interface on cloned vm.

1. Open /etc/sysconfig/network-scripts/ifcfg-eth0 and delete the following line and save the file

HWADDR=52:54:00:8f:62:01

2. Remove the following filen and reboot the virtual machine

/etc/udev/rules.d/*persistent-net*'

After reboot eth0 network interface will be available.

Tuesday, June 28, 2011

Scientific Linux 6

Recently I start using Scientific Linux on KVM virtual hosts. For anyone new to Scientific its a Enterprise Linux based on RHEL just like Centos maintained by Fermi National Accelerator Laboratory and the European Organization for Nuclear Research 'CERN' - and RHEL, of course :)

Scientific Linux folks is closely following the upstream srpm provider (RHEL) and its already shipped with version 6 just like RHEL 6.

The other things which inspired me to give a try to Scientific Linux is the latest version of Linux Kernel with latest hardware support, the ext4 filesystem is the default, KVM enhancement, latest versions of software eg PHP, Mysql which means I don't have to mess around with test repos or yum priorities

For detail What's new in RHEL/Scientific Linux please refer to RHEL.

I encourage anyone interested in RHEL and/or building your own test server, to experiment with this distro.

Monday, June 20, 2011

Medialess installation of Redhat Enterprise 6/Centos/Scientic Linux 6

This procedure assumes you are already using Red Hat Enterprise Linux or another relatively modern Linux distribution, and the GRUB boot loader. It also assumes you are a somewhat experienced Linux user.

To perform medialess installation of Redhat Enterprise 6/Centos/Scientific Linux 6 without media or a PXE server, the system must have two files stored locally, a kernel and an initial RAM disk

Copy the vmlinuz and initrd.img files from a Red Hat Enterprise Linux DVD (or DVD image) to the /boot/ directory, renaming them to vmlinuz-install and initrd.img-install.

Editing the GRUB Configuration

The GRUB boot loader uses the configuration file /boot/grub/grub.conf. To configure GRUB to boot from the new files, add a boot stanza to /boot/grub/grub.conf that refers to them


title Installation
    root (hd0,0)
    kernel /boot/vmlinuz-install ip=xxx.xxx.xx.x netmask=255.255.255.0 gateway=xxx.xx.xx.x dns=xxx.xx.xx.x vnc vncpassword=qwerty repo=http://ftp1.scientificlinux.org/linux/scientific/6/x86_64/os/ lang=en_US keymap=us
    initrd /boot/initrd.img-install

If using network interface other than eth0 then you must have to specify it with ksdevice=ethX, then the kernel line will read something like this for eth1

kernel /boot/vmlinuz-install ip=xxx.xxx.xx.x netmask=255.255.255.0 gateway=xxx.xx.xx.x dns=xxx.xx.xx.x ksdevice=eth1 vnc vncpassword=qwerty repo=http://ftp1.scientificlinux.org/linux/scientific/6/x86_64/os/ lang=en_US keymap=us

The following options are generally useful for medialess installations:

IP = yourIP
netmas = Netmask
gateway = your Gateway
dns = your dns
vnc (for remote graphical installation)
vncpassword = Yourpassword
repo = Redhat/Centos/SL repo (In the sample I use the Scientific Linux 6 repo)

Also change the entry "default 0" to boot from new kernel entries, when done reboot the system.

Completing the installation:
From your local system use vncviewer to connect to the remote server and complete the installation process

$ vncviewer RemoteHostIP

Sunday, June 19, 2011

KVM virt-install: Install Scientific Linux 6 (RHEL6) as KVM Guest

Network installation of SL6 64bit as KVM guest.

virt-install --name se6 \
--ram 884 \
--os-type='linux' \
--disk path=/var/lib/libvirt/images/se6.img,size=10 \
--network network:default \
--accelerate \
--vnc \
--location http://ftp1.scientificlinux.org/linux/scientific/6/x86_64/os/

Connect from your local system to continue the installation

virt-viewer -c qemu+ssh://root@IPAdress/system se6

Friday, June 17, 2011

Installing skype on Fedora 14 64bit

Skype only available for 32bit version of Fedora while most of the folks already get into wagon of 64bit OS, here is short howto installing the skype on 64bit Fedora. The hack is to install 32bit version of the following packages on 64bit Fedora.

yum install glibc.i686 alsa-lib.i686 libXv.i686 libXScrnSaver.i686 qt.i686 qt-x11.i686
Download Skype Fedora 13+ package from Skype official site http://www.skype.com/intl/en-us/get-skype/on-your-computer/linux/

And then install it.

yum install --nogpgcheck skype-2.1.0.81-fc10.i586.rpm

Hoping this is helpful

Monday, May 30, 2011

Upgrade to Fedora 14 using Preupgrade

Few days back Fedora folks released Fedora 15, however I was still running Fedora 13 on my work laptop. So it was good time to upgrade before Fedora 13 become unsupported version.

Backup Backup Backup
Its recommended to backup your important stuff before going for online upgrade using preupgrade or yum to avoid any data loose in case of system goes to its knees :P

The Upgrade
Preupgrade is a nice tool for upgrading Fedora from one version to another, it can be run from GUI and also from CLI.

# preupgrade-cli "Fedora 14 (Laughlin)"

Depends on your Internet pipe it will takes quite some time to download all the required Fedora 14 packages, once packages successfully downloaded reboot is required to boot the system into Fedora 14 and complete the installation process of the packages.

Go get cup of tea while the installation process running. Once installation finished a final reboot and you will find your box booted into shiny Fedora 14.

Its was a clean upgrade, everything working fine after upgrade. Thumbs up for Fedora folks.

For detail please refer to Preupgrade wiki.

Note: I prefer not to go for Fedora 15 at this time due to the fuse around the Gnome 3, but will wait until the community find some solid solutions. I do not want to loose my desktop icons and application launchers ;)