Last active
March 9, 2024 13:04
-
-
Save timotif/705d0540419c25898151dce0dffd80dc to your computer and use it in GitHub Desktop.
Ubuntu on Mac Silicon for dummies: a guide to Multipass for 42 Linux campuses
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install Homebrew (https://brew.sh/) | |
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" | |
# Install multipass via homebrew | |
brew install --cask multipass | |
# Create a Multipass VM instance | |
# 'jammy' is Ubuntu 22.04LTS. | |
# Please note that the alias cannot start with a number so '42berlin' is not valid | |
# Default username is ubuntu: you can use your Linux skills to create a different one later on if you want | |
multipass launch jammy <alias> | |
# Find and copy to clipboard instance's IPv4 | |
multipass info <alias> | |
# In the ssh config file of the host add the instance | |
<<EOF cat >> ~/.ssh/config | |
Host <alias_name> | |
HostName <IP> # from multipass list or multipass info <alias> | |
User <username> # (default ‘ubuntu’) | |
EOF | |
# Append your Host public key to ~/.ssh/authorized_keys | |
## On the host (Mac) | |
cat ~/.ssh/id_ed25519.pub | |
# Select and copy the content | |
## On the VM (Ubuntu) | |
<<EOF cat >> ~/.ssh/authorized_keys | |
<paste_public_key> | |
EOF | |
# To get your new Ubuntu VM up to speed | |
sudo apt update | |
sudo apt upgrade | |
sudo apt install build-essential | |
sudo apt install valgrind | |
sudo apt install python3-pip | |
pip install norminette==3.3.53 | |
# To make a folder accessible in the VM | |
multipass mount /path/on/the/host/ <instance_name>:/mount/point | |
# For example if I wanted to mount the folder ~/Desktop/projects in the campus42 instance and find it in my home under the folder vm-projects the command would be | |
multipass mount ~/Desktop/projects campus42:~/vm-projects | |
## On VSCode on the host (Mac) | |
# Install SSH Remote extension | |
https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh | |
# In the bottom left corner of your VSCode GUI there's a Open Remote Window button | |
Click the button | |
Connect to Host... | |
From the dropdown pick the name you previously added to your .ssh/config file | |
VSCode will download VSCode-server to the VM (about 45M) | |
# Seat back and enjoy! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Super basic multipass cheat sheet | |
multipass launch <ubuntu_img> -n <instance_name> # where ver 22.04LTS is jammy. It creates a new default instance with given name | |
multipass list # shows a list of the created instances | |
multipass info <instance_name> # gives detailed information on the selected instance | |
multipass start <instance_name> # it starts the selected instance | |
multipass stop <instance_name> # it stops the selected instance | |
multipass shell <instance_name> # it starts a shell session on the selected instance | |
multipass delete <instance_name> # marks as deleted | |
multipass recover <instance_name> # marks a deleted instance as stopped | |
multipass purge # erases deleted instances |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 42 related useful stuff | |
sudo apt install python3-pip | |
pip install norminette==3.3.53 | |
https://github.com/ttshivhula/minilibx/issues/2 | |
sudo apt install llibxext-dev | |
sudo apt install libbsd-dev | |
## VSCode Extensions | |
https://marketplace.visualstudio.com/items?itemName=kube.42header | |
https://marketplace.visualstudio.com/items?itemName=MariusvanWijk-JoppeKoers.codam-norminette-3 | |
# Oh-my-zsh | |
sudo apt install zsh | |
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" | |
## Plugins | |
### To add a plugin: | |
clone it in ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/ | |
in the file ~/.zshrc edit the plugin section adding your new plugin (space separated) | |
I recommend at least zsh-autosuggestions and zsh-syntax-highlighting | |
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions | |
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting | |
vim ~/.zshrc | |
plugins=( | |
# other plugins... | |
zsh-autosuggestions | |
zsh-syntax-highlighting | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To backup and restore your VM | |
> multipass stop --all | |
> sudo launchctl unload /Library/LaunchDaemons/com.canonical.multipassd.plist | |
You have to install gnutar as the tar that comes with MacOS is the BSD tar and it seems to have some sort of issue with links. | |
I am using the multipass version in the backup name for my own purposes: | |
> sudo su | |
> gtar -cvpzf /yourbackuplocation/YOUR-HOST-NAME-Multipass-1.12.0+mac-backup.tar.gz /var/root/Library/Application\ Support/multipassd/qemu/vault | |
To Restore: | |
> multipass stop --all | |
> sudo launchctl unload /Library/LaunchDaemons/com.canonical.multipassd.plist | |
> sudo gtar -xvpzf /yourbackuplocation/YOUR-HOST-NAME-Multipass-1.12.0+mac-backup.tar.gz -C / --numeric-owner |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment