Skip to content

Instantly share code, notes, and snippets.

@Scherso
Last active June 4, 2024 12:04
Show Gist options
  • Save Scherso/3706cc80f0117ada2c93a3ba9be1365d to your computer and use it in GitHub Desktop.
Save Scherso/3706cc80f0117ada2c93a3ba9be1365d to your computer and use it in GitHub Desktop.
Macbook Air 2020 T2 Arch Linux Installation Guide

Installing Arch Linux with T2 Linux

What You Will Need
  • A USB Drive, I reccomend this one.
  • If you do not have a USB-A drive, you will need an adapter, I reccomend this one.
  • You will need Wi-Fi for this install, but I would assume you have a wireless connection.

Creating your Disk Partition with Disk Utility

  1. Open Disk Utility -> press the keys Command + space and type "Disk Utility" into spotlight search.
  2. Press Enter or Return on your keyboard depending on your keyboard.
  3. Click on the disk "Macintosh HD".
  4. Once you have clicked on Macintosh HD at the top of the window, click Parition.
See a Graphical Example

  1. Select the Amount of space you want to give Linux, give the Parition a Label, then press apply.

NOTE: If you would like to see a more detailed guide, see Apple's guide to partitioning your disk.


Create a bootable media drive with your Arch ISO

Downloading the ISO

  1. Download a Wi-Fi enabled ISO here.

Opening Terminal

  1. Once the ISO has installed open Terminal.
  • You can do this my pressing Command + space and typing "Terminal" then pressing Enter on your keyboard.

Creating the bootable Media with MacOS dd

  1. In your newly opened Terminal window run the command:
diskutil list
  • Your USB device will appear as something like /dev/disk2 (external, physical). Verify that this is the device you want to erase by checking its name and size and then use its identifier for the commands below instead of /dev/diskX.
  1. A USB device is normally auto-mounted in macOS, and you have to unmount (not eject) it before block-writing to it with dd. In Terminal, do:
diskutil unmountDisk /dev/diskX
  1. Now copy the ISO image file to the device. The dd command is similar to its Linux counterpart, but notice the 'r' before 'disk' for raw mode which makes the transfer much faster:
dd if=path/to/archlinux-version-x86_64.iso of=/dev/rdiskX bs=1m

Disabling Secure Boot Options

Open Startup Security Utility

  1. Restart your Mac, then press and hold Command (⌘)-R immediately after you see the Apple logo. Your Mac starts up from macOS Recovery.
  2. When you're asked to select a user you know the password for, select the user, click Next, then enter their administrator password.
  3. When you see the macOS utilities window, choose Utilities > Startup Security Utility from the menu bar.
  4. When you're asked to authenticate, click Enter macOS Password, then choose an administrator account and enter its password.
  5. Select No Security for Secure Boot, and Allow Boot Media

NOTE: For a more detailed guide follow Apple's guide to startup security.


Booting into the Live ISO

  1. Plug the Bootable USB you created earlier in step 2
  2. Boot while holding the Option key (⌥), this will put you in macOS Startup Manager.
  3. Select the orange EFI option with arrow keys and press return/enter on it.

Connecting to Wifi with Network Manager

Connecting through CLI

Connecting through the command nmcli

  1. List nearby Wi-Fi networks by running:
nmcli device wifi list
  1. Connecting to your Wi-Fi by running the following command:

NOTE: Replace WifiName with your Wi-Fi network's name, and WifiPassword with the corresponding password.

nmcli device wifi connect WifiName password WifiPassword
Connecting through TUI

Connecting through the command nmtui

  1. First, run the command:
nmtui
  • This will bring you into a Text-Based User Interface, (that's what TUI stands for if you're wondering)
  1. Use your arrow keys to navigate to Activate a Connection, once it is highlighted red, press 'enter' or 'return' on your keyboard.

  2. You wil be greeted to a screen listing local Wi-Fi devices, from here navigate to your Wi-Fi's label, and press 'enter' on your keyboard.

  3. Once you have clicked 'enter' on your Wi-Fi label, you will be greeted to a password prompt, from here, enter your Wi-Fi's password and navigate to the <OK> label.

  4. From here, you can navigate to <Back> and then <Quit>, you should now be connected to Wi-Fi.

Testing your Connection

  1. Once you are connected, test your connection by pinging a domain, for example:
ping archlinux.org
  1. If it is successful, press ctrl + c on your keyboard, and move on to the next step.

For more help see the documentation.


Updating your System Clock

  • Run the command:
timedatectl set-ntp true

to test these changes run timedatectl status, make sure the minutes correspond to an accurate clock.


Partitioning the Disks

  1. To view your disk partitions run:
lsblk

NOTE: The Arch Wiki mentions the EFI system partition, there will be one at /dev/nvme0n1p1

  1. Find the name of the partition that is roughly ~7 GiB's less than the partition your created on your disk at the start of this guide. For example: nvme0n1p3 8:3 0 82.9G 0 part

  2. Once you have found your partition run the following command:

