Turns out there was nothing, but it was in interesting exercise in converting a single disk partition into a VM - something that is not trivial.
I plugged my old drive into a USB hard disk docking station and had a look. It contained Windows XP and Linux from an old PC dating from 2004-2007 I believe.
"Hey!" I thought. I could virtualize this for no good reason and show how easy it is using free and open source software.
Ubuntu Packages
Create VirtualBox VM
- Select New
- Name your VM (say TEST)
- Select Windows and Windows XP
- Set memory size (default is ok)
- Select 'do not add a virtual hard drive' - we will create this later in tis VM's directory.
Create Virtual Disk Drive
#!/bin/bash
DISK=/dev/sdd
PART=1
printf "Copy boot sector image...\n"
sudo dd if=$DISK of=mbr.img bs=512 count=1 || { printf "FAILED\n"; exit 1; }
printf "Done\n"
# put 'normal' mbr incase grub or something was used
printf "Replace MBR code..."
sudo install-mbr mbr.img -t 36 || { printf "FAILED\n"; exit 1; }
printf "Done\n"
printf "Copy disk (%s) partition %d...(at 10MB/s 1GB will take 100s)...\n" "$DISK" $PART
PARTIMG=part${PART}.img
sudo dd if=${DISK}${PART} of=$PARTIMG bs=512 || { printf "FAILED\n"; exit 1; }
sudo chown $USER:$USER $PARTIMG
printf "Done\n"
printf "Make VirtualBox VMDK image with MBR...\n"sudo VBoxManage internalcommands createrawvmdk -filename ./disk.vmdk -rawdisk $DISK -partitions $PART -mbr ./mbr.img || { printf "FAILED\n"; exit 1; }
# VB needs this owned by user
sudo chown $USER:$USER disk-pt.vmdkprintf "Done\n"
# switch to partition image and zero starting offset
# eg.
# from this: RW 8514387 FLAT "/dev/sdd" 63
# to this: RW 8514387 FLAT "/home/phil/Development/pc-part2disk/part1.img" 0
printf "Modify VMDK files to use disk partition image...\n"
sudo cat disk.vmdk | sed "s@\"$DISK.*@\"./$PARTIMG\" 0@" > diskimage.vmdk
sudo chown $USER:$USER diskimage.vmdk
printf "Done\n"
# remove VB vmdk that points to physical drive - no longer required
sudo rm disk.vmdk
exit 0
Also, run chmod +x
Run my script.
It may take a while if you have budget hardware and a USB connected hard drive.
You will get some output like this:
phil@del:~/VirtualBox VMs/test$ ~/Development/pc-part2disk/pc-part2disk.bash
Copy boot sector image...
[sudo] password for phil:
1+0 records in
1+0 records out
512 bytes (512 B) copied, 0.00106311 s, 482 kB/s
Done
Replace MBR code...Done
Copy disk (/dev/sdd) partition 1...(at 10MB/s 1GB will take 100s)...
8514387+0 records in
8514387+0 records out
4359366144 bytes (4.4 GB) copied, 292.02 s, 14.9 MB/s
Done
Make VirtualBox VMDK image with MBR...
RAW host disk access VMDK file ./disk.vmdk created successfully.
Done
Modify VMDK files to use disk partition image...
Done
If you ls -la, you should see some new files:
phil@del:~/VirtualBox VMs/test$ ls -la
total 4257296
drwxr-xr-x 2 phil phil 4096 Jan 12 17:41 .
drwxr-xr-x 6 phil phil 4096 Jan 12 17:30 ..
-rw-r--r-- 1 phil phil 650 Jan 12 17:41 diskimage.vmdk
-rw------- 1 phil phil 64512 Jan 12 17:41 disk-pt.vmdk
-rw-r--r-- 1 root root 512 Jan 12 17:36 mbr.img
-rw-r--r-- 1 phil phil 4359366144 Jan 12 17:41 part1.img
-rw------- 1 phil phil 6190 Jan 12 17:32 test.vbox
-rw------- 1 phil phil 6087 Jan 12 17:32 test.vbox-prev
- test* files are you VB VM config files.
- mbr.img is your virtual disk MBR (probably not needed anymore).
- partX.img is an image of your windows (in this case) partition.
- disk-pt.vmdk seems to be your new MBR, partition table and possibly 60-odd sectors pulled from your hard disk.
- diskimage.vmdk is a vmdk definition file that makes a virtual hard drive from all these bits.
Add Virtual Disk Drive to VM
- Edit settings on your VM again.
- Under Storage, select your IDE controller, and add and attachment.
- Add a hard disk and select 'choose and existing disk'
- Select your diskimage.vmdk file.
- Power on your VM.
It will eventually display MBR (and possibly some characters) but after 2 seconds it should start booting your Windows XP VM.
For me, once I clicked into VM's window, it took XP about 2 minutes to workout how to use my keyboard and mouse so you need to wait.
Later you can install VB guest additions and things should work better.
No comments:
Post a Comment
Please use family friendly language.