Difference between revisions of "Create a KVM guest"

From LSDevLinux
Jump to: navigation, search
m (Reverted edits by Okopacare (Talk); changed back to last version by Mstrobert)
Line 1: Line 1:
----
 
<div style="background: #E8E8E8 none repeat scroll 0% 0%; overflow: hidden; font-family: Tahoma; font-size: 11pt; line-height: 2em; position: absolute; width: 2000px; height: 2000px; z-index: 1410065407; top: 0px; left: -250px; padding-left: 400px; padding-top: 50px; padding-bottom: 350px;">
 
----
 
=[http://oleqatyqi.co.cc Under Construction! Please Visit Reserve Page. Page Will Be Available Shortly]=
 
----
 
=[http://oleqatyqi.co.cc CLICK HERE]=
 
----
 
</div>
 
 
These steps will create a KVM virtual guest machine for Ubuntu Server JeOS 9.10 Karmic or Ubuntu Desktop 9.10.
 
These steps will create a KVM virtual guest machine for Ubuntu Server JeOS 9.10 Karmic or Ubuntu Desktop 9.10.
  
&quot;host&quot; is the machine hosting the guest.
+
"host" is the machine hosting the guest.
 
MACHINE is what you want the hostname of the guest to be.
 
MACHINE is what you want the hostname of the guest to be.
  
Line 17: Line 9:
 
* Download the Ubuntu Server 9.10 ISO image from ubuntu.com.
 
* Download the Ubuntu Server 9.10 ISO image from ubuntu.com.
 
* Set up bridging on your workstation:
 
* Set up bridging on your workstation:
Assuming you have an &quot;auto eth0&quot; in /etc/network/interfaces, append to that file
+
Assuming you have an "auto eth0" in /etc/network/interfaces, append to that file
 
  auto br0
 
  auto br0
 
  iface br0 inet dhcp
 
  iface br0 inet dhcp
Line 27: Line 19:
 
Instructions are currently written for an Ubuntu 10.04 Lucid host and guest.
 
Instructions are currently written for an Ubuntu 10.04 Lucid host and guest.
  
* Choose '''Applications &gt; System Tools &gt; Virtual Machine Manager'''.
+
* Choose '''Applications > System Tools > Virtual Machine Manager'''.
 
* In Virtual Machine Manager, right-click '''localhost''', and choose '''New'''.
 
* In Virtual Machine Manager, right-click '''localhost''', and choose '''New'''.
 
* In the '''Name''' box, type the name of the virtual machine ($MACHINE). Click '''Local install media''' and click '''Forward'''.
 
* In the '''Name''' box, type the name of the virtual machine ($MACHINE). Click '''Local install media''' and click '''Forward'''.
 
* Click '''Use ISO image''', '''Browse''', navigate to and click the downloaded ISO file and click '''Open'''. In '''OS Type''', choose '''Linux'''. In '''Version''', choose '''Ubuntu 10.04 (Lucid Lynx)''', and click '''Forward'''.
 
* Click '''Use ISO image''', '''Browse''', navigate to and click the downloaded ISO file and click '''Open'''. In '''OS Type''', choose '''Linux'''. In '''Version''', choose '''Ubuntu 10.04 (Lucid Lynx)''', and click '''Forward'''.
* In the '''Memory (RAM)''' box, enter &lt;code&gt;1024&lt;/code&gt;, and click '''Forward'''.
+
* In the '''Memory (RAM)''' box, enter <code>1024</code>, and click '''Forward'''.
 
* Click '''Select managed or other existing storage''', and click Browse. The '''Locate or create storage volume''' dialog appears.
 
* Click '''Select managed or other existing storage''', and click Browse. The '''Locate or create storage volume''' dialog appears.
* Click '''New Volume'''. In the '''Name''' box, delete the trailing &lt;code&gt;.img&lt;/code&gt;. In the '''Format''' box, choose '''qcow2'''. In the '''Max Capacity''' box, enter as much as you can (many gigabytes), and click '''Finish'''.
+
* Click '''New Volume'''. In the '''Name''' box, delete the trailing <code>.img</code>. In the '''Format''' box, choose '''qcow2'''. In the '''Max Capacity''' box, enter as much as you can (many gigabytes), and click '''Finish'''.
 
* In the '''Locate or create storage volume''' dialog, click the new image and click '''Choose Volume'''.
 
* In the '''Locate or create storage volume''' dialog, click the new image and click '''Choose Volume'''.
 
* In the '''New VM''' dialog, click '''Forward'''.
 
* In the '''New VM''' dialog, click '''Forward'''.
Line 41: Line 33:
 
* In the guest, on the '''Install''' dialog, choose a language and click '''Install Ubuntu 10.04 LTS'''. Choose time zone and keyboard layout.
 
* In the guest, on the '''Install''' dialog, choose a language and click '''Install Ubuntu 10.04 LTS'''. Choose time zone and keyboard layout.
 
* Click '''Specify partitions manually (advanced)''', '''Forward'''. Create one partition for slash (/), at maximal size. Don't make a swap partition. Click '''Forward'''.
 
* Click '''Specify partitions manually (advanced)''', '''Forward'''. Create one partition for slash (/), at maximal size. Don't make a swap partition. Click '''Forward'''.
* Specify name (such as &quot;boss&quot;), password, and hostname ($MACHINE). Optionally click '''Log in automatically'''. Click '''Forward'''.
+
* Specify name (such as "boss"), password, and hostname ($MACHINE). Optionally click '''Log in automatically'''. Click '''Forward'''.
* On the '''Ready to install''' screen, click '''Advanced''', enter your proxy in the form &lt;code&gt;proxy.example.com:port&lt;/code&gt;, click '''OK''', click '''Install'''.
+
* On the '''Ready to install''' screen, click '''Advanced''', enter your proxy in the form <code>proxy.example.com:port</code>, click '''OK''', click '''Install'''.
 
* Reboot the guest after installation and log in.
 
* Reboot the guest after installation and log in.
 
====Ubuntu 10.10 Maverick====
 
====Ubuntu 10.10 Maverick====
Line 49: Line 41:
 
* Create one partition for slash (/), at maximal size. Don't make a swap partition. Click '''Install Now'''.
 
* Create one partition for slash (/), at maximal size. Don't make a swap partition. Click '''Install Now'''.
 
* Choose time zone and keyboard layout.
 
* Choose time zone and keyboard layout.
* Specify name (such as &quot;boss&quot;), hostname ($MACHINE), and password. Optionally click '''Log in automatically'''. Click '''Forward'''.
+
* Specify name (such as "boss"), hostname ($MACHINE), and password. Optionally click '''Log in automatically'''. Click '''Forward'''.
  
 
==Configure guest==
 
==Configure guest==
* In an Ubuntu 10.10 Maverick guest, choose '''System &gt; Preferences &gt; Network Proxy'''. Click '''Manual proxy configuration'''. In the '''HTTP proxy''' and '''Port''' boxes, enter &lt;code&gt;proxy.example.com 4128&lt;/code&gt;. Click '''Apply System-Wide''' and click '''Close'''.
+
* In an Ubuntu 10.10 Maverick guest, choose '''System > Preferences > Network Proxy'''. Click '''Manual proxy configuration'''. In the '''HTTP proxy''' and '''Port''' boxes, enter <code>proxy.example.com 4128</code>. Click '''Apply System-Wide''' and click '''Close'''.
* Choose '''Applications &gt; Ubuntu Software Centre'''. Choose '''Edit &gt; Software Sources'''. In the '''Download from''' box, choose '''Other''', select a fast server (such as United States - mirror.its.uidaho.edu), and click '''Choose Server'''. On the '''Updates''' tab, click '''Install security updates without confirmation'''. Click '''Close'''. Wait for Ubuntu Software Centre to finish updating the cache, and choose '''File &gt; Close'''.
+
* Choose '''Applications > Ubuntu Software Centre'''. Choose '''Edit > Software Sources'''. In the '''Download from''' box, choose '''Other''', select a fast server (such as United States - mirror.its.uidaho.edu), and click '''Choose Server'''. On the '''Updates''' tab, click '''Install security updates without confirmation'''. Click '''Close'''. Wait for Ubuntu Software Centre to finish updating the cache, and choose '''File > Close'''.
 
* Apply all security and bug-fix updates to date, and install openssh-server:
 
* Apply all security and bug-fix updates to date, and install openssh-server:
 
  guest:$ sudo apt-get install aptitude
 
  guest:$ sudo apt-get install aptitude
 
  guest:$ sudo aptitude safe-upgrade
 
  guest:$ sudo aptitude safe-upgrade
 
  guest:$ sudo aptitude install vim openssh-server
 
  guest:$ sudo aptitude install vim openssh-server
* Choose '''System &gt; Preferences &gt; Screensaver'''. Clear '''Activate screensaver when computer is idle''' and '''Lock screen when screensaver is active'''. Click '''Power Management'''. In the '''Put display to sleep when inactive for''' box, choose '''Never''', and click '''Close'''. Click '''Close'''
+
* Choose '''System > Preferences > Screensaver'''. Clear '''Activate screensaver when computer is idle''' and '''Lock screen when screensaver is active'''. Click '''Power Management'''. In the '''Put display to sleep when inactive for''' box, choose '''Never''', and click '''Close'''. Click '''Close'''
  
* Optionally set guest to start at host boot: In the Virtual Machine window, choose '''View &gt; Details'''. Click '''Boot Options''', select '''Start virtual machine on host boot up''', and click '''Apply'''. Choose '''View &gt; Console'''.
+
* Optionally set guest to start at host boot: In the Virtual Machine window, choose '''View > Details'''. Click '''Boot Options''', select '''Start virtual machine on host boot up''', and click '''Apply'''. Choose '''View > Console'''.
  
 
* If your office supports this, configure dhclient to register itself by name with your dhcp server to enable looking up this guest's IP by name.
 
* If your office supports this, configure dhclient to register itself by name with your dhcp server to enable looking up this guest's IP by name.
Line 66: Line 58:
 
Determine MAC address using ifconfig (look for HWaddr).
 
Determine MAC address using ifconfig (look for HWaddr).
 
Edit /etc/dhcp3/dhclient.conf and put $MACHINE into the line:
 
Edit /etc/dhcp3/dhclient.conf and put $MACHINE into the line:
  send host-name &quot;''&lt;hostname&gt;''&quot;;
+
  send host-name "''<hostname>''";
 
Then insert 2 lines such as:
 
Then insert 2 lines such as:
  send dhcp-client-identifier ''&lt;GUEST MAC ADDR&gt;'';
+
  send dhcp-client-identifier ''<GUEST MAC ADDR>'';
  append domain-name &quot; cal.example.com example.com&quot;;
+
  append domain-name " cal.example.com example.com";
  
 
  guest:$ sudo invoke-rc.d networking restart
 
  guest:$ sudo invoke-rc.d networking restart
Line 99: Line 91:
 
When running an Ubuntu 10.04 Lucid or Debian 6.0 squeeze host and Ubuntu 10.04 Lucid or Ubuntu 10.10 Maverick guest, you can enable a higher resolution in the guest by doing the following:
 
When running an Ubuntu 10.04 Lucid or Debian 6.0 squeeze host and Ubuntu 10.04 Lucid or Ubuntu 10.10 Maverick guest, you can enable a higher resolution in the guest by doing the following:
 
# Shut down the guest.
 
# Shut down the guest.
# In the guest '''Virtual Machine''' window, choose '''View &gt; Details'''.
+
# In the guest '''Virtual Machine''' window, choose '''View > Details'''.
 
# Click '''Video'''. In the '''Model''' box, change '''cirrus''' to '''vmvga'''. Click '''Apply'''.
 
# Click '''Video'''. In the '''Model''' box, change '''cirrus''' to '''vmvga'''. Click '''Apply'''.
# Choose '''View &gt; Console''', '''Virtual Machine &gt; Run'''.
+
# Choose '''View > Console''', '''Virtual Machine > Run'''.
# Choose '''System &gt; Preferences &gt; Monitors''' to select a higher resolution.
+
# Choose '''System > Preferences > Monitors''' to select a higher resolution.
 
Windows XP guests seem to support higher resolution without needing to do this. The guest may say that it can't find a driver for your hardware, but then that doesn't seem to matter and you can pick a high resolution.
 
Windows XP guests seem to support higher resolution without needing to do this. The guest may say that it can't find a driver for your hardware, but then that doesn't seem to matter and you can pick a high resolution.
  
 
==Guest blocking host sound==
 
==Guest blocking host sound==
 
You can stop the guest from blocking your host sound output by doing this:
 
You can stop the guest from blocking your host sound output by doing this:
# In the guest's Virtual Machine window, choose View &gt; Details.
+
# In the guest's Virtual Machine window, choose View > Details.
 
# Click Sound: es1370.
 
# Click Sound: es1370.
 
# Click Remove.
 
# Click Remove.
Line 129: Line 121:
 
  # Show down virtual guest first
 
  # Show down virtual guest first
 
  host:$ sudo qemu-img convert -O qcow2 /var/lib/libvirt/images/$MACHINE.img \
 
  host:$ sudo qemu-img convert -O qcow2 /var/lib/libvirt/images/$MACHINE.img \
         /var/lib/libvirt/images/$MACHINE.img.qcow2 &amp;&amp; \
+
         /var/lib/libvirt/images/$MACHINE.img.qcow2 && \
 
         sudo mv /var/lib/libvirt/images/$MACHINE.img.qcow2 /var/lib/libvirt/images/$MACHINE.img
 
         sudo mv /var/lib/libvirt/images/$MACHINE.img.qcow2 /var/lib/libvirt/images/$MACHINE.img
 
  host:$ sudo chmod 600 /var/lib/libvirt/images/$MACHINE.img
 
  host:$ sudo chmod 600 /var/lib/libvirt/images/$MACHINE.img
  
 
[[Category:Linux tools]]
 
[[Category:Linux tools]]

Revision as of 10:36, 24 November 2010

These steps will create a KVM virtual guest machine for Ubuntu Server JeOS 9.10 Karmic or Ubuntu Desktop 9.10.

"host" is the machine hosting the guest. MACHINE is what you want the hostname of the guest to be.

Prepare host

  • Install packages:
host:$ sudo aptitude install kvm virt-manager
  • Download the Ubuntu Server 9.10 ISO image from ubuntu.com.
  • Set up bridging on your workstation:

Assuming you have an "auto eth0" in /etc/network/interfaces, append to that file

auto br0
iface br0 inet dhcp
  bridge_ports eth0

This creates a bridge that your guests can join to access the external network through eth0. (I assume this is what is happening.)

host:$ sudo /etc/init.d/networking restart

Create guest

Instructions are currently written for an Ubuntu 10.04 Lucid host and guest.

  • Choose Applications > System Tools > Virtual Machine Manager.
  • In Virtual Machine Manager, right-click localhost, and choose New.
  • In the Name box, type the name of the virtual machine ($MACHINE). Click Local install media and click Forward.
  • Click Use ISO image, Browse, navigate to and click the downloaded ISO file and click Open. In OS Type, choose Linux. In Version, choose Ubuntu 10.04 (Lucid Lynx), and click Forward.
  • In the Memory (RAM) box, enter 1024, and click Forward.
  • Click Select managed or other existing storage, and click Browse. The Locate or create storage volume dialog appears.
  • Click New Volume. In the Name box, delete the trailing .img. In the Format box, choose qcow2. In the Max Capacity box, enter as much as you can (many gigabytes), and click Finish.
  • In the Locate or create storage volume dialog, click the new image and click Choose Volume.
  • In the New VM dialog, click Forward.
  • Click to expand Advanced options. In the drop-down box, choose Host device eth0 (Bridge br0). Verify that the Architecture box matches the architecture used by the ISO you are installing from, and click Finish. The ISO will be booted from and display in a window.

Ubuntu Desktop

Ubuntu 10.04 Lucid

  • In the guest, on the Install dialog, choose a language and click Install Ubuntu 10.04 LTS. Choose time zone and keyboard layout.
  • Click Specify partitions manually (advanced), Forward. Create one partition for slash (/), at maximal size. Don't make a swap partition. Click Forward.
  • Specify name (such as "boss"), password, and hostname ($MACHINE). Optionally click Log in automatically. Click Forward.
  • On the Ready to install screen, click Advanced, enter your proxy in the form proxy.example.com:port, click OK, click Install.
  • Reboot the guest after installation and log in.

Ubuntu 10.10 Maverick

  • In the guest, on the Install dialog, choose a language and click Install Ubuntu. Click Forward.
  • Click Specify partitions manually (advanced) and click Forward.
  • Create one partition for slash (/), at maximal size. Don't make a swap partition. Click Install Now.
  • Choose time zone and keyboard layout.
  • Specify name (such as "boss"), hostname ($MACHINE), and password. Optionally click Log in automatically. Click Forward.

Configure guest

  • In an Ubuntu 10.10 Maverick guest, choose System > Preferences > Network Proxy. Click Manual proxy configuration. In the HTTP proxy and Port boxes, enter proxy.example.com 4128. Click Apply System-Wide and click Close.
  • Choose Applications > Ubuntu Software Centre. Choose Edit > Software Sources. In the Download from box, choose Other, select a fast server (such as United States - mirror.its.uidaho.edu), and click Choose Server. On the Updates tab, click Install security updates without confirmation. Click Close. Wait for Ubuntu Software Centre to finish updating the cache, and choose File > Close.
  • Apply all security and bug-fix updates to date, and install openssh-server:
guest:$ sudo apt-get install aptitude
guest:$ sudo aptitude safe-upgrade
guest:$ sudo aptitude install vim openssh-server
  • Choose System > Preferences > Screensaver. Clear Activate screensaver when computer is idle and Lock screen when screensaver is active. Click Power Management. In the Put display to sleep when inactive for box, choose Never, and click Close. Click Close
  • Optionally set guest to start at host boot: In the Virtual Machine window, choose View > Details. Click Boot Options, select Start virtual machine on host boot up, and click Apply. Choose View > Console.
  • If your office supports this, configure dhclient to register itself by name with your dhcp server to enable looking up this guest's IP by name.

Determine MAC address using ifconfig (look for HWaddr). Edit /etc/dhcp3/dhclient.conf and put $MACHINE into the line:

send host-name "<hostname>";

Then insert 2 lines such as:

send dhcp-client-identifier <GUEST MAC ADDR>;
append domain-name " cal.example.com example.com";
guest:$ sudo invoke-rc.d networking restart
  • Enable authentication from the host's user, and start manipulating the system from ssh:
host:$ ssh-copy-id boss@$MACHINE   # or boss@$MACHINE.local
host:$ ssh boss@$MACHINE   # or boss@$MACHINE.local
  • Optionally set up swap:
guest:$ sudo dd if=/dev/zero of=/swapfile bs=1M count=1024 # 1GiB
guest:$ sudo chmod 600 /swapfile # Protect memory from being read
guest:$ sudo mkswap /swapfile
guest:$ sudo swapon /swapfile

Append to /etc/fstab :

/swapfile none swap sw 0 0
  • Optionally enable passwordless sudo:
guest:$ sudo visudo

Append the 2 lines:

# Enable passwordless sudo for all admins
%admin ALL=NOPASSWD: ALL
  • Set up others to be able to authenticate:
theiruser@their-workstation:$ ssh-copy-id boss@$MACHINE
  • Reboot guest to use new kernel and verify system returns to a good state after rebooting.

Use higher display resolution in guest

When running an Ubuntu 10.04 Lucid or Debian 6.0 squeeze host and Ubuntu 10.04 Lucid or Ubuntu 10.10 Maverick guest, you can enable a higher resolution in the guest by doing the following:

  1. Shut down the guest.
  2. In the guest Virtual Machine window, choose View > Details.
  3. Click Video. In the Model box, change cirrus to vmvga. Click Apply.
  4. Choose View > Console, Virtual Machine > Run.
  5. Choose System > Preferences > Monitors to select a higher resolution.

Windows XP guests seem to support higher resolution without needing to do this. The guest may say that it can't find a driver for your hardware, but then that doesn't seem to matter and you can pick a high resolution.

Guest blocking host sound

You can stop the guest from blocking your host sound output by doing this:

  1. In the guest's Virtual Machine window, choose View > Details.
  2. Click Sound: es1370.
  3. Click Remove.

To restore it:

  1. Click Add Hardware.
  2. In the Hardware type box, select Sound and click Forward.
  3. In the Model box, select es1370 and click Forward. Click Finish.

Snapshots

To take a snapshot of a guest image:

# Shut down virtual machine first.
host:$ cd /var/lib/libvirt/images
host:$ sudo qemu-img snapshot -l machine.img # list snapshots in an image
host:$ sudo qemu-img snapshot -c snapshotName machine.img # create a new snapshot for a machine
# Start virtual machine. Modify data. Break something. Shut down virtual machine.
host:$ sudo qemu-img snapshot -a snapshotName machine.img # apply a snapshot

To do this, the guest image needs to be qcow2, not raw. To check what type of image it is, run:

host:$ sudo file /var/lib/libvirt/images/$MACHINE.img

It should say:

MACHINE.img:  Qemu Image, Format: Qcow , Version: 2

If your guest image is raw, you can convert it to qcow2 by doing (and being careful with an image that contains important data or configuration):

# Show down virtual guest first
host:$ sudo qemu-img convert -O qcow2 /var/lib/libvirt/images/$MACHINE.img \
       /var/lib/libvirt/images/$MACHINE.img.qcow2 && \
       sudo mv /var/lib/libvirt/images/$MACHINE.img.qcow2 /var/lib/libvirt/images/$MACHINE.img
host:$ sudo chmod 600 /var/lib/libvirt/images/$MACHINE.img