View Source

The following article describes the steps needed to create a customized CentOS LiveCD, with support for Microsoft Hyper-V virtual machines, for the purpose of performing Bare-Metal Restores in CDP. The article is meant to be a proof of concept. The methods outlined can be used to create LiveCDs with other Linux distros.

Creating a LiveCD is not as daunting a task as many people think. The customized LiveCD is based on a standard CentOS 5.6 LiveCD.

{code}[root@livecd ~]# cat /etc/redhat-release
CentOS release 5.6 (Final){code}

To create the customized LiveCD, follow the instructions below.

1. Obtain the standard LiveCD and boot from it.

2. After booting, you have to provide some writable disk space (at least 10 gigabytes). In this document it is assumed that the writable space is a hard disk partition and this partition is mounted in {color:blue}/usr/src{color} directory. If you do not have a hard disk, you can use USB flash drive or network share.

3. After you have configured writable space, install development tools (GNU C compiler, make, etc.) and kernel sources. The kernel sources should be exactly the same version as the kernel on LiveCD (for CentOS 5.6 it is version 2.6.18-238.el5) . So do not use {color:blue}yum{color} for installing kernel sources and other tools, because {color:blue}yum{color} will try to upgrade your kernel to a newer version. You should download all rpms directly from one of CentOS mirrors:

{code}[root@livecd ~]# rpm -i http://mirror.rackspace.com/CentOS/5.6/os/i386/CentOS/kernel-headers-2.6.18-238.el5.i386.rpm
[root@livecd ~]# rpm -i http://mirror.rackspace.com/CentOS/5.6/os/i386/CentOS/kernel-devel-2.6.18-238.el5.i686.rpm
[root@livecd ~]# rpm -i http://mirror.rackspace.com/CentOS/5.6/os/i386/CentOS/glibc-headers-2.5-58.i386.rpm
[root@livecd ~]# rpm -i http://mirror.rackspace.com/CentOS/5.6/os/i386/CentOS/glibc-devel-2.5-58.i386.rpm
[root@livecd ~]# rpm -i http://mirror.rackspace.com/CentOS/5.6/os/i386/CentOS/libgomp-4.4.4-13.el5.i386.rpm
[root@livecd ~]# rpm -i http://mirror.rackspace.com/CentOS/5.6/os/i386/CentOS/gcc-4.1.2-50.el5.i386.rpm
[root@livecd ~]# rpm -i http://mirror.rackspace.com/CentOS/5.6/os/i386/CentOS/make-3.81-3.el5.i386.rpm{code}

4. Next, you have to download Linux Integration Components for Windows Server 2008 Hyper-V R2 from Microsoft's website to a *Windows 2008 R2 machine*. At the time of writing this the URL was as follows:

