Blogs » WildCoast.Com's blog

Convert physical machine to Virtual Machine

 

PRIONYX:

mount -o vers=3 -o nolock 10.7.0.1:/export/users /mnt/prionyx/
nano ~/.bashrc
cd /home/jeff/
mkdir hertz
cd hertz/
qemu-img create image.raw 1000204886016
du -sh
ls -l
ls -al
dd if=./mbr.bin of=./image.raw bs=512 count=1 conv=notrunc
ls -al
fdisk -l image.raw
losetup /dev/loop0 image.raw -o 8592031744 --sizelimit 536870912
losetup /dev/loop1 image.raw -o 1048576 --sizelimit 8589934592
losetup /dev/loop2 image.raw -o 9129951232 --sizelimit 991074806784
df -h
mkfs.ext3 /dev/loop0
mkfs.ext4 /dev/loop2
du -sh
ls -al
ls -al /dev/loop0
ls -al /dev/loop1
mkdir /mnt/hertz
mount /dev/loop2 /mnt/hertz/
mkdir /mnt/hertz/boot
mount /dev/loop0 /mnt/hertz/boot/
umount /mnt/hertz/boot
umount /mnt/hertz/
mount
mkdir ../mnt
mount /dev/loop2 /home/jeff/mnt/
mkdir ../mnt/boot
mount /dev/loop0 /home/jeff/mnt/boot/
ls -al ../mnt/boot/
du -sh ../mnt/

HERTZ:
mount -o vers=3 -o nolock 10.7.0.1:/export/users /mnt/prionyx/
489 ls -al /mnt/prionyx/
490 fdisk -ul /dev/sda
491 fdisk -l
492 mount
493 ls -al /mnt/prionyx/jeff/
494 mount
495 df -h
496 fdisk -ul /dev/sdb
497 fdisk -l /dev/sdb
498 fdisk -l /dev/sda
499 cat ~/.bashrc
500 nano ~/.bashrc
501 fdisk -l /dev/sda
502 dd if=/dev/sda of=./mbr.bin bs=512 count=1
503 ls -ltr
504 mv mbr.bin /mnt/prionyx/jeff/hertz/
505 fdisk -l
506 fdisk -l /dev/sda
507 df -h
508 fdisk -l /dev/sda1
509 fdisk -l /dev/sda
510 df -h
511 mount
512 ls -al /mnt/
513 ls -al /mnt/prionyx/jeff/mnt/
514 rsync -aAXvP / /mnt/prionyx/jeff/mnt/ --delete --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found,/home/*/.gvfs}

virt-install -n hertz-vm -r 4096 --extra-args "console=ttyS0" -v --os-variant debianwheezy --disk /var/lib/libvirt/images/image.raw,device=disk,bus=virtio,cache=none --nonetworks --import --prompt

http://manuel.kiessling.net/2013/03/19/converting-a-running-physical-machine-to-a-kvm-virtual-machine/

FLU.FF DISK PARAMETERS

99 cd /home/jeff/flu.ff/
100 ls -al
101 losetup /dev/loop0 ff.raw -o 32256 --sizelimit 156280287744
102 mkfs.ext3 /dev/loop0
103 fdisk -l ff.raw
104 losetup /dev/loop1 ff.raw -o 156280320000 --sizelimit 2714342400
105 mkswap /dev/loop1

RSYNC LESS /home/*,/var/virtual,/var/log/
rsync -aAXvP / /mnt/sheri/jeff/flu.ff/ --delete --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found,/home/*,/var/virtual/*,/var/log,}

FIX BOOT
chroot the mounted partition
nano /etc/initramfs-tools/modules # Add these lines:
virtio_pci
virtio_blk
#update-initramfs -u

(https://wiki.debian.org/DebianKVMGuests)
then fix the guest os
http://wiki.libvirt.org/page/Virtio

qemu-img convert -f raw -O qcow2 /home/jeff/flu.ff/ff.raw /var/lib/libvirt/images/ff.qcow2

Mount qcow2 image
modprobe nbd max_part=63
qemu-nbd -c /dev/nbd0 image.img
mount /dev/nbd0p1 /mnt/image

Fix boot loader:
sudo mount /dev/vdb1 /mnt
sudo mount --bind /dev /mnt/dev
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys
sudo chroot /mnt
update-initramfs -u
update-grub
reboot

Reinstall GRUB
grub-install --boot-directory=/mnt/boot /dev/vda

MOUNT QCOW2:
modprobe nbd max_part=63
qemu-nbd -c /dev/nbd0 /var/lib/libvirt/images/ff.qcow2
mount /dev/nbd0p1 /mnt/image

qemu-nbd -d /var/lib/libvirt/images/ff.qcow2

rsync -aAXvP / /mnt/prionyx/jeff/mnt/ \
--delete \
--exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found,/home/*/.gvfs}

rsync -aAXvP / /mnt/sheri/jeff/flu.ff/ --delete --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found,/home/*,/var/virtual/*,/var/log,}

virt-install -n ff-vm -r 4096 --extra-args "console=ttyS0" -v --os-variant debianwheezy --disk /var/lib/libvirt/images/ff.raw,device=disk,bus=virtio,cache=none --nonetworks --import --prompt

Add new comment