Tag Archives: kvm

Mounting partitions contained in an LVM

Introduction

When creating a virtual machine with an LVM partition, it will create partitions within that LVM partition. Mounting those ‘sub’ partitions requires an extra step to access them. I used this when I was cloning virtual machines so that I could change the hostname of the copied host before booting it up.

A tool called kpartx is your friend here. It allows the system to see partitions within a LVM partition, so they can be mounted. In this guide we will be accessing partitions created as part of my mogilefs playground virtual machines. Below are the partitions that we are trying to access:

$ sudo fdisk -l /dev/vhosts/mogile2

Disk /dev/vhosts/mogile2: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders, total 10485760 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000b30be

Device Boot Start End Blocks Id System
/dev/vhosts/mogile2p1 * 2048 9437183 4717568 83 Linux
/dev/vhosts/mogile2p2 9439230 10483711 522241 5 Extended
/dev/vhosts/mogile2p5 9439232 10483711 522240 82 Linux swap / Solaris

NOTE: Make sure that the virtual machine is NOT running before mounting these partitions

So let’s try and mount one of these partitions (/dev/vhosts/mogile2p1):


$ sudo mount /dev/vhosts/mogile2p1 /mnt/temp
mount: special device /dev/vhosts/mogile2p1 does not exist

So the following will help map these partitions to the host OS so they can be mounted. If you haven’t got kpartx installed, then on debian/ubuntu systems install with sudo apt-get install kpartx

kpartx guide

To allow the host system to see the partitions for mounting, we run the following:

$ sudo kpartx -a /dev/vhosts/mogile2

We can then mount with

$ sudo mount /dev/mapper/vhosts-mogile2p1 /mnt/temp

And then use it as we normally would. In this case, I used it to edit the /mnt/temp/etc/hostname and /mnt/temp/etc/hosts file

Finally un mount it:
$ sudo umount /mnt/temp

And if you are done with it, and cleaned up, then remove it from the partition tables:

$ sudo kpartx -d /dev/vhosts/mogile2

Reference(s):

https://www.normation.com/en/blog/2011/04/07/mounting-partitions-stored-in-a-logical-volume-or-a-disk-image/

Facebooktwittergoogle_plusredditpinterestlinkedinmail

Creating a base 14.04 Ubuntu using LVM and KVM

Creating a new virtual machine

Introduction

I wanted to create a base install of Ubuntu so that I could keep all the security patches up to date, and then create copies of the base image for other tests, and playing around.

The guide was made when installing a basic Ubuntu 14.04 server image on a KVM hypervisor. All the commands were run as root (or via sudo).

Creating the file system

Firstly, I create the file system the machine would use, on the existing LVM partitions:

$ sudo lvcreate -L 5G -n base-1404 vhosts
Logical volume "base-1404" created

Just using a small volume for the base install (5G). To see the current volumes that exist use lvdisplay to list them all.:

Creating the virtual host

Next to create the virtual host, this is relatively simple to get started:

$ sudo virt-install -n base-1404 -r 512 --disk path=/dev/vhosts/base-1404 -c /home/software/os/linuxisos/ubuntu-14.04.2-server-amd64.iso --os-type linux --os-variant ubuntutrusty --accelerate --network=bridge:br0 --hvm --vnc --noautoconsole

Starting install…
Creating domain… | 0 B 00:04
Domain installation still in progress. You can reconnect to the console to complete the installation process.

The options give 512MB ram, the location to the hard drive to use, a location to a cdrom drive to use (or image) for install. Type of OS, and the variant. Whether to use acceleration, what network to use, and to start with a vnc console, to install it with.

Note: To get a list of os variants available, use:

$ sudo virt-install --os-variant list

Connection to the vhost over VNC

To connect the VNC console to actually carry out the installation, have a look at what is being listened to on the network:

Listing all VNC terminals for the KVM virtual hosts
Listing all VNC terminals for the KVM virtual hosts

The last one should be the one to connect to, so lets tunnel from desktop machine to there, and try and connect:

$ ssh sb1 -L5905:localhost:5905

And then connect using your VNC software:

Conecting to the new virtual machine using remmina and VNC
Conecting to the new virtual machine using remmina and VNC

And away you go:

Ubuntu install page over KVM
Ubuntu install page over KVM

If you need the network address, look in the folder: /etc/libvirt/qemu for the xml configuration file (in this case base-1404.xml), and look for the tag. Or xmldump from the virsh.

Facebooktwittergoogle_plusredditpinterestlinkedinmail