[http://www.microsoft.com/downloads/en/details.aspx?FamilyID=c299d675-bb9f-41cf-b5eb-74d0595ccc5c&displaylang=en]

5. Launch the executable file on Windows 2008 machine. This executable is a self-extracting archive. You will have to upload extracted {color:blue}LinuxIC v2.iso{color} file to Linux. Rename it so that there are no spaces in the name - for example, to {color:blue}LinuxICv2.iso{color} \- and place in {color:blue}/usr/src{color} directory. Mount this {color:blue}iso{color} file using loopback device:

{code}[root@livecd ~]# mkdir /mnt/ICv2
[root@livecd ~]# mount -o loop /usr/src/LinuxICv2.iso  /mnt/ICv2{code}

6. The {color:blue}iso{color} file is mounted read-only. But to be able to compile drivers for Hyper-V virtual hardware, the directory with the drivers' source code should be writable. Copy the content of the {color:blue}iso{color} file to the writable space using {color:blue}tar{color} instead of {color:blue}cp{color}, so all file permissions are preserved:

{code}[root@livecd ~]# cd /mnt/ICv2
[root@livecd ICv2]# mkdir /usr/src/ICv2work
[root@livecd ICv2]# tar -c -f - * | tar -C /usr/src/ICv2work -x -f -{code}

7. Enter {color:blue}/usr/src/ICv2work{color} directory and run the "{color:blue}setup.pl drivers{color}" command to build drivers:

{code}[root@livecd ICv2]# cd /usr/src/ICv2work/
[root@livecd ICv2work]# ./setup.pl drivers
Updating Linux integration components (vmbus, enlightened ide, enlightened scsi and network drivers) for Hyper-V...
Building vmbus driver...done.
Building blkvsc driver...done.
Building storvsc driver...done.
Building netvsc driver...
........{code}

8. Errors in creating {color:blue}initrd{color} image are safe to ignore. Make sure that the drivers have been built successfully. If they have, the directory {color:blue}/lib/modules/2.6.18-238.el5/kernel/drivers/vmbus{color} should exist and contain five files:

{code}[root@livecd ICv2work]# ls -al /lib/modules/2.6.18-238.el5/kernel/drivers/vmbus
total 1216
-rwxr-xr-x 1 root root 297963 May 24 14:34 blkvsc.ko
-rwxr-xr-x 1 root root 365 May 24 14:34 Module.symvers
-rwxr-xr-x 1 root root 320448 May 24 14:34 netvsc.ko
-rwxr-xr-x 1 root root 296318 May 24 14:34 storvsc.ko
-rwxr-xr-x 1 root root 279208 May 24 14:34 vmbus.ko{code}

9. The next step is to embed the drivers into LiveCD image. It is a good idea to embed R1Soft repository configuration too, so after booting from this customized LiveCD you can always install the latest version of CDP Server or Agent using {color:blue}yum{color}.

Copy the content of the CentOS LiveCD to the writable space. The content of LiveCD is in {color:blue}/mnt/live{color} directory:

{code}[root@livecd ~]# mkdir /usr/src/LiveCDwork
[root@livecd ~]# cd /mnt/live
[root@livecd live]# cp -R * /usr/src/LiveCDwork
[root@livecd live]# cd /usr/src/LiveCDwork{code}

10. Inside the {color:blue}LiveCDwork{color} you should see {color:blue}LiveOS{color} directory, and inside {color:blue}LiveOS{color} there is the {color:blue}squashfs{color} image file - {color:blue}squashfs.img{color}:

{code}[root@livecd LiveCDwork]# cd LiveOS
[root@livecd LiveOS]# ls -al squashfs.img
-r-xr-xr-x 1 root root 719618048 May 24 14:13 squashfs.img{code}

11. You should unpack this {color:blue}squashfs{color} image using {color:blue}unsquashfs{color} command (it will create {color:blue}squashfs-root{color} directory):

{code}[root@livecd LiveOS]# unsquashfs squashfs.img
created 1 files
created 2 directories
created 0 symlinks
created 0 devices
created 0 fifos
[root@livecd LiveOS]# ls
livecd-iso-to-disk osmin.img squashfs.img squashfs-root TRANS.TBL
[root@livecd LiveOS]# cd squashfs-root
[root@livecd squashfs-root]# ls
LiveOS
[root@livecd squashfs-root]# cd LiveOS
[root@livecd LiveOS]# ls
ext3fs.img{code}

12. Inside the {color:blue}squashfs-root{color} directory there is another {color:blue}LiveOS{color} directory, and inside this {color:blue}LiveOS{color} directory there is the {color:blue}ext3fs.img{color} file, that has to be modified. This file can be mounted read-write using the loopback device. Mount it and examine its content:

{code}[root@livecd LiveOS]# mkdir /mnt/ext3
[root@livecd LiveOS]# mount -o loop ext3fs.img /mnt/ext3
[root@livecd LiveOS]# ls /mnt/ext3
bin boot dev etc home lib lost+found media misc mnt opt proc root sbin selinux srv sys tmp usr var{code}

13. Now you should copy {color:blue}/lib/modules/2.6.18-238.el5/kernel/drivers/vmbus{color} directory to {color:blue}/mnt/ext3/lib/modules/2.6.18-238.el5/kernel/drivers{color} and then run {color:blue}depmod{color} to rebuild module dependencies:

{code}[root@livecd LiveOS]# cp -R /lib/modules/2.6.18-238.el5/kernel/drivers/vmbus /mnt/ext3/lib/modules/2.6.18-238.el5/kernel/drivers
[root@livecd LiveOS]# depmod -b /mnt/ext3{code}

14. Next, create the R1Soft repository configuration for {color:blue}yum{color}. Open the file {color:blue}/mnt/ext3/etc/yum.repos.d/r1soft.repo{color} in the text editor and enter the following text:

{code}[r1soft]
name=R1Soft Repository Server
baseurl=http://repo.r1soft.com/yum/stable/$basearch/
enabled=1
gpgcheck=0{code}

15. Save the file, exit from the text editor, exit {color:blue}/mnt/ext3{color} directory, and unmount the {color:blue}ext3{color} image:

{code}[root@livecd LiveOS]# cd
[root@livecd ~]# umount /mnt/ext3{code}

16. Delete the {color:blue}squashfs.img{color} file and recreate it:

{code}[root@livecd ~]# cd /usr/src/LiveCDwork/LiveOS
[root@livecd LiveOS]# rm -f squashfs.img
[root@livecd LiveOS]# mksquashfs squashfs-root squashfs.img
Creating little endian 3.0 filesystem on squashfs.img, block size 65536.
Little endian filesystem, data block size 65536, compressed data, compressed metadata, compressed fragments
Filesystem size 703333.81 Kbytes (686.85 Mbytes)
        16.77% of uncompressed filesystem size (4194560.32 Kbytes)
Inode table size 79376 bytes (77.52 Kbytes)
        30.26% of uncompressed inode table size (262306 bytes)
Directory table size 46 bytes (0.04 Kbytes)
        100.00% of uncompressed directory table size (46 bytes)
Number of duplicate files found 0
Number of inodes 3
Number of files 1
Number of fragments 0
Number of symbolic links  0
Number of device nodes 0
Number of fifo nodes 0
Number of socket nodes 0
Number of directories 2
Number of uids 1
        root (0)
Number of gids 0{code}

17. Change directory to {color:blue}/usr/src/LiveCDwork{color}, remove {color:blue}squashfs-root{color} directory, and create the ISO file using {color:blue}mkisofs{color} command:

{code}[root@livecd ~]# cd /usr/src/LiveCDwork
[root@livecd LiveCDwork]# rm -rf LiveOS/squashfs-root
[root@livecd LiveCDwork]# mkisofs -o /usr/src/CentOS-5.6-i386-LiveCD-plus.iso -b isolinux/isolinux.bin
-c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -r -R -J -V "CentOS-5.6-i386-LiveCD"
-A "CentOS-5.6-i386-LiveCD" -T.
INFO:   UTF-8 character encoding detected by locale settings.
        Assuming UTF-8 encoded filenames on source filesystem,
        use -input-charset to override.
Size of boot image is 4 sectors -> No emulation
  1.41% done, estimate finish Tue May 24 14:54:20 2011
  2.82% done, estimate finish Tue May 24 14:53:45 2011
**********************skipped***********************
 97.16% done, estimate finish Tue May 24 14:53:27 2011
 98.57% done, estimate finish Tue May 24 14:53:27 2011
Total translation table size: 4937
Total rockridge attributes bytes: 1749
Total directory bytes: 4096
Path table size(bytes): 40
Max brk space used 1a000
355092 extents written (693 MB){code}

18. Transfer the ISO file you have just created ({color:blue}/usr/src/CentOS-5.6-i386-LiveCD-plus.iso{color}) to your Hyper-V server and boot the VM you want to restore from this ISO. After logging in as root, load the {color:blue}netvsc{color} module and check if {color:blue}seth0 intrface{color} has appeared:

{code}[root@livecd ~]#  modprobe netvsc
[root@livecd ~]#  ifconfig seth0{code}

19. If you see the interface, you can assign IP address to it manually, or run {color:blue}dhclient{color} to obtain IP address from DHCP server. When the network is configured, you can install CDP Agent or CDP Server Standard or Advanced Edition using {color:blue}yum{color}. If you are using Agent, do not forget to turn off the firewall which blocks the Agent port and to restart Agent in recovery mode:

{code}[root@livecd ~]# /etc/init.d/iptables stop
[root@livecd ~]# touch /usr/sbin/r1soft/.recovery-mode
[root@livecd ~]# /etc/init.d/cdp-agent restart{code}

20. Now you can go to the Web Interface of CDP Server and start the Bare-Metal Restore process. See [CDP3:Launching Bare-Metal Restore].{excerpt:hidden=true}Instructions on how to create a customized CentOS LiveCD, with support for Microsoft Hyper-V
virtual machines, for the purpose of performing Bare-Metal Restores in
CDP.{excerpt}