User:ScholarsMate

From ArchWiki

Hi, I am ScholarsMate. Just an ArchWiki user.

Currently, I am installing Arch on my mid 2012 Macbook Pro to dual boot with OSX Yosemite. I thought I'd go ahead and document my experiences as I go along.

Overview

Installing rEFInd

Following the guide on the rEFInd page, I installed rEFInd. I first mounted my ESP by finding what partition it was on using:

diskutil list

My EFI partition was on /dev/disk0s1. I mounted it using:

sudo diskutil mount /dev/disk0s1

This mounted it to /Volumes/EFI. The next step is to add the directory that rEFInd will be located in. This is accomplished by using:

mkdir /Volumes/EFI/EFI/refind

The next step is to copy rEFInd into this directory. Download it and unzip it. Inside will be a rEFInd subdirectory. This is the one we want to copy.

cp -r /Path/to/refind/* /Volumes/EFI/EFI/refind

Next, we need to bless it so that it is registered with the firmware. This will set it as the default boot manager. You can return to using Apple's boot manager by holding down option while booting. You can also remove the rEFInd files from the ESP if you are not going to use it anymore. Alternately, you can bless another boot manager.

The boot manager can be blessed using one of the following commands:

sudo bless --mount /Volumes/esp --setBoot --file /Volumes/esp/efi/refind/refind_x64.efi --shortform

or

sudo bless --mount /Volumes/esp --setBoot --file /Volumes/esp/efi/refind/refind_x64.efi

The only difference between the two is the --shortform option. Some users report that they must wait around 30 seconds before rEFInd will load. The --shortform solved this issue for me, but for other users, using the --shortform option may actually cause the wait time. You can always bless the boot manager again with or without the option if you find that you have issues.

Warning: DO NOT RUN bless --info. DOING SO CAN CORRUPT YOUR DISK

There is a bug with bless that can corrupt your disk if you use the above command if you have an Advanced Format disk. If you know you have, or suspect you have one, don't run the command.

From here, the next step is to reboot and see if it works!

Preparing Disk

The next step is to partition the disks to prepare for the install. In my case, I am not using swap, and I am only making one partition. I am using Apple's EFI partition instead and mounting it as my /boot partition. Another consideration was my BOOTCAMP partition with windows, which I removed.

Removing BOOTCAMP

Because I had a BOOTCAMP partition, the first thing was to remove it using the Boot Camp Assistant. This was a simple process that was completely automated. After rebooting however, rEFInd did not load. The default Apple bootloader took over. To fix this, I simply blessed rEFInd again and was able to load it. There was an option in rEFInd to boot into an "Legacy OS from unknown volume" left over from Windows, however. After some searching on the web, I determined that Windows had written to the MBR of the disk. This was not removed when Boot Camp Assistant removed my Windows partition. I fixed this by adding the following line into refind.conf:

dont_scan_volumes "Unknown Volume"

Resizing OSX

If you updated to Yosemite from a previous version of OSX, this will be straight forward. I opened up Disk Utility and resized my OSX partition, leaving 200GB of free space for Arch to be installed into. The MacBook#OS X With Arch Linux page has a good guide on this. This will be the partition I am using for LVM.

If you installed Yosemite from scratch, or your MacBook came preinstalled with Yosemite, you have to go through an extra step. Yosemite uses a type of LVM and Disk Utility will not allow you to make changes to sizes from the graphical interface. Instead you need to use diskutil from the command line. The physical volume, the volume group, and one of the logical volumes needs to be resized. This can be done using some undocumented commands.

I found the commands from this blog. The command I used was the resizeStack command.

#diskutil coreStorage resizeStack lvUUID size

Replace lvUUID with the UUID of your logical volume.

Partitioning the Disk

I booted up an Arch Linux live cd using Drive Droid on my phone. The rest of the partitioning will be done in Arch using fdisk. Use fdisk to edit the partition table.

fdisk /dev/sda

You can press p to see the current partition table. Use n to create a new partition and 4 so that it is the fourth partition. According to MacBook#OS X With Arch Linux, OSX likes to see a 128MiB space between partition. I didn't verify this on my own, so I don't know if this is still the case, or if it is no longer necessary. With this in mind, I made the start of the partition about 128 MiB after the partition before it. From fdisk, I can see that each sector is 512 bytes. I want a 128MiB space which is 1048576 bytes. 1048576 bytes divided by 512 bytes/sector gives me 262144 sectors. The partition before it starts ends at 1071702247 which means the next sector would start one sector after it. Add these together to get the starting sector of 1071964392. I want the partition to take up the rest of the disk, so I set the ending partition as the last one (default). Now that I have the partition, I can press t to change the type of the partition to an LVM. After this, you can press p to look at your partition table to ensure everything looks as it should. Finally, w will write the changes to your disk.

Setting up LVM

Since I decided to go with LVM, I needed to set it up. This requires internet to install the package since the Arch live cd I was running did not have it installed (I don't know if updated versions of the live cd do have it installed). The drivers required for WiFi are not installed, so ethernet was the only option. After plugging in the cable, dhcpd enp1s0f0 will connect it to the internet. I installed the lvm2 package. After that, I ran the command:

lvmdiskscan

and

lsblk

to ensure that I would be using the correct partition. I know that I will be using /dev/sda4. Now it is time to create the physical volume. Use the following command to create it:

pvcreate /dev/sda4

This creates a header so that it may be used in LVM volume groups. In this case, my volume group will only contain one device: the partition that I made earlier. I want to name my volume group lvm To make the volume group, use:

vgcreate lvm /dev/sda4

After this, it's time to make the logical volumes. This is done with the lvcreate command. To set up the / partition, I use the command:

lvcreate -L 20G lvm -n root

This creates a logical volume with a size of 20GB in the volume group lvm under the name "root." -L is to specify size, and -n is to specify the name to create the volume under. Next, I create my home partition using the same command, but with a size of 50G and the name "home." Now, the volumes are ready for a file system. I am using EXT4 for both of my partitions. The command mkfs.ext4. I am going to use the arguments -m to reserve less space for root.

mkfs.ext4 -m .1 /dev/lvm/root
mkfs.ext4 -m 0 /dev/lvm/home

Labels can be added to make managing the volumes easier. This is done with the e2label command.

e2label /dev/lvm/root root
e2label /dev/lvm/home home

With this, the disks are prepared and it is time to install Arch Linux

Installing Arch Linux

This part is mostly a standard install. The Installation guide can be followed to install the system. The only special notes here are making an initramfs so that LVM is supported, and setting up the bootloader. Neither of these is Mac specific, but I'll document them anyways.

Initramfs

Because I am using LVM, I need to make an initramfs so that I can load my / partition. This is done by editing the /etc/mkinitcpio.conf file and adding in some new hooks. Systemd should be added as a hook to replace base and udev. The sd-lvm2 hook also needs to be added between blocks and filesystems. The hooks line should look like this:

HOOKS="systemd autodetect modconf block sd-lvm2 filesystems keyboard fsck"

This adds the needed hook, and optimizes for speed as well. Now it is ready to be built

mkinicpio -p linux

This will create the initramfs and add it to the /boot partition

Configuring rEFInd

Now, we need to add a menu entry for Arch Linux in rEFInd. This is done by adding a manual boot stanza in /boot/EFI/refind/refind.conf. I used the following configuration:

menuentry "Arch Linux" {
     icon EFI/refind/icons/os_linux.png
     loader vmlinuz-linux
     initrd initramfs-linux.img
     options "root=LABEL=root rw quiet init=/usr/lib/systemd/systemd"
     submenuentry "Boot with fallback initramfs" {
          initrd initramfs-linux-fallback.img
          options "root=LABEL=root rw init=/usr/lib/systemd/systemd"
     }
}

The use of "" allows special character like spaces to be passed without being interpreted by rEFInd. So for example:

menuentry Arch Linux {
...

This would only display Arch as the title because the space is being interpreted. This is especially important for the options. The submenu entry appears when you press F2 in rEFInd for more info. rEFInd also automatically scans vmlinuz-linux and adds it to the boot menu. This is the kernel we are using, but does not use the menu entry we gave it, so does not have any options. It is best to hide this to prevent any confusion. The following line can be added to boot/EFI/refind/refind.conf to do so:

dont_scan_files vmlinuz-linux

With this, the system should be ready to be rebooted.

Post Install

The first thing I did was add a user for myself and gave it sudo privileges. The rest of the setup should be done as this user for security purposes. The rest of the steps from here should be installing the correct drivers to get the system functioning as intended.

Networking

The first thing I wanted setup was networking. The MacBook uses non-free drivers for WiFi and must be installed. Ethernet needed to be setup first. I used systemd-networkd to do so. I added a profile in /etc/systemd/network with the name enp1s0f0.profile. It looks like this:

[Match]
Name=enp1s0f0

[Network]
DHCP=v4

Next, I wanted to use DHCP to setup DNS. This is done by symlinking /run/systemd/resolve/resolv.conf to /etc/resolv.conf. After this, I enabled all the needed services.

systemctl enable systemd-networkd
systemctl enable systemd-resolved
systemctl start systemd-networkd
systemctl start systemd-resolved
ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf

Now that I have ethernet working, I can install the drivers for my WiFi. The command:

lspci | grep Network

Will list the WiFi chip I am using. My MacBook uses a Broadcom BCM4331. This chip currently has reverse engineered drivers in the form of the b43 drivers. These drivers have been included in the kernel since 2.6.37. The only thing I needed to download is the b43-firmwareAUR from the AUR and install it. Download the package and install it. This requires base-devel.

pacman -S --needed base-devel
wget https://aur.archlinux.org/packages/b4/b43-firmware/b43-firmware.tar.gz
tar -xzf b43-firmware.tar.gz
cd b43-firmware
makepkg -s
pacman -U /path/to/b43-firmware-version_number-any.pkg.tar.xz

The firmware should now be installed. After rebooting, you should see the WiFi chip if you run ip a. I am going to be setting up WiFi using WPA supplicant and systemd-networkd. This will involve making a profile with the information of my SSID. To do this, copy /etc/wpa_supplicant/wpa_supplicant.conf to /etc/wpa_supplicant/wpa_supplicant-wlp2s0b1.conf. This will be the config file we edit. Make it look like this, filling in the needed info:

# EAP-PEAP/MSCHAPv2
network={
     ssid="SSID"
     key_mgmt=WPA-EAP
     eap=PEAP
     identity="username"
     password="password"
     phase1="peaplabel=0"
     phase2="auth=MSCHAPV2"
     priority=10
}

This is the config for my university, but any netork config should work fine. Storing passwords in plaintext is bad. This can be encrypted, by for right now, it is easier to set the file to only allow root to read. Use the chmod command to do so.

chmod -600 /etc/wpa_supplicant/wpa_supplicant-wlp2s0b1.conf

Now we need to make a profile for the interface. This is the same as when we made one for the ethernet. The name of the profile doesn't matter, but naming it wlp2s0b1.network is a good idea. Make it look like this:

[Match]
Name=wlp2s0b1

[Network]
DHCP=v4

Now, systemd-networkd will be able to use the wifi interface. Systemd will be able to launch wifi using our configuration file like so:

systemctl start wpa_supplicant@wlp2s0b1
systemctl enable wpa_supplicant@wlp2s0b1

Anything after the @ is interpreted as the variable %i or %I in the service file. This will start wpa_supplicant using the configuration file we made earlier. This should allow you to connect whenever the service is running

X-server

To-do

Screen and keyboard backlight

To-do

Media hotkeys

To-do

Touchpad configuration

To-do

Power management

To-do

i3 configuration

To-do