Additional ways to migrate to Proxmox VE: Difference between revisions

From Proxmox VE
Jump to navigation Jump to search
mNo edit summary
Line 1: Line 1:
= Introduction =
= Introduction =


If you have not read the [[Migration to Proxmox VE|main wiki article about migrating to Proxmox VE]], or the [[Advanced Migration Techniques to Proxmox VE]] article yet, you should do so now.
If you have not read the [[Migrate to Proxmox VE|main wiki article about migrating to Proxmox VE]], or the [[Advanced Migration Techniques to Proxmox VE]] article yet, you should do so now.
They contain the most relevant options to migrate to Proxmox VE.
They contain the most relevant options to migrate to Proxmox VE.
In contrast, this article gathers years of knowledge for special cases.
In contrast, this article gathers years of knowledge for special cases.

Revision as of 16:54, 13 February 2024

Introduction

If you have not read the main wiki article about migrating to Proxmox VE, or the Advanced Migration Techniques to Proxmox VE article yet, you should do so now. They contain the most relevant options to migrate to Proxmox VE. In contrast, this article gathers years of knowledge for special cases.

SSH Migration of a Windows machine to a VM raw file

Assumptions:

  • You have a physical machine in which you imported the File:Mergeide.zip, as shown on top of this page
  • The physical machine has disk device /dev/sda (read this with "fdisk -l", and look for "hda" or "sda" or similar, NOT dm- or other...)
  • You have already created a virtual machine with a raw type, file-based disk in stopped state.
  • The VM has VMID 101 (read this from the VM list in the web interface)

Download SystemRescueCD, burn it and reboot the physical machine with it in the CD tray.

At its bash prompt, give eth0 an IP, or use DHCP:

To assign IP:

ifconfig eth0 192.168.1.10 netmask 255.255.255.0 up  (use IP on same subnet as Proxmox VE server) 

To use DHCP:

dhcpcd eth0

To start the image process on the physical machine:

dd if=/dev/sda | ssh root@proxmox dd of=/var/lib/vz/images/vmid/diskname.raw

Change the root@proxmox to root@yourproxmoxip and change the vmid/diskname to the VMID number and the name you want to call the disk. I.E. VMID 101 and disk called vm-101-disk-1.raw would be:

 dd if=/dev/sda | ssh root@proxmox dd of=/var/lib/vz/images/101/vm-101-disk-1.raw

Once this completes you can assign this disk file to your VM on the Proxmox VE interface.

Tested a 8GB physical server over gigabit network and was running in about 10 minutes.

Migrate a Windows machine to a VM logical volume using netcat

Assumptions:

  • You have a physical machine in which you imported the File:Mergeide.zip, as shown on top of this page
  • The physical machine has disk device /dev/sda (read this with "fdisk -l", and look for "hda" or "sda" or similar, NOT dm- or other...)
  • You have already created a virtual machine with a disk on LVM, larger in size than the physical machine one (at least 1 GB more), STOPPED, do NOT start it during this procedure!
  • The VM has VMID 103 (read this from the VM list in the web interface)
  • The LVM VG is named SHARED-VG (read this with: "vgdisplay -s")
  • So the LV partition is /dev/SHARED-VG/vm-103-disk-1 (read this with: "lvdisplay |grep LV|grep 103")

Download SystemRescueCD, burn it and reboot the physical machine with it in the CD tray.

At its bash prompt, give eth0 an IP, coherent with the network of one Proxmox VE server (in the following example: 10.0.0.27):

ifconfig eth0 10.0.0.17 netmask 255.255.255.0 up

then assign root user a password, so you can log in via ssh:

passwd

Log in via SSH on both the physical machine and the Proxmox VE server.

On the Proxmox VE server, give the command:

date; netcat -w30 -vvnlp 3333 | gzip -dc > /dev/SHARED-VG/vm-103-disk-1; date

and on the physical machine give the command:

dd if=/dev/sda | gzip -c | nc -w30 -vvn 10.0.0.27 3333

You have to start the second command WITHIN 30 seconds of issuing the first one (the -w30...)!

This way, the Proxmox VE machine is waiting for a stream of bytes on TCP port 3333, then gunzip it and redirects on the vm virtual disk.

The physical machine outputs its ENTIRE disk as a stream of bytes, gzip it and pass it via netcat to the Proxmox VE server.

