Difference between pages "Windows 10 Virtualization with KVM" and "LVM Install Guide"

From Funtoo
(Difference between pages)
Jump to navigation Jump to search
 
 
Line 1: Line 1:
This page describes how to set up Funtoo Linux to run Windows 7 Professional 32-bit within a KVM virtual machine. KVM is suitable for running Windows 7 for general desktop application use. It does not provide 3D support, but offers a nice, high-performance virtualization solution for day-to-day productivity applications. It is also very easy to set up.
{{fancywarning| This page is currently a work in progress }}
 


== Introduction ==
== Introduction ==
This tutorial will show you how to install Funtoo, including the rootfs, on logical volumes. This guide is meant to complement the regular [[Funtoo_Linux_Installation|Funtoo Installation Guide]]. It is recommended to open it in another tab, window ect.. and follow along with it as we will only be documenting the steps that are different or in addition to the regular guide.


KVM is a hardware-accelerated full-machine hypervisor and virtualization solution included as part of kernel 2.6.20 and later. It allows you to create and start hardware-accelerated virtual machines under Linux using the QEMU tools.
=== Introduction to LVM ===
 
LVM (Logical Volume Management) offers a much more flexible way of managing your storage devices. Not only does it allow you to resize your volumes while the system is still up, it also frees you from having to decide exactly how many or how big volumes need to be at the time of installation.  
[[File:Windows7virt.png|400px|Windows 7 Professional 32-bit running within qemu-kvm]]
 
== KVM Setup ==
 
