Introduction

Virtualization packages are means for users to run various operating systems without "bare-metal" hardware - basically, you can run more than one operating system on a single computer without dual-booting or similar approaches. Virtualization software emulates a real machine and "fools" the guest operating system into thinking it's running on a real computer. Besides the more obvious advantages, virtual machines help create a greener and easier to administer computing environment. Looking at the trends in the IT industry, virtualization has seen quite a boom in the last few years, because it fits the concepts of utility computing and/or software as a service. Virtualization can be useful to you if you are an enterprise architect, developer, a home user or basically everything in between. We will begin with a short introduction about virtualization in general, then we will specifically treat VirtualBox and KVM as they seem to be most popular open source full virtualization solutions. You are expected to know your way around Linux systems, how to install a Linux distribution and how to install software on it, although we will show you how to install the two aforementioned virtualization packages on some of the popular Linux distributions.

There are two types of virtualization : one that can run the guest system as-is (as in, unmodified) and another that request a modified kernel on the guest's side in order to run. The first category is named full virtualization, because it emulates a complete hardware environment, the second is named paravirtualization , because it doesn't emulate hardware and hence needs special modifications at guest level, a good example of this type of virtualization being Xen. These are part of a bigger category named hardware virtualization, but there are also other (software, network or storage, amongst others) virtualization types, which we will not detail here. The two pieces of software we will talk about fit into the full virtualization category. Other popular hardware virtualization technologies include QEMU, Bochs, VMware, Parallels, HyperV or OpenVZ.

When is virtualization useful?

Linux distributions

The Linux world is full of interesting and tempting offers. There are over 600 (!) Linux distributions to choose from, which makes it hard for a person that only has one computer to try them all, or just a few even. LiveCDs aren't always helpful, so one may need to install in order to get the gist of it. Every Linux distribution release brings new and exciting features, and you may feel the thrill and the impulse to install and test it. Enter virtualization. You download the ISO, install the distro in a virtual environment and you're good to go, all in a short time. You don't like it, you delete it. Especially when you're kinda new to the Linux world and you might be confused by the big number of available distributions, this might just be what you need. Also, if you're a developer and need to run the development branch of your distro (think Fedora Rawhide or Debian Sid) but that is too unstable for everyday use, install in a VM and start developing.

Other operating systems

This extends to other operating systems you might need : maybe you have a propgram that runs only on Windows and you don't wanna install Windows just for that one program. Maybe you want to learn Solaris but lack the hardware. Provided you have the appropriate computer configuration that supports virtualization, now you can do it.

What you will need

Modern processors have special CPU instructions for hardware emulation. You can live without, but you really don't want to, since the host operating system will have to emulate the lacking virtualization instruction and this will slow down your guest(s) significantly. We presume your host OS has Linux installed and your CPU has the necessary virtualization capabilities. The most simple way to check if your CPU has what it takes, do

 $ egrep ‘(vmx|svm)’ /proc/cpuinfo 

and if that returns either vmx (Intel CPUs) or svm (AMD CPUs), you're good to go. But that of course isn't the only request on the hardware side. Check the web page of the system you want to install as guest to check if you meet its' hardware requirements. We recommend at least 20GB free in your home directory and a minimum of 2GB of memory on the host, so you can allocate a mean amount of 768MB to the guest for optimal performance. Of course, should you want to run multiple virtual machines (maybe in parallel), those requirements grow considerably.

KVM or VirtualBox?

First of all, why would we offer you two virtualization packages? Why not one for all your needs? Well, we believe in the "right tool for the job" concept. KVM offers some features that VirtualBox does not and the other way around. There is no such thing in the IT world as a universal tool, so it's important to use something that fits your needs. The basic idea is : if you want to install a binary Linux distribution as a guest, use KVM. It's faster and its' drivers are included in the official kernel tree. If your guest involves lots of compiling and needs some more advanced features, and/or isn't a Linux system, better go with VirtualBox.

The technical reasons are quite simple : KVM is better integrated with Linux, it's smaller and faster, and while you can use it with other guests besides Linux, we found the experience to be quite troublesome : BSDs tend to have slow I/O and Solaris (OpenIndiana, to be exact) tends to panic immediately after booting the installation ISO. Since we use CURRENT versions of BSD (and compile/update the system from source often) and also need Solaris, we found VirtualBox to be a better option. Another plus for Oracle VirtualBox is the fact that it supports suspend, that is you can save the machine state on the host's hard disk and close VirtualBox and when (re)starting, the system will pick up from where it left. That is why we referred to source compilation : if you have a noisy machine you don't wanna leave on overnight but your Gentoo virtual machine just compiles a new gcc version, suspend the machine state, shut down the host and continue tomorrow.

