Professional Documents
Culture Documents
Tutorial search
Tutorials How To Virtualize A Physical Linux Machine
On this page
How To Virtualize A Physical Linux
Machine How To Virtualize A Physical Linux Machine
This tutorial shows how you can virtualize a physical Linux machine. It
is intended not only for virtualization, but for any relocation of a RedHat Linux based system from one machine to another.
Here are the steps to be completed:
1. Install a virtualization software on the desired machine.
2. Create an empty virtual machine with enough disk space, selecting the OS you’re
going to migrate.
3. Download a Linux LiveCD ISO (e.g. Knoppix).
4. Burn one copy on a CD and then copy the ISO to the virtualization server (the
host).
5. Reboot the original Linux box (the physical machine that you want to virtualize) with the CD you’ve just burnt, and connect the ISO to the
newly created virtual machine (i.e., boot the VM from the ISO).
6. Check both live CDs have net connection correctly configured and that they can see each other.
7. In the virtual machine, type this:
nc l p 10000 | dd of=/dev/hda
8. On the machine you’re migrating, type:
dd conv=noerror if=/dev/hda | nc $IP_OF_THE_VM 10000
9. Wait until dd finishes its job and do a clean reboot of the virtual machine.
10. Boot in rescue mode with the distro's first CD or DVD and chroot to the new system (on the virtual machine).
11. Run kudzu to remove old devices and find the new ones (or manually edit your /etc/modprobe.conf file, which is the most important
since it includes your scsidevice). For SuSE Linux systems, you may need to run yast to discover the new hardware.
12. Create a new init using mkinitrd on your kernel version. Example:
/sbin/mkinitrd v f /boot/initrd2.6.201new.img 2.6.201
https://www.howtoforge.com/howtovirtualizeaphysicallinuxmachine 1/5
11/11/2016 How To Virtualize A Physical Linux Machine
13. Edit your /boot/grub/menu.lst file to boot your newly created initrd image.
14. Keep your fingers crossed and reboot your VM.
view as pdf | print
Share this page: Tweet
Follow @howtoforgecom 23.6K followers Recommend 5 2
13 Comment(s)
Add comment
Name * Email *
p
Submit comment
I'm not a robot
reCAPTCHA
Privacy - Terms
Comments
From: Reply
Great tutorial. thx
Sam
From: Reply
smart use of netcat here,
great tutorial... thanks for sharing it!
From: Reply
I am looking for something like this for (k)ubuntu.
Does this also work for (k)ubuntu Since I really need to virtualize my physical kubuntu machine
Thanks in advance
From: maddog Reply
wow never thought about such netcat usage great idea!
From: Reply
to move the data out of the physical HDD and onto the virtual one, this HowTo should do the trick. I'm no Debian/Ubuntu expert, but there
should be a way to rescan for hardware changes and set up the new found hardware accordingly
https://www.howtoforge.com/howtovirtualizeaphysicallinuxmachine 2/5
11/11/2016 How To Virtualize A Physical Linux Machine
From: Reply
For ubuntu its pretty much the same except:
On the VM machine
Load from the Desktop CD and choose run ubuntu
open a terminal (Applications > Accessories > Terminal)
sudo passwd root (give it something like password)
su (giving the password)
nc l 10000 | dd of=/dev/sda
On the host
same as VM for 1 2 3 and 4
nc $IP_ADDRESS_OF_VM 10000 | dd conv=noerror if=/dev/sda
This worked for me
From: Reply
Its almost the same as the above except:
Boot the physical machine from the CD of Ubuntu desktop and the VM from the Ubuntu ISO
MAKE SURE THE VM IS BRIDGED
Open a terminal window
enter the following
sudo passwd root
enter a password (u can use password as it isnt saved after a reboot)
and retype
enter superuser
su
and use the password you just created
On the VM box type
nc ‐l 10000 | dd of=/dev/sda
On the physical machine type
dd conv=noerror if=/dev/sda | nc IPA.DDR.ESS.??? 10000
and that will copy it over the network
From: Anonymous Reply
I'm trying to execute these commands but am told that /dev/hda is readonly. It is, after all, the cdrom. My target vm has SDA and SDA2
(largest drive space) after booting with Knoppix. Should I be using these instead?
:)
From: Reply
first have a look at what disks you have in the system with fdisk l
From: Sergiu Pol Reply
For general usage this tutorial is very good. Actually is a general tutorial for cloning a HDD with Linux installed.
But if you care about the following things, the above steps are not enough:
1) The physical HDD can be large (250, 500, 750 or 1000 GB) and the Linux partition can be only 2030 GB. Or some percentage of HDD space
can be unpartitioned for later usage. Applying the tutorial ALL the source HDD will be coppied to the destination HDD (the virtual one).
2) The file systems in partitions from the physical HDD can be only 50% or less utilized so is very inefficient to clone the whole FS in the virtual
HDD.
Among the above written steps I used some solutions to use in the VM as little space as possible:
A. Reduce the source FS and the device it sits on (partition or logical volume)
B. Copy the HDD without the unpartitioned space
Along with A. and B., we can use some tricks that can make this faster:
http://tipstricksandmore.blogspot.com/2009/01/afterconvertingphysicalrhel4system.html
http://kb.vmware.com/selfservice/microsites/search.do?
cmd=displayKC&docType=kc&externalId=1002402&sliceId=2&docTypeID=DT_KB_1_1&dialogID=14730726&stateId=0%200%204678181
http://bisqwit.iki.fi/source/lvm2defrag.html
https://www.howtoforge.com/howtovirtualizeaphysicallinuxmachine 3/5
11/11/2016 How To Virtualize A Physical Linux Machine
usage of dd over the network with compression (good especially for empty spaces) and 4k IO size (faster than default IO size): dd bs=4096
if=/dev/sda | gzip | ssh root@destination_hostname "gzip dc | dd bs=4096 of=/dev/sda"
clone the MBR (1st soltion): dd if=/dev/sda of=/dev/hda bs=512 count=1
clone the MBR (1st soltion): sfdisk d /dev/sda | sfdisk f /dev/sdb (over the network you can use sfdisk d /dev/sda | ssh
root@destination_hostname "sfdisk f /dev/sdb")
modify destination hostname and network settings (RHEL and Fedora):
1. check name: (C) uname n; (C) hostname a
2. edit /etc/hosts
3. edit /etc/sysconfig/network
4. edit /etc/sysctl.conf
5. reboot (or echo hostname.mydomain.com > /proc/sys/kernel/hostname)
6. edit /etc/sysconfig/networkscripts/ifcfgeth0 eth1 ...
7. restart network service or computer
Have fun :)
From: Reply
I used this implementation to rescue the data and OS from an old and low performance machine (PIII Xeon). The installed HDD wasn't that
big, so dd was a good choice for the time being. The server in cause was a simple 1U old HP server, with a pretty small HDD (I don't recall
its size anymore). I guess there are lot's of people out there that want to get rid of the old hardware, and to keep the valuable data along
with OS. For this purpose, the described method is the way to do it. But there's always room for improvement....
From: Colin Reply
I used a variation of this method to transfer an ubuntu desktop installation which was being used more as a server than anything. As there
were other partitions on the drive that I didn't want transferred I used the command: dd conv=noerror if=/dev/sda1 bs=4096 |gzip |nc {IP
ADDR OF VM} {PORT} nc l p {PORT} | gzip dc dd bs=4096 of=/dev/sda1 I then transferred the boot sector with the command: dd
if=/dev/sda bs=512 count=1 |nc {IP ADDR OF VM} {PORT} nc l {PORT} |dd bs=512 count=1 of=/dev/sda For reasons unknown to me,
while it successfully copied over the entire filesystem, it didnt boot. The other thing which was odd was that it actually recreated the full
paritition table from the old machine (which I thought was located somewhere between the boot sector and the first partition). While
everything had copied, Gparted showed the entire virtual drive as unallocated, which was no small concern. To get it to boot I just reinstalled
the grub bootloader by booting a live CD in the VM and typing: sudo grub root (hd0,0) setup (hd0) After that it booted fine I didn't do the
kudzu or mkinitfd as I had troubles with the ubuntu equivalent and the chrooted environment. It booted fine in the VM except for all its
complaints about missing partitions. Deleting the nonexistent paritions in FDISK and resaving fixed the 'unallocated' parition and everything
now appears fine. Now if I can just get it to recognise more than 640x480... Thanks for the HowTo.
From: Petersen Allen Reply
This worked like a charm for migrating a physical Centos 5.3 machine to VMWare, but I did run into one problem. After performing the
instructions above, the machine wouldn't boot and was hanging on udev initialization. The original box had two CPUs, as did the VM. But once
I changed the VM to only use one CPU it booted just fine. Just something to keep in mind.
Tutorials How To Virtualize A Physical Linux Machine
Sign up now!
https://www.howtoforge.com/howtovirtualizeaphysicallinuxmachine 4/5
11/11/2016 How To Virtualize A Physical Linux Machine
Tutorial Info
Author: mannes
Tags: virtualization
Share This Page
Tweet
Recommend 5
Howtoforge © projektfarm GmbH. Terms
https://www.howtoforge.com/howtovirtualizeaphysicallinuxmachine 5/5