gdisk /dev/yourPartition

NOTE: Replace yourPartition in the command above with the partition you created for Linux.

  1. You will see the prompt Command (? for help): type 'N' then press 'enter' or 'return' on your keyboard.
  2. To the next following prompts simply press enter, do not type anything
  3. When you are given the prompt Do you want to proceed? (Y/N): type 'Y' and then press 'enter' or 'return' on your keyoard.

Formatting the Partitions

Formating your Main Partition

  1. Clear your terminal (type "clear" and press enter) and run the command lsblk
  2. Find the name of the partition that is roughly ~7 GiB's less than the partition your created on your disk at the start of this guide. For example: nvme0n1p3 259:3 0 83.8G 0 part
  3. Run the following command to format it:
mkfs.ext4 /dev/yourPartition

NOTE: Replace yourPartition in the command above with the partition you created for Linux.

  1. Respond 'Y' to the following prompts.

Formatting your EFI Partition

  1. The Arch Wiki mentions the EFI system partition, there will be one at /dev/nvme0n1p1
  2. To format this partition run:
mkfs.fat -F 32 /dev/nvme0n1p1

For more info see the documentation.


Mounting the Partitions

  1. Mounting your main partition to the /mnt directory:
mount /dev/yourPartition /mnt

NOTE: Replace yourPartition in the command above with the partition you created for Linux.

  1. Making your /mnt/boot/efi directory:
mkdir -p /mnt/boot/efi
  1. Mounting your EFI partition to /mnt/boot/efi
mount /dev/nvme0n1p1 /mnt/boot/efi

For more info see the documentation


Installing Essential Packages

  • Use the pacstrap script to install the base package, Linux kernel and firmware for common hardware:
  • Note: Remove the grub efibootmgr packages from this if you intend to use systemd-boot as your bootloader.
pacstrap /mnt base linux-t2 linux-t2-headers linux-t2-docs apple-bcm-wifi-firmware dkms linux-firmware iwd grub efibootmgr vim intel-ucode networkmanager

Configuring the System

Generate an fstab file (use -U or -L to define by UUID or labels, respectively):

genfstab -U /mnt >> /mnt/etc/fstab

Make sure the informating is correct by running cat /mnt/etc/fstab

Entering the Root (Chroot)

  • If you wish to exit chroot, you can press cntrl + d on your keyboard, or type exit
arch-chroot /mnt

Making a Swap File

  • While in chroot, (command to enter: arch-chroot /mnt) run the following commands:
  • The command below will create a 2 GiB swap file, to edit the size, change the value count which is equal to 2 in the example.
dd if=/dev/zero of=/swapfile bs=1G count=2 status=progress

You must be in Chroot when making your swapfile.

  • Setting the swapfile's permissions
chmod 600 /swapfile
  • After creating the swapfile, format it to swap:
mkswap -U clear /swapfile
  • Activating the swapfile:
swapon /swapfile
  • Finally, edit your fstab file to account for your swapfile
  • The command below will enter your into a text editor called vim
vim /etc/fstab
  • Once you are editing the fstab file, go to the bottom line with the arrow keys, press I and type:
/swapfile none swap defaults 0 0
  • To exit vim press "escape" on your keyboard, followed by typing :wq followed by pressing "enter", this wil save the file and exit.
Example
# Static information about the filesystems.
# See fstab(5) for details.

# <file system> <dir> <type> <options> <dumb> <pass>
# /dev/example
UUID=example    /   ext4    rw,relatime   0 1

# /dev/eaxmple LABEL=EFI
UUID=example  /boot/efi   vfat    rw,relatime,fmask=example,dmask=example,codepage=example,iocharset=isoExample,shortname=example,utf8,errors=remount-ro    0 2 

/swapfile none swap defaults 0 0 
  • Replace Region and City with your location corresponding to the titles.
  • To see time zones you can run cat /usr/share/zoneinfo | grep yourCountriesName
ln -sf /usr/share/zoneinfo/Region/City /etc/localtime
  • Run hwclock to generate /etc/adjtime:
hwclock --systohc

Note: This command assumes the hardware clock is set to UTC. See System time#Time standard for details.

Localization

  • Edit /etc/locale.gen and uncomment en_US.UTF-8 UTF-8, and other needed locales. You can edit by running:
  • To uncomment, delete the # before the line of text.
vim /etc/locale.gen
  • Once you have uncommented, press "escape" on your keyboard, then type :wq, followed by pressing enter.

Once you have saved the file, you can generate the locales by running:

locale-gen
  • You will also need to make a locale.conf, to do this running:
echo LANG=en_US.UTF-8 >> /etc/locale.conf 

