http:// www.jms1.net / xen / base-install.shtml

Xen - Base OS Install

I normally use CentOS 4.2 as the operating system of the servers that I build for myself and my clients. This page will describe how I set up CentOS using LVM, the Linux Volume Manger system, to manage the disks. This allows me to later create as many partitions as I need for other things (such as xenU clients.)

LVM is a system which gives you a lot of flexibility in how you create and use disk partitions. The idea is that LVM creates "virtual disks" which may be made up of multiple physical partitions, which may contain up to 256 "virtual partitions", and these partitions can be dynamically resized without having to worry about whether the disk blocks making up each partition are contiguous (or are even on the same physical disk.)

LVM works using three layers of containers:

The only real problem I have encountered with LVM is that the grub bootloader does not know how to use LVM, and therefore cannot boot from an LVM logical volume. For this reason we will be creating one physical partition for "/boot", and using the remainder of the drive as an LVM physical volume.

There is a lot more to say about LVM, but this page isn't the place for it. Here is a list of links where you can learn more about LVM:

We will be building a very simple LVM system- one PV, one VG, and (for now) two LVs. Additional xenU sessions will involve creating more LVs, for which we will leave room. If you physically run out of space, you can add a second physical disk to the machine and then add its space to be used for any new LVs you may create.


Creating the LVM containers

I prefer using the CentOS text-mode installer- that's just a personal preference of mine. I've been doing it since the days of RedHat 5.1 and it's what I'm used to using. These steps can be followed using the graphical installer as well, but the example will walk through using the text-mode installer.

The first step, of course, is to boot the first CD and tell it to use the text-mode installer. I normally add "vga=791" to the mix, because I like how a 128x48 console looks on the screen.

boot: linux text vga=791

The installer starts by asking whether I want to test my installation CD's. It shows a window with two buttons, "Check" and "Skip". Because I have used these particular CD's to install about fifteen systems and have never had a problem with them, I select "Skip".

Using the text-mode windows: To use the text-mode windows (which are generated by the "ncurses" library) you can use the TAB key to move from one interface item to the next, the directional arrows to select between different items in a list, and the SPACE BAR to "push" a button.

Which means in this case, I press TAB (to move to the "Skip" button) and then SPACE BAR (to press the button.)

The system then scans the hardware and then starts going through the basics- what language do I want to use during the install process, what kind of keyboard do I have, and so forth.

When I reach the point where it asks what kind of system I want to install (Personal Desktop, Workstation, Server, or Custom) I choose "Custom", because later this will allow me to choose exactly which packages I do and don't want installed on the system. It's also the only option which allows you to build a box without support for the X/window system (which is something I don't install on servers.)

The next screen asks whether I want to use "Autopartition" or "Disk Druid". While this choice is on the screen, I press ALT-F2 to get a command line. (If you are using the graphical installer, you will need to press CTRL-ALT-F2 instead.) I then run the "fdisk" program to manually create partitions.

Because the disk I'm using has been used before, but now contains no data that I need to save, my first step with fdisk is to delete all of the existing partitions.

-/bin/sh-3.00# fdisk /dev/hda The number of cylinders for this disk is 3970. There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with: 1) software that runs at boot time (e.g., old versions of LILO) 2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): p
Disk /dev/hda: 30.7 GB, 30735581184 bytes 240 heads, 63 sectors/track, 3970 cylinders Units = cylinders of 15120 * 512 = 7741440 bytes
Device Boot Start End Blocks Id System /dev/hda1 * 1 11 83128+ 83 Linux /dev/hda2 12 78 506520 82 Linux swap /dev/hda3 79 3970 29423520 83 Linux
Command (m for help): d Partition number (1-4): 3
Command (m for help): d Partition number (1-4): 2
Command (m for help): d Selected partition 1
Command (m for help): p
Disk /dev/hda: 30.7 GB, 30735581184 bytes 240 heads, 63 sectors/track, 3970 cylinders Units = cylinders of 15120 * 512 = 7741440 bytes
Device Boot Start End Blocks Id System
Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-3970, default 1): 1 Last cylinder or +size or +sizeM or +sizeK (1-3970, default 3970): +100m
Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 2 First cylinder (15-3970, default 15): 15 Last cylinder or +size or +sizeM or +sizeK (15-3970, default 3970): 3970
Command (m for help): t Partition number (1-4): 2 Hex code (type L to list codes): 8e Changed system type of partition 2 to 8e (Linux LVM)
Command (m for help): p
Disk /dev/hda: 30.7 GB, 30735581184 bytes 240 heads, 63 sectors/track, 3970 cylinders Units = cylinders of 15120 * 512 = 7741440 bytes
Device Boot Start End Blocks Id System /dev/hda1 * 1 14 105808+ 83 Linux /dev/hda2 12 3970 29907360 8e Linux LVM
Command (m for help): w The partition table has been altered!
Calling ioctl() to re-read partition table. Syncing disks. -/bin/sh-3.00#

The next step is to set up the LVM structure. This includes writing an LVM PV (physical volume) signature in /dev/hda2, creating a VG (volume group) to use that space, and then creating two LV's (logical volumes) for use by CentOS.

-/bin/sh-3.00# lvm lvm> pvcreate /dev/hda2 Physical volume "/dev/hda2" successfully created lvm> vgcreate disks /dev/hda2 Volume group "disks" successfully created lvm> lvcreate --size 512m --name 0swap disks Logical volume "0swap" created lvm> lvcreate --size 2g --name 0root disks Logical volume "0root" created lvm> exit Exiting. -/bin/sh-3.00#

