Ubuntu Vm On Mac



Currently I’ve setup the Ubuntu Server 18.04 LTS from the Azure marketplace and I’m trying to access it via VNC Server setup on the Linux machine. Also, you’ll need a vnc client like RealVNC or you can also use the screen-sharing client available on your Mac.

  1. Install Ubuntu On Mac Mini 2014
  2. Macos Vm On Ubuntu
  3. Ubuntu Vm On Macos

Loginvia SSH:

VirtualBox download: Desktop 20.04 download: to create an Ubuntu Virtual Machine on y. Install Ubuntu Server normally, making sure to enable the SSH server. Once it restarts you can connect to the VM from your terminal by running ssh -p 2222 user@localhost. To send a shutdown signal to your VM, run virsh shutdown ubuntu. To force shutdown, run virsh destroy ubuntu. Before we begin, you should have VMware Fusion. installed on your Mac and have downloaded the Ubuntu Desktop 20.04 ISO. Create the Ubuntu Desktop VM. Open VMware Fusion, click + then New. Click Install from disc or image. Either drag the Ubuntu ISO image from finder into the box with the arrow or click the Use another disc or image button. The following instructions will enable you to create an Ubuntu virtual machine. They have been created specifically for a Mac computer, but are essentially the same for Windows. As you follow the instructions, you will see they have been adapted so that even a beginner can complete this task.

First you need to login to your Linux VM as a non-root user which you’ve created while setting up the VM. To spin up a new Linux VM, you can check out this post. You can use the Cloud shell to connect to your VM using the non-root username and password to your machine via SSH. Use the Connect menu of your VM and copy the SSH command to run in the Cloud shell.

You just need to replace the your_user_name and IP_Address parts in the above command. Enter the password you’re prompted for to complete the Login as SSH.

Install the required packages:

We now need to install the required packages like Xfce desktop environment and VNC Server which are not bundled in the Ubuntu OS by default. Xfce is a free and open-source desktop environment for Unix and Unix like Operating Systems.

Update list of packages:
Install Xfce Desktop environment and wait for the installation to complete:
Install the VNC Server:

$ sudo apt install tightvncserver

Complete the initial configuration and provide the setup password:

Providing a view-only password is optional. You’ll get the below Output as the initial configuration completes:

Creating default startup script /home/your_user_name/.vnc/xstartup Starting applications specified in /home/your_user_name/.vnc/xstartup Log file is /home/your_user_name/.vnc/your_hostname:1.log

Configure VNC Server:

The VNC Server is by default configured on the port 5901 and display port :1. VNC can launch multiple instances on other ports like :2, :3 and so on.

Let’s first kill the current instance for further configuration that we require:

Install Ubuntu On Mac Mini 2014

Output:

Killing Xtightvnc process ID <ID>

Backup the xstartup file before modifying:

Create a new xstartup file and open in editor:

Add the following lines to your file in the nano editor and save it:

This is making certain settings to the graphical desktop like colours, themes and fonts. The last line is starting the Xfce desktop. Now, let’s convert the file to an executable and restart:

Now, let’s connect to the VNC Server from your Mac by creating a SSH tunnel and use Screen-sharing client to connect.

Run this command on your Mac terminal:

Do replace the your_user_name with your sudo non-root username and your_server_ip with the IP Address of your Linux VM. Provide the password when prompted for your username.

Now, open your screen sharing App available in the Finder Go Menu on your Mac that says “Connect to Server…”.

Click on Connect and provide your password when prompted again and you’ll see the Xfce Desktop running via Screen-sharing.

I first learned about libvirt and QEMU three years ago when I wrote a guide on how to virtualize macOS on a Linux system. Today I will be showing the opposite, virtualizing Linux on macOS using the same tools. I was surprised that with so many software developers using MacBooks everyday, nobody has created a guide on how to use libvirt and QEMU with macOS.

Why is libvirt and QEMU better? First of all, it's free and open-source. Unlike Parallels Desktop and VMWare Fusion, you won't need to pay for expensive subscriptions or manage licenses. There does exist an open-source alternative (from Oracle!) called VirtualBox, which works pretty well. However, VirtualBox does not support macOS's Hypervisor.Framework, a virtualization API created to limit kernel modification. This means the installer will ask for admin access to install kernel extensions, a feature Apple is now phasing out for security reasons. QEMU on the other hand has had support for Hypervisor.Framework since 2018. Just say no to kexts!

Furthermore, like many developers, I like to run VMs headless, i.e. without a desktop GUI, so that I can SSH into them. Running VMs in the background seems like a simple feature, but it requires a lot of complex configuration for both VirtualBox and VMWare Fusion. And Parallels wants you buy the Pro Edition to gain access. Market segmentation at its finest... With libvirt, VMs start headless. Plus, when you shutdown macOS, it sends a shutdown signal to your VMs as well.

To be clear, this method doesn't support USB Passthrough, GPU Passthrough, or bridge networking. But if you just need to test, for example, node.js or nginx on a Linux VM, then this method is great.

Installing libvirt and QEMU

  1. First, install homebrew, which is a package manager for macOS.
  2. Run brew install qemu gcc libvirt.
  3. Since macOS doesn't support QEMU security features, we need to disable them:
  4. Finally start the libvirt service, with brew services start libvirt. It will start after boot as well.

Installing Ubuntu Server 20.04

There are two ways to access the virtual display of the VM, either using a VNC client or the virt-viewer program. I recommend RealVNC Viewer. The VNC client is responsive and quick to install, but if you have multiple VMs you need to manually manage the different ports. With virt-viewer, you get a popup with all the VMs currently running, but it is laggy and takes an eternity to install. virt-viewer can be installed through homebrew. The rest of this guide uses VNC.

Macos Vm On Ubuntu

Ubuntu
  1. Create a vms folder in your home directory, and generate a disk image. Change 50g to the size of your prefered disk:

  2. Download the Ubuntu Server 20.04 Install Image and my libvirt XML template and place the .iso and .xml files in the same folder.

  3. Modify the following elements in the ubuntu.xml file to match your your VM preferences and file paths. Save, then run virsh define ubuntu.xml followed by virsh start ubuntu.

  4. Start RealVNC Viewer and connect to localhost. Click the Ctrl+Alt+Del button to reboot the machine, and quickly press Esc to get into the boot menu. Press the number that matches the Ubuntu Server image.

  5. Install Ubuntu Server normally, making sure to enable the SSH server. Once it restarts you can connect to the VM from your terminal by running ssh -p 2222 user@localhost.

  6. To send a shutdown signal to your VM, run virsh shutdown ubuntu. To force shutdown, run virsh destroy ubuntu.

  7. To forward a port, e.g. port 443 from the VM to port 8443 locally, run the following: ssh -p 2222 -L8443:localhost:443 user@localhost

Ubuntu Vm On Macos

Multiple VMs

If you want to create multiple VMs, create an XML file for each machine with a unique UUID, VM name, and VNC port. Also, change the hostfwd argument so that each VM exposes a different port for SSH, e.g. 2223 instead of 2222. After you have defined them all, you can get a list of the VMs that are currently running with virsh list.

References:

Note: More discussion on Hacker News