As a part of my current network
and infrastructure make-over I am replacing my old little home server here
that is running on one of these zotac z-boxes with something still small but a bit more
powerful – this ultra small factor pc here which has a better processor, more ram and more
disk. But how am I going to migrate all the stuff that I am running on this old server to the new
one ? I think I’ll make it virtual. Stay tuned. (intro) In some of my videos I showed you how to build
virtual environments. For example in this video we built a whole little home network in virtualbox.
In other videos I showed you how to build your own home lab server with virtualbox or Proxmox. Today
I will use the proxmox server in order to migrate my old system from physical or “bare metal” like
it’s called into a virtual machine running on the new server. Guys, please use the time markers
to skip to the chapter that you’re interested in if you don’t want to watch the whole
episode. First let’s prepare the old system. The first thing that I do is I
log into my portainer because al of the services on the old machine are running
under docker. There is just one particularity on my system and that is that I am not using
Docker to autostart services but rather systemd. So I wrote a short script to disable all of them
by launching systemctl with the service name. One thing I forgot though – would be nice to
still have portainer itself, so let me just restart that. I’ll stop it but leave it enabled –
that will be convenient once I have migrated the machine. Just taking note of the USB identifiers
on that machine such as the smart card reader, the satellite receiver and the UART which interfaces
with my central heating system over ebus. OK, good night old server. Shutdown. Cool, so now I have disabled
all services on my old system. This way I won’t run into situations that my
backup starts and possibly backs up data from the wrong location accidentally as soon as
I start the machine in the new environment. That enables me to start the services on
the new system in a controlled manner. Next - let’s convert the physical machine
to virtual and import it into ProxMox. And guys – this would be more or less exactly the
same on virtualbox or any other environment. First I need some additional disk space where I
can store the converted disk images to. I have a 5 TB USB Disk which I just quickly mount to a folder
on my linux PC. As you can see, I have roughly 2 Terrabytes available – that should do. The command
which I will use in order to convert the physical disk (which in my case is /dev/sde) is vboxmanage.
So my plan is to just output the content of the raw disk and pipe it over to vboxmanage with the
convertfromraw option. Now this option has two operating modes – one that reads a file and the
other which I want to use and that reads from the standard input. But for this I need to specify
the numbers of bytes because stdin has no end of stream marker. Launching fdisk on the old
disk tells me that number of bytes here. So I copy-pasted that value into the command line. And
here we go, here is my converted disk vdi file. Awesome, as you could see, converting a
physical disk to a virtual environment really requires no magic. It can be done very
easily. Now – this disk is quite big – it’s got 120 Gigabytes. On my proxmox Server I
have a 1 TB SSD but I don’t want to use up more than 10 % of the available space just or
this one disk. Also, only 30% of the disk are used – what I’m going to do is that I will
shrink it before I import it into proxmox I will do this in a virtual machine. I do not
want to mess up the original disk but rather stick to the golden rule number one of forensic
operations – and that is “Always work on a copy!”. I will first add the target disk. And in order
to save storage space that shall be a dynamically allocated VMDK disk. It shall of course be at
least as large as the original disk but as I will copy only the shrinked partition it should
not become larger than let’s say 40 gigabytes. I like to do that type of operations
with Knoppix. So what I do is that I add both disks to my virtual Knoppix machine. Once both disks are added, I can then start the
Knoppix VM. In Knoppix I use the graphical gnome front end to parted, which is gparted. Here I can
nicely resize the disk by just sliding the marker to the left or to the right. Once I confirm my
changes then gparted will launch all necessary tools in the background. It will align the blocks
at the beginning of the partition, then shrink the filesystem and then shrink the partition itself.
The second partition which I had deleted here was the swap partition. That can easily be
recreated. Great, the process is finished – launching parted quickly shows me that the first
and only partition on that disk is 42.6 Gigabytes in size. It is actually an MBR partition, so
it is not a GPT partition scheme. That means we need to use fdisk or sfdisk in order to now
copy the partition schema over to the new disk. Quickly checking the new disk shows
that there is no partition table yet. If you launch sfdisk with the d option then
it will dump the partition table of a harddisk and the nice thing is that this can be
piped over to sfdisk on a second disk and what this will do is that it copies the
partition table over from one disk to another. And tadaa – the second disk now has the
exact same partitions as the first one. Now we can copy the shrinked partition from
the first disk over to the same partition on the second disk. For this I use dd. Be extremely
careful with dd. It’s very easy to mess things up. Let’s monitor the progress on our host system
where we can now see the vmdk file grow. As predicted, it stops to grow at
roughly 40 Gigabytes even though it’s exactly the same logical disk size.
OK I think we’re done here with Knoppix. As I have showed you, you can shrink a disk
with an offline linux that you booted from a USB stick or that is running from an ISO in a
virtual environment. The process takes a long time – in my case it was nearly a day. But I
know that if I hadn’t done this then it would constantly nag me like “Why is this half
empty disk using so much space” – so I had to do it once and I’ll be good for a long time.
Great, next let’s import that disk into proxmox. I have already created a VM with the identifier
999 so now I can use the qm importdisk command. I am quite sure that I could as well just have
copied it over to the repository but – let’s go by the book. That again is a quite
lengthy task so let’s accelerate this a bit. Don’t you sometimes whish you could just
fast forward like this in real life ? Cool, the disk is listed in the hardware of the
Virtual machine and just needs to be attached. It was a SATA disk in the real world so
I’ll just keep that in the virtual world. All other values look OK so
I leave them as they are. That looks good. Next I just need to
make sure that the VM gets the hardware it expects such as the card reader and the dvb
satellite receiver which both are USB devices. Under Hardware – I click on the Add
button and select to add USB devices. With this I can pass through
the USB device directly and it will be presented to the VM as if it
were attached to it directly. Here we go. As we have just seen you can
easily map hardware devices directly to a virtual
machine. This works with USB, but it can also be done with PCI devices. Very
convenient. Great, let’s start the server. A brief quick check on the
parameters. They look good, so lets go – I start the VM and connect
to the console – and – it’s booting. Perfect. Quickly logging in with
the old root password works – great. Awesome, the server starts and everything
looks OK. Now let’s go to portainer and launch the docker containers in that
machine so that my services are back. In the new system I have just
checked the network configuration. Now let me see if the USB devices are ther. That
looks OK. So let me be optimistic and just start the first container which is my satellite TV
receiver. Let’s check with the KODI frontend. And – TV is OK. Perfect. I’ll do the
same with the other containers later. Cool, that’s it – we’re back in business
– file, backup and tv – all running again and I can now sell the old PC on
eBay – I don’t need it any more. Over time I can now migrate single services such
as the shinobi video surveillance system over to linux containers and hence integrate
them directly into the proxmox console. But – again – that will be
a separate episode. Guys, many thanks for watching, liking and
subscribing. Please leave a comment and share this video with others if you found it
useful. Stay safe, stay healthy, bye for now.