The 2 date commands are useful to have a trace of when this process starts and ends.

Tested migrating a 75GB disk in about 90 minutes on a 100Mbit LAN. VM started and worked as expected, after recognizing at first boot the new IDE controllers.

An alternate method for Windows VMs is using ntfsclone with ncat. First, create the actual VM, and boot it with the System Rescue CD. Partition it to match the partition structure of the host machine. Once you have the partitions built out, you can copy the partitions directly from the source machine to the new VM. This will only copy used data. The commands are:

On the destination system :

# nc -l -p 1234 | ntfsclone -r -O /dev/sda3 -

On the source system :

# nc -s -o - /dev/sdb1 | netcat DestSrvIP 1234

Migration to a a smaller partition on a VM

While it's quite easy to "clone" a partition to another (real or virtual) of the same or bigger size, it's not so simple to do the same if the destination partition is smaller than the original one. This is possible, fortunately, and at least a proven method follows, but you have to take care of some pre-conditions:

  • Since you want to clone to a smaller partition, we will operate at the file system level, copying all the files from the source file system to the destination one.
  • So, we have to make sure that the destination partition has enough room to get all the files, at least, with better some free space left there.
  • The cloning is not possible directly, i.e disk-to-disk, but we have to "save" the source partition, and then "restore" it on the destination one.
  • Must be sure that the tools used are known very well as to how to copy files on the file systems involved, including symlinks, hardlinks, file system specific attributes, and so on.

FSArchiver

One free tool you can use for this is FSArchiver, which is a system tool that allows you to save the contents of a file-system to a compressed archive file. The file-system can be restored on a partition which has a different size and it can be restored on a different file-system. Unlike tar/dar, FSArchiver also creates the file-system when it extracts the data to partitions. Everything is check summed in the archive in order to protect the data. If the archive is corrupt, you just loose the current file, not the whole archive. FSArchiver is released under the GPL-v2 license. It's still under heavy development so it must not be used on critical data. So, you've been warned. Latest FSArchiver should be in the latest SystemRescueCD, although you can obtain it on your favorite recent distribution.

Cloning NTFS, be sure to use either version 0.6.10 or a patched previous version, because there was a bug that caused errors with NTFS junctions (something like Linux symlinks).

If your origin physical server is configured in RAID-1 using "Fake Raid" (MB Bios raid), see the section about it in this article

mergeide

As said above, install File:Mergeide.zip on the physical Windows machine (see Microsoft KB article for details) to provide support for the natively supported IDE controllers in Windows. Without this, cloned XP booting failed for me.

Running FSArchiver from SystemRescueCd

Use the latest SystemRescueCD available, that has a recent FSArchiver version:

Confirm the version is right with:

# fsarchiver -V

it should be at least "0.6.10", particularly if you are cloning NTFS file systems. Then run:

# fsarchiver probe simple

that will report your disks/partitions current layout in a simple, understandable way, like:

[======DISK======] [=============NAME==============] [====SIZE====] [MAJ] [MIN]
[sda             ] [WDC WD5002ABYS-5               ] [    15.00 GB] [  8] [  0]

[=====DEVICE=====] [==FILESYS==] [======LABEL======] [====SIZE====] [MAJ] [MIN] 
[loop0           ] [squashfs   ] [<unknown>        ] [   671.85 MB] [  7] [  0] 
[sda1            ] [ntfs       ] [System           ] [    15.00 GB] [  8] [  1] 
[ramzswap0       ] [swap       ] [<unknown>        ] [   248.47 MB] [251] [  0] 

You have to provide a folder to save the partition "backup", which will be quite large (FSArchiver has several compression level, but just to be sure have enough free space there to accommodate all the uncompressed file...) if you need to reach a "tmpfolder" windows share, you have to install the smbfs package before (standard repositories), so that then you can

# mkdir /mnt/tmpfolder
# mount -t smbfs //windows/tmpfolder /mnt/tmpfolder -o user=username

giving a suitable password when asked.

Backup the partition

Now you have to perform the "backup", BE CAREFUL the first path is the backup file to save, the second the source partition, do not invert

I used:

# fsarchiver savefs -v -o /mnt/tmpfolder/physical.fsa /dev/sda1

(-v is verbose, shows each file is backing up, and if you have a lot of files and a slow video card can slow down a lot the entire process)