What you will learn

We will show you how to install KVM and VirtualBox and how to install and configure a Linux guest on a Linux host. Examples with other Unices are very similar, so we see no need to repeat ourselves.

Installation

KVM

Although KVM advertises Solaris, BSD, ReactOS, Windows and others as supported guests, our experiences were less than fruitful. This isn't a criticism, since we did not, in all honesty, sit down and examine the issue too much. But this is not out of laziness : after talking with other people on the 'Net, we found that we are not the only ones with issues regarding Unix(-like) guests besides Linux, so we just went with VirtualBox for those. As always, your mileage may vary : we too would want to use KVM exclusively because it's more "free", but because of the aforementioned problems, which of course might just be something specific to our setup, we had to use VirtualBox. At the moment, KVM is developed by Red Hat and is easily installable on most Linux distributions. As we did before, we will outline only the installation procedures pertaining to major Linux distributions.

Fedora

Since Red Hat, the sponsor of Fedora, is now developing KVM, Fedora offers a plethora of tools for virtualization. The official documentation, although it's for Fedora 13, is applicable to later versions. You can just install KVM with

 # yum install kvm 

to go the command-line way, or you can install some graphical tools to help you manage your virtual installations :

 # yum install virt-manager libvirt libvirt-python python-virtinst 

You will not need to execute further commands since the installation process on Fedora will mark the kvm module for autoloading. If you don't want to reboot, use modprobe to load the module in-place.

Debian

Debian's wiki comes to the rescue yet again, and if one follows the instructions, one will have KVM installed and ready to go in no time. It's all about

 # apt-get install qemu-kvm libvirt-bin 

to install, setup and have the kvm-(amd|intel) kernel module loaded at boot.

Slackware

Slackbuild for KVM which you can use according to this guide. If you have a modified kernel or just want to make sure your kernel has KVM enabled, type

 $ cat /boot/config |grep -i kvm 

and also check /etc/rc.d/rc.modules to see if the kvm module is set to be loaded at boot.

Arch

The wiki Arch Linux is a good guide for everything KVM-related. Since Arch, like Slackware, is a DYI distribution, you might need to take a few extra steps to start using KVM. The installation is as simple as

 # pacman -S qemu-kvm 

The same steps are to be taken here as on a Slackware machine : add your user, check that your CPU supports virtualization and that KVM is enabled in your kernel.

VirtualBox

Fedora

The VirtualBox site offers a repo file to be added in /etc/yum.repos.d/ and then perform a

 # yum update

to let yum know about your new repo and index it. Then perform a

 # yum install VirtualBox-4.0 dkms gcc
 # /etc/init.d/vboxdrv setup 
 # usermod -G vboxusers -a username 

and you should be set.

Debian

We don't want to take sides here, but it looks like Debian's documentation is better and more thorough. To install, just type

 # apt-get install linux-headers-$version virtualbox-ose 

which will install all necessary packages, compile the kernel module for you and set it to load at startup.

Slackware

SlackBuilds.org has a VirtualBox (the Open Source edition, which is the only one we will talk about here) entry. For a HOWTO on using slackbuilds, go here. Additional info can be found on linuxquestions.org, info which you might find useful especially if you are on a Slackware 13.37 64-bit machine. Remember to read the README of the slackbuild and it should be ok.

Arch

Arch's documentation is helpful and complete, on par with Debian's, so you should have no issues finding the info you need. All you need to do installation-wise is

 # pacman -S virtualbox qt 

and you're set. You will need Qt for the GUI, if you need just CLI, don't install it.The rest of the configuration steps are resemblant to Fedora's so use the documentation to be able to get started.

Usage

KVM

As you might have noticed, we're against copying blindly from a manual page and trying to substitute said manual. We will outline general and usual options and command-line flags (yes, we recommend the usage of CLI when working with KVM and GUI when working with VirtualBox), but you reading the manual page is essential, especially when dealing with a piece of somewhat complex software like this.

Storage

We recommend you create a separate directory where you will store the virtual disk images and another separate directory that will hold the ISO files used for installation. In the end, only you know best how to organize your files, but this setup, we think, will make your life easier. For the sake of example, let' s say we want to install Fedora. We noticed when using KVM a somewhat smaller bandwidth than that available from our ISP, a problem that VirtualBox doesn't seem to have. So, we install from DVD :

 $ cd ~ && mkdir iso && cd iso/ 
 $ wget -c ftp://ftp.heanet.ie/mirrors/fedora/linux/releases/15/Fedora/\
x86_64/iso/Fedora-15-x86_64-DVD.iso

