How to install CentOS 6 on Microsoft Hyper-V virtualization

Many developers rely on Linux, but often work in a Windows infrastructure environment. Often it’s not feasible to install a flow-blown VSphere or XenServer setup when everything else runs on Windows Server and there’s limited hardware, but virtualization has many advantages. Enter Hyper-V, which can be looked after by Windows system administrators, but let you use Linux in virtual machines as you would in any other virtualized environment.

With a few caveats mind you…

Create a new Virtual Machine

Creating a Virtual Machine in Hyper-V is much the same as any other virtualization platform, simply click through the wizard to set it up. The only real choice at this stage is how to configure the initial IDE disk that the server will use to boot from.

1 new vm 2 ram 3 network 4 vhd 5 iso 17 name

Setup bootable IDE hard drive

The VM will need a bootable hard drive to install CentOS on. Due to Hyper-V restrictions this must be an IDE hard drive and cannot be larger than 128GB. This is due to the IDE-emulation that Hyper-V uses, which hopefully will be fixed in a future release.

If you need additional storage (as if often required) you can add a second IDE or SCSI hard drive, which is explained later.

Changing Network Adapter

One thing that needs to be done pre-installation if you are installing from a netinstall ISO, or otherwise want to use networking during the installation process, is to change the Network Adapter. This is because Linux won’t understand how to interact with the synthetic network adapter initially, and you can’t load the drivers until after installation is complete.

6 settings 7 legacy_nic 8 assign_legacy_nic

Install CentOS

Use any of the ISO’s that you can download from a CentOS mirror, although I found using the net install the easiest as it verifies that your networking is up and running before you install (it can be a pain to sort out post-install if eth0 isn’t detected)

9 start 12 connect11 install 10 skip_disk

Installing from URL

If you want to install from a URL as opposed to a CD/DVD ISO (which is my preferred method) you need to both configure networking then point the installer at a URL to install from. I commonly use the University of Kent mirror although there are plenty of other CentOS mirrors.

14 nfs 15 ip_settings 16 configure 18 netinst

Graphical installation

Once the net install has downloaded the files required to install, the graphical installer will boot. The only major decision to make it to ensure you use all of the virtual hard drive created (even if it is dynamically resizing, which it is by default)

19 storage 20 disk_format 23 space 25 config

Install Linux IC

Get the latest Linux Integrated Components from Microsoft (currently 3.4) Mount the Linux Integrated Components ISO and copy the files to the virtual machine somewhere, then run the installer

mkdir /opt/linuxic
mkdir /mnt/cdrom
mount /dev/cdrom /mnt/cdrom
cd /mnt/cdrom
cp * -R /opt/linuxic/
cd /opt/linuxic
cd RHEL63
./install.sh

30 dvd_drive 31 mount_ic 32 install_ic

You should then get the message

Linux Integration Services for Hyper-V has been installed. \
Please reboot your system.

Once this has completed you will be able to access the synthetic networking and storage adapters that come with Hyper-V. Reboot the virtual machine you should have access to the network adapter (instead of the legacy network adapter) and SCSI virtual disks, as explained below.

Configure synthetic network adaptor

To configure the synthetic network adapter instead of the legacy adapter, once Linux IC are installed you can turn off the VM and switch them over. If CentOS installed successfully with the legacy network adaptor, it should be configured as eth0.

With the VM turned off, go into the settings and copy the dynamic MAC address of the legacy network adaptor into the synthetic network adaptor (labelled just network adapter) and set the MAC address to be static.

33 remove_ic 34 legacy_nic_mac 35 nic 36 nic_mac

Once you boot the VM, CentOS should switch to using the new network adaptor as eth0 in place of the old legacy network adaptor, and should work with no additional configuration.

Setup additional hard drive

On the assumption that you will use the 2nd IDE channel for mounting CD/DVD images (such as the Linux IC .iso) you can add additional hard drives via SCSI. In theory once Linux IC are installed the SCSI emulation should be faster than the IDE emulation…

If you need help partitioning, formattting and mounting the new disk there is a guide for adding a new disk drive to a CentOS system on Techotopia.

fdisk /dev/sdb

Create a new primary partition on the drive using all available space, then write the changes to the device. As a shortcut just type n, p, 1, (empty), (empty), w

/sbin/mkfs.ext4 -L /var /dev/sdb1
mv /var /var_old
mount /dev/sdb1 /var

5 comments

Leave a Reply to Andrew Kirkpatrick Cancel reply