Virtualization

21
Master on Free Software Virtualization Alberto Garcia Gonzalez <[email protected]>

Transcript of Virtualization

Master on Free Software

Virtualization

Alberto Garcia Gonzalez<[email protected]>

Master on Free Software

Virtual machinesand types of virtualization

Master on Free Software

Virtual machine

● Computer implemented on software that runs programs like a real one.

● Two kinds of virtual machines:● The ones that implement a whole system.● The ones that run a single process.

Master on Free Software

Process virtual machines

● Platform-independent environment for applications.

● High level abstraction.● Examples: Java, .NET, Flash, ...

Master on Free Software

System virtual machines

● Implement a complete hardware platform.● Designed to run a full operating system (called “guest OS”).

● Difficult to implement efficiently in some architectures.

● Multiple uses:● Security (isolation).● Resource sharing.● Testing, debugging.

● Examples: VmWare, VirtualBox, QEMU, ...

Master on Free Software

Emulation

● Software that emulates a program or (usually) a complete hardware platform.

● Programs are not executed: they are interpreted.

● Emulation is very slow.● A completely different hardware architecture can be emulated.

● Examples: QEMU, DOSBox, MAME, ...

Master on Free Software

Paravirtualization

● Designed to overcome the problems present in some architectures for full virtualization.

● The guest OS is modified (“ported”) to run inside a virtualized environment.

● Very good performance.● Examples: Xen

Master on Free Software

Hardware-assisted virtualization

● Full virtualization using specific hardware capabilities.

● Virtual machines are easier to implement.● Good performance.● Supported in recent Intel and AMD processors.● Examples: KVM, VMWare, Xen, VirtualBox, ...

Master on Free Software

OS-level virtualization

● Many self-contained environments inside the same operating system.

● Only one instance of the operating system.● Very good performance.● Limitation: all virtual environments use the same kernel.

● Examples: OpenVZ, Linux-VServer, ...

Master on Free Software

Some virtualization solutions

Master on Free Software

debootstrap

● Tool useful to create virtual systems.● It downloads a basic Debian/Ubuntu installation to a directory.

● Usage:$ debootstrap lenny /dest http://ftp.es.debian.org

Master on Free Software

chroot

● Not really a virtualization system.● Changes the root directory of a process, thus showing it a different (limited) filesystem.

● Useful for testing and cross-platform development.

● Provides extra security to the processes inside the chroot.

Master on Free Software

Linux-VServer

● “A chroot with more security features”● Each virtual server has its own network and is more isolated from the host.

● All virtual servers share the same kernel.● Requires modifications to the Linux kernel.● Similar solutions: OpenVZ, jail (FreeBSD)

Master on Free Software

User-mode Linux (1)

● Linux ported to itself.● Integrated in recent versions of Linux.● Reasonable performance.● Easy to use.

Master on Free Software

User-mode Linux (2)

● Create a file system image (512 MB):$ dd if=/dev/zero of=root.img bs=1k count=512k

● Format it:$ mkfs.ext3 root.img

● Mount it and unpack the bootstrap there$ mount -t ext3 root.img /mnt -o loop

● Set a host name in /mnt/etc/hostname● Add this to /mnt/etc/hosts:

127.0.0.1 localhost● Add this to /mnt/etc/fstab:

/dev/ubd0 / ext3 defaults 0 1proc /proc proc defaults 0 0

Master on Free Software

User-mode Linux (3)

● Add this to /mnt/etc/network/interfaces:auto loiface lo inet loopback

● Add this to /mnt/etc/securetty:tty0ttys/0

● Edit /mnt/etc/inittab:1:2345:respawn:/sbin/getty 38400 tty0#2:23:respawn:/sbin/getty 38400 tty2#3:23:respawn:/sbin/getty 38400 tty2#4:23:respawn:/sbin/getty 38400 tty2#5:23:respawn:/sbin/getty 38400 tty2#6:23:respawn:/sbin/getty 38400 tty2

Master on Free Software

User-mode Linux (and 4)

● Umount the image:$ umount /mnt

● Boot User-mode Linux:linux ubd0=root.img mem=128M

● You can also create swap space and other partitions.

Master on Free Software

QEMU: CPU emulation

● Emulates many CPUs: x86, amd64, MIPS, SPARC, ARM, ...

● Can run Linux binaries compiled for other architectures.

● Very slow (CPU is emulated).● Accelerated support for some architectures using a kernel module (KQEMU).

Master on Free Software

QEMU: virtualization

● Emulates a full system.● Guest OS can run unmodified.● Supports disk images in several formats.● Virtual hardware: network, sound, video...● Built-in servers: VNC, TFTP, DHCP, ...● Does not require root privileges on the host.

Master on Free Software

KVM

● Virtualization using Intel and AMD hardware extensions.

● KVM is a Linux kernel module.● To boot a complete system there is a modified version of QEMU with KVM support.

● Very good performance.

Master on Free Software

qemu-img

● Used to create hard disk images● Several formats supported● qcow is QEMU's native format● Superseded by qcow2● Usage:

$ qemu-img create -f qcow2 root.img 4G