VirtualBox Raw Disk needs Root Access [solved]

Questions about virtualization software
Forum rules
Before you post please read how to get help
Post Reply
User avatar
lewtwo
Level 3
Level 3
Posts: 143
Joined: Wed Oct 29, 2014 8:33 pm

VirtualBox Raw Disk needs Root Access [solved]

Post by lewtwo » Tue Oct 30, 2018 7:41 am

I have a somewhat unusual setup. I am building a machine to 'ween' my friend off of Windows. It is dual (triple) boot with Windows 7 and Linux Mint 19 (Mate user interface). Hardware:
HP 8300 Small Form Factor, I5-3470, 8 Gbytes Ram with a SSD for the Operating systems.
There is an additional drive for the user data and a third for backups.

The first hard drive is divided into two partitions with Windows 7 X64 installed on the first primary partition which is of course NTFS. After the Windows 7 was fully installed updated, defragmented, consolidated and operating normally: I saved a copy of the Master Boot Record to a file: "Win7X64.mbr". Then I installed Linux Mint 19 on a second primary partition which is formatted as EXT4. Standard Grub boot with both "Linux Mint 19 Tara" and "Windows 7" as menu options for grub.

I chose to use VirtualBox because it can run the Windows guest OS in "seamless" mode so that the Windows applications appear to be running on the Mate Desktop. Oral VirtualBox 5.2.20 was installed on Linux Mint along with the Oracle VirtualBox extension pack. Then I made a vdmk file to point to the first partition of the disk drive:
sudo VBoxManage internalcommands createrawvmdk -filename "win7x64.vmdk" -rawdisk /dev/sda -partitions 1 -mbr "win7x64.mbr" -relative

I can now run the Windows 7 OS inside VirtualBox or Boot that same Windows 7 OS from the grub menu (I had read that this could not be done --- it can). There is a bit of a performance hit for the VM mode:
PCMark7 Comparel.PNG
So here is the RUB:
In order for VirtualBox to access the raw disk it has to be run as root. With the loss of gksudo that means opening up a terminal window and running the command:
sudo virualbox --startvm Win7Test

That leaves two extra windows/tabs on the desktop/menu bar: One for the terminal window and the other for the virtualbox gui. I am tring to figure out how to launch the virtualbox gui without resorting to using a terminal window.
Last edited by lewtwo on Tue Oct 30, 2018 8:39 am, edited 3 times in total.
"Engineering is the art of planning and forethought."
http://www.keywild.com

User avatar
lewtwo
Level 3
Level 3
Posts: 143
Joined: Wed Oct 29, 2014 8:33 pm

Re: VirtualBox Raw Disk needs Root Access (Triple Boot)

Post by lewtwo » Tue Oct 30, 2018 7:53 am

Thought I would explain the third drive and the reference to Triple boot.

The third drive "sdc" is an old 3.5 inch Western Digital 1.5 Tbyte hard disk. It has a 40 Gbyte ext4 partition with Ubuntu 18.04 Mate "minimal install". The rest of the disk is a LARGE ext4 partition labeled "BACKUPS". This OS is there so "dd" can be used to make backups of the two OS partitions on the first hard disk "sda". A third entry was added to the Grub boot menu: 'Backup System'.
"Engineering is the art of planning and forethought."
http://www.keywild.com

gm10
Level 13
Level 13
Posts: 4599
Joined: Thu Jun 21, 2018 5:11 pm

Re: VirtualBox Raw Disk needs Root Access

Post by gm10 » Tue Oct 30, 2018 8:19 am

lewtwo wrote:
Tue Oct 30, 2018 7:41 am
That leaves two extra windows/tabs on the desktop/menu bar: One for the terminal window and the other for the virtualbox gui. I am tring to figure out how to launch the virtualbox gui without resorting to using a terminal window.
Several ways this can be done. My suggestion would be to run my little script here:

Code: Select all

mkdir -p ~/.local/bin;echo -e "#/bin/sh\n"'/usr/bin/pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY HOME=$HOME "$@"' > ~/.local/bin/gksudo;chmod u+x ~/.local/bin/gksudo
This will create a gksudo command that works like sudo but supports GUI programs (you should avoid using sudo for that).

Then you can edit the vbox launcher in the menu (right click > edit) and prefix the command with gksudo.

User avatar
lewtwo
Level 3
Level 3
Posts: 143
Joined: Wed Oct 29, 2014 8:33 pm

Re: VirtualBox Raw Disk needs Root Access

Post by lewtwo » Tue Oct 30, 2018 8:38 am

Thank Thee :D :D :D
As I already had the bin directory I just created a file with those lines in it.
#/bin/sh
/usr/bin/pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY HOME=$HOME "$@"


Now the command for the Virtual Box Desktop Icon reads:
/home/jack/bin/gksudo.sh VirtualBox %U

The window for the terminal no longer appears.
Thank Thee :D :D :D

Next task is to redirect Users folders (Documents, Downloads, Music, Pictures, Videos) to the same location for both operating systems.
Win7 On Linux.jpg
Last edited by lewtwo on Tue Oct 30, 2018 8:51 am, edited 1 time in total.
"Engineering is the art of planning and forethought."
http://www.keywild.com

gm10
Level 13
Level 13
Posts: 4599
Joined: Thu Jun 21, 2018 5:11 pm

Re: VirtualBox Raw Disk needs Root Access

Post by gm10 » Tue Oct 30, 2018 8:49 am

lewtwo wrote:
Tue Oct 30, 2018 8:38 am
As I already had the bin directory I just created a file with those lines in it.
My script accounted for that (mkdir's -p parameter), but I'll never object to someone taking it apart rather than running it blindly! :)
lewtwo wrote:
Tue Oct 30, 2018 8:38 am
Next task is to redirect Users folders (Documents, Downloads, Music, Pictures, Videos) to the same location for both operating systems.
Move them all to the NTFS partition then for each of them

Code: Select all

ln -s /source ~
with /source being the full path to the folder on the ntfs partition.

User avatar
lewtwo
Level 3
Level 3
Posts: 143
Joined: Wed Oct 29, 2014 8:33 pm

Re: VirtualBox Raw Disk needs Root Access [solved]

Post by lewtwo » Tue Oct 30, 2018 3:17 pm

So I hit my GOTCHA! :roll:

I can point both Windows and Linux to new locations for the users files but VB/Windows may or may not write the changes until it shuts down. So the linux OS will not see the changes. I can get round that problem by using VirtualBox's shared folders but that would kind of leave the Windows 7 boot option missing its target folders.

So yee old compromise is going to have to be VirtualBox's shared folders and tell the user wants both systems to be able to access the data then he is going to have to put the files there .... and the files will NOT be available when Windows 7 is booted.

I can not see anyway round this without using a network server which defeats the use scenario in this case.
"Engineering is the art of planning and forethought."
http://www.keywild.com

Post Reply

Return to “Virtualization”