Then (if no errors reported) run the same Live CD in a KVM VM with a 15GB virtual empty disk, better if a bit larger, (virtio), so /dev/vda. After mounting the smb share in the same way, run GParted (present in SystemRescueCd, startx to enter the graphical interface and run it) and created a empty NTFS partition there, /dev/vda1, and set the boot flag.

Restore the partition

Then run

Note: i use here /dev/vda1 while the original was /dev/sda1, and id=0 because i restore the first partition in the physical.fsa (yes, it may store more than one) as /dev/vda1

# fsarchiver restfs -v /mnt/tmpfolder/physical.fsa id=0,dest=/dev/vda1

check if there are no restore errors. It was quite quick and just worked.

Successful cases

  • I successfully cloned an Windows XP professional machine from a physical 40GB (used 12GB) partition to a virtual (KVM) 15GB one, stored on Proxmox VE LVM. The archive file was around 7GB. (i had just 2 hard link restore errors, but in the log were reported on non critical files, although i would prefer 0 errors...)
  • I successfully cloned an Windows 2003 AD controller machine from a physical 250GB (used 5GB) partition to a virtual (KVM) 15GB one, stored on Proxmox VE LVM. The archive file was around 3,4GB. (i had just 0 restore errors of any kind)
  • Cloned a physical Ubuntu 9.04 desktop from a 32 raid5 disk to a virtual KVM 12 disk. Just had to reinstall grub to make it boot inside KVM. No errors.

SelfImage

Warning : SelfImage does not do snapshot of physical disk. So, shutdown services and avoid writes during the copy process

Prepare the Windows operating system

Install SelfImage on the physical Windows machine. Execute the File:Mergeide.zip (see Microsoft KB article for details) to provide support for the natively supported IDE controllers in Windows.

Prepare the Proxmox VE VM

Create an new KVM container with a suitable disk size. It is recommended that you choose the size 1 GB bigger than the size of the physical disk that you want to migrate to make sure all your data fits to the virtual disk.

Use VNC or SSH to connect to console on the Proxmox VE host. Export the qcow2 disk in the container directory with NBD

qemu-nbd -t /var/lib/vz/images/xxx/vm-xxx-disk.qcow2 -p 1024

where xxx is the VM ID.

If you use LVM as storage model, you can also export the logical volume created by Proxmox VE via the web interface

qemu-nbd -t /dev/VolumeGroup/vm-xxx-disk-1 -p 1024

Do the migration

Start SelfImage on the physical machine, choose to image entire hard disk, not partition. On output file select NBD with your PVE host IP and port 1024 as parameters. Click Start.

When imaging is complete press CTRL+C on the PVE console to stop the export of your virtual disk file.

Start the virtual machine and have fun.

Windows backup

This may be useful if any other approach fails, or looks too complicated for you, as does not involve other software except Windows and PVE itself. It was used successfully to convert a live Windows 2000 server sp4 to PVE 1.5, and was inspired from a blog post related to a similar migration to XEN, but proved to be effective also for PVE, and probably any other VE around.

Here is an archive of the original blog post

Here is the cache of the post along with the NewSID file.

The Workflow

This method is about

  • making a backup on your physical machine (pm)
  • creating a virtual machine (vm) from scratch, identical as possible to the pm
  • installing the same base OS of the pm on the vm, from the original supports
  • restoring the backup of the pm on the vm

easy, uh? well, it works! Of course there are some point to take care of, and some drawbacks, too, but it is a very simple method, and you can find the drawbacks (if any) worth for the easiness you have in return!

You don't need to get new software, or learn fancy Linux commands: all you got to know (and it's supposed you ALREADY know) is

  • how to create a vm in Proxmox VE (KVM)
  • how to make a backup/restore from windows (with the bundled software!)

OK, follow me:

Backup the physical machine

The program you need is NTBackup, on a standard installation you can find it under the menu

  • Start/Program Files/Accessories/System utilities/Backup
  • if it has been removed, you can add it back from your windows CD

Start a backup that includes

  • ALL the windows hard drives
  • the system state (this include the whole registry, IPs, hostname, and so on)

Then, choose the "file" option as a destination

  • be sure to create this file on a network share, or a USB drive but NOT on the disks you are backing up
  • be sure that the network share has enough space to hold the BIG file...

