Tag Archives: Ubuntu

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.

    WordPress behind forward proxy

    How to configure WordPress behind forward proxy. The tutorial explains why and how to configure your WordPress installation to make outbound connections via a forwarding proxy.

    Why?

    Most WordPress installations are allowed to make direct outbound connections. Outbound connections are needed to fetch updates or to connect to various services like the WordPress.com Jetpack or Google Analytics.

    However, allowing all sorts of outbound connections means that you don’t know what URL’s are being accessed. After infection it is possible that your installation connects back to Command & Control servers. This is something that I don’t want and it’s the main reason why I want to keep visibility and control on every outbound connection made from my WordPress installation.

    How?

    You start by adding the following lines to your wp-config.php

    define('WP_PROXY_HOST', '192.168.84.101');
    define('WP_PROXY_PORT', '8080');

    This is the bare minimum. If you have to authenticate against the proxy or want to exclude certain domains, these options can be used as well.

    WP_PROXY_HOST - Enable proxy support and host for connecting.</li>
    WP_PROXY_PORT - Proxy port for connection. No default, must be defined.</li>
    WP_PROXY_USERNAME - Proxy username, if it requires authentication.</li>
    WP_PROXY_PASSWORD - Proxy password, if it requires authentication.</li>
    WP_PROXY_BYPASS_HOSTS - Will prevent the hosts in this list from going through the proxy. You do not need to have localhost and the blog host in this list, because they will not be passed through the proxy. The list should be presented in a comma separated list, wildcards using are supported, eg. *.wordpress.org,

    After saving the file, your outbound connections should be going via your proxy. Now it’s best to check your proxy logs. My installation was missing curl for php. This caused https lookups to fail. It’s clearly visible in the logs because the WordPress installation tries to do a POST for HTTPS websites. The result is a error 501 from the proxy server. Squid is being used in this case.

    1421584726.310      0 172.16.x.y NONE/501 3680 POST https://accounts.google.com/o/oauth2/token - HIER_NONE/- text/html

    This can be fixed by installing cURL for php. On Ubuntu, this can be done by installing the package php5-curl.

    apt-get install php5-curl

    This will automatically reconfigure and restart your apacha/php. Checking your proxy logs will show this.

    1421740626.118    105 172.16.x.y TCP_MISS/200 4313 CONNECT accounts.google.com:443 - HIER_DIRECT/74.125.136.84 -

    Perfectly valid again and your WordPress installation is good to go for both http and https.

    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:

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

    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
       address 172.16.11.1
       network 172.16.11.0
       netmask 255.255.255.0
       broadcast 172.16.11.255
    
    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