You will need KVM to be set up on the machine that will be running the virtual machine. This can be a local Linux system, or if you are using SPICE (see [[#SPICE (Accelerated Remote Connection)|SPICE]]), a local or remote system. See the SPICE section for tweaks that you will need to make to these instructions if you plan to run Windows 7 on a Funtoo Linux system that you will connect to remotely.
 
Follow these steps for the system that will be running the virtual machine.
 
If you are using an automatically-built kernel, it is likely that kernel support for KVM is already available.
 
If you build your kernel from scratch, please see [[KVM|the KVM page]] for detailed instructions on how to enable KVM. These instructions also cover the process of emerging qemu, which is also necessary. [[KVM|Do this first, as described on the KVM page]] -- then come back here.
 
{{fancyimportant|Before using KVM, be sure that your user account is in the <tt>kvm</tt> group so that <tt>qemu</tt> can access <tt>/dev/kvm</tt>. You will need to use a command such as <tt>vigr</tt> as root to do this, and then log out and log back in for this to take effect.}}
 
Prior to using KVM, modprobe the appropriate accelerated driver for Intel or AMD, as root:
 
<console>
# ##i##modprobe kvm_intel
</console>
 
== Windows 7 ISO Images ==
 
In this tutorial, we are going to install Windows 7 Professional, 32-bit Edition. Microsoft provides a free download of the ISO DVD image, but this does require a valid license key for installation. You can download Windows 7 Professional, 32 bit at the following location:
 
http://msft-dnl.digitalrivercontent.net/msvista/pub/X15-65804/X15-65804.iso
 
{{fancynote|Windows 7 Professional, 32-bit Edition is a free download but requires a valid license key for installation.}}
 
In addition, it's highly recommended that you download "VirtIO" drivers produced by Red Hat. These drivers are installed under Windows and significantly improve Windows 7 network and disk performance. You want to download the ISO file (not the ZIP file) at the following location:
 
http://alt.fedoraproject.org/pub/alt/virtio-win/latest/images/
 
== Create Raw Disk ==
 
In this tutorial, we are going to create a 30GB raw disk image for Windows 7. Raw disk images offer better performance than the commonly-used QCOW2 format. Do this as a regular user:
 
<console>
$ ##i##cd
$ ##i##qemu-img create -f raw win7.img 30G
</console>


We now have an empty virtual disk image called <tt>win7.img</tt> in our home directory.
For a detailed tour and introduction to LVM please consult the [[LVM Fun]] page.


== QEMU script ==


Now, we'll create the following script to start our virtual machine and begin Windows 7 installation. Note that this script assumes that the two ISO files downloaded earlier were placed in the user's <tt>Downloads</tt> directory. Adjust paths as necessary if that is not the case. Also be sure to adjust the following parts of the script:
== Live CD ==
Please read the [[Funtoo Linux Installation#Live CD|Live CD]] section in the regular guide. The only thing you need in addition to the [[Requirements|requirements]] it mentions is the sys-fs/lvm2 package or equivalent. If you use [http://www.sysresccd.org/ System Rescue CD], it includes the lvm2 package.


* Adjust the name of <tt>VIRTIMG</tt> to match the exact name of the VirtIO ISO image you downloaded earlier
== Prepare Hard Disk ==
* Adjust the <tt>smp</tt> option to use the number of CPU cores and threads (if your system has hyperthreading) of your Linux system's CPU.
Preparing the hard disk for an LVM install isn't much different from a normal install except that we won't be creating a bunch of partitions as we are going to use logical volumes instead. All we need is a /boot partition, if your using gpt, you'll need the GRUB partition, and the rest of the space will just be one big partition which we'll create our logical volumes out of.


Use your favorite text editor to create the following script. Name it something like <tt>vm.sh</tt>:
{{fancynote|We're using the previous mentioned setup to keep things simple in this guide. We are also assuming your only using one hard disk though LVM supports adding multiple hard disks and partitions to a volume group. Please adapt these instructions to suit your needs}}


<syntaxhighlight lang="bash">
The regular install guide does a good job explaining MRB, GPT, and gdisk/fdisk so we won't be repeating that here. Read through the [[Funtoo Linux Installation#Prepare Hard Disk|Prepare Hard Disk]] section and create the previous mentioned partitions.  
#!/bin/sh
If your following our setup your partition table should look like the following when completed:
export QEMU_AUDIO_DRV=alsa
DISKIMG=~/win7.img
WIN7IMG=~/Downloads/X15-65804.iso
VIRTIMG=~/Downloads/virtio-win-0.1-74.iso
qemu-system-x86_64 --enable-kvm -drive file=${DISKIMG},if=virtio -m 2048 \
-net nic,model=virtio -net user -cdrom ${WIN7IMG} \
-drive file=${VIRTIMG},index=3,media=cdrom \
-rtc base=localtime,clock=host -smp cores=2,threads=4 \
-usbdevice tablet -soundhw ac97 -cpu host -vga vmware
</syntaxhighlight>


Now, make the script executable:
'''GPT partition table'''
<console>Command (? for help): ##i##p
Disk /dev/sda: 83886080 sectors, 40.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): A4E5208A-CED3-4263-BB25-7147DC426931
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 83886046
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)


<console>
Number  Start (sector)    End (sector)  Size      Code  Name
$ ##i##chmod +x vm.sh
  1            2048        1026047  500.0 MiB  8300  Linux filesystem
  2        1026048        1091583  32.0 MiB    EF02  BIOS boot partition
  3        1091584        83886046  39.5 GiB    8300  Linux filesystem
</console>
</console>


Here is a brief summary of what the script does. It starts the <tt>qemu-kvm</tt> program and instructs it to use KVM to accelerate virtualization. The display will be shown locally, in a window. If you are using the SPICE method, described later in this document, no window will appear, and you will be able to connect remotely to your running virtual machine.
'''MRB partition table'''
 
<console>Command (? for help): ##i##p
The system disk is the 30GB raw image you created, and we tell QEMU to use "virtio" mode for this disk, as well as "virtio" for network access. This will require that we install special drivers during installation to access the disk and enable networking, but will give us better performance.
 
To assist us in installing the VirtIO drivers, we have configured the system with two DVD drives -- the first holds the Windows 7 installation media, and the second contains the VirtIO driver ISO that we will need to access during Windows 7 installation.
 
The <tt>-usbdevice tablet</tt> option will cause our mouse and keyboard interaction with our virtual environment to be intuitive and easy to use.


{{fancyimportant|1=
Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 sectors
For optimal performance, adjust the script so that the <tt>-smp</tt> option specifies the exact number of cores and threads on your system -- on non-HyperThreading systems (AMD and some Intel), simply remove the <tt>,threads=X</tt> option entirely and just specify cores. Also ensure that the <tt>-m</tt> option provides enough RAM for Windows 7, without eating up all your system's RAM. On a 4GB Linux system, use <tt>1536</tt>. For an 8GB system, <tt>2048</tt> is safe.}}
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x6919e82c


== SPICE (Accelerated Remote Connection) ==
  Device Boot      Start        End      Blocks  Id  System
SPICE is a new technology that has been incorporated into QEMU, which allows the virtual machine to run on one system, and allows you to use <code>spicec</code>, the SPICE client, to connect to your remote virtual machine. In real-world use, you can run a SPICE server (via QEMU) and client on the same machine if you like, or have them on the same local area network, or have server and client connect over an Internet connection. Here are some important facts about SPICE:
/dev/sda1            2048    1026047      512000  83  Linux
* SPICE provides accelerated, optimized video updates over the network, similar to VNC
/dev/sda2        1026048    83886079    41430016  83  Linux
* QEMU can be configured to run a SPICE server, which you can connect to via <code>spicec</code>, the SPICE client. The SPICE client renders to a local window on your system.
* SPICE allows easy copying and pasting across operating systems -- for example, you can copy something in GNOME, paste it into the <code>spicec</code> window and have it appear on your Windows 7 system.
 
=== SPICE Setup ===
To set up SPICE, you need to perform the following changes to the "standard" steps described in this document:
# Emerge QEMU with the <code>spice</code> USE variable on the system that will be running the Windows 7 virtual machine.
# Emerge <code>spice</code> on the system that you will be using to connect to your remote Windows 7 virtual machine.
# In the <code>vm.sh</code> script, remove the existing <code>-vga vmware</code> <code>qemu-kvm</code> option, and add these options: <code>-vga qxl -device virtio-serial-pci -spice port=5900,password=mypass -device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0 -chardev spicevmc,id=spicechannel0,name=vdagent</code>
# Run <code>vm.sh</code> as described in the next section on your remote server (your Windows 7 system will now boot, but you can't see the virtual machine display) and then connect to it by running the following command on your local system:
<console>
# ##i##spicec -h remotehost -p 5900 -w mypass
</console>
</console>
The SPICE client window will appear locally and allow you to interact with your Windows 7 system.


== Starting Windows 7 Installation ==
== Creating Logical Volumes ==
 
In this section we will cover the basics of creating volume groups and logical volumes. For an in depth explanation please see the [[LVM Fun]] page.
Now, it's time to start Windows 7 installation. Run <tt>vm.sh</tt> as follows:
 
<console>
$ ##i##./vm.sh
</console>


Windows 7 installation will begin. During the installation process, you will need to enter a valid license key, and also load ''both'' VirtIO drivers from Red Hat when prompted (Browse to the second DVD, then win7 directory, then x86).
=== Creating a Physical Volume ===
Our first step is to create a physical volume which basically just tells the lvm where to write the data to.
Create a physical volume out of the big partition we created in the previous step. If your using the MRB setup then change /dev/sda3 to /dev/sda2 in the following command
<console># pvcreate /dev/sda3</console>


After some time, Windows 7 installation will complete. You will be able to perform Windows Update, as by default, you will have network access if your host Linux system has network access.
=== Creating a Volume Group ===
Now that we have a place to store our data we need to create a volume group for it. A volume group is simply a named group of at least one physical volume. This allows multiple physical volumes to be used to store data. In our simple example we only have one physical volume so we'll create a volume group and add our physical volume to it in one command. We are going to call our volume group "vg" but you can name it anything you want. Remember to adjust the device path if your using MRB.
<console># vgcreate vg /dev/sda3</console>


Enjoy your virtualized Windows 7 system!
=== Creating Logical Volumes ===


[[Category:Tutorial]]
[[Category:HOWTO]]
[[Category:First Steps]]
[[Category:Install]]
[[Category:Virtualization]]
[[Category:KVM]]
[[Category:Official Documentation]]
[[Category:Official Documentation]]

Revision as of 14:55, June 5, 2014

   Warning
This page is currently a work in progress 


Introduction

This tutorial will show you how to install Funtoo, including the rootfs, on logical volumes. This guide is meant to complement the regular Funtoo Installation Guide. It is recommended to open it in another tab, window ect.. and follow along with it as we will only be documenting the steps that are different or in addition to the regular guide.

Introduction to LVM

LVM (Logical Volume Management) offers a much more flexible way of managing your storage devices. Not only does it allow you to resize your volumes while the system is still up, it also frees you from having to decide exactly how many or how big volumes need to be at the time of installation.

For a detailed tour and introduction to LVM please consult the LVM Fun page.


Live CD

Please read the Live CD section in the regular guide. The only thing you need in addition to the requirements it mentions is the sys-fs/lvm2 package or equivalent. If you use System Rescue CD, it includes the lvm2 package.

Prepare Hard Disk

Preparing the hard disk for an LVM install isn't much different from a normal install except that we won't be creating a bunch of partitions as we are going to use logical volumes instead. All we need is a /boot partition, if your using gpt, you'll need the GRUB partition, and the rest of the space will just be one big partition which we'll create our logical volumes out of.

   Note

We're using the previous mentioned setup to keep things simple in this guide. We are also assuming your only using one hard disk though LVM supports adding multiple hard disks and partitions to a volume group. Please adapt these instructions to suit your needs

The regular install guide does a good job explaining MRB, GPT, and gdisk/fdisk so we won't be repeating that here. Read through the Prepare Hard Disk section and create the previous mentioned partitions. If your following our setup your partition table should look like the following when completed:

GPT partition table

Command (? for help): p
Disk /dev/sda: 83886080 sectors, 40.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): A4E5208A-CED3-4263-BB25-7147DC426931
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 83886046
Partitions will be aligned on 2048-sector boundaries
Total free space is 2014 sectors (1007.0 KiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         1026047   500.0 MiB   8300  Linux filesystem
   2         1026048         1091583   32.0 MiB    EF02  BIOS boot partition
   3         1091584        83886046   39.5 GiB    8300  Linux filesystem

MRB partition table

Command (? for help): p

Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x6919e82c

   Device Boot      Start         End       Blocks   Id  System
/dev/sda1            2048     1026047       512000   83  Linux
/dev/sda2         1026048    83886079     41430016   83  Linux

Creating Logical Volumes

In this section we will cover the basics of creating volume groups and logical volumes. For an in depth explanation please see the LVM Fun page.

Creating a Physical Volume

Our first step is to create a physical volume which basically just tells the lvm where to write the data to. Create a physical volume out of the big partition we created in the previous step. If your using the MRB setup then change /dev/sda3 to /dev/sda2 in the following command

root # pvcreate /dev/sda3

Creating a Volume Group

Now that we have a place to store our data we need to create a volume group for it. A volume group is simply a named group of at least one physical volume. This allows multiple physical volumes to be used to store data. In our simple example we only have one physical volume so we'll create a volume group and add our physical volume to it in one command. We are going to call our volume group "vg" but you can name it anything you want. Remember to adjust the device path if your using MRB.

root # vgcreate vg /dev/sda3

Creating Logical Volumes