Of course, if you prefer curl, kget or other download manager, use it. The same applies to the mirror : use one close to you for faster downloading. Now to set up our virtual disk(s) environment :

 $ cd ~ && mkdir kvmhdd && cd kvmhdd 
 $ kvm-img create fedora15.img 15G 

Before going further we recommend you run kvm-img with no arguments to see its main options and disk formats. What the second line above does : it creates a virtual disk file (img format) named fedora15 and having 15 gigabytes in size.

Installation

Now we're ready to start the installation of Fedora 15 on our newly created disk :

 $ kvm -m 768 -boot d -cdrom ~/iso/Fedora-15-x86_64-DVD.iso -hda fedora15.img & 

What we just did : -m represents the size in megabytes of allocated memory, -boot tells kvm the primary boot device (think Windows drive letters), -cdrom is obvious, -hda is the first hard disk (you can use more than one disk, if you have the space, with -hdb being the second disk, and so on), and we used the ampersand at the end of the command line to regain control of the terminal. Ctrl+Alt will give/take control to/from the virtual machine in terms of mouse capture.

Using the virtual machine

After you install Fedora, in order to boot the newly installed system, change '-boot d' to '-boot c' and eliminate the '-cdrom ...' part if you don't need it, or use the host's CD-ROM drive with -cdrom /dev/sr0, for example :

 $ kvm -m 768 -boot c -hda fedora15.img & 

Suggestion: create a file in the kvmhdd (or the name you chose for the work directory) named fedora15.sh that will contain the above line, make it executable and, when you need it, just run it :

 $ cd ~/kvmhdd && echo "kvm -m 768 -boot c -hda fedora15.img &" > fedora15.sh && \
chmod +x fedora15.sh && ./fedora15.sh

That's about it. Should you need more options, refer to the kvm manual page as it's well written and will help you for certain.

VirtualBox

Creating a virtual machine

VirtualBox's GUI takes the wizard approach in order to help you create a new virtual machine and we see the interface as quite a smart piece of software. Press Ctrl + N to create a new VM, then enter the name you want to give it (use something suggestive, like "Fedora15x86_64". Based on such naming, VirtualBox will automatically determine what kind of system you want to set up and adjust itself automatically.

Next, choose the amount of memory you want Fedora to have, and VirtualBox tries to suggest a value depending on the OS and architecture. We recommend you don't go much lower, as your VM might freeze because of out-of-memory problems (by the way, Anaconda will refuse to start the installation in graphical mode with less than 768 MB). Then create the hard disk and enter its size (the recommendation related to suggestions applies here too), allocating it dynamically (not a big problem if you don't, just that we found this method to be a little faster in terms of I/O) and you're set. In the main VirtualBox window you will see your new virtual machine listed and to the right, its' settings. Change them as you see fit, and be careful to boot from DVD. Also, if you have multiple cores and want to use them, the System section is the place to go to.

Running a virtual machine

After installation, halt the VM and change the boot order so you can boot from the hard disk, then start by right-clicking on the entry on the left and, of course, "Start". If everything's alright, you will now boot Fedora 15 in a VirtualBox environment. We said earlier that the guest OS on KVM and VBOX doesn't need alterations. While we were right, the guest experience can be improved in VirtualBox with things like full screen view or shared folders by installing the VirtualBox guest additions. This is basically a kernel module and some Xorg drivers for the guest, which you can install on your new Fedora by following the following steps :

 # yum update kernel && yum install kernel-devel kernel-headers dkms gcc gcc-c++ 

Reboot the VM after installing, then go to the Devices menu, select "Install Guest Additions", which will mount the existing Guest Additions ISO image on the guest (on /media), and, as root, just do

 # cd /media/VBOXADD$version && sh ./VBoxLinuxAdditions.run 

Afterwards, restart again and you will have advanced features of VirtualBox at your disposal.

Conclusion

When it comes to choosing virtualization solutions, as it is with editors, desktop environments or even operating systems, everyone has a personal opinion based on experience, reading and what their friends use. This is our experience, and we invite you to experiment and tweak until you find the best path to follow. There are, of course, other virtualization software packages but the limited space wouldn't let us write about all of them. These are the most appropriate solutions for a home user (Open Source, that is), but that does not mean they aren't used at enterprise-level too. We just hope this will help you get to get started.