NOTE: Some services may "lock" some files in a way that NTBackup won't be able to copy them (while they're in use):

  • this is normal, and usually some of this locked files are:
    • files used by the open programs the logged user has (e.g. NTBackup logs...)
    • SQL data files, web server logs, and so on (usually running as services)
  • You can find "locked" files running NTBackup once, and then looking at its log for lines containing a "will be ignored" string
    • to find such lines in a BIG log file (mine had 250k lines) use the console FIND command ("c:\FIND /?" is your friend)
  • the only workaround is, during the backup time frame:
    • close all the open (interactive) programs the logged user has
    • temporarily stop the services that are locking the files (if you can)

Cloning the virtual machine

  • on PVE, you must create a vm configured just like the pm you want to migrate
    • same OS (you have to use a CD or a ISO for that)
    • same %WINDIR% folder name (e.g.: c:\windows or c:\winnt, etc), (the source blog post doesn't mention this but i did it...)
    • same SP (service pack applied) level, hotfixes, etc.
    • same CPU number
    • same page file configuration (the source blog post doesn't mention this but it turned out to matter in my conversion)
    • same drive layouts
      • number of disks and partitions, those on the vm must be at least equal in size to the pm ones
      • same drive letters mapping
    • same network card number

Now, when your vm is just like your pm, except it doesn't have any of the programs and configuration the pm has:

  • add one more temporary drive to hold (temporary) files during the migration, assign it a drive letter not used in the pm
  • on this temporary drive, copy
    • the file c:\boot.ini from the vm
    • the whole folder c:\windows\repair or c:\winnt\repair, or whatever your %WINDIR% is on your vm
    • the backup file you previously did with NTBackup, stored somewhere on your network

Then, before restoring, switch the vm NIC to a non-used network in PVE, e.g.:

  • create a new fake bridge, not connected to any eth<x>,
  • then delete the "working" vm NIC and
  • re-add another NIC on the vm, linked to the new fake bridge

otherwise your new vm would "talk" to the real network / domain controllers, etc, and would result in a duplicate machine, duplicate IP address, and so on. This would be BAD.

Restore the backup on the virtual machine

Log on to the vm and perform a restore of the backup file you have on the temporary disk

  • note: choose "always replace the files on my computer" (see tools>options>restore in NTBackup)

BEFORE REBOOTING (at the end of the restore NTBackup asks you to reboot, hold down your mouse for a while...)

  • restore
    • the file c:\boot.ini from the vm
    • the whole folder c:\windows\repair or c:\winnt\repair, or whatever your %WINDIR% is on your vm

replacing those restored from the backup file.

Reboot the virtual machine

if you got any BSOD (blue screens) you may try to:

  • boot in safe mode
  • remove unrecognized components (e.g.: SCSI card)
  • make windows detect those components and reinstall drivers

I didn't see any BSOD, so nothing to tell here.

Otherwise, log on to the vm,

  • some component may not work, e.g. (mine) the mouse cursor may seem "out of sync" with the VNC one, be patient and wait because:
  • windows may recognize more virtual components and install them automatically (PCI, video, network, and so on: after a reboot they will work as expected)

After that, you can

  • turn off the pm
  • on the vm add a NIC linked to the real network, assigning the real IP the pm had
  • reboot and log into the domain

Windows systems specific issues

inaccessible boot device

Booting a virtual clone (IDE) of a physical Windows system partition may fail with a BSOD referring to the problem

STOP: 0x0000007B (0xF741B84C,0xC0000034,0x00000000,0x00000000)
INACCESSIBLE_BOOT_DEVICE 

this means that the source physical windows machine had no support for IDE controller, or at least the one virtually replaced by KVM (see Microsoft KB article article for details): as Microsoft suggests, create a mergeide.reg file (File:Mergeide.zip) file on the physical machine and merge that in the registry, 'before the P2V migration. By the way, it may not be necessary but should be no harm, anyway, and save you lots of time and headaches.

Windows 2000: see [1]

Disk booting tips

  • check that your disk has "boot flag" enabled (you can check this with GParted, on NTFS disks, booting the vm from a live CD ISO, see this GParted manual page) maybe not so windows-specific but better remind it here.
  • be sure that boot.ini on your system partition is still suitable to your current disk/partition configuration (see this kb article and this kb article)

Hidden non present devices

If your source physical machine had network interface controllers (NICs) with static IP assigned and then you clone the system to a vm, you will need to add a virtual Ethernet controller, provided by KVM, but Windows won't let you assign the same fixed IP to the new virtual NIC, because (it reports) there is a hidden and nonpresent devices already configured with the same IP (see Microsoft KB article).

For sure it should be removed from windows "known" hardware but, you won't find it in "device management", even if you specify "show hidden peripherals", why? because Microsoft is complicated :-)

To be able to see, and then remove the old physical NIC from "device management", you have to

  • open a console window
  • type:
    set devmgr_show_nonpresent_devices = 1
    and press enter
  • then, in the same console (do not close it) type:
    start devmgmt.msc
    and press enter
  • this will open the same "device management" panel you could have open from the "control panel", but now if you set the "show hidden peripherals" flag, the "nonpresent" devices will appear, although dimmed somehow, and you will be able to remove them, freeing the IP for your virtual NIC.

Other suggested pages

Fake Raid specific issues

If you have a physical PC to clone and you use a method that requires access to the file system (like with FSArchiver) from GNU/Linux, you can be in troubles if you have a so called "fake raid", that is a raid created using the motherboard bios configuration. Let's say we have a RAID1. In short GNU/Linux (i.e. SystemRescueCd) sees the device, sees that the disks have some Raid metadata, and when you try to mount them it uses the "mdadm" libraries, that can't work since that raid is totally different. To avoid this, you have to boot with the boot parameter 'nodmraid'. For example, if you boot with SystemRescueCd, at the menu where you can choose what to boot hit "tab" key You will have something like:

ifcpu64.c32 rescue64 scandelay=1 -- rescue32 scandelay=1

modify it (on both sides of the "--" separator) like this:

ifcpu64.c32 rescue64 scandelay=1 nodmraid -- rescue32 scandelay=1 nodmraid

Physical Linux server to Container

Take a look at these links if you want to migrate something that is not a Linux server to containers:

Here we explain how to do a Physical-to-Virtual migration from a Linux installation into a Proxmox VE LXC container.

Log into the machine you want to migrate into a PVE container as root and first stop any running services such as web servers or databases e.g. `systemctl stop apache2`, `systemctl stop mysql` etc. You need to be root (or run with sudo) so that tar can access and archive all files correctly using commands such as:

# cd /
# tar -cvpzf backup.tar.gz --exclude=/backup.tar.gz /

The tar -p switch is critical for preserving file permissions. Copy this tarball into the container templates cache directory on the PVE server which defaults to /var/lib/vz/template/cache . You may then create a new container using this tarball as a template via the web UI or using pct. If you choose to use the PVE web UI to create the new container, be sure to uncheck the 'Unprivileged Container' option (under the General options tab) else you are likely to run into file ownership issues. Creating a new privileged i386 container on ZFS storage with container ID 101 using pct would look something like this:

# pct create 101 local:vztmpl/backup.tar.gz -arch i386 -hostname your.hostname.here -onboot 1 -rootfs local-zfs:300 -memory 4096 -cores 2

Note this command doesn't configure networking. I enable networking after creating the container via the Proxmox web interface.

Move OpenVZ containers to Proxmox VE

OpenVZ is depreacated and was superseeded by the Linux Container (LXC) project - which is using mainline kernel features.

You can move existing OpenVZ containers (CT) with vzdump to Proxmox VE. Then check out the Convert OpenVZ to LXC article.

Convert Windows to use (VirtIO) SCSI (KVM)

This procedure is required to get Windows to load and active the SCSI drivers, once active you can switch the disk and it should "Just Work".

  • With the VM powered off:
    • ensure the SCSI controller is set to VirtIO, this will work best on Windows 7 or newer.
    • add a new temporary SCSI virtual disk, can be small - for example, 0.1 GB big
    • add the VirtIO Driver ISO to a CD-ROM drive
  • Start the VM and make sure the drivers load for the new disk. You do not need to format it, just make sure you can see it in Device Manager
  • Shut down the Virtual Machine
  • detach the dummy disk and remove it afterwards
  • detach the real disk(s) and re-attach (edit) them as SCSI
  • Add the disks you just removed back as SCSI disks and boot the Virtual Machine.