Accessing a physical hard drive in VirtualBox on openSUSE Tumbleweed requires creating a VMDK wrapper file via the command line, as the GUI does not support direct device selection. This method allows your virtual machine to read and write directly to the disk partition while maintaining proper permissions through udev rules.
Understanding Raw Disk Access
VirtualBox provides a feature called "raw disk access" that lets a virtual machine interact with a physical block device rather than a virtual disk image. This is particularly useful for testing operating systems installed on separate partitions or for benchmarking storage performance without the overhead of file system emulation. However, this approach carries significant risks. If the virtual machine writes to the wrong sector, it can corrupt the host system or other guest OS installations. Therefore, strict isolation and correct permission handling are mandatory before starting any configuration. On openSUSE Tumbleweed, which uses systemd and udev, managing these permissions is more robust than simple manualchmod commands. The key challenge is that VirtualBox needs read-write access to the raw device node, typically located at /dev/sdXN, but standard user accounts do not have these privileges by default. Attempting to run VirtualBox as root is insecure and often fails due to sandbox restrictions. Instead, we will use a combination of a VMDK wrapper and a persistent udev rule.
Creating the VMDK Wrapper File
The first step is to create a small descriptor file that tells VirtualBox how to interpret the raw disk. You cannot select the raw disk directly from the VirtualBox Manager interface. You must use theVBoxManage utility available in your terminal. First, identify the target partition using lsblk. For example, if you want to attach the second partition of the first SATA drive, it might be /dev/sdb2.
Run the following command to generate the wrapper:
VBoxManage internalcommands createrawvmdk \
-filename /path/to/your/disk.vmdk \
-rawdisk /dev/sdb2 \
-partitions 2
This command creates a .vmdk file that acts as a pointer to the physical partition. Note the use of the -partitions flag; this ensures that only the specified partition is exposed to the VM, preventing accidental access to the entire disk structure which could cause boot failures or data corruption. Replace /path/to/your/disk.vmdk with an absolute path where you have write permissions, such as your home directory or a dedicated VMs folder. The -rawdisk parameter must point to the exact block device node.
Configuring Permissions with Udev Rules
Simply creating the VMDK file is not enough. When you add this file to your VM settings, VirtualBox will attempt to open the underlying/dev/sdb2 device. Without proper permissions, this operation will fail with an I/O error. On openSUSE, relying on temporary ownership changes is fragile because they reset after reboots or device replugging. A permanent solution involves creating a udev rule.
Create a new file in /etc/udev/rules.d/, for example, 99-virtualbox-rawdisk.rules. Add a line that matches your specific device and grants access to the group running VirtualBox, typically vboxusers.
SUBSYSTEM=="block", KERNEL=="sdb2", GROUP="vboxusers", MODE="0660"
After saving this file, reload the udev rules using:
sudo udevadm control --reload-rules
sudo udevadm trigger
This ensures that every time the kernel detects /dev/sdb2, it automatically assigns the correct group and permissions. Verify the change by checking the properties of the device node with ls -l /dev/sdb2; the group should now show as vboxusers and the mode as rw-r-----.
Attaching the Disk to Your VM
Now that the wrapper and permissions are set, you can configure the virtual machine. Open the VirtualBox Manager, select your VM, and go to Settings > Storage. Under the Storage Tree, click the empty optical drive icon or add a new controller if necessary. Click the disk icon next to "Controller: IDE" (or SATA) and choose "Add Hard Disk." Browse to the.vmdk file you created earlier.
Select the wrapper file. VirtualBox will recognize it as a linked raw disk. Ensure the controller type matches your VM's architecture. For modern setups, SATA is preferred over IDE for performance. Once added, start the VM. If configured correctly, the guest operating system will see the physical partition as a local disk.
For networking considerations, if your VM also requires internet access, refer to our guide on VirtualBox Guest with NAT and DHCP for Windows Networking to ensure network connectivity does not interfere with disk operations.
Safety and Troubleshooting
Always double-check the device path before attaching. Attaching/dev/sda instead of /dev/sda1 can overwrite partition tables. If the VM fails to boot or reports disk errors, check the VirtualBox log file for I/O errors. These usually indicate a permission mismatch or an incorrect device path.
If you need to manage snapshots for this setup, note that raw disks do not support traditional snapshotting in the same way VDI files do. You may need to rely on external backup strategies. For managing standard virtual disks, see our article on Shrinking a Snapshot of a VDI in VirtualBox for best practices on disk maintenance.
Frequently Asked Questions
Can I use the VirtualBox GUI to select a raw disk?
No, the graphical interface does not allow direct selection of Linux block devices like/dev/sdX. You must create a VMDK wrapper file using the VBoxManage command-line tool and then attach that wrapper file through the GUI.
What happens if I lose power during a raw disk write?
Raw disk access bypasses the file system cache of the host OS. Sudden power loss can lead to data corruption in both the host and the guest file systems. It is highly recommended to use a UPS or ensure stable power conditions when performing heavy I/O operations on raw disks.How do I detach the raw disk safely?
You do not need to unmount anything inside the guest. Simply shut down the VM normally. Then, remove the disk from the VM settings in VirtualBox. To revoke permissions, you can either remove the udev rule or change the group back todisk or root depending on your security policy.
Does this work with LUKS encrypted drives?
Yes, but the encryption must be unlocked on the host before VirtualBox can access the raw device. VirtualBox sees the decrypted block device. If the drive is encrypted on the guest side, the VM will handle decryption independently, provided the host has access to the raw block device.Why does my VM report "I/O Error" even with correct permissions?
This often occurs if the device is mounted by the host OS. VirtualBox requires exclusive access to the raw block device. Ensure that no partitions from the target disk are mounted in openSUSE Tumbleweed before starting the VM. Useumount /dev/sdXN if necessary.