I had a client who needed to keep an application that was running on her old Windows 10 laptop. This application could not be re-licensed on her Windows 11 laptop. The aim is to convert the hard drive (actually a 500GB SATA 2.5 inch SSD) into a virtual machine on her new laptop.
The first step was to image the source device using dd. The target image is a file on a 3TB hard drive. To do this I booted the client's old laptop using an Ubuntu 24.04.1 LTS live USB stick and used a USB dock to mount the target 3TB archive drive.
# dd if=/dev/nvme0n1 of=/mnt/archive/disk-images/bev/laptop.img bs=1M
A couple hours later I have a 500GB laptop.img file of the client's laptop.
After completing the raw image and shutting down the source laptop, I moved the 3TB drive into my linux desktop and booted it up. I copied the laptop.img file to a file on a 1TB SSD in the desktop then used vboxmanage to convert to a dynamic vdi.
# vboxmanage convertfromraw laptop.img laptop.vdi
Several hours later I have a 189GB laptop.vdi file.
I created a virtualbox machine with similar settings to the original laptop: 4 CPUs, 8GB RAM, etc. It is important to enable EFI boot in System->Motherboard->Extended Features. Add a SATA controller and add the laptop.vdi file as a storage device. Also add an optical device so we can mount vboxguesadditions.
If necessary, change the owner of the laptop.vdi file so it's the same as the user running virtualbox.
Boot the system. It works but is very slow.
Install vboxguestadditions.
Go to Settings->System->Advanced System Settings->Advanced->Performance Settings. Disable everything except "Smooth edges of screen fonts".
Remove all the software that we don't need. Remove user files that we don't need. Reboot several times. The system will gradually get faster.
In the virtual machine, run Disk Cleanup to get rid of unnecessary files.
In the virtual machine, in C: drive properties, Tools tab select Optimize. Optimize and defrag the drive. This might take several hours.
In the virtual machine download sdelete from sysinternals and run it in a cmd window with admin privileges.
sdelete c: -z
Several hours later, when sdelete has completed, shutdown the virtual machine then run this command on the host:
# vboxmanage modifymedium --compact laptop.vdi
Again, a long wait but not as long as some of the other stuff. Now my laptop.vdi file is only 89GB.
In the host, using the virtualbox GUI, export the virtual machine to an ova file on a USB drive for transfer to the client's computer.