Tag Archives: KVM

Migrating from file to lvm storage

Steps to take for migrating from file to lvm storage. This tutorial will make use of virsh from libvirt. Tested on Ubuntu 14.04 (Trusty Tahr).

Before we begin

I assume you already have an LVM storage pool created and active. You can list your storage pools with this command.

root@flipflop /home/data # virsh pool-list
 Name                 State      Autostart 
 mylvmpool            active     yes 

On my system, only 1 storage book is started. It’s called ‘mylvmpool’. Click here for steps how to create an LVM storage pool. Use this command to display more detailed information about the storage pool.

root@flipflop /home/data # virsh pool-info mylvmpool
Name:           mylvmpool
UUID:           cf2438fa-eeb7-457d-ae48-7c05f3cc8dc8
State:          running
Persistent:     yes
Autostart:      yes
Capacity:       2.73 TiB
Allocation:     569.81 GiB
Available:      2.17 TiB

Migrating from file to lvm storage

Continue reading

New LVM pool in existing volume group

These commands show how you can create a new LVM pool in an existing volume group. Virsh from libvirt is used for the task.
I’ve tested everything on a fresh Ubuntu Server 14.04 (Trusty Tahr).

How we start

During the installation of this server, I created 1 large volume group which spanned almost the whole disk ( except for /boot which sits on its own primary partition ). That single volume group lives in partition 2.

root@flipflop ~ # sgdisk -p /dev/sda
Disk /dev/sda: 5860533168 sectors, 2.7 TiB
Logical sector size: 512 bytes
Disk identifier (GUID): D09D3D4B-01CE-4A1F-8ED0-4E68253A85D6
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 5860533134
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            4096         1052671   512.0 MiB   FD00  
   2         1052672      5860533134   2.7 TiB     FD00  
   3            2048            4095   1024.0 KiB  EF02  
root@flipflop ~ #

The installer of Ubuntu created this partition table. Note that we’re using a Guid Partition Table (GPT). A normal MBR is not possible anymore since the disk is over 2TB in size. In this partition, a Logical Volume Group (LVM) has been created.

root@flipflop ~ # vgdisplay
  --- Volume group ---
  VG Name               vg0
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                4
  Open LV               4
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               2.73 TiB
  PE Size               4.00 MiB
  Total PE              715236
  Alloc PE / Size       143872 / 562.00 GiB
  Free  PE / Size       571364 / 2.18 TiB
  VG UUID               YOVLIn-I0bX-0bND-JhuX-EnxI-YuO8-5ux86P
root@flipflop ~ #

Defining the new storage pool

To define the storage pool, I’m using the virsh command from libvirt with the pool-define-as option.
If you want to see all options, issue this command.

root@flipflop ~ # virsh help pool-define-as

To define the actual pool, I’ve run this command.

root@flipflop ~ # virsh pool-define-as mylvmpool logical - - /dev/sda2 vg0 /dev/vg0

This command defines the pool. There is no need to run ‘virsh pool-create’ because the pool already exists.
If you want to autostart the storage pool.

root@flipflop ~ # virsh pool-autostart mylvmpool

Checking the storage pool

Right now we can manipulate the vg using the virsh command. A couple of examples:

  • Listing all storage pools
  • root@flipflop ~ # virsh pool-list
     Name                 State      Autostart 
     mylvmpool            active     yes
  • Getting detailed info about a storage pool
  • root@flipflop ~ # virsh pool-info mylvmpool
    Name:           mylvmpool
    UUID:           cf2438fa-eeb7-457d-ae48-7c05f3cc8dc8
    State:          running
    Persistent:     yes
    Autostart:      yes
    Capacity:       2.73 TiB
    Allocation:     562.00 GiB
    Available:      2.18 TiB
  • Listing all volumes in the storage pool
  • root@flipflop ~ # virsh vol-list mylvmpool
     Name                 Path                                    
     home                 /dev/vg0/home                                             
     root                 /dev/vg0/root                           
     swap                 /dev/vg0/swap
  • Creating a new volume
  • root@flipflop ~ # virsh vol-create-as mylvmpool newvol 100G
    Vol newvol created
  • Checking if the volume has been created
  • root@flipflop ~ # virsh vol-list mylvmpool
     Name                 Path                                    
     home                 /dev/vg0/home                                         
     newvol               /dev/vg0/newvol                         
     root                 /dev/vg0/root                           
     swap                 /dev/vg0/swap
  • Listing the details of the new volume
  • root@flipflop ~ # virsh vol-info newvol --pool mylvmpool
    Name:           newvol
    Type:           block
    Capacity:       100.00 GiB
    Allocation:     100.00 GiB
  • Deleting the new volume
  • root@flipflop ~ # virsh vol-delete newvol --pool mylvmpool
    Vol newvol deleted

    This post explained how to create a new LVM storage pool in an existing Logical Volume Group. It also show how volumes can be listed, created and deleted.

    Install a KVM host on Ubuntu 14.04 Trusty Tahr

    How to install a KVM host and configure KVM with libvirt and Open vSwitch on Ubuntu 14.04 Trusty Tahr. The following steps have been tested on freshly installed server installation. Let’s start from scratch by installing all required packages.

    Install required packages

    # apt-get install openvswitch-switch qemu-kvm libvirt-bin

    And wait until all packages are downloaded and installed.
    Afterwards, let’s continue by destroying the default bridge and creating the new ovs bridge.

    Setup networking

    # ovs-vsctl add-br ovsbr0
    # virsh net-destroy default

    Edit the config from the default bridge with this command.

    # virsh net-edit default

    And make sure, you change the file to this:

    <forward mode='bridge'/>
    <bridge name='ovsbr0'/>
    <virtualport type='openvswitch'/>

    Remove the old bridge completely and make sure the new bridge is autostarted.

    # virsh net-undefine default
    # virsh net-autostart ovsbr0

    I’d like to keep my networking configuration in /etc/network/interfaces. That’s why I added the following section to that file.

    auto ovsbr0
    iface ovsbr0 inet static
    iface ovsbr0 inet6 static
       address 2001:xxxx:xxxx:1::1
       netmask 64

    Test new installed KVM host

    Now reboot your machine and check with following commands if you’re network is properly configured.

    # virsh net-list
    # ip addr
    # ovs-vsctl show

    Congratulations! You’ve installed a KVM host. Now you can proceed and install virtual machines on this new host. The network interfaces will be added to the freshly created Open vSwitch bridge.

    Edit on 2014/05/14 : changed the ovsbr0 XML file
    Edit in 2014/05/28 : only tested on a Server installation of Ubuntu 14.04