Accessing Raw Partitions in Virtualbox
I just wanted to resize an NTFS partition in Linux just to realize, that gparted had some problems resizing. Maybeit was an unclean unmount or a necessary chkdisk session. who knows.
The solution I had in mind was to simply "mount"; the partition inside a Windows 7 VM running in Virtualbox. Giving Windows 7 raw access to the partition should enable it to do its Windows NTFS specific stuff and even resize the partition for me.
First of all: enable read/write operations on the partition for my "normal"; user (because this is where VirtualBox will get its privileges from)
1 |
$ sudo chmod 777 /dev/sda3 |
After that, simply use the "VBoxManage"; utility (pay attention to the capitalization) utility to create a vmdk file pointing to the partition:
1 |
VBoxManage internalcommands createrawvmdk -filename /ntfs.vmdk -rawdisk /dev/sda -partitions 3 -relative -register |
This will create a file called ntfs.vmdk (and a ntfs-pt.vmdk) that point to the /dev/sda3 partition (which is the NTFS partition in question) and register it within the virtualbox harddisk manager thingy
The resulting vmdk file will probably look something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
$ cat WinHD.vmdk # Disk DescriptorFile version=1 CID=108af78c parentCID=ffffffff createType="partitionedDevice" # Extent description RW 63 FLAT "WinHD-pt.vmdk" RW 157581522 ZERO RW 551109825 FLAT "/dev/sda3" RW 63 FLAT "WinHD-pt.vmdk" 63 RW 265377672 ZERO RW 63 FLAT "WinHD-pt.vmdk" 126 RW 2698857 ZERO RW 5103 ZERO # The disk Data Base #DDB ddb.virtualHWVersion = "4" ddb.adapterType="ide" ddb.geometry.cylinders="16383" ddb.geometry.heads="16" ddb.geometry.sectors="63" ddb.uuid.image="d22d1f60-8f49-4050-94b4-ac427899a2e2" ddb.uuid.parent="00000000-0000-0000-0000-000000000000" ddb.uuid.modification="70447f47-959f-4ccd-a9a3-a0c1b699dd85" ddb.uuid.parentmodification="00000000-0000-0000-0000-000000000000" ddb.geometry.biosCylinders="1024" ddb.geometry.biosHeads="255" ddb.geometry.biosSectors="63" |
Next thing to do: Then simply add the created new vmdk image to your VM in question. This can be done via GUI or on the commandline:
1 |
VBoxManage modifyvm win7 --hdb /home/marc/WinHD.vmdk |
After doing that, you should be able to simply boot your VM and have chkdsk/whatever do it's magic.
p.s. as usual: this could destroy your partitions yadda yadda yadda