Wednesday 13 April 2022

Howto make Virtual Machines running in VirtualBox using Physical Partitions on OS-X

(very old draft - may not be complete)

My goal is to run Linux on my new MacBook Pro 9,1.

Whilst I can sort-of can run Linux, it is not really usable until all this new hardware is understood and drivers built to manage it.

So, next best is to run Linux in a VM. I like FOSS so I will use VirtualBox.

Unfortunately, this seems hard to do, so I have document my approach for others to improve upon.

Requirements

1. Run Linux in a VM using VirtualBox running on OS-X

2. Use real/physical disk partitions so that when this laptop is better supported, I will be able to boot into these physical partitions and drop my VirtualBox and OS-X layers

Procedure 

Before proceeding, you need to understand that if you or I make a mistake, OS-X partitions, EFI partitions, and any other recovery data on our hard drives could be lost or a pain to recover.

Your setup is likely to be different to mine so don't simply copy my detail and expect your system to work.

I have re-partitioned my hard drive as follows:


rex:~ phil$ diskutil list
/dev/disk0
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *500.1 GB   disk0
   1:                        EFI                         209.7 MB   disk0s1
   2:                  Apple_HFS Macintosh HD            70.0 GB    disk0s2
   3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3
   4: 21686148-6449-6E6F-744E-656564454649               200.0 MB   disk0s4
   5:       Microsoft Basic Data                         20.0 GB    disk0s5
   6:       Microsoft Basic Data                         20.0 GB    disk0s6
   7:       Microsoft Basic Data                         350.0 GB   disk0s7
   8:                 Linux Swap                         19.8 GB    disk0s8

Partition 1 is my EFI partition - I don't want to touch this.
Partition 2 is my shrunk OS-X partition - again, I'd like to keep this in good working order.
Partition 3 is OS-X recovery files - probably a CD/DVD image that I also need to keep safe.
Partition 4 is something that OS-X disk manager created - I'll leave that alone too.
Partition 5 already has a mostly-working Linux root file system - I don't want to mess with this.
Partition 6 will be my new Virtual Machine root file system (and possibly swap area).
Partition 7 already is formatted ext4 and has my /home file system - I want to keep this.
Partition 8 is a Linux swap area I will look at using a bit later.


So, I only want to work with Partition 6 and 7.


rex:phys phil$ ls -la /dev/disk0*
brw-r-----  1 root  operator   14,   0 22 Jul 19:47 /dev/disk0
brw-r-----  1 root  operator   14,   2 22 Jul 19:47 /dev/disk0s1
brw-r-----  1 root  operator   14,   1 22 Jul 19:47 /dev/disk0s2
brw-r-----  1 root  operator   14,   3 22 Jul 19:47 /dev/disk0s3
brw-r-----  1 root  operator   14,   4 22 Jul 19:47 /dev/disk0s4
brw-r-----  1 root  operator   14,   5 22 Jul 19:47 /dev/disk0s5
brw-rw-rw-  1 root  operator   14,   6 26 Jul 22:37 /dev/disk0s6
brw-rw-rw-  1 root  operator   14,   7 26 Jul 21:51 /dev/disk0s7
brw-r-----  1 root  operator   14,   8 22 Jul 19:47 /dev/disk0s8

So that VirtualBox can access these partitions, I ran these commands to give everyone read and write access:

sudo chmod a+rw /dev/disk0s6
sudo chmod a+rw /dev/disk0s7

Note: I suspect that after a reboot, I will need to re-run these commands - I'll solve that later.

Create a new VM in VirtualBox.

I called mine phys, and told VB it will hold a 64-bit version of Ubuntu.
I gave it 2048 MB RAM, and told it not to worry about a start-up disk.

I now have a ~/VirtualBox/phys folder for this VM.

cd ~/VirtualBox/phys

VirtualBox needs a VMDK file to tell it how to manage each of these partitions.

sudo VBoxManage internalcommands createrawvmdk -rawdisk /dev/disk0s6 -filename d0s6.vmdk
sudo VBoxManage internalcommands createrawvmdk -rawdisk /dev/disk0s7 -filename d0s7.vmdk

Since these new files are owned by root, I ran chown to fix this - you would use your own account name here:

sudo chown phil:staff d0s6.vmdk
sudo chown phil:staff d0s7.vmdk

This makes 2 VMDK files in my current VM directory.


rex:phys phil$ ls -la
total 56
drwxr-xr-x  8 phil  staff   272 26 Jul 21:31 .
drwxr-xr-x  7 phil  staff   238 26 Jul 22:44 ..
-rw-r--r--  1 phil  staff   153 23 Jul 01:21 HOWTO.txt
drwx------  6 phil  staff   204 26 Jul 21:32 Logs
-rw-------  1 phil  staff   633 26 Jul 22:47 d0s6.vmdk
-rw-------  1 phil  staff   634 26 Jul 21:50 d0s7.vmdk
-rw-------  1 phil  staff  7524 26 Jul 21:31 phys.vbox
-rw-------  1 phil  staff  7524 26 Jul 21:28 phys.vbox-prev

Now I added these two physical disk descriptions to my VM.


You do this in Settings - Storage, select SATA, click 'Add Attachment' icon, select Hard Disk, and select your VMDK file. I did this for each VMDK file.

You will also need to add your Linux distribution ISO either using a real CD/DVD or using an ISO stored on your file system somewhere.

Don't forget to make your VM boot from CD/DVD first.

I have been terse here since those actions should be known by anyone who is experienced at creating VMs in VirtualBox.

You can make other changes to your VM if you like, or you can do it later.

You can now boot your VM.

This is where I ran into problems: I could not get Ubuntu to format my d0s6.vmdk partition during install. Instead, I ran Ubuntu's live CD and launched Ubuntu's Disk Utility. It showed 2 disks as expected. I added a GUID partition table to d0s6.vmdk, created a 4000 MB swap partition and a 16 GB ext4 root file system. I then formatted the file system.

Now I installed Ubuntu: I told it to use the swap partition, and to use my 16 GB partition for root. To do this I told Ubuntu NOT to format it again since I formatted it earlier.

I also told Ubuntu to use my existing home drive and again, to NOT format it since I want to keep its data.

My install took hours, so be patient.





No comments:

Post a Comment

Please use family friendly language.