Now that the containers have been created, we can proceed with the normal CentOS installation. Press ALT-F1 to return to the text-mode installer, or ALT-F7 to return to the graphical installer.

Adding another disk

This is a side note, and is not necessary to install the system. I am including it as a way to illustrate how to dynamically add a disk to an existing system, with allows you to create more LVs or extend the LVs you already have.

These directions assume that you already have a working system, with the LVM utilities installed. If you are doing this on a Xen machine, these commands need to run in the xen0 session (since the xenU sessions can't access the hardware directly.)

For this example, /dev/hda is the existing disk (as shown above) and /dev/hdb is the new, empty disk (the same model as the first drive.) We start by creating a single partition on the new disk, which totally fills the disk.

[root@xen0 ~]# fdisk /dev/hdb The number of cylinders for this disk is 3970. There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with: 1) software that runs at boot time (e.g., old versions of LILO) 2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): p
Disk /dev/hdb: 30.7 GB, 30735581184 bytes 240 heads, 63 sectors/track, 3970 cylinders Units = cylinders of 15120 * 512 = 7741440 bytes
Device Boot Start End Blocks Id System
Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-3970, default 1): 1 Last cylinder or +size or +sizeM or +sizeK (1-3970, default 3970): 3970
Command (m for help): t Selected partition 1 Hex code (type L to list codes): 8e
Command (m for help): p
Disk /dev/hdb: 30.7 GB, 30735581184 bytes 240 heads, 63 sectors/track, 3970 cylinders Units = cylinders of 15120 * 512 = 7741440 bytes
Device Boot Start End Blocks Id System /dev/hdb1 1 3970 30013168+ 8e Linux LVM
Command (m for help): w The partition table has been altered!
Calling ioctl() to re-read partition table. Syncing disks. [root@xen0 ~]#

Once the partition exists, we use the LVM command-line tools to create a PV in the partition and then add the PV to the existing "disks" VG.

[root@xen0 ~]# pvcreate /dev/hdb1
  Physical volume "/dev/hdb1" successfully created.
[root@xen0 ~]# vgextend disks /dev/hdb1
  Volume group "disks" successfully extended

At this point you have the entire capacity of /dev/hdb available to create or extend LVs within the "disks" VG.


Installing CentOS

The text-mode installer will ask whether you wish to "Autopartition" or use "Disk Druid". In this case we will use Disk Druid. Because we have created the LVM structures, you will see these items on Disk Druid's screen, in addition to the physical partitions you are used to seeing.

Device Start End Size Type Mount Point VG disks 29204M VolGroup LV 0swap 512M foreign LV 0root 2048M foreign /dev/hda hda1 1 14 103M ext3 hda2 15 3970 29206M physical v New Edit Delete RAID OK Back


The first step is to move down to "/dev/hda1" and press F3 (or "Edit".) It will pop up another window like this:

Mount Point:<Not Applicable>_____ File System Type: Linux native Size (MB): 103 File System Option:Leave unchanged OK File System Options Cancel  


Click the "File System Options" button.

Please choose how you would like to prepare the file system on this partition. ( ) Leave unchanged (preserve data) (*) Format as: ext2 ext3 # OK Cancel


Choose "Format as:" (i.e. press DOWN so the cursor is on the space next to "Format as:", then press SPACE) and then make sure the filesystem type is set to "ext3" (i.e. press TAB to move into the list of filesystem types and use the up and down arrows until "ext3" is selected.) Press OK to return to the first dialog, and enter "/boot" as the mount point.

Mount Point:/boot_______________ File System Type: ext3 Size (MB): 103 File System Option:Format as ext3 OK File System Options Cancel  


Next we move up to the "LV 0swap" line and press F3 (or "Edit".) It will pop up the same window as before- select "File System Options", and on that window choose "Format as:" and set the type to "swap" (use the up and down arrows, "swap" is on the list- the text interface isn't very good at showing a scroll bar to tell you that there are more than two items on the list.) Select OK, then OK on the first window.

Now move down to the "LV 0root" line and press F3 (or "Edit".) It will pop up the same window, again select "File System Options" and choose "Format as:" and "ext3". Press OK. Change the mount point to "/" and then press OK.

When it's done, you should see the following:

Device Start End Size Type Mount Point VG disks 29204M VolGroup LV 0swap 512M swap LV 0root 2048M ext3 / /dev/hda hda1 1 14 103M ext3 /boot hda2 15 3970 29206M physical v New Edit Delete RAID OK Back


Now press F12 (or the "OK" button) to finalize the use of each partition. The installer will show you a summary of what you have chosen, which will look something like this:

The following pre-existing partitions have been selected to be formatted, destroying all data. Select 'Yes' to continue and format these partitions, or 'No' to go back and change these settings. /dev/hda1 ext3 /boot /dev/disks/0root ext3 / /dev/disks/0swap swap Yes No


When you click the YES button, the installer will continue like any other CentOS install.


Finishing the installation

When you reach the package selection portion of the installer, make sure to UN-check every single option. The idea is to install as little as possible. Remember that the install you're doing right now will become the xen0 session, and will probably not be used for much more than maintenance on xenU sessions.

After the installation is done the machine will reboot. Log in as root and make sure that whatever packages you have installed are up to date.

# yum update