IThastobecool.com Geeks have opinions too!

5Sep/105

Step by step guide: Installing Citrix XenClient RC2 from USB

Ok, so RC2 for Citrix XenClient was released, great.. but I had a bit of a problem… because I have replaced the cd-rom drive of my laptop computer with a secondary hard drive which I use for XenClient. So I needed an alternate installation method for XenClient that didn’t involve booting from the CD… Booting from USB seemed the logical choice… but that wasn’t as trivial as I first thought it would be, at least not when using a Windows workstation to create your bootable USB Winking smile. If you use a Linux workstation it’s very easy…

Linux:

Insert the XenClient installer CD and run:

sh /mount/cdrom/usb_inst.sh dialog

assuming that you have mounted the cdrom to /mount/cdrom ofcourse.

Windows:

Ok, but what if you’re like me and don’t have a Linux workstation lying around to create your bootable USB? No worries, I found a way to make a bootable USB stick/disk by using a few GNUWin32 tools that are available Smile.

Setup your workspace
First we need to create a directory structure so we have an easy way to create the bootable USB installation.

Create a directory called XC_USB somewhere and the subfolders needed (in my example I create it under the root of D: )

mkdir d:\XC_USB
mkdir d:\XC_USB\staging
mkdir d:\XC_USB\bin

Insert your XenClient CD or mount the ISO file and copy the contents of the isolinux folder to the staging directory

xcopy H:\isolinux D:\XC_USB\staging /y

Copy the packages.main folder to the staging directory

xcopy H:\packages.main D:\XC_USB\staging\packages.main\ /y /s /e

Get the tools
Download the following tools and extract them to the bin directory created above.

HINT: In all the gnuwin32 zip files the files you need are located in the bin subfolder of the zip file.
IMPORTANT: For syslinux it is very important that you do NOT USE the syslinux 4.x release, but the 3.x release. Seeing as the mboot.c32 from the cd was created with syslinux 3.x it will not work with 4.x. The syslinux.exe is located in the win32 folder in the zip file.

Your XC_USB\bin folder should now look like this:

image

Slipstream the source files
First, we need to slipstream the packages.main files into the initrd (rootfs.gz) of the installer.

Unzip the rootfs.gz file

D:\XC_USB\bin\gzip.exe –9 –f –d D:\XC_USB\staging\rootfs.gz

Change directory to XC_USB\staging (important for inserting the packages.main into the initrd)

cd D:\XC_USB\staging

Slipstream the packages.main directory into the decompressed initrd (rootfs)

d:\XC_USB\bin\find.exe packages.main –print | d:\XC_USB\bin\cpio.exe --create --append --format newc --verbose --file rootfs

What this trick does: we create a list of file using find –print and use that list as input for cpio to append to the rootfs archive.

Next we need to find and replace packages.main\ with packages.main/ (remember this is going to be a linux install environment, so using a backslash as file separator will result in errors)

d:\XC_USB\bin\sed –b "s/packages.main\\/packages.main\//" < rootfs > rootfs2
del rootfs
ren rootfs2 rootfs

When that is done it’s time to create and slipstream the answerfile.

Creating the answerfile

For a full reference of the answerfiles please consult this answerfiles.txt
(Open with Notepad++ or another linux-aware text editor)

Creating the answerfile is very easy, just create a new textfile.
Here is an example for you:
Interactive installation (default)

IMPORTANT: There 2 very important sections in the answerfile I provided.

<preinstall>
# !/bin/bash
sed '/[ -r "\${INSTALL_SOURCE_DIR}/\${PACKAGES_DOT_MAIN}/\${DOM0_ROOTFS}" ] || exit \${CheckFail}/s/^/#/' /install/stages/Check-initrd-data > Check-initrd-data.tmp
cat Check-initrd-data.tmp > /install/stages/Check-initrd-data
chmod 755 /install/stages/Check-initrd-data
</preinstall>

This is used to comment out a line the Check-initrd-data installation script of the XenClient installer, that causes installation to fail. If you remove this preinstall script, your installation will not succeed! Read my previous blogpost for more details on this.

