Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Physical to Virtual GNU/Linux
- # @ Paolo Pedaletti 2013-02-16
- # http://pedalinux.blogspot.it/2013/02/physical-to-virtual-step-by-step.html
- # this is free software
- #
- # change this when you have done:
- DEBUG=""
- DEBUG="echo "
- ROOTSIZEGB="20"
- ROOTSIZEB=$((ROOTSIZEGB * 1024 * 1024 * 2))
- SWAPSIZEGB="4"
- SWAPSIZEB=$((SWAPSIZEGB * 1024 * 1024 * 2))
- OFFSET=2048
- VDISK=/home/kvm/test/sda.bin
- $DEBUG qemu-img create -f raw $VDISK $((ROOTSIZEGB + SWAPSIZEGB))G
- CMD="$OFFSET,$ROOTSIZEB,83\n$((ROOTSIZEB + OFFSET)),$((SWAPSIZEB - OFFSET)),82"
- echo -e "sfdisk : $CMD"
- echo -e "$CMD" | sfdisk -uS $VDISK
- $DEBUG sfdisk -l $VDISK
- $DEBUG mkdir /mnt/test-sda
- $DEBUG losetup --offset $OFFSET /dev/loop1 $VDISK
- $DEBUG mkfs.ext4 /dev/loop1
- $DEBUG mount /dev/loop1 /mnt/test-sda
- $DEBUG cd /mnt/test/sda
- echo "clone physical machine:"
- $DEBUG rsync -e ssh -au --stats -h --numeric-ids --exclude /proc --exclude /tmp --exclude /sys root@REMOTEHOST:/ /mnt/test-sda/
- echo "chroot to VM:"
- $DEBUG mount --bind /dev/ /mnt/test-sda/dev/
- $DEBUG mount -t devpts pts /mnt/test-sda/dev/pts/
- $DEBUG mount -t tmpfs none /mnt/test-sda/dev/shm/
- $DEBUG mount -t proc none /mnt/test-sda/proc/
- $DEBUG mount -t sysfs sys /mnt/test-sda/sys/
- $DEBUG chroot /mnt/test/sda
- echo "fix mtab and fstab:"
- $DEBUG vim /etc/mtab
- $DEBUG vim /etc/fstab
- echo "rebuild initramdisk:"
- $DEBUG mkinitrd ...
- echo "install grub:"
- $DEBUG grub-install /dev/loop1
- echo "umounting virtual image:"
- $DEBUG exit
- $DEBUG cd ..
- $DEBUG umount /mnt/test-sda/sys/
- $DEBUG umount /mnt/test-sda/proc/
- $DEBUG umount /mnt/test-sda/dev/shm
- $DEBUG umount /mnt/test-sda/dev/pts
- $DEBUG umount /mnt/test-sda/dev/
- $DEBUG umount /mnt/test-sda/
- $DEBUG losetup -d /dev/loop1
- echo "run virtual machine:"
- $DEBUG kvm -m 4096 -cpu kvm32 -name VMclone $VDISK
- echo "grub:"
- $DEBUG linux /boot/vmlinux... boot=/dev/sda1
- $DEBUG initrd /boot/initrd....
- $DEBUG boot
- echo "All correct?"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement