Second day and finally now I can Dual boot my Macbook Air with Arch Linux and OS X (Mountain lion). Moments of happiness :D If you are a regular Windows user the rest of the article would probably be of no use (also boring may be) to you, so I recommend you check out my other posts.

Phew.. So with Windows fan gone, lets go on to the next level, if you have been a Linux user for a while using Linux in a virtual machine or one of those [fillAnyThingHere]untus then you must be wondering why I wrote this post, as Linux installation unlike in 90s is pretty straight forward nowadays.

So just to put some light, I was using Ubuntu(and it’s variants) since last few years, but as they started adding lots and lots of bells and whistles to it, just to attracted the newly migrated (Windows) users, it turned into an ugly OS which takes few seconds just to open the unity launcher(or whatever fancy name they gave it).

Check out this video on Why Linux (read Ubuntu) Sucks, just for fun.

One more reason as to why I got stuck to these -untus was because we have a clone of Ubuntu’s repository in our local server at my college so installing anything was just a matter of seconds. Getting irritated (read Saturated if you are a -untu user) I finally decided to make a switch to Arch Linux. Which is a bare bone GNU/Linux OS which come with minimal set of packages and you add everything on your own whatever you wish to, a true DIY OS. Arch FTW! :D

But there was cost to it, once I made the switch I would be accessing package repositories at my internet speed (which is usually pathetic in my college), (My college got Arch repo mirror finally, ftp://ftp.iitm.ac.in/archlinux) so I kept procrastinating it, but finally while my internship at Microsoft India (writing this post from my cabin right now) I got a good internet bandwidth and finally made the switch.

Unlike those -untus the process of installing Arch Linux (I’m talking about Dual boot here, not just Arch on your entire hard disk) on Macbook Air is not just a ‘Press Next’ process. You have to configure everything on your own starting from hard disk partition and type to your networking and even bootloader. It took me two days to get it the way I wanted. So I thought I would document it down for the people from the future.

Before I start I would like to point it out that Arch Linux’s wiki is one of the best documentations out there, though some people might argue that Gentoo has the best documentation, to which I won’t disagree. So read it up, have it at your side while installation, it’s THE Bible.

Prepare the USB for booting

  • Download the latest ISO of Arch Linux
  • Make a bootable USB of Arch linux while you are in your OS X using dd

'dd if==<path to .iso file> of==/dev/ bs==1M'</code>

(You can find your device Id by using diskutil type diskutil list in your OS X terminal)

Plug in your USB key and hold ‘alt/option’ button while your system boots up, choose the USB to boot from.

Partitioning

Use cgdisk

When the system is up and running. open cgdisk.

cgdisk /dev/sda

It would list you existing partion, don’t mess up with the Mac partition (there would be 3, normally) just use the free space and create 4 new partition (You can create more, I used same partion for root and home and had a swap partition).

Press down arrow key to select the free space and create new partitions, leave a free space of at least 128MB after Mac partitions before making the first partition.

Make the following 4 partitions:

Size            Partition Type          Partition Name

128 MB          Apple HFS+              Boot Loader
256 MB          Linux filesystem        Boot
X MB            Linux Swap              Swap space
Rest of space   Linux filesystem        Root

Try to keep swap space (X) double the size of your physical memory (RAM).

Keep the network ready

As you are gonna download lot many packages you need to be online, so plugin your ethernet cable via adapter. Or you can do USB tethering from your smartphone.

To connect to WiFi network run

wifi-menu

To check run:

ping google.com

Format and mount partition

mkfs.ext4 /dev/sda5
mkswap /dev/sda6
mkfs.ext4 /dev/sda7
mount /dev/sda7 /mnt
mkdir /mnt/boot && mount /dev/sda5 /mnt/boot
swapon /dev/sda6

Installation

pacstrap /mnt base base-devel
genfstab -p /mnt >> /mnt/etc/fstab

[VERY IMP] If your hard disk in SSD the change your fstab file parameters, open your fstab file

nano /mnt/etc/fstab

and make changes in it as below:

/dev/sda5      /boot  ext2  defaults,relatime,stripe=4    0 2
/dev/sda7        /      ext4  defaults,noatime,discard,data=writeback   0 1

Configure system

arch-chroot /mnt /bin/bash 
echo archer > /etc/hostname     #Replace archer by whatever hostname you want to use
ln -s /usr/share/zoneinfo/Asia/Calcutta /etc/localtime 
hwclock --systohc --utc 
useradd -m -g users -G wheel -s /bin/bash myusername && passwd mypassword   #Replace myusername and mypassword
sudo pacman -S sudo

Give yourself sudo right:

nano /etc/sudoers # uncomment wheel line

To set up your locale, run:

sudo nano /etc/locale.gen

Uncomment the desired locals. For me this was:

en_US.UTF-8 UTF-8

en_CA.UTF-8 UTF-8

Generate these locales by running:

locale-gen
echo LANG=en_US.UTF8 > /etc/locale.conf
export LANG=en_US.UTF-8

Modify your /etc/mkinitcpio.conf file to insert keyboard after autodetect in the HOOK section. Then run:

mkinitcpio -p linux

Here comes the Bootloader

This is the trickiest part, so don’t go anywhere.

What we will be doing is to boot using OS X native EFI boot loader, so install grub-efi-x86_64

pacman -S grub-efi-x86_64

change /etc/default/grub to look like

GRUB_CMDLINE_LINUX_DEFAULT="quiet rootflags=data=writeback"

Now generate boot.efi with GRUB

grub-mkconfig -o boot/grub/grub.cfg
grub-mkstandalone -o boot.efi -d usr/lib/grub/x86_64-efi -O x86_64-efi -C xz boot/grub/grub.cfg

Now boot.efi would be present in the current directly (or somewhere else if you changed the path in the command above), copy it somewhere.

How?

You can mount your USB and copy to it:

mkdir /mnt/usbdisk && mount /dev/sdb /mnt/usbdisk 
cp boot.efi /mnt/usbdisk/

Or you can SCP it to some other computer (for SSH you need to install openssh package).

If you only have WiFi at your disposal and don’t have an ethernet then you might wanna install the following packages before rebooting for the WiFi to work on reboot:

pacman install iw wireless_tools wpa_supplicant dialog

also install networkmanager and enable it using NetworkManager.service. Read Arch wiki for more info.

Reboot (Back to the Mac world)

  • exit chroot: exit
  • Reboot your system sudo reboot
  • Launch Disk Utility
  • Format the partition made for boot (/dev/sda4), using Max OS X(Journaled) filesystem.
  • Create the following the directories and file in /dev/sda4:
|___mach_kernel
|___System
       |
       |___Library
              |
              |___CoreServices
                      |
                      |___SystemVersion.plist
                      |___boot.efi

Commands for above:

cd /Volumes/disk0s4
mkdir System mach_kernel
cd System
mkdir Library
cd Library
mkdir CoreServices
cd CoreServices
touch SystemVersion.plist

Copy the boot.efi generated while installation to CoreServices directory, and paste the following in SystemVersion.plist

<xml version="1.0" encoding="utf-8"?>
<plist version="1.0">
<dict>
    <key>ProductBuildVersion</key>
    <string></string>
    <key>ProductName</key>
    <string>Linux</string>
    <key>ProductVersion</key>
    <string>Arch Linux</string>
</dict>
</plist>

and now bless this partition to make it bootable

sudo bless --device /dev/disk0s4 --setBoot

Now you are all set, you can reboot and hold ‘alt/option’ key and choose disk0s4 to boot from to boot into Arch Linux.

Post Installtion

Xorg

Install Xorg server

pacman -S xorg xf86-input-synaptics acpid
systemctl enable acpid

Network

  • Use iwconfig to check the ethernet and run systemctl start dhcpcd.service@eth0 #or whatever your ethernet name is
  • You can use wifi-menu to connect to Wi-Fi Networks

Sound

  • Install ALSA pacman -S alsa-utils
  • Unmute the master channel amixer sset Master unmute

Screen Backlight

Works OTB

Keyboard Backlight

You can control by echoing values to

/sys/devices/platform/applesmc.768/leds/smc::kbd_backlight/brightness

echo 40 > /sys/devices/platform/applesmc.768/leds/smc\:\:kbd_backlight/brightness

GUI

There are lot many options for it, some might prefer living without it, some might go for something light, like awesome or enlightenment. But as of now I’m mentoring a student under GSoC for a project which is in digiKam so I prefered going for KDE.

For minimal install, install kdebase for full install of all the basic KDE packages install kde

pacman -S kdebase

For launching KDE:

  • Using xinitrc
    • Add exec startkde to ~/.xinitrc
    • After log-in run startx to launch KDE GUI
  • Using KDM
    • Install kdm
    • Enable it systemctl start kdm.service, from next start you would get a GUI asking for your password to login

rEFInd

If you find this whole business of holding ‘alt/option’ key for few seconds on system start to choose OS irritation, then you can install rEFInd it would present you with a nice GUI on system start where you can choose which OS to boot.

Install Application

You can install any package using pacman

pacman -S <package name>

You can go here and check the list of Application which you might wanna use/install.

Well, so that’s all about it.