Why?


Search This Blog

Wednesday, May 27, 2015

KVM create Windows guest Centos 6.6 and 7



KVM create Windows guest

This is what works best for me. I have a Centos 6.6 with 3.19.8 kernel I use for my KVM host. I use this at home for testing/play.

This also works for Centos7. I have used the same procedure.

My KVM host is an i5 4590 with 16GB (2x8GB) Corsair DDR3 1600 RAM, 120GB Samsung PRO SSD for boot and OS, with 4x WD RED 3TB in zfs RAID 10.

# zpool create myraid mirror /dev/sdb /dev/sdc mirror /dev/sdd /dev/sde

I used the name myraid for the pool.

My KVM host, I mention above, is headless and I have Gnome and VNC installed on it. I manage most everything through the cli via ssh, but working with KVM for Windblows, I mean Windows, quest is very difficult without a desktop. Of course I have virt-manager, virt-viewer, virt-win, etc... on it.

I found this procedure works fairly well. Sometimes I see heavy CPU load from the Windows guest I occasional run on it, but hey, it’s Windows.

First I create a 100GB disk in my pool for the image. For this example I use disk1, to keep it simple.

# zfs create -V 100G myraid/disk1

Verify the new zvol is there

# ls -l /dev/zvol/myraid
total 0
lrwxrwxrwx 1 root root 9 May 26 18:54 disk1 -> ../../zd0

# ls -l /dev/zvol/myraid/disk1
lrwxrwxrwx 1 root root 9 May 26 18:54 /dev/zvol/myraid/disk1 -> ../../zd0

We now have a block device in our zfs pool we can manage like any other block device in Linux. The fdisk commands below are:

n = for new partition.
p = when asking for primary or extended.
1 = is the partition number.
Then hit enter key twice to choose default first cylinder.
p = to to print to screen our new partition, verify it looks good.
w = for write changes.

Now let’s get a partition on it

# fdisk /dev/zvol/myraid/test1
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-20805, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-20805, default 20805):
Using default value 20805

Command (m for help): p

Disk /dev/zvol/myraid/test: 10.7 GB, 10737418240 bytes
16 heads, 63 sectors/track, 20805 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 8192 bytes
I/O size (minimum/optimal): 8192 bytes / 8192 bytes
Disk identifier: 0x094e7df9

                Device Boot      Start         End      Blocks   Id  System
/dev/zvol/myraid/test1               1       20805    10485688+  83  Linux
Partition 1 does not start on physical sector boundary.

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
#

Lets put a file system on it

# mkfs.ext4 /dev/zvol/myraid/disk1

Make a directory for a mount point. I used /disk1 for simplicity here

# mkdir /disk1

Mount it so we can us it

# mount /dev/zvol/myraid/disk1 /disk1

To make this mount on boot edit your fstab file and add a line like the following to bottom of file:

# vi /etc/fstab
/dev/zvol/myraid/disk1   /disk1   ext4    defaults,_netdev    0 0

I used the _netdev above as I was getting a failed to mount message in my boot.log, although it got mounted by the end of the boot. It was trying to mount this before zfs loaded, therefore not able to mount a zvol. The _netdev I think makes it wait for the services to start before trying to mount.

I then issue the following command so I don't have any permission issues later down the road. Remember this is home play setup, not corporate production.

# chmod 777 /disk1

Now create your KVM guest image on /disk1 using the virt-manager in the Gnome desktop, via VNC if your headless like me. Options I found that run the best for me are:

Storage format: virtio and raw
Cache mode: none (not default!)
I/O mode: native

I Also create a floppy and CDROM, and attach the virt-win drivers to each. ISO gets the CDROM and the floppy gets the fd. !!NOTE you must have these mounted and available on quest boot our the quest will not have a hard drive to use. Hence the virtio.

I also use the virt-nic and virt-mem found in the virt-win drivers ISO. The virt-nic gave me a 10GB network card and really improved my network speed.

Get virtio drivers for windows.

# wget https://fedorapeople.org/groups/virt/virtio-win/virtio-win.repo

Copy the contents of the virtio-win.repo file you just downloaded and paste in this new file

# vi /etc/yum.repos.d/virtio-win.repo

As of 8/24/2015 the contents of virtio-win.repo are.

# virtio-win yum repo
# Details: https://fedoraproject.org/wiki/Windows_Virtio_Drivers

[virtio-win-stable]
name=virtio-win builds roughly matching what was shipped in latest RHEL
baseurl=http://fedorapeople.org/groups/virt/virtio-win/repo/stable
enabled=1
skip_if_unavailable=1
gpgcheck=0

[virtio-win-latest]
name=Latest virtio-win builds
baseurl=http://fedorapeople.org/groups/virt/virtio-win/repo/latest
enabled=0
skip_if_unavailable=1
gpgcheck=0

[virtio-win-source]
name=virtio-win source RPMs
baseurl=http://fedorapeople.org/groups/virt/virtio-win/repo/srpms
enabled=0
skip_if_unavailable=1
gpgcheck=0

Now install the virtio-win drivers.

# yum -y install virtio-win

Drivers are now located at.

# ls -lsah /usr/share/virtio-win/

Have fun!

No comments:

Post a Comment