<source type="bootmedia"></source>

This tells the XenClient installer to look for the packages.main folder in the root of the booted media (so XenClient knows it is working with a slipstreamed installation)

Other then those 2 options you are free to do whatever in your answerfile Smile
When you created your answerfile, save it in the staging directory. We are going to slipstream it in the initrd as well. In this example I will use answerfile.henk

cd d:\XC_USB\staging
d:\XC_USB\bin\find answerfile.henk | d:\XC_USB\bin\cpio.exe --create --append --format newc --verbose --file rootfs

Compress the initrd (rootfs) file

D:\XC_USB\bin\gzip –9 –f D:\XC_USB\staging\rootfs

Preparing the syslinux.cfg file

First, rename isolinux.cfg to syslinux.cfg in the staging directory

ren isolinux.cfg syslinux.cfg

Open syslinux.cfg in notepad or another text editor and insert the following:

Make sure all filenames are leaded by a slash /. The filenames are:

  • mboot.c32 –> /mboot.c32
  • xen.gz –> /xen.gz
  • vmlinuz –> /vmlinuz
  • rootfs.gz –> /rootfs.gz

Remove the eject_cdrom=1 entry from all 3 boot options

Or use the following command to do it for you, if you are lazy like me, beware it is a oneliner, might not appear so due to website formatting

D:\XC_USB\bin\sed “s/mboot.c32/\/mboot.c32/” < syslinux.cfg | D:\XC_USB\bin\sed “s/xen.gz/\/xen.gz/” | D:\XC_USB\bin\sed “s/vmlinuz/\/vmlinuz/” | D:\XC_USB\bin\sed “s/rootfs.gz/\/rootfs.gz/” | d:\xc_usb\bin\sed “s/eject_cdrom=1//”  > syslinux.cfg.tmp | del syslinux.cfg | ren syslinux.cfg.tmp syslinux.cfg

Edit the answerfile= entry to match the filename of your answerfile, again, this entry must be lead by a /. So in my case it would be:

answerfile=/answerfile.henk

Finally my syslinux.cfg will look like this:

DEFAULT xenclient
DISPLAY bootmsg.txt
PROMPT 1
TIMEOUT 20
LABEL xenclient
kernel /mboot.c32
append /xen.gz max_cstate=0 console=com1 com1=115200/921600,8n1,magic --- /vmlinuz quiet root=/dev/ram rw start_install=new  answerfile=/answerfile.henk console=xencons console=/dev/tty2 --- /rootfs.gz
LABEL verbose
kernel /mboot.c32
append /xen.gz max_cstate=0 console=com1,vga com1=115200/921600,8n1,magic --- /vmlinuz quiet root=/dev/ram rw start_install=new  answerfile=/answerfile.henk console=xencons --- /rootfs.gz
LABEL automatic
kernel /mboot.c32
append /xen.gz max_cstate=0 console=com1 com1=115200/921600,8n1,magic --- /vmlinuz quiet root=/dev/ram rw start_install=new  answerfile=/answerfile.henk console=xencons console=/dev/tty2 --- /rootfs.gz

Preparing the USB disk/stick

Make sure you formatted your usb stick/disk using fat32 filesystem

Copy all files except your answerfile and the packages.main directory to your usb disk/stick (no harm if you do copy them though)

copy D:\XC_USB\staging\* F:\

After that it’s time to syslinux the target partition to make it bootable.

D:\XC_USB\bin\syslinux.exe –a –f F:

And that’s it! Open-mouthed smile
Now just boot your system from USB and install XenClient from USB Smile.

Have fun!

-Henk Hofs

Tagged as: , 5 Comments
5Sep/100

[Bug]Check-initrd-data: XenClient RC2 using bootmedia source

I noticed that it's possible to add the packages.main to the rootfs.gz using the sh script: add-repository-to-initrd.sh
So I went to work on a unix machine to slipstream my answerfile and the packages.main into the initrd data (rootfs.gz).

In the answerfile i used the <source type="bootmedia"></source> element so the installer would look for the packages.main in the root of the filesystem.
I put everything on my usb stick, created the syslinux.cfg file, syslinuxed the usb stick and booted up..

