DEV Community

Margai Wangara(he/him)
Margai Wangara(he/him)

Posted on

Setting up macOS on a Partition of your Linux Machine

So, woke up this morning, checked my LinkedIn account, and, the most amazing thing happened. Someone had posted a solution to a problem I have been having for a long time, and it was awesome. Being a once in a while mobile apps developer, I always looked for ways to be able to test my hybrid React Native apps on an iPhone device to no avail. Basically, unless you have a macOS, or an iPhone, good luck testing your app. This always led to issues, like the well-known Internet Explorer explorer issues, whereby your app looks great on Chrome and Firefox but when you it check out Internet Explorer it looks like the app went to hell and came back.

Based on the post, one can use sosumi to run macOS on their Linux machines. So, I embarked on a journey to try and figure out how I can pull this off. I then came across this article by Logix on the Linux Uprising blog, which provides an awesome step by step guide on getting the stuff running on one's machine. I definitely suggest a read. While trying out the steps, I hit a snag, kind of a big one, my machine did not have enough space for a complete installation. I however had different partitions with enough space to accommodate the installation. The problem though, is that I didn't know how to install it in a different partition. Then came a comment by Hikmat E Ustad, providing an alternative way to install from a YouTube video he created. The video can be found here.

The video did not provide a solution to my problem but after contacting him(basically wrote a comment), he directed me to a link which provided me a with a starting point. That is when the fun started.

Creating a Virtual Drive

  1. To create a virtual drive, search and open virt-manager on your Linux OS, I use Ubuntu so it was already installed.
  2. We then add the disk to the KVM Storage pool via virt-manager. To create a new VM, on the menu bar, click on edit, then choose "Connection Details".
  3. Open the "Storage" tab then click the green + button on the far bottom left. On the popup window, write the Name, then on the Type dropdown choose dir: Filesystem Directory, on the Target Path, click the Browse button on the right.
  4. The File Explorer will popup and you have to select a location as your target. This is where we select the partition we want.
  5. To select a partition, click on + Other Locations on the left sidebar of the file explorer window. You will then see the list of all your partitions, normally with a /dev/<some name> on the right. Mine was /dev/sdb2. Click on the partition to mount it then you can create a folder inside and set the folder as your target path. You can then click the green button on the top-right of the window. The most important part is getting the path to the partition, this can be found once you click the green button at the top right, and on the next popup window, click finish.

  6. Once you are done creating the pool above, the "Connection Details" window will be open and from the left sidebar choose the name of the pool you created. Details of that pool will be displayed on the right. Keep this window open and follow the instructions below to install macOS on your machine.

Installing macOS

Go to this repo and follow the instructions step by step up to the part below:

qemu-img create -f qcow2 mac_hdd_ng.img 128G
Enter fullscreen mode Exit fullscreen mode

The command above creates a virtual hdd image where macOS will be installed. We have to change the location to the pool target we created above. Go back to point 6. and copy Location, it is usually something like this /media/<username>/01D6CA5DC685C8B0/<folder you created>. Replace the above command with:

# PS: 128G is the size of the virtual drive in Gigabytes that will be created
qemu-img create -f qcow2 /media/<username>/01D6CA5DC685C8B0/<folder you created>/mac_hdd_ng.img 128G
Enter fullscreen mode Exit fullscreen mode

The command creates a 128GB virtual hdd in the location you specified, in this situation, the partition you added to the pool. After running the command above, since we changed the location of our virtual hdd, we also need to set this location in our script which will be run immediately after this command. So before running the script, we need to open it and change the location. To open the script:

nano ./OpenCore-Boot.sh
Enter fullscreen mode Exit fullscreen mode

This opens the script in the terminal, we can then create a new variable, find the line with the variable REPO_PATH="." and on the next line add this variable:

NVM_PATH="/media/<username>/01D6CA5DC685C8B0/<folder you created>"
Enter fullscreen mode Exit fullscreen mode

Then find this line:

-drive id=MacHDD,if=none,file="$REPO_PATH/mac_hdd_ng.img",format=qcow2
Enter fullscreen mode Exit fullscreen mode

and replace $REPO_PATH with $NVM_PATH, then save and close by pressing ctrl+X then Enter. You can then run the script by typing:

./OpenCore-Boot.sh
Enter fullscreen mode Exit fullscreen mode

From this point, you can read this article or watch this video to complete the installation.

Note: This might not necessarily be the best approach but it it the approach that worked for me. In case I made any mistake, please feel free to constructively criticize in the comments.

Discussion (0)