Virtualizing a Linux System (Creating a Linux VM P2V)
from http://www.localizingjapan.com/blog/2011/03/05/virtualizing-a-linux-system-creating-a-linux-vm-p2v/
This tutorial article is going to show you how to create a Linux virtual machine from a physical Linux system. These instructions are generic enough to work with any Linux distribution, such as Ubuntu, Fedora, Red Hat, CentOS, Debian, Mint, etc.
There are many reasons why you would create a VM of a physical system you have running. You might want to test out things before you try them on your actual system. It is useful when you are translating to have both the English and Japanese (or other language) OS and applications open side by side to reference the correct translations easily. Whatever the reason, this article will show you one way to do it pretty easily.
Overview of the Linux VM creation task:
Tools and Resources Needed
- SystemRescueCd ISO file
- KVM (libvirt)
- Preparation Tasks
Main Tasks
- Create an empty Virtual Machine
- Create the hard drive partitions (LVM)
- Restore files
- Set up the boot loader
- Final Task – Boot the VM
Create an empty Virtual Machine
add one SATA-Disk (qcow2, 150GB) and cdrom with SystemRescueCd.iso
Create the hard drive partitions
Turn the computer on and boot to SystemRescueCd Linux.
Create 2 partitions boot (500MB) and data
fdisk /dev/sda
Create LVM stuff
pvcreate /dev/sda2
vgcreate vg0 /dev/sda2
lvcreate -n swap -L 4G vg0 /dev/sda2
lvcreate -n tmp -L 10G vg0 /dev/sda2
lvcreate -n var -L 6G vg0 /dev/sda2
lvcreate -n root -L 20G vg0 /dev/sda2
lvcreate -n mysql -L 5G vg0 /dev/sda2
lvcreate -n mail -L 15G vg0 /dev/sda2
lvcreate -n www -L 80G vg0 /dev/sda2
mkfs.ext4 /dev/sda1
mkfs.ext4 /dev/mapper/vg0-root
mkfs.ext4 /dev/mapper/vg0-tmp
mkfs.ext4 /dev/mapper/vg0-var
mkfs.ext4 /dev/mapper/vg0-www
mkfs.ext4 /dev/mapper/vg0-mail
mkfs.ext4 /dev/mapper/vg0-mysql
Mount filesystem and create dirs
mkdir /clone
mount /dev/mapper/vg0-root /clone
mkdir /clone/boot
mkdir /clone/tmp
mkdir /clone/var
mkdir /clone/srv
mkdir /clone/srv/www
mkdir /clone/srv/vmail
mkdir /clone/srv/mysql
mount /dev/sda1 /clone/boot
mount /dev/mapper/vg0-tmp /clone/tmp
mount /dev/mapper/vg0-var /clone/var
mount /dev/mapper/vg0-www /clone/srv/www
mount /dev/mapper/vg0-mail /clone/srv/vmail
mount /dev/mapper/vg0-mysql /clone/srv/mysql