Skip to content

Instantly share code, notes, and snippets.

@gsf
Last active October 31, 2025 06:54
Show Gist options
  • Save gsf/c7bb24178700ffcaeab9c100c63264bb to your computer and use it in GitHub Desktop.
Save gsf/c7bb24178700ffcaeab9c100c63264bb to your computer and use it in GitHub Desktop.

Revisions

  1. gsf revised this gist Jun 6, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ubu-on-mac.md
    Original file line number Diff line number Diff line change
    @@ -61,7 +61,7 @@ sshfs 10.0.2.2:/Users/gsf/Downloads ~/Downloads
    That command will set that `~/Downloads` mount until the next boot. To make it automatic, I generate an SSH keypair on the guest, add the public key to authorized_keys on the host, and [make the sshfs mount on boot](https://askubuntu.com/questions/710149/how-to-convert-sshfs-command-to-fstab-entry) by adding the following to `/etc/fstab`:

    ```
    sshfs#[email protected]:/Users/gsf/Downloads /home/gsf/Downloads fuse _netdev,allow_other,identityfile=/home/gsf/.ssh/id_ed25519 0 0
    sshfs#[email protected]:/Users/gsf/Downloads /home/gsf/Downloads fuse _netdev,allow_other,uid=1000,gid=1000,idmap=user,identityfile=/home/gsf/.ssh/id_ed25519 0 0
    ```

    That's it! I kept notes on discoveries along the way below.
  2. gsf revised this gist Jun 1, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ubu-on-mac.md
    Original file line number Diff line number Diff line change
    @@ -61,7 +61,7 @@ sshfs 10.0.2.2:/Users/gsf/Downloads ~/Downloads
    That command will set that `~/Downloads` mount until the next boot. To make it automatic, I generate an SSH keypair on the guest, add the public key to authorized_keys on the host, and [make the sshfs mount on boot](https://askubuntu.com/questions/710149/how-to-convert-sshfs-command-to-fstab-entry) by adding the following to `/etc/fstab`:

    ```
    sshfs#[email protected]:/Users/gsf/Downloads /home/gsf/Downloads fuse defaults,_netdev,allow_other,identityfile=/home/gsf/.ssh/id_ed25519 0 0
    sshfs#[email protected]:/Users/gsf/Downloads /home/gsf/Downloads fuse _netdev,allow_other,identityfile=/home/gsf/.ssh/id_ed25519 0 0
    ```

    That's it! I kept notes on discoveries along the way below.
  3. gsf revised this gist Apr 22, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ubu-on-mac.md
    Original file line number Diff line number Diff line change
    @@ -52,7 +52,7 @@ Once installation is done I add the contents of my public SSH key to `~/.ssh/aut
    ssh -i ~/.ssh/gsf_id_ed25519 -p 2222 -t localhost 'screen -D -R'
    ```

    I also need to share directories between host and guest, but [Plan 9 and virtfs are not available in QEMU on macOS](https://apple.stackexchange.com/a/423461/448889), so I use sshfs ([IP address of host is 10.0.2.2](https://wiki.qemu.org/Documentation/Networking)):
    I also need to share directories between host and guest, but ~~[Plan 9 and virtfs are not available in QEMU on macOS](https://apple.stackexchange.com/a/423461/448889)~~(see update below!), so I use sshfs ([IP address of host is 10.0.2.2](https://wiki.qemu.org/Documentation/Networking)):

    ```
    sshfs 10.0.2.2:/Users/gsf/Downloads ~/Downloads
  4. gsf revised this gist Feb 13, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ubu-on-mac.md
    Original file line number Diff line number Diff line change
    @@ -34,7 +34,7 @@ qemu-system-x86_64 \
    -device "virtio-net-pci,netdev=n1,bus=pcie.0,addr=0x19"
    ```

    Options (many of these are lifted from https://www.arthurkoziel.com/qemu-ubuntu-20-04/):
    Explanation of options (many of these are lifted from https://www.arthurkoziel.com/qemu-ubuntu-20-04/):

    - `-cdrom` boots the VM from the ISO file for installation. **Drop it on subsequent boots once Ubuntu is installed.**
    - `-hda` specifies the hard drive file we'll be using.
  5. gsf revised this gist Feb 13, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ubu-on-mac.md
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ First, install QEMU (see https://wiki.qemu.org/Hosts/Mac for other options):
    brew install qemu
    ```

    Now create the image that will serve as the hard drive for the VM:
    Now create the file that will serve as the hard drive for the VM:

    ```
    qemu-img create -f qcow2 ubuntu.qcow2 50g
  6. gsf revised this gist Feb 11, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ubu-on-mac.md
    Original file line number Diff line number Diff line change
    @@ -52,7 +52,7 @@ Once installation is done I add the contents of my public SSH key to `~/.ssh/aut
    ssh -i ~/.ssh/gsf_id_ed25519 -p 2222 -t localhost 'screen -D -R'
    ```

    I also need to share directories between host and guest, but [Plan 9 and virtfs are not available in QEMU on macOS](https://apple.stackexchange.com/a/423461/448889), so use I use sshfs ([IP address of host is 10.0.2.2](https://wiki.qemu.org/Documentation/Networking)):
    I also need to share directories between host and guest, but [Plan 9 and virtfs are not available in QEMU on macOS](https://apple.stackexchange.com/a/423461/448889), so I use sshfs ([IP address of host is 10.0.2.2](https://wiki.qemu.org/Documentation/Networking)):

    ```
    sshfs 10.0.2.2:/Users/gsf/Downloads ~/Downloads
  7. gsf revised this gist Feb 11, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ubu-on-mac.md
    Original file line number Diff line number Diff line change
    @@ -77,4 +77,4 @@ Multipass and minikube use hyperkit, which sets up bridged networking. This is w

    I'm still on an Intel MacBook but looking for a solution that I can continue using on an M1 processor. That rules out xhyve: https://github.com/machyve/xhyve/issues/218

    Another good post on running Ubuntu with QEMU on macOS: https://graspingtech.com/ubuntu-desktop-18.04-virtual-machine-macos-qemu/
    This was also helpful in laying out steps for running Ubuntu with QEMU on macOS: https://graspingtech.com/ubuntu-desktop-18.04-virtual-machine-macos-qemu/
  8. gsf revised this gist Feb 11, 2022. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions ubu-on-mac.md
    Original file line number Diff line number Diff line change
    @@ -46,13 +46,13 @@ This command will open a QEMU window you can Alt-Tab to in order to monitor mach

    <img width="1440" alt="Screen Shot 2022-02-11 at 12 33 46 PM" src="https://user-images.githubusercontent.com/151913/153640591-654a6ab0-cb35-4400-a993-f597a08fc9af.png">

    Once installation is done I add the contents of public ssh key at gsf_id_ed25519.pub to `~/.ssh/authorized_keys` and ssh into it with the following (starting or attaching to a screen session on login):
    Once installation is done I add the contents of my public SSH key to `~/.ssh/authorized_keys` in the VM, then ssh in with the following (starting or attaching to a screen session on login):

    ```
    ssh -i ~/.ssh/gsf_id_ed25519 -p 2222 -t localhost 'screen -D -R'
    ```

    I need to share directories between host and guest, but [Plan 9 and virtfs are not available in QEMU on macOS](https://apple.stackexchange.com/a/423461/448889), so use I use sshfs ([IP address of host is 10.0.2.2](https://wiki.qemu.org/Documentation/Networking)):
    I also need to share directories between host and guest, but [Plan 9 and virtfs are not available in QEMU on macOS](https://apple.stackexchange.com/a/423461/448889), so use I use sshfs ([IP address of host is 10.0.2.2](https://wiki.qemu.org/Documentation/Networking)):

    ```
    sshfs 10.0.2.2:/Users/gsf/Downloads ~/Downloads
  9. gsf revised this gist Feb 11, 2022. 1 changed file with 20 additions and 33 deletions.
    53 changes: 20 additions & 33 deletions ubu-on-mac.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,8 @@
    # Minimal Ubuntu VM on macOS with QEMU
    # Ubuntu VM on macOS with QEMU

    For work I have an i5 MacBook. With the [Docker Desktop license changes](https://www.techrepublic.com/article/docker-launches-new-business-plan-with-changes-to-the-docker-desktop-license/) I looked into [minikube](https://arnon.me/2021/09/replace-docker-with-minikube/) and [Multipass](https://ubuntu.com/blog/replacing-docker-desktop-on-windows-and-mac-with-multipass) but both failed when I got on our VPN with Cisco AnyConnect due to bridged networking in hyperkit (see links at bottom). I also passed on VirtualBox to avoid depending on [legacy system extensions](https://www.virtualbox.org/ticket/14217). I landed on [libvirt for the VM](https://www.naut.ca/blog/2020/08/26/ubuntu-vm-on-macos-with-libvirt-qemu/), then realized I could remove libvirt from the equation to finally end up at this quick, simple setup for an Ubuntu VM on macOS.
    For work I have an Intel Core i5 MacBook. With the [Docker Desktop license changes](https://www.techrepublic.com/article/docker-launches-new-business-plan-with-changes-to-the-docker-desktop-license/) I looked into [minikube](https://arnon.me/2021/09/replace-docker-with-minikube/) and [Multipass](https://ubuntu.com/blog/replacing-docker-desktop-on-windows-and-mac-with-multipass) but both failed when I got on our VPN with Cisco AnyConnect due to bridged networking in hyperkit (see links at bottom).

    I realized I would be happy SSHing into a local Linux VM but passed on VirtualBox to avoid depending on [legacy system extensions](https://www.virtualbox.org/ticket/14217). I landed on [libvirt for the VM](https://www.naut.ca/blog/2020/08/26/ubuntu-vm-on-macos-with-libvirt-qemu/), then realized I could remove libvirt from the equation to finally end up at this quick, simple setup for an Ubuntu VM on macOS with QEMU.

    First, install QEMU (see https://wiki.qemu.org/Hosts/Mac for other options):

    @@ -44,50 +46,35 @@ This command will open a QEMU window you can Alt-Tab to in order to monitor mach

    <img width="1440" alt="Screen Shot 2022-02-11 at 12 33 46 PM" src="https://user-images.githubusercontent.com/151913/153640591-654a6ab0-cb35-4400-a993-f597a08fc9af.png">

    Once installation is done I add the contents of public ssh key at gsf_id_ed25519.pub to `~/.ssh/authorized_keys` and ssh into it with the following (starting or attaching to a screen session on login):

    ```
    ssh -i ~/.ssh/gsf_id_ed25519 -p 2222 -t localhost 'screen -d -RR default'
    ssh -i ~/.ssh/gsf_id_ed25519 -p 2222 -t localhost 'screen -D -R'
    ```

    I need to share directories between host and guest, but [Plan 9 and virtfs are not available in QEMU on macOS](https://apple.stackexchange.com/a/423461/448889), so use I use sshfs ([IP address of host is 10.0.2.2](https://wiki.qemu.org/Documentation/Networking)):

    ```
    sshfs 10.0.2.2:/Users/gsf/Downloads ~/Downloads
    ```

    That command will set that `~/Downloads` mount until the next boot. To make it automatic, I generate an SSH keypair on the guest, add the public key to authorized_keys on the host, and [make the sshfs mount on boot](https://askubuntu.com/questions/710149/how-to-convert-sshfs-command-to-fstab-entry) by adding the following to `/etc/fstab`:

    ```
    sshfs#[email protected]:/Users/gsf/Downloads /home/gsf/Downloads fuse defaults,_netdev,allow_other,identityfile=/home/gsf/.ssh/id_ed25519 0 0
    ```

    https://www.naut.ca/blog/2020/08/26/ubuntu-vm-on-macos-with-libvirt-qemu/

    Multipass and minikube use hyperkit, which sets up bridged networking. This is what clashes with the networking AnyConnect's VPN
    https://github.com/canonical/multipass/issues/961#issuecomment-521647822

    Minikube also fails on VPN due to hyperkit https://github.com/kubernetes/minikube/issues/6296

    Avoid VirtualBox due to use of the Legacy System Extension.


    I'm still on an Intel MacBook but looking for a solution that I can continue using on an M1 processor.

    https://computingforgeeks.com/virsh-commands-cheatsheet/

    No support for M1 on xhyve: https://github.com/machyve/xhyve/issues/218

    https://computingforgeeks.com/virsh-commands-cheatsheet/

    https://rabexc.org/posts/p9-setup-in-libvirt

    Plan 9 and virtfs are not available in QEMU on macOS, so use sshfs: https://apple.stackexchange.com/a/423461/448889

    IP address of host is 10.0.2.2 https://wiki.qemu.org/Documentation/Networking

    https://www.arthurkoziel.com/qemu-ubuntu-20-04/

    https://askubuntu.com/questions/710149/how-to-convert-sshfs-command-to-fstab-entry
    That's it! I kept notes on discoveries along the way below.

    https://graspingtech.com/ubuntu-desktop-18.04-virtual-machine-macos-qemu/
    ## Notes

    https://minikube.sigs.k8s.io/docs/handbook/vpn_and_proxy/
    Multipass and minikube use hyperkit, which sets up bridged networking. This is what clashes with the AnyConnect client:

    https://multipass.run/docs/troubleshooting-networking-on-macos
    - https://github.com/canonical/multipass/issues/961#issuecomment-521647822
    - https://multipass.run/docs/troubleshooting-networking-on-macos
    - https://github.com/kubernetes/minikube/issues/6296
    - https://minikube.sigs.k8s.io/docs/handbook/vpn_and_proxy/

    I'm still on an Intel MacBook but looking for a solution that I can continue using on an M1 processor. That rules out xhyve: https://github.com/machyve/xhyve/issues/218

    Another good post on running Ubuntu with QEMU on macOS: https://graspingtech.com/ubuntu-desktop-18.04-virtual-machine-macos-qemu/
  10. gsf revised this gist Feb 11, 2022. 1 changed file with 38 additions and 4 deletions.
    42 changes: 38 additions & 4 deletions ubu-on-mac.md
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,48 @@
    # Minimal Ubuntu VM on macOS with QEMU

    For work I have an i5 MacBook. With the [Docker Desktop license changes](https://www.techrepublic.com/article/docker-launches-new-business-plan-with-changes-to-the-docker-desktop-license/) I looked into [minikube](https://arnon.me/2021/09/replace-docker-with-minikube/) and [Multipass](https://ubuntu.com/blog/replacing-docker-desktop-on-windows-and-mac-with-multipass) but both failed when I got on our VPN with Cisco AnyConnect due to bridged networking in hyperkit (see links at bottom). I also passed on VirtualBox to avoid depending on [legacy system extensions](https://www.virtualbox.org/ticket/14217). I landed on [libvirt for the VM](https://www.naut.ca/blog/2020/08/26/ubuntu-vm-on-macos-with-libvirt-qemu/), then realized I could remove libvirt from the equation to finally end up at this quick, simple setup for an Ubuntu VM on macOS.

    First, install QEMU (see https://wiki.qemu.org/Hosts/Mac for other options):

    ```
    brew install qemu
    ```

    Now create the image that will serve as the hard drive for the VM:

    ```
    qemu-img create -f qcow2 ubuntu.qcow2 50g
    ```

    Download an Ubuntu ISO file (or any other linux):

    ```
    curl -LO https://releases.ubuntu.com/20.04/ubuntu-20.04.3-live-server-amd64.iso
    ```

    Next, run this command to boot the VM (I put this in a script I call `boot.sh`):

    ```
    qemu-system-x86_64 \
    -machine "type=q35,accel=hvf" \
    -cdrom "ubuntu-20.04.3-live-server-amd64.iso" \
    -hda "ubuntu.qcow2" \
    -machine "type=q35,accel=hvf" \
    -m "4G" \
    -cdrom "ubuntu-20.04.3-live-server-amd64.iso" \
    -netdev "user,id=n1,hostfwd=tcp::2222-:22" \
    -device "virtio-net-pci,netdev=n1,bus=pcie.0,addr=0x19"
    ```

    The `-cdrom` line boots from the iso image for installation. Drop it on subsequent boots once Ubuntu is installed.
    Options (many of these are lifted from https://www.arthurkoziel.com/qemu-ubuntu-20-04/):

    - `-cdrom` boots the VM from the ISO file for installation. **Drop it on subsequent boots once Ubuntu is installed.**
    - `-hda` specifies the hard drive file we'll be using.
    - `-machine` uses the latest machine type and the macOS native hypervisor
    - `-m` is the max amount of memory the machine may use
    - `-netdev` and `-device` set up networking so we can ssh into the VM on port 2222

    This command will open a QEMU window you can Alt-Tab to in order to monitor machine startup and proceed with installation. That window also has a handy "Power Down" dropdown option in the "Machine" item in the menu bar.

    <img width="1440" alt="Screen Shot 2022-02-11 at 12 33 46 PM" src="https://user-images.githubusercontent.com/151913/153640591-654a6ab0-cb35-4400-a993-f597a08fc9af.png">

    ```
    ssh -i ~/.ssh/gsf_id_ed25519 -p 2222 -t localhost 'screen -d -RR default'
    @@ -30,7 +64,7 @@ https://github.com/canonical/multipass/issues/961#issuecomment-521647822
    Minikube also fails on VPN due to hyperkit https://github.com/kubernetes/minikube/issues/6296

    Avoid VirtualBox due to use of the Legacy System Extension.
    https://www.virtualbox.org/ticket/14217


    I'm still on an Intel MacBook but looking for a solution that I can continue using on an M1 processor.

  11. gsf revised this gist Feb 11, 2022. 1 changed file with 25 additions and 7 deletions.
    32 changes: 25 additions & 7 deletions ubu-on-mac.md
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,27 @@
    ```
    qemu-system-x86_64 \
    -machine "type=q35,accel=hvf" \
    -hda "ubuntu.qcow2" \
    -m "4G" \
    -cdrom "ubuntu-20.04.3-live-server-amd64.iso" \
    -netdev "user,id=n1,hostfwd=tcp::2222-:22" \
    -device "virtio-net-pci,netdev=n1,bus=pcie.0,addr=0x19"
    ```

    The `-cdrom` line boots from the iso image for installation. Drop it on subsequent boots once Ubuntu is installed.

    ```
    ssh -i ~/.ssh/gsf_id_ed25519 -p 2222 -t localhost 'screen -d -RR default'
    ```

    ```
    sshfs 10.0.2.2:/Users/gsf/Downloads ~/Downloads
    ```

    ```
    sshfs#[email protected]:/Users/gsf/Downloads /home/gsf/Downloads fuse defaults,_netdev,allow_other,identityfile=/home/gsf/.ssh/id_ed25519 0 0
    ```

    https://www.naut.ca/blog/2020/08/26/ubuntu-vm-on-macos-with-libvirt-qemu/

    Multipass and minikube use hyperkit, which sets up bridged networking. This is what clashes with the networking AnyConnect's VPN
    @@ -22,10 +46,6 @@ Plan 9 and virtfs are not available in QEMU on macOS, so use sshfs: https://appl

    IP address of host is 10.0.2.2 https://wiki.qemu.org/Documentation/Networking

    ssh -i ~/.ssh/gsf_id_ed25519 -p 2222 -t localhost 'screen -d -RR default'

    sshfs 10.0.2.2:/Users/gsf/Downloads ~/Downloads

    https://www.arthurkoziel.com/qemu-ubuntu-20-04/

    https://askubuntu.com/questions/710149/how-to-convert-sshfs-command-to-fstab-entry
    @@ -36,6 +56,4 @@ https://minikube.sigs.k8s.io/docs/handbook/vpn_and_proxy/

    https://multipass.run/docs/troubleshooting-networking-on-macos

    ```
    sshfs#[email protected]:/Users/gsf/Downloads /home/gsf/Downloads fuse defaults,_netdev,allow_other,identityfile=/home/gsf/.ssh/id_ed25519 0 0
    ```

  12. gsf revised this gist Feb 11, 2022. 1 changed file with 19 additions and 3 deletions.
    22 changes: 19 additions & 3 deletions ubu-on-mac.md
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,10 @@
    https://www.naut.ca/blog/2020/08/26/ubuntu-vm-on-macos-with-libvirt-qemu/

    Multipass and minikube use hyperkit, which sets up bridged networking. This is what clashes with the networking AnyConnect's VPN
    Multipass and minikube use hyperkit, which sets up bridged networking. This is what clashes with the networking AnyConnect's VPN
    https://github.com/canonical/multipass/issues/961#issuecomment-521647822

    Minikube also fails on VPN due to hyperkit https://github.com/kubernetes/minikube/issues/6296

    Avoid VirtualBox due to use of the Legacy System Extension.
    https://www.virtualbox.org/ticket/14217

    @@ -18,8 +20,22 @@ https://rabexc.org/posts/p9-setup-in-libvirt

    Plan 9 and virtfs are not available in QEMU on macOS, so use sshfs: https://apple.stackexchange.com/a/423461/448889

    IP address of host is 10.0.2.2
    IP address of host is 10.0.2.2 https://wiki.qemu.org/Documentation/Networking

    ssh -i ~/.ssh/gsf_id_ed25519 -p 2222 -t localhost 'screen -d -RR default'

    sshfs 10.0.2.2:/Users/gsf/Downloads ~/Downloads
    sshfs 10.0.2.2:/Users/gsf/Downloads ~/Downloads

    https://www.arthurkoziel.com/qemu-ubuntu-20-04/

    https://askubuntu.com/questions/710149/how-to-convert-sshfs-command-to-fstab-entry

    https://graspingtech.com/ubuntu-desktop-18.04-virtual-machine-macos-qemu/

    https://minikube.sigs.k8s.io/docs/handbook/vpn_and_proxy/

    https://multipass.run/docs/troubleshooting-networking-on-macos

    ```
    sshfs#[email protected]:/Users/gsf/Downloads /home/gsf/Downloads fuse defaults,_netdev,allow_other,identityfile=/home/gsf/.ssh/id_ed25519 0 0
    ```
  13. gsf created this gist Feb 10, 2022.
    25 changes: 25 additions & 0 deletions ubu-on-mac.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    https://www.naut.ca/blog/2020/08/26/ubuntu-vm-on-macos-with-libvirt-qemu/

    Multipass and minikube use hyperkit, which sets up bridged networking. This is what clashes with the networking AnyConnect's VPN
    https://github.com/canonical/multipass/issues/961#issuecomment-521647822

    Avoid VirtualBox due to use of the Legacy System Extension.
    https://www.virtualbox.org/ticket/14217

    I'm still on an Intel MacBook but looking for a solution that I can continue using on an M1 processor.

    https://computingforgeeks.com/virsh-commands-cheatsheet/

    No support for M1 on xhyve: https://github.com/machyve/xhyve/issues/218

    https://computingforgeeks.com/virsh-commands-cheatsheet/

    https://rabexc.org/posts/p9-setup-in-libvirt

    Plan 9 and virtfs are not available in QEMU on macOS, so use sshfs: https://apple.stackexchange.com/a/423461/448889

    IP address of host is 10.0.2.2

    ssh -i ~/.ssh/gsf_id_ed25519 -p 2222 -t localhost 'screen -d -RR default'

    sshfs 10.0.2.2:/Users/gsf/Downloads ~/Downloads