Yes. set your CD in the VM to a linux distro iso like Linux, set boot from the CD in the vm, then you can use all the tools on your ISO to do whatever you want to the vm.
Linux
From Wikipedia, the free encyclopedia
Linux is a family of open source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991 by Linus Torvalds. Linux is typically packaged in a Linux distribution (or distro for short).
Distributions include the Linux kernel and supporting system software and libraries, many of which are provided by the GNU Project. Many Linux distributions use the word "Linux" in their name, but the Free Software Foundation uses the name GNU/Linux to emphasize the importance of GNU software, causing some controversy.
Rules
- Posts must be relevant to operating systems running the Linux kernel. GNU/Linux or otherwise.
- No misinformation
- No NSFW content
- No hate speech, bigotry, etc
Related Communities
Community icon by Alpár-Etele Méder, licensed under CC BY 3.0
Your idea is correct, but I don't know how to do this in Wndows (while this is pretty simple in linux). However I want to warn you that if the partition that you are dumping is used by the OS, the resulting image will most likely be corrupted. Better use a linux live system and ensure that the partition is not mounted.
What you're trying to do is called a P2V (Physical to Virtual). You want to directly copy the partition as going through a file share via Linux will definitely strip some metadata Windows wants on those files.
First, make a disk image that's big enough to hold the whole partition and 1-2 GB extra for the ESP:
qemu-img create -f qcow2 YourDiskImageName.qcow2 300G
Then you can make the image behave like a real disk using qemu-nbd:
sudo modprobe nbd
sudo qemu-nbd -c /dev/nbd0 YourDiskImageName.qcow2
At this point, the disk image behaves like any other disk at /dev/nbd0
.
From there create a partition table, you can use cgdisk
or parted
or even the GUI GParted will work on it.
And finally, copy the partition over with dd
:
sudo dd if=/dev/sdb3 of=/dev/nbd0p2 bs=4M status=progress
You can also copy the ESP/boot partition as well so the bootloader works.
Finally once you're done with the disk image, unload it:
sudo qemu-nbd -d /dev/nbd0
I wasn't expecting a Step-by-Step, amazing, Thanks for your effort!
Metadata is something I would've never thought of but besides that seems like my guess wasn't that far off which im happy for
I also wanted to put an emphasis on how working with virtual disks is very much the same as real ones. Same well known utilities to copy partitions work perfectly fine. Same cgdisk/parted and dd dance as you otherwise would.
Technically if you install the arch-install-scripts
package on your host, you can even install ArchLinux into a VM exactly as if you were in archiso with the comfort of your desktop environment and browser. Straight up pacstrap
it directly into the virtual disk.
Even crazier is, NBD (Network Block Device) is generic so it's not even limited to disk images. You can forward a whole ass drive from another computer over WiFi and do what you need on it, even pass it to a VM boot it up.
With enough fuckery you could even wrap the partition in a fake partition table and boot the VM off the actual partition and make it bootable by both the host and the VM at the same time.
Learning to use QEMU I started to grasp those possibilities actually, now getting these tips I do feel like I could dive into lots of "sandboxing" and generally be able to try anything with it, my only constrain now shall be disk space
It's called physical-to-virtual, or p2v. Proxmox uses qemu under the hood, so you should be able to start from their docs to create the VM: https://pve.proxmox.com/wiki/Advanced_Migration_Techniques_to_Proxmox_VE
Here be dragons. But basically:
-
Run a VM from contents of a physical disk: use ’dd’ to create disk image. If on linux, try to boot and fix all the errors, hopefully few.
-
Run VM as physical machine: other way around.
You won’t find this in a tutorial. You need to understand concepts, read manuals, fit everything together, execute, fail and retry until it works.
For Windows, I have no idea. Conceptually, I figure it’s similar.
The Host is Linux (arch, btw) so just the guest would be Windows and im ready to squash errors too, so thanks for the heads up