Comments on 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.

15 Comment(s)

Add comment

Please register in our forum first to comment.

Comments

By:

Great tutorial. thx

Sam 

By:

smart use of netcat here,

great tutorial... thanks for sharing it!

By:

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

By: maddog

wow never thought about such netcat usage - great idea!

By:

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

By:

For ubuntu its pretty much the same except:

On the VM machine

  1. Load from the Desktop CD and choose run ubuntu
  2. open a terminal (Applications > Accessories > Terminal)
  3. sudo passwd root (give it something like password)
  4. su (giving the password)
  5. nc -l 10000 | dd of=/dev/sda

On the host

  1. same as VM for 1 2 3 and 4
  2. nc $IP_ADDRESS_OF_VM 10000 | dd conv=noerror if=/dev/sda

This worked for me

 

 

By:

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

 

By: Anonymous

I'm trying to execute these commands but am told that /dev/hda is read-only.  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?

:)

By:

first have a look at what disks you have in the system with fdisk -l

By: Sergiu Pol

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 20-30 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/after-converting-physical-rhel4-system.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
- 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/network-scripts/ifcfg-eth0 eth1 ...
7. restart network service or computer

Have fun :)


By:

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....

By: Jamison

Can I hire you to move my old over the new machine??

By: Colin

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 non-existent paritions in FDISK and re-saving fixed the 'unallocated' parition and everything now appears fine. Now if I can just get it to recognise more than 640x480... Thanks for the How-To.

By: Petersen Allen

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.

By: Jamison

I am so new to linux that I don't even know where to begin.

I have a physical machine running Ubuntu 18.04.2 LTS Bionic.

I have an program that is running on it that I need to transfer the either the database or the whole install to preserve the data it has collected the last 10 months.

The company that sold me the license to run the LPR software stated I could use MYSQLDUMP and MYSQLRESTORE, but that is all he would tell me as it is not a supported tech instruction.

I was given a Dell R610 with dual Xeon CPU's, 36GB Ram and 6 bay SAS drives.

I stumbled across this post and now got to thinking I want to move the the install from the old machine to the server machine.

I'm installing hyper-v 2019 on it now.

Can someone please tell me what the exact procedure and commands are to produce the results of moving the old machine to the server machine?

If I have to pay someone I will. I have been trying to get this done for almost 6 months now.

Please, anyone...