Notebook of Multipass

Multipass Basics

Install via Snap:

sudo snap install multipass

Start and stop multipass service:

sudo snap restart multipass

List of available sources

multipass find

Create an instance

multipass launch --cpu 2 --mem 2G --disk 12G --name cheeky-peacock jammy

That means you’ll get 2GB memory with 24GB capped disk space ubuntu 22.04 with a name that given, otherwise it produces a name for the user automatically.

Inspect your instance:

multipass info [INSTANCE NAME]

How to setup a multipass instance as a remote server

NTFS drives gets mounted as root access as default, not possible to change it according to the permission settings’ difference between windows and linux filesystems. To be able to mount a folder writable in ext. drive which is not possible to format to an ext4, for example, this setup works well for Ubuntu 22.

Setup Mounting an NTFS formatted External Drive

Get UUID of the external drive

blkid

Mount the drive

This mounts the drive in order to be able to navigate it on Nautilus or any file explorer app on the side bar, instead of root access /mnt/ folder.

UUID=<UUID_of_disk> /media/<username>/<root_of_external_drive> ntfs-3g defaults,windows_names,locale=en_US.utf8,permissions 0 0

How to Setup External Drive to Use Multipass Instances

Those instructions are originally from: https://multipass.run/docs/configure-multipass-storage#heading–linux. If there will be an issue of externalizing multpiass instances, check for the updates.

Stop the service, step-by-step:

sudo snap stop multipass
sudo snap connect multipass:removable-media # for /mnt or /media
sudo snap connect multipass:all-home # for /home/*
mkdir -p /media/<username>/<root_of_external_drive>/multipass_media
sudo chown root /media/<username>/<root_of_external_drive>/multipass_media

sudo mkdir /etc/systemd/system/snap.multipass.multipassd.service.d/

sudo tee /etc/systemd/system/snap.multipass.multipassd.service.d/override.conf <<EOF
[Service]
Environment=MULTIPASS_STORAGE=/media/<username>/<root_of_external_drive>/multipass_media
EOF

sudo systemctl daemon-reload

Now you can transfer the data from its original location to the new location:

sudo cp -r /var/snap/multipass/common/data/multipassd <path>/data
sudo cp -r /var/snap/multipass/common/cache/multipassd <path>/cache

Finally, start the Multipass daemon:

sudo snap start multipass

You can delete the original data at your discretion, to free up space:

sudo rm -rf /var/snap/multipass/common/data/multipassd
sudo rm -rf /var/snap/multipass/common/cache/multipassd

Continue to

Start the instance if not yet

multipass start cheeky-peacock

How to setup fixed SSH connection to the Instance

Normally multipass shel cheeky-peacock does SSH to the instance but it is not easy to use for mounting a folder from instance in host, or some other features like using code editor from host machine to develop a project folder inside the machine, etc…

Create SSH key without password

ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519-cheeky-peacock

Create an alias to be able to access only with a name

Get IP address of the instance

multipass info cheeky-peacock | grep IPv4 | cut -d ':' -f 2

Edit local SSH config file.

vim ~/.ssh/config

Add new alias:

# cheeky-peacock Multipass Instance 
Host cheepee
    Hostname <IP_address_of_instance>
    User ubuntu
    IdentitfyFile ~/.ssh/id_ed25519-cheeky-peacock

Get into the instance and paste the pub key manually

At the host, extract the pub key string and save it into clipboard (xclip required). If xclip won’t work, only the cat part then copy the string manually.

cat ~/.ssh/id_ed25519-cheeky-peacock | xclip -sel clip

Then shell into the instance and past the string in authorized_keys file as a next line.

multpiass shell cheeky-peacock
sudo vim ~/.ssh/authorized_keys

How to mount a specific folder at multipass instance

Reqiures sshfs app from apt repository.

sudo apt update && sudo apt install sshfs

Then mount the folder that required to be accessed and work on it remotely.

sshfs -o port=22 cheepee: /media/<username>/<mount_folder_name_at_remote>

Now in any code editor, mounted folder could be opened as a working dir.