|
Creating Disk Image for Root Filesystem
|
There are multiple ways for building a Xen Virtual Guest Filesystem on a Disk Image. This document describes the Cloning Host System. |
To create a disk image:
Use
dd command.
A blank disk image is generated.
|
The following example use dd to create a 6Gb disk image called XenGuest1.img: dd if=/dev/zero of=XenGuest1.img bs=1024k seek=6144 count=0
The output of this command looks like: 0+0 records in 0+0 records out 0 bytes (0 B) copied, 1.2e-05 seconds, 0.0 kB/s. |
Create a filesystem.
|
The filesystem should be able to store the files and directories that comprise the root file system. |
Following command creates an ext3 filesystem on the above created disk image:
|
mkfs identifies the disk as an image file rather than a block device and seeks confirmation that a filesystem is to be created. When prompted simply enter y: |
mkfs -t ext3 ImageFileName.img
Output of this command looks like:
mke2fs 1.39 (29-May-2006)
ImageFileName.img is not a block special device.
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
786432 inodes, 1572864 blocks
78643 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1610612736
48 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem is automatically checked after every 31 mounts or 180 days (whichever comes first). Use tune2fs -c or -i to override. One of the easiest ways to install the necessary files on the guest OS root filesystem is to simply copy the files from the host operating system.
|
Prior to copy files from the host operating system, remember that the steps described later in this document copies everything from the host operating system to the guest root filesystem. |
Suppose,you may need a minimal Linux installation for your guest OS. If the host system has graphical desktop environments,office productivity applications and other packages not needed by the guest OS then cloning the host environment may not be the best approach.
If,on the other hand,you are confident that everything on your host operating system is of use in the guest system,or are unconcerned about disk space then this approach is better.
Prior to copy any file onto the root filesystem disk image, you should mount it. Disk images are mounted using the Linux loopback interface and require a pre-existing mount point. In the following example a mount point is created at /mnt:
mount -o loop ImageFileName.img /mnt
Copy
the relevant files from the host operating system to guest root filesystem
image
cp -ax /{bin,dev,etc,lib,root,sbin,usr,var} /mnt
It takes some time. Once the files are
copied, a number of additional directories need to be created.
mkdir /mnt/{home,proc,opt,sys,tmp}
The tmp directory created above must have read/write access for all users. To ensure this the chmod command needs to be run:
chmod 777 /mnt/tmp.
The /mnt/etc/fstab file currently present in the guest root filesystem is a direct replica of the file used by the host operating system. The following command shows a typical file from a CentOS, Red Hat Enterprise Linux or Fedora host operating system
cat /mnt/etc/fstab
Output of this command looks like:
/dev/VolGroup00/LogVol00 |
/ |
ext3 |
defaults,usrquota |
1 |
1 |
LABEL=/boot |
/boot |
ext3 |
defaults |
1 |
2 |
tmpfs |
/dev/shm |
tmpfs |
defaults |
0 |
0 |
devpts |
/dev/pts |
devpts |
gid=5,mode=620 |
0 |
0 |
sysfs |
/sys |
sysfs |
defaults |
0 |
0 |
proc |
/proc |
proc |
defaults |
0 |
0 |
/dev/VolGroup00/LogVol01 |
swap |
swap |
defaults |
0 |
0 |
The guest OS copy of the fstab file needs to be modified such as:
/dev/xvda1 |
/ |
ext3 |
defaults |
1 |
1 |
/dev/xvda2 |
none |
swap |
sw |
0 |
0 |
none |
/dev/pts |
devpts |
gid=5,mode=620 |
0 |
0 |
none |
/dev/shm |
tmpfs |
defaults |
0 |
0 |
none |
/proc |
proc |
defaults |
0 |
0 |
none |
/sys |
sysfs |
defaults |
0 |
0 |
|
The root and swap device used here must match the root and swap device that you will provide while adding the template from the panel. |