Raw Disk Access with Virtualbox

By | 2010/06/26

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

^Note: In older pre-Virtualbox 4.x, tack on -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!

10 thoughts on “Raw Disk Access with Virtualbox

  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.

    Reply
  2. scott Post author

    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,

    Reply
  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 🙂

    Reply
  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;)

    Reply
    1. tom

      Once I virtualized Linux in Windows via VirtualBox and Linux ran from partition of Windows host’s disk.
      With careful config it was possible to boot this Linux during computer boot as well.

      Reply
  5. scott Post author

    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

    Reply
  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.

    Reply
    1. Serge

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

      Reply
  7. PavelNL

    Contrary to both, I have a good experience running SR6 via VB VM raw disk method.
    First, it is the only way to do it on Apple hardware up to date. Since Steve still promising the SR6.1 version, but it is not yet (as of beginning 2016) available.
    Secondly, I’ve re-used old Atom-based HTPC for SR6 and was fighting with BIOS setting for quite some time to get it working.
    The author himself recommended to use VMs because current version via BIOS is pretty slow anyway and could get advantage of modern OS (I prefer Linux or OSX) to access disks faster.
    Finally, speed is not critically slower in most of cases, but sometimes IMO faster.
    Regards, PavelNL

    Reply
  8. Richard

    Thank you for the instructions. I have not had the need to run SpinRite in a VM often, and get a little forgetful just how to do it. I used to keep a derelict e-Machine around just to SpinRite drives, but I find myself more often run SpinRite against USB devices, SD and Micro-SD cards. Thanks again.

    Reply

Leave a Reply

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

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