Build the Xen usable .img file

In this post which is part of the series on how to import YubiRadius, a Free Radius appliance implementing OTP validation, into Xen Open source Hypervisor, we will build an .img file containing a filesystem, mount it and then copy the Virtual Appliance files into it
The first step consist in creating a file of the proper size with

dd if=/dev/zero of=/workdir/empty.img bs=516096c count=#cyl

This statement sets input file /dev/zero output file to empty image somewhere and reads block of 516096 bytes for count times. If we set count=10000 we create an empty file of 5 Gb filled with zero’s. Now we need to create a file system. In order to do that it is necessary to find a free loop device by issuing:

root@Lithium-Dom0:/mnt/img# losetup /dev/loop0
/dev/loop0: [0805]:57348 (/xen/images/domains/rhodium/disk.img)
root@Lithium-Dom0:/mnt/img# losetup /dev/loop32

If the loop device is busy the command output the file name associated otherwise the loop device can be used.

losetup /dev/loop32 /workdir/empty.img
mkfs -t ext3 -m 1 -v /dev/loop32
losetup -d /dev/loop0

The above sequence connects the image to a loopback device, creates the filesystem and then disconnects the image from the loopback device.

The whole process can be replicated for the swapfile:

root@Lithium-Dom0:/mnt/sdb1/download# dd if=/dev/zero of=./swap.img bs=516096c count=768
768+0 records in
768+0 records out
396361728 bytes (396 MB) copied, 1.22937 s, 322 MB/s
root@Lithium-Dom0:/mnt/sdb1/download# losetup /dev/loop32 ./swap.img
root@Lithium-Dom0:/mnt/sdb1/download# mkswap /dev/loop32
Setting up swapspace version 1, size = 387068 KiB
no label, UUID=d6af6798-2c71-4992-bc99-af7a21575b04
root@Lithium-Dom0:/mnt/sdb1/download# losetup -d /dev/loop32
root@Lithium-Dom0:/mnt/sdb1/download#

At this stage, we have an empty file with an etx3 filesystem and a swapfile ready for use. If we mount the will be root filesystem on the /mnt/img mount point we can simply untar the content of the YubiRadius applicance in place.

mkdir /xen/images/domain/yubirad
cp /workdir/empty.img /xen/images/domain/yubirad/disk.img
cp /workdir/swap.img /xen/images/domain/yubirad/swap.img
cd /mnt /xen/images/domain/yubirad/swap.img /mnt/img
mount –o loop
tar –xvf YubiRadius.tar

About Fabio

Love of technology and flying have been the drivers of my life, more about me.
Tagged , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

Couldn't connect to server: Connection timed out (110)