Using QEMU to Build and Deploy Virtual Machines (Vms) from Scratch on Ubuntu 10.04 LTS
Total Page:16
File Type:pdf, Size:1020Kb
GOV Cloud Comp Labs Using QEMU to Build a Virtual Machine from Scratch on Ubuntu 10.04 LTS v1.1 Global Open Versity Cloud Computing Hands-on Labs Training Manual Using QEMU to Build and Deploy Virtual Machines (VMs) from Scratch on Ubuntu 10.04 LTS Kefa Rabah Global Open Versity, Vancouver Canada [email protected] www.globalopenversity.org Table of Contents Page No. USING QEMU TO BUILD AND DEPLOY VIRTUAL MACHINES (VMS) FROM SCRATCH ON UBUNTU 10.04 LTS 2 1.0 Introduction 2 Hands-On Labs Session 3 Part 1: Using QEMU to create VM locally on UI: 3 Step 1: Install Pre-requisite Packages 3 Step 2: Preparation of the QEMU Virtual Environment 4 Step 3: VM Contextualization 4 Step 4: Run & Install your Distro of an Operating Systems from ISO to the QEMU Environment 5 Step 5: Shutdown the your DSL Virtual Machine 10 Part 2: Optional - System with HVM Capability 11 Part 3: Troubleshooting VM Installation “pxe-rtl8139.bin” Error 12 Part 4: Need More Training on Linux: 12 Ubuntu Server Administration Training 12 Cloud Computing Training 13 Part 5: Hands-on Labs Assignments 13 Other Related Articles & Hands-on Lab Manuals References: 13 http://creativecommons.org/licenses/by-nc-sa/3.0/ A GOV Open Access Technical Academic Publications Enhancing education & empowering people worldwide through eLearning in the 21st Century 1 April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada www.globalopenversity.org GOV - High Performance Computing Labs GOV Cloud Comp Labs Using QEMU to Build a Virtual Machine from Scratch on Ubuntu 10.04 LTS v1.1 Global Open Versity Cloud Computing Hands-on Labs Training Manual Using QEMU to Build and Deploy Virtual Machines (VMs) from Scratch on Ubuntu 10.04 LTS By Kefa Rabah, [email protected] Aug 15, 2010 GTS Institute 1.0 Introduction QEMU is a fast processor emulator. The package currently supports arm, powerpc, sparc and x86 emulation. By using dynamic translation it achieves reasonable speed, while being easy to port to new host CPUs. QEMU has two operating modes: 1. User mode emulation: QEMU can launch individual Linux processes compiled for one CPU on another CPU. 2. Full system emulation: QEMU can emulate a full system, including the processor and peripherals. This enables testing and debugging of system code in a contained (and quarantined) virtual system. It can even be used to host several virtual machines simultaneously on a single server (given enough host processor power and RAM). As QEMU requires no host kernel patches to run, it is safe and easy to use. It creates a virtual machine, similar to VMWare, Virtualbox, KVM, and Xen. It allows you to run one operating system from within another operating system. The operating systems can be the same ones, or different. Your memory resources will be divided between your native (host) OS and your virtual machine (guest) OS. You will, therefore, notice a decrease in performance of activities in both the host OS and the guest OS. Hence, if you plan to use QEMU only to create a Windows virtual environment in order to run Windows programs, consider using one of several free Linux SoftwareEquivalents instead. If you need to run only a single Windows program, also consider using Wine instead of QEMU. Running a virtual machine environment such as QEMU will slow down your computer noticeably. In this Hands-on Labs session, we’re going to lean how to install & configure virtual machines on the Linux Ubuntu 10.04 LTS (Lucid Lynx) server option. Canonical has high hopes that Ubuntu 10.04 LTS (Long Term Support) will easily become the platform of choice for anybody who intends to build and deploy large-scale enterprise infrastructure deployment, whether you're trying to build the next Facebook, or the next Google, or the next eBay. If you want to start on [Amazon's cloud-platform] EC2 and migrate to your own managed private cloud, Ubuntu 10.04 is going to be the platform for you. Lucid Lynx will be the third LTS release by Ubuntu. It’s based on open source Debian GNU/Linux. LTS releases arrive bi-annually and are supported for three years on desktops and five years for servers of free security and maintenance updates. 2 April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada www.globalopenversity.org GOV - High Performance Computing Labs GOV Cloud Comp Labs Using QEMU to Build a Virtual Machine from Scratch on Ubuntu 10.04 LTS v1.1 Assumptions: 1. It’s assumed that you have a good understanding of Linux operating system and its working environment. It’s also assumed that you know how to install and configure Ubuntu Linux server, if not go ahead and pop over to scribd.com and check out a good hands-on manual entitled “Step-By-Step Install Guide Ubuntu 10.04 LTS (Lucid Lynx) Server” to get you started. Hands-On Labs Session In this Hands-on manual, you will learn build from scratch a virtual machine and how to setup and install it on Ubuntu 10.04 LTS (Lucid Lynx). Upon completion of this hands-on lab session you should have gained expertise and skills to plan design implement and deploy your own virtual machines on Linux Ubuntu 10.04 LTS server. You could put your virtual machine for all kind of uses: Data storage & backup, web server, database server etc. You can use this knowledge to build VM for cloud computing e.g., when building your own cloud using OpenNebula cloud computing. Part 1: Using QEMU to create VM locally on UI: Why use an emulator? - QEMU emulates everything, including the CPU, so it is slower than the host system. Hardware acceleration will not be as effective for a software OS emulator. Nevertheless, it is a pretty good way of testing a distribution, without having to repartition your drive or set up new hardware Also consider trying a QEMU interface, such as Qemulator, or the package qemu-launcher. Another QEMU GUI is virt-manager. It manages virtual machines not only for QEMU, but also for KVM and Xen, in a consistent fashion (through libvirt). Step 1: Install Pre-requisite Packages QEMU is available as a standard package in the Universe repository. (There are on how to install packages elsewhere in this guide. Unlike some other virtualization systems (like VMWare), separate kernel modules are not needed. Recent QEMU versions support networking out of the box. There is a "linux-test" add-on at QEMU's site, a one-line script. 1. Download and install "qemu-kvm " Alternatively you an use "apt-get install" command: sudo apt-get install qemu-kvm –y sudo apt-get install aptitude kvm-pxe –y Note: You’ll need to run the second command to avoid getting the error: "pci_add_option_rom: failed to find romfile "pxe-rtl8139.bin" 3 April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada www.globalopenversity.org GOV - High Performance Computing Labs GOV Cloud Comp Labs Using QEMU to Build a Virtual Machine from Scratch on Ubuntu 10.04 LTS v1.1 Step 2: Preparation of the QEMU Virtual Environment 1. A virtual disk is needed for the virtual machine. A virtual disk is made by creating a file of a size appropriately large to contain the full guest OS. 2. Let’s create a clean "Hard disk" as follows: qemu-img create mydistro.img 3G where configuration file is lactated at: "/etc/libvirt/qemu.conf" file Note 1: If your machine has CPU with KVM capability, then you can also create your image container as follows: sudo qemu-img create -f qcow2 mydistro.img 10G Note 2: You may need to change ownership of your image file to root user and make it writable, as follows: sudo chown root:root mydisk.img sudo chmod 755 mydisk.img 3. Now download your favorite distro, this could also be Windows OS: wget http://mydistro.iso 4. In this lab session, we’re going to use Damnsmall Linux distro: wget ftp://ibiblio.org/pub/Linux/distributions/damnsmall/current/dsl-4.4.10.iso or you can hope over and manually download Damnsmall Linux distro from here at their main site. Note: Download the Ubuntu ISO file if you wish to install one into a virtual QEMU environment from here: the latest development version of Ubuntu. 5. Let’s create a clean "Hard disk" as follows: qemu-img create dsl-image.img 3G 6. You’re done with this section. Step 3: VM Contextualization 1. The ISO image has the contextualization for that VM as indicated in Fig. 1. 4 April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada www.globalopenversity.org GOV - High Performance Computing Labs GOV Cloud Comp Labs Using QEMU to Build a Virtual Machine from Scratch on Ubuntu 10.04 LTS v1.1 Fig. 1 Here: • context.sh: contains configuration variables • init.sh: script called by VM at start to configure specific services • certificates: directory that contains certificates for some service • service.conf: service configuration 2. You’re done with this section. Step 4: Run & Install your Distro of an Operating Systems from ISO to the QEMU Environment We are now ready to install the guest OS. Assuming, for example, your ISO image is named "mydistro.iso". 1. Then you can boot it with a virtual cdrom attached as follows: qemu –hda mydistro-image –cdrom mydistro.iso –m 192 –boot d that is: qemu –hda dsl-image –cdrom dsl-4.4.10.iso –m 192 –boot d Note 1: Alternatively, run this command before starting the emulator: sudo /sbin/ifconfig eth0 172.20.0.1 Note 2: If your machine has CPU with KVM capability, then you can also boot your image as follows: sudo kvm -hda dsl-image -cdrom dsl-4.4.10.iso -m 1024 -boot d 2.