formats

Raw Disk Access with Virtualbox

Published on June 26, 2010, by + in linux.






How can I use Virtualbox to access a raw hard disk?

First, make sure drive is connected and not mounted.
Also, make note of the drive location either by issuing dmesg or using the Ubuntu System > Administration > Disk Utility. In my case, it’s /dev/sde .

Then issue this single command:

 sudo VBoxManage internalcommands createrawvmdk -filename ~/rawdisk.vdi -rawdisk /dev/sde -register



^Note: as of Virtualbox 4.x, there is no need to issue -register at the end.

This will output the following in the terminal:


Oracle VM VirtualBox Command Line Management Interface Version 3.2.6

(C) 2005-2010 Oracle Corporation

All rights reserved.

RAW host disk access VMDK file /home/user/rawdisk.vdi created successfully.


Due to the nature of having raw disk access, you must start virtualbox with sudo (Eek!). (Of course you should not normally do this.)

Next, start virtualbox with sudo:

sudo VirtualBox



Now make a new machine as DOS for example, if you are using any various hard drive utilities. At the Virtual Hard Disk step, choose the rawdisk.vdi you created.


01vboxraw_edit

I’m going to scan this drive with spinrite, for an example of what you could do with raw disk access!

02vboxraw_edit
spinrite doing its magic

Done!

7 Responses

  1. John

    I am surprised that no one else has commented on this post.
    I am curious about how well you have found this to work.
    This is the exact scenario that I am currently planning to configure.

    - VirtualBox running under Ubuntu 10.10
    - SpinRite Guest booting via ISO image
    - Direct Access to HDD Hardware Devices connected via IDE, SATA/ESATA and SAS

    I am planning to buy a dedicated machine for running multiple virtualized SpinRite Guests in tandem (on discrete devices of course).
    My main point of concern comes from the host OS. I want the VM to have a lock on the whole device, if that is possible.
    I do not want the Host OS to interfere with SpinRite disk operations.

    What would be the best way to go about ensuring that the Host OS merely serves the device to the Guest?
    Can I disallow all other processes from polling this device while it is assigned to a Guest OS?
    Does SpinRite have complete access and control of the disk in this scenario, to the degree that all of it’s DynaStat Tricks are as effective as they can be?

    I will be using this setup to run nearly continuous maintenance and recovery operations on my many many drives.

    Any insight that you have on this scenario would be much appreciated.

  2. scott
    Twitter:

    Yep – The whole process involves an umounted hard disk – your host OS will not touch it.

    What I have noticed is through virtualbox (or also vmware with raw access) it does not send smart monitoring, but all else works as normal with spinrite.

    Spinrite seems to run much slower via this method vs booting spinrite natively to a bare disk, if that matters.

    Also try out vmware which can do raw disk access as well,

  3. John

    Performance will be critical, since spinrite can potentially take days or weeks to solve the toughest cases.
    I wonder if VMware maps this any faster?

    The lack of SMART reporting does bother me.
    It means that VBox isn’t really getting raw hardware access, which is to be expected when I think about it.

    I may attempt a XenServer implementation, being a Type1 Hypervisor it would have the potential at least to provide true direct hardware access.
    Still though, this is an excellent fallback implementation and it’s good to know that SpinRite will at least perform it’s primary functions in this mode.

    Thanks for the response, as I dig deeper I will post back what I find, since this is one of the most direct answers to my search that I have found yet.
    Now off to read some of your other stuff :)

  4. ChrisNova777

    Im very interested in this. I just had the idea, as im sitting here with a few laptops behind me running spinrite to try to breathe some life into a few old backup drives… it ocurred to me, i have more then one usb device, and surely its not that processor intensive.. isnt there a way for me to run more then one spinrite instance on the same laptop or pc as we all know it takes a few days upward to a week to go through a modern sized disk with spinrite.

    Would this be possible under windows or osx? or only in linux? id love to have a usb flash drive with a micro linux install booting up to run multiple instances of spinrite on a given machine, hard drive infirmary v1.0;)

  5. scott
    Twitter:

    Yep you can create as many instances of this as you want.

    But use caution – doing hard disk and other actions over USB may be iffy. Hard drives typically need a native IDE or similar connection to talk to the recovery software (or with spinrite the bios) which USB does not offer.

    I believe virtualbox command utilities are cross platform but I’ve only done this in Linux.

    http://www.virtualbox.org/manual/ch08.html

  6. Serge

    Just in case anyone else comes across this, I’ve successfully got this working from Windows with little trouble. The only real difference being the way the target disk is specified (\\.\PhysicalDisk1 vs /dev/sda2) and the ‘-register’ option is not valid for v4.1.4 of the VBoxManage app. The number of the PhysicalDisk can be easily determined by looking at the ‘Disk Management’ console.

    And, yes, it’s slow.

    • Serge

      Sorry, I should have added that I was specifically looking for a virtualized SpinRite solution.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.

Home linux Raw Disk Access with Virtualbox