Changing your Keymap

  • If you use a US keyboard, you can skip this step.

  • If you need to set the console keyboard layout from the US default, make the changes persistent vconsole.conf(5) by following the nest steps:

echo KEYMAP=your-keymap >> /etc/vconsole.conf

Network Configuration

Create the hostname file:

  • Your host name will be the name of your computer, ex. user@hostname
echo yourHostName >> /etc/hostname
  • Creating your hosts file:

  • To enter a text editor to edit the file run:

vim /etc/hosts
  • Once you are editing the text file, you will enter the following:
127.0.0.1         localhost
::1               localhost
127.0.1.1         yourHostName.localdomain  yourHostName
  • To exit vim press 'escape' on your keyboard, followed by typing :wq followed by pressing 'enter', this wil save the file and exit.

NOTE: Replace yourHostName with the host name you created in the step above.

Example
# Static table lookup for hostnames.
# See hosts(5) for more details.

127.0.0.1         localhost
::1               localhost
127.0.1.1         Macbook-Air.localdomain Macbook-Air

Root password

  • You can set the root password by running the following command:
passwd
  • You will be greated with a prompt to enter your password, and then verify it, pick a secure password for your root.

Adding a User

  • To add a user you must run:

  • Replace yourUserName with any name of your choice, you will use this name to log in later.

useradd -mG wheel yourUserName
  • Adding a password to your user:
passwd yourUserName
  • You will be greated with a prompt to enter your password, and then verify it

Setting up Sudo

  • First you must install sudo by running:
pacman -S sudo
  • Once sudo is installed, you must add your user to the sudoers file, you can do this by editing it.
EDITOR=vim visudo
  • Once you have entered vim, find the uncommented line root = ALL=(ALL) ALL 3 lines below this line will be a commented line # %wheel ALL=(ALL:ALL) ALL, you will need to uncomment this.
What this should look like
## 
## User privilege specification
##

## Uncomment to allow members of group wheel to execute any command
%wheel ALL=(ALL:ALL) ALL
  • To exit vim press "escape" on your keyboard, followed by typing :wq followed by pressing "enter", this wil save the file and exit.

Testing Sudo

  1. To test if sudo works, switch to your user:
su userName
  1. Once you have switched to your user, you can test a sudo command by running:
sudo echo test
  1. You will be greeted with a password prompt, enter your password and press 'enter' on your keyboard.

  2. If test is outputted in your terminal followed by entering your password, sudo works, and you can move on to the next step.

Enabling Services and Daemons with systemd

systemctl enable NetworkManager
  • If you installed any other services, you can enable them with systemctl enable serviceName

Setting up GRUB

What is GRUB?

GRUB(GRand Unified Bootloader) is a boot loader, this bootloader provides an inferface to load into operating systems or applications.

Installing and Setting up GRUB

  1. You will need to edit /etc/default/grub, you can edit the text file by running:
vim /etc/default/grub
  1. Near the top, find the line: GRUB_CMDLINE_LINUX="", from here you will need to add the following text to the quotes. Add:
intel_iommu=on iommu=pt pcie_ports=compat
Example
# GRUB boot loader configuration

GRUB_DEFAULT=0
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="Arch"
GRUB_CMDLINE_LINUX_DEFAULT="quiet"
GRUB_CMDLINE_LINUX="intel_iommu=on iommu=pt pcie_ports=compat"
  • To exit vim press 'escape' on your keyboard, followed by typing :wq followed by pressing 'enter', this wil save the file and exit.
  1. Installing GRUB for x86_64-efi:
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=GRUB --no-nvram --removable
  1. Making your Config:
grub-mkconfig -o /boot/grub/grub.cfg
  1. Configuring nvram and efivars
  • We are making our nvram/efivars automatically remount as readonly, as writing to them causes a panic.
echo efivarfs /sys/firmware/efi/efivars efivarfs ro,remount,nofail 0 0 >> /etc/fstab
  • If this doesn't work, you can instead add the efi=noruntime kernel parameter as described when installing your bootloader, however, do NOT use both kernel parameters at the same time.

Unmounting and Rebooting

  1. Once you have followed all the intrusctions above you will need to exit root, you can do this by pressing cntrl + d on your keyboard, or using the command:
exit
  1. Once you have exited root, unmount all your partitions by running:
umount -a
  1. Once you have unmounted your partitions, you can reboot and remove your USB drive from your machine, you can reboot by running:
reboot

Logging in

  • You will be greeted with the GRUB UI, navigate to Arch Linux with your arrow keys, and press 'enter' once it is highlighted.

Logging into your user

  1. You will be greeted with Hostname login:, enter the username that you picked earlier, follow that by pressing 'enter' or 'return' on your keyboard.

  2. You will then be greeted with password, enter your password, follow that by pressing 'enter' or 'return' on your keyboard

Congrats, you're now in Arch Linux. 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment