Virtualizing a Linux System (Creating a Linux VM P2V)

Aus crazylinux.de
Zur Navigation springen Zur Suche springen

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

  1. Create an empty Virtual Machine
  2. Create the hard drive partitions (LVM)
  3. Restore files
  4. Set up the boot loader
  5. 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


Restore files

Copy files from live system to clone

rsync --stats --progress --numeric-ids -axAhHSP /etc/ clone_IP:/clone/etc/
rsync --stats --progress --numeric-ids -axAhHSP /boot/ clone_IP:/clone/boot/
rsync --stats --progress --numeric-ids -axAhHSP /var/ clone_IP:/clone/var/
rsync --stats --progress --numeric-ids -axAhHSP /lib/ clone_IP:/clone/lib/
rsync --stats --progress --numeric-ids -axAhHSP /lib64/ clone_IP:/clone/lib64/
rsync --stats --progress --numeric-ids -axAhHSP /usr/ clone_IP8:/clone/usr/
rsync --stats --progress --numeric-ids -axAhHSP /sbin/ clone_IP:/clone/sbin/
rsync --stats --progress --numeric-ids -axAhHSP /srv/mysql/datadir55/ clone_IP:/clone/srv/mysql/datadir55/
rsync --stats --progress --numeric-ids -axAhHSP /srv/www/xxxxx.de/ clone_IP:/clone/srv/www/xxxxx.de/

Links

http://wiki.ubuntuusers.de/Ubuntu_umziehen