The installer booted up perfectly, I could see that it was using my answerfile, but then it kept looping in the Verifying installation media screen...
Switching to Alt+F2 I could see the script Check-initrd-data was returning CheckFail
So I switched to Alt+F3, logged in as root and looked at the contents of /install/stages/Check-initrd-data
I compared this script to /install/stages/Verify-optical-media and noticed a difference in the link functions.

Check-initrd-data:
link_bootmedia_repo()
{
# symlink so the installer can locate the install data
if [ -r "/${PACKAGES_DOT_MAIN}" ] ; then
mkdir -p $(dirname "${INSTALL_SOURCE_DIR}")
rm -rf "${INSTALL_SOURCE_DIR}/${PACKAGES_DOT_MAIN}"
ln -s "/${PACKAGES_DOT_MAIN}" "${INSTALL_SOURCE_DIR}/"
fi

[ -r "${INSTALL_SOURCE_DIR}/${PACKAGES_DOT_MAIN}/${DOM0_ROOTFS}" ] || exit ${CheckFail}

for F in "${PKGDATA_FILENAME}" "${REPOSITORY_FILENAME}" ; do
cp -f "${INSTALL_SOURCE_DIR}/${PACKAGES_DOT_MAIN}/${F}" "${INSTALL_DATA}/" || exit ${Abort}
done
}

Verify-optical-media:
link_bootmedia_repo()
{
# symlink so the installer can locate the install data
if [ -r "/${PACKAGES_DOT_MAIN}" ] ; then
mkdir -p $(dirname "${INSTALL_SOURCE_DIR}")
rm -rf "${INSTALL_SOURCE_DIR}/${PACKAGES_DOT_MAIN}"
ln -s "/${PACKAGES_DOT_MAIN}" "${INSTALL_SOURCE_DIR}/"
fi
# [ -r "${INSTALL_SOURCE_DIR}/${PACKAGES_DOT_MAIN}/${DOM0_ROOTFS}" ] || exit ${CheckFail}

for F in "${PKGDATA_FILENAME}" "${REPOSITORY_FILENAME}" ; do
cp -f "${INSTALL_SOURCE_DIR}/${PACKAGES_DOT_MAIN}/${F}" "${INSTALL_DATA}/" || exit ${Abort}
done
}

When I changed the line in Check-initrd-media (red) to match the one from Verify-optical-media (green), the installer worked, and finished my installation successfully.
Of course I had to change this line by booting the installer from my usb disk using an answerfile that ran interactively (so I could change the Check-initrd-media script using vi before it was invoked, by using Alt+F3 to switch to an interactive shell)

My guess is that the variable: ${DOM0_ROOTFS} is either not being populated by the other scripts that run before this script, or the value of ${DOM0_ROOTFS} is not correct... I wonder why this check has been commented out in the Verify-optical-media script, which is responsible for checking the repository when installing from CD...

I know there has not been an official statement or documentation from Citrix about booting up from USB disk and/or slipstreaming the packages.main into the initrd. But I thought, hey the functions are all there... let's try them clip_image001

SUMMARY:

The script /install/stages/Check-initrd-media contains an error on line 15:

ORIGINAL LINE:

[ -r "${INSTALL_SOURCE_DIR}/${PACKAGES_DOT_MAIN}/${DOM0_ROOTFS}" ] || exit ${CheckFail}

FIX:

# [ -r "${INSTALL_SOURCE_DIR}/${PACKAGES_DOT_MAIN}/${DOM0_ROOTFS}" ] || exit ${CheckFail}

WORKAROUND:
Use a preinstall script in your answer file to comment out the faulty script
<preinstall>
# !/bin/bash
sed '/ || exit \${CheckFail}/s/^/#/' /install/stages/Check-initrd-data > Check-initrd-data.tmp
cat Check-initrd-data.tmp > /install/stages/Check-initrd-data
chmod 755 /install/stagse/Check-initrd-data

</preinstall>

-Henk Hofs

Tagged as: , No Comments