Virtualization solutions on Linux systems - KVM and VirtualBox的更多相关文章

  1. VMWare、KVM、Virtualbox克隆或复制Linux虚拟机后eth0找不到的解决方案

    快速处理办法: cat /etc/sysconfig/network-scripts/ifcfg-eth0 sed -i '/UUID/d' /etc/sysconfig/network-script ...

  2. Linux 桌面玩家指南:07. Linux 中的 Qemu、KVM、VirtualBox、Xen 虚拟机体验

    特别说明:要在我的随笔后写评论的小伙伴们请注意了,我的博客开启了 MathJax 数学公式支持,MathJax 使用$标记数学公式的开始和结束.如果某条评论中出现了两个$,MathJax 会将两个$之 ...

  3. Virtio: An I/O virtualization framework for Linux

    The Linux kernel supports a variety of virtualization schemes, and that's likely to grow as virtuali ...

  4. Xen、KVM和VirtualBox比拼

    vbox 与 kvm 的区别: vbox 是由 qemu 改写而成,包含大量 qemu 代码.可以使用于 不支持 虚拟化的cpu.值得说的一点:vbox 在图形方面比较好,能进行2D 3D加速.cpu ...

  5. 【转】How to Start Intel Hardware-assisted Virtualization (hypervisor) on Linux to Speed-up Intel Android x86 Emulator

    [转]How to Start Intel Hardware-assisted Virtualization (hypervisor) on Linux to Speed-up Intel Andro ...

  6. Linux中KVM虚拟机是什么

    概念: Kernel-based Virtual Machine的简称,是一个开源的系统虚拟化模块,自Linux 2.6.20之后集成在Linux的各个主要发行版本中.它使用Linux自身的调度器进行 ...

  7. 在 Linux 的 KVM虚拟机 上安装 Mac OS 系统的研究总结

    在 Linux 的 KVM虚拟机 上安装 Mac OS 系统的研究总结 一.资料来源:    网上一共找到两个方法,一个是视频上的教程,一个是网页资料. 二.视频资料方法内容:1.install qe ...

  8. Kali linux 2016无法打开virtualbox问题解决

    Kali Linux在安装完virtualbox后,打开虚拟机会出现:kernel driver not installed (rc=1908)错误提示,根据提示,大概可以看出是由于缺少内核模块引起的 ...

  9. Linux中KVM桥接的配置

    Linux中KVM桥接的配置 1. 原理 1.1 说明 在安装一个拥有虚拟化功能的Linux操作系统(此处以CentOS为例),一般我们有两种方法: .在光盘安装的时候安装好虚拟化包或者PXE服务器上 ...

随机推荐

  1. iOS中如何根据UIView获取所在的UIViewController

    原理 Responder Chain 事件的响应者链 大概的传递规则就是从视图顶层的UIView向下到UIViewController再到RootViewController再到Window最后到Ap ...

  2. 「个人训练」Can you solve this equation?(HDU-2199)

    题意与分析 纯粹水题.本来想做下放松心情的,结果还是被坑了qaq 重点就是在浮点误差.比较左右的下次就直接上1e-10,别看着题目说1e-4然后给个-5,结果暴wa.气傻了..... 代码 #incl ...

  3. CSS实现自适应下保持宽高比

    在项目中,我们可能经常使得自己设计的网页能自适应.特别是网站中的图片,经常要求在网页放大(或缩小)时,宽高同时放大(或缩小),而且不变形(即保持正常的长宽比).为了不变形,常用的方法就是设置width ...

  4. 07-Mysql数据库----数据类型

    介绍 存储引擎决定了表的类型,而表内存放的数据也要有不同的类型,每种数据类型都有自己的宽度,但宽度是可选的 详细参考链接:http://www.runoob.com/mysql/mysql-data- ...

  5. spring+apache dbcp +oracle 连接池配置以及优化

    特此记录 <!-- 数据源配置, 使用应用中的DBCP数据库连接池 --> <bean id="dataSource" class="org.apach ...

  6. c free 使用MSDN library定制

    为了不使用vc6但是还要使用visual assist的各种自动功能,决定使用c free ,但是怎么调用微软的MSDN library呢,我目前使用的版本是MSDN 1.5精简版bing自动翻译的. ...

  7. 文本向量化及词袋模型 - NLP学习(3-1)

    分词(Tokenization) - NLP学习(1) N-grams模型.停顿词(stopwords)和标准化处理 - NLP学习(2)   之前我们都了解了如何对文本进行处理:(1)如用NLTK文 ...

  8. 机器学习 (三) 逻辑回归 Logistic Regression

    文章内容均来自斯坦福大学的Andrew Ng教授讲解的Machine Learning课程,本文是针对该课程的个人学习笔记,如有疏漏,请以原课程所讲述内容为准.感谢博主Rachel Zhang 的个人 ...

  9. Python不同进制之间的转换

    不同的进制 二进制    0b101 以数字0和字母b打头的表示二进制数 如果出现大于等于2的数 会抛出SyntaxError异常 八进制    0711 以数字0打头的数字表示八进制数 如果出现大于 ...

  10. Internet History,Technology and Security

    Internet History,Technology and Security(简单记录) First Week High Stakes Research in Computing,and Comm ...