How to install Archlinux on MacBook Pro 8,2[Part.2]

In Part 2, we are going to discuss how to install Xorg-server and work nicely with it. (Part 1) The problem is that, currently (if you have followed as Part.1) Xorg-server will run with framebuffer, not from the video card you have inside Mac. In Macbook Pro 8,2 there are two video cards ATI radeon and Intel. We are going to use ATI even though two graphical cards should work nicely with the strategy below.

The issue of not using video card without any tweak is because of KMSmode. On EFI system, it is using EFI system bootloader, which is different from bios one as in any os booting CD or Windows system. This will prevent the KMS mode to be on, otherwise the system won’t boot. Last time, we turn off the KMS setup by doing ‘nomodeset’ on the grub setting and this made the KMS to be turned off. However without KMS, Xorg-server won’t work with the video card, rather it will complain that the modeset is wrong for itself.

So what we need to do is
1. apply patches for Radeon video card on Linux kernel
2. compile the kernel for that
3. Create a vbios emulation which will be copied from any bootable CD
4. Set modeset to the other way around; turn on the KMS mode.

So I will go step by step.

1. Apply patches for radeon video card on Linux kernel.

Thankfully, there is a github of patches+kernel of ‘fooblahblah’ so that you can download.

There is PKGBUILD file included so that you can patch them. However I wanted to add some patches for macbook pro so that I
corrected the PKGBUILD a bit and added some patches. The patches can be found here with explanations.

2. Compile the kernel

Before doing this, make a back of your files /boot/initramfs-linux.img and /boot/vmlinuz-linux (no need if you compile those files with different name, which is recommended)

Now we can compile. If you have made the pkg correctly, then you can use

pacman -U filename.tar.bz

to apply the patch, and it will create a new linux-mainline img file for you.

3. Create a vbios emulation which will be copied from any bootable CD

Now we are going to make video bios from any of bootable bios cd.
I used archlinux liveCD for that.

This is how to;
-boot from the CD
-type 
 dd if=/dev/mem of=vbios.bin bs=65536 skip=12 count=1
 dd if=/dev/mem of=/boot/int10.bin bs=4 skip=16 count=1
-copy the vbios.bin and int10.bin into /lib/firmware/radeon and /boot
That's all.

4. Now we are going to correct the grub.cfg file.

This is a part of my grub.cfg file. Go down through the file and find the right place.

### BEGIN /etc/grub.d/10_linux ###
menuentry 'Arch Linux GNU/Linux, with Linux mainline kernel' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-mainline kernel-true-a8ca6c35-c261-4b1c-9858-88a12804302d' {
 load_video
 set gfxpayload=keep
 insmod gzio
 insmod part_gpt
 insmod ext2
 set root='hd0,gpt4'
 if [ x$feature_platform_search_hint = xy ]; then
 search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt4 --hint-efi=hd0,gpt4 --hint-baremetal=ahci0,gpt4 a8ca6c35-c261-4b1c-9858-88a12804302d
 else
 search --no-floppy --fs-uuid --set=root a8ca6c35-c261-4b1c-9858-88a12804302d
 fi
 loadbios /boot/vbios.bin /boot/int10.bin
 echo 'Loading Linux mainline kernel ...'
 linux /boot/vmlinuz-linux-mainline root=/dev/sda4 ro loglevel=7 radeon.modeset=1 i915_lvds_channels=2 i915.modeset=1 i915.lvds_use_ssc=0 acpi_backlight=vendor vt.handoff=7
 echo 'Loading initial ramdisk ...'
 initrd /boot/initramfs-linux-mainline.img
}

Then you will be able to boot and your video card should work now with KMS mode. If you have an external monitor, your now it will
automatically work as well.

To install Xorg-server and setting up the monitor, there are many documents for instance, here

Some Remarks

– Do not update your linux kernel after you compile it. Freeze pacman into a certain date. I closed up ‘core’ repository on the mirror file for pacman. (/etc/pacman.d/mirrorlist)
– If anyone with another model of macbook pro with nVidia video card there is a patch for that too.
-Do not forget to install the video driver from pacman : xf86-video-ati, xf86-video-intel
-On the video card setup for Xorg-server, two videos are not working together so far. I use radeon.

References:
http://ubuntuforums.org/showthread.php?t=1695746&page=85
https://bugs.freedesktop.org/show_bug.cgi?id=26891
https://help.ubuntu.com/community/UEFIBooting#Apple_Mac_EFI_systems
http://www.b1c1l1.com/blog/
http://cgit.freedesktop.org/nouveau/linux-2.6/commit/?id=c9b07e9e85e5b7fe38c9f009967e8bed51d3760b

How To Install Archlinux on MacBook Pro 8,2 [Part.1]

After a long time struggling, finally I am able to write this post on Archlinux!

The reason why I choose Arch; simplicity/configurable/curiosity

I am not a long-term linux user yet, and this installation process has helped me to understand further how the system works. Especially, this apple product made it extra hard, which challenged me even more. I had so much fun(?) and quite happy for now.

I thought it is really necessary to post this, since when I was installing, I had lack of information especially on MacBook pro 8,2. Some existing post for me was very confusing ; this is probably because I am not mature enough on this world. I wish this can be a help for people like me.

Part 1 is going to be focused on the installation process, and Part 2 is to work with Xorg-server by configuring those two problematic video cards!

0. Before you install

-Install rEFit on OSX for choosing the boottable partition. I have seen some complains that this doesn’t work on OSX, but it works fine without any issue.

-check your harddrive name; in orx ->disk0s1 disk0s2 but in Linux -> sda0 sda1. You should know which hard drive you are going to use in order to avoid an accidental erase of your other system.

You need to be able to use either ‘nano’ or ‘vi’ in order to edit some files on the process.

1. Choosing the right installation method

You will need a cd room for installation. The UEFI system on apple machin makes tricky to install from USB. This is the same as any other installer such as Ubuntu.  I will not talk about how to make partition. This can be done with DiskUtility from OSX.

I installed first with the official iso, and yes you can install with this. But there is a bug when you meet the moment to choose which harddrive partition you would like to install. So I choose ‘Archboot‘ Download this iso for macbook pro.

Download it -> make a CD -> boot with CD (pressing C button when booting)

2. Remarks on Installation Process

Then there is setup process. I will explain only remarkable parts because the installer is quite friendly and there is a wonderful document ‘Beginner’s guide’ After you setup font/date etc, you will enter here.

   Menu2: Prepare hard drive 

Do not use the first option ‘Auto-Prepare’ which will erase all data from the harddrive. Go to the 4th option ‘Set Filesystem Mountpoints’

This is to set where you would like to install the system.

If you have an extra partition for swap, set up here too. I set one swap partition and one main one with ‘EXT3.’ (Some how EXT4 had more trouble with booting. Ext3 is more stable for me.)

It will ask for label and additional setup, which you can skip, but I set up the label only as ‘Arch.’

Then it will prepare the partition for you.

**warning message -> /boot is not set : you can ignore this unless you have a different partition for the booting sector. I did on .’/’ .

Then it will install the core system for you. Packages were already choosen by default and you can just follow it easily.

After that, it will show a menu for system configuration. Please check the beginner’s guide for any other information

For MBP, here you need to do somethings like;

mkinitcpio.conf : add on the MODULE=”ahci libahci’

pacman.conf : go down to mirror connection-> remove ‘#’ mark for [core][extra][community] sections.

  Installing Bootloader

There are two options ‘Refind’ Grub2′. Either is okay, but I only tried here with Refind. This will be installed on your top partition for EFI drive. (/dev/sda1) I was frightened when I realize that. rEFind is fine for anything, but your kernel will be uploaded up there, and then you will have to mount this partition all the time. So I recomment ‘Grub2’ which is easier to figure out, and many information is out there to help you.

The installer will lead you to the ‘editing’ the configuration for grub. Skip this part because any way you should come back and install grub again!

Then the installation finished.

3. After the installation; the real war

Reboot and come back to CD. then do;

 mkdir /mnt/arch
 mount /dev/sdXX /mnt/arch ###X is your system partition number. mine is sda4
 cd /mnt/arch
 mount -t proc proc proc/
 mount -t sysfs sys sys/
 mount -o bind /dev dev/
 chroot .

(You can do this whenever you need to configure the new system from the LiveCD.)

Now you get into your new system. Here you are going to install grub correctly and configure.

Install grub

mkdir -p /boot/efi

mount /dev/sdXX /boot/efi ### yes you are mount the disk you are in into the booting erea.sdXX for me is sda4 again.

grub-install --directory=/usr/lib/grub/x86_64-efi --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=arch_grub --boot-directory=/boot --recheck --debug

Create the configuration file;

grub-mkconfig -o /boot/grub/grub.cfg

That’s it.

Then let’s check the grub.cfg file. Go down a bit and find like this;

/boot/grub/grub.cfg
menuentry 'Arch Linux GNU/Linux, with Linux mainline kernel' --class arch --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-mainline kernel-true-a8ca6c35-c261-4b1c-9858-88a12804302d' {
 load_video
 set gfxpayload=keep
 insmod gzio
 insmod part_gpt
 insmod ext2
 set root='hd0,gpt4'
 if [ x$feature_platform_search_hint = xy ]; then
 search --no-floppy --fs-uuid --set=root --hint-bios=hd0,gpt4 --hint-efi=hd0,gpt4 --hint-baremetal=ahci0,gpt4 a8ca6c35-xxxx-xxxx-xxxx-xxxx
 else
 search --no-floppy --fs-uuid --set=root a8ca6c35-c261-4b1c-9858-88a12804302d
 fi
 echo 'Loading Linux mainline kernel ...'
 linux /boot/vmlinuz-linux root=/dev/sda4 ro nomodeset
 echo 'Loading initial ramdisk ...'
 initrd /boot/initramfs-linux.img
}

-‘root’ part will be shown up with UUID. check your UUID of your disk and see if that matches. (don’t worry if it looks not exactly the same as this. I added some things too. We’ll discuss it later.)

ls -l /dev/disk/by-uuid/

-Important!!! : there in the middle of the ‘grub.cfg’ file, you can see ‘ro’ and you won’t see ‘nomodeset’, which you will need to add like I did. Otherwise your videocard will prevent from booting. We are going to do the videocard set up later on. For now we set up like this.

-Copy ‘grubx64.efi’ in /boot/efi/EFI/arch_grub/ into /boot/efi/EFI/boot/bootx64.efi in order to make a backup. This will prevent any problem from linux kernel upgrade.

Now you need to re-generate initramfs-linux.img file. Do it as below;

mkinitcipio -p linux

Then please check on /boot directory if you have those two files;

initramfs-linux.img 
vmlinuz-linux

Then go boot to OSX. We are going to set the efi booting.

on terminal :

mkdir /Volumes/esp
 sudo mount -t msdos /dev/disk0s1 /Volumes/esp   ####disk0s1 here should be your linux system partition; it can be disk0s2, disk0s3 etc.
 sudo bless --mount /Volumes/esp --setBoot --file /Volumes/esp/EFI/arch_grub/grub.efi

This worked for me only once, and I cannot explain why it is not working anymore.

If this doesn’t for you, try to install ‘OSXFUSE’ together with ‘fuse-ext2’ on OSX, which will support mounting ext2, ext3 format on osx.
This is the way to do with those tool;

sudo fuse-ext2 /dev/disk0s4 /Volumes/arch -o force

If bless doesn’t work after all you have tried, this worked for me too;

sudo /usr/sbin/bless --device /dev/disk0s1 --mount /Volumes/esp --setBoot --file /Volumes/esp/EFI/arch_grub/grub.efi

Now you should be able to boot to the new system. Check if refit can show your partition.

Please feel free to ask any question. I have spent quite a few days to figure this out, and I think I know all possible errors it can take. I did this procedure over 10 times, and wrote this by heart.

Blacklist some modules;
 go to /etc/modprobe.d/modprobe.conf and add
blacklist sdhci-pci
blacklist sdhci

I didn’t explain how to configure all the other files such as /etc/rc.conf. Those can be found on the arch wiki page below. So please do not think that this is all that you need.

I will see you on Part2 soon!

References :
grub2: https://wiki.archlinux.org/index.php/GRUB2
MBP on arch: https://wiki.archlinux.org/index.php/MacBook_Pro_8,1_/_8,2_/_8,3_(2011_Macbook_Pro)
https://wiki.archlinux.org/index.php/MacBook_Pro_8,1_/_8,2_/_8,3_(2011_Macbook_Pro)
https://bbs.archlinux.org/viewtopic.php?pid=1117490

 

Jack to work with SuperCollider in Linux

I am still quite new to Linux in general. I am learning a lot by just trying to use it, and trying not to move back to OSX just to do a simple task. So that this post might be for a person like me, who has struggled a lot on this ‘new’ way of patching sound in and out and configuring in a right way.
I have used Jack before in OSX when I was trying to do a virtual multichannel test, but there was a graphical interface, not at all complicated. There is also ‘system preference’ that OSX offers. When I change the soundcards, or using different inputs/outputs, I didn’t need to do much. But here, it might be a simple thing, but I was in panic.
So that I would like to share my experience if this can help anyone who is like me.

I have two different versions of linux that I am using in different laptop. 11.04/11.10.

Here I am focusing on 11.04, because 11.10 had less issues.

Jack versions and library installed : jackd, libjack-jackd2-dev, jackd2-firewire, jackd2, libjack-jack2-0, libasound2-plugins

First of all, I was at the first moment trying to use ‘qjackctl‘ that offers graphical user interface. But weiredly, the value that I have changed was not applied to the result.

Screenshot of qjackctl setup window

The default sample rate was set to 48000, and I wanted to change it into 44100. Even though I was doing it, it didn’t change.

Asking some people around, I found that pulsa audio can be the cause of issue, so I removed it and tried to use only ‘alsa.’

Jack setup

When I run scvim, I use a bash script in order to reduce any possible complications such as already-running-sclang. I saved it as ‘iscvim’ and fixed chmod to an exacutable, and put it into a path (i.g. /usr/local/bin.).

Here I include jack setup as well.

#!/bin/bash
cd ~
killall jackd
killall sclang
killall scsynth
killall scvim
killall sclangpipe_app
jackd -t 500 -d alsa -d hw:0 -r 44100 -p 1024 -s -S &
sleep 1
scvim

Here I set to use alsa as the driver, and device as hw:0, sample rate: 44100, period 1024, softmode and the last of -S is to cofigure card for 16bit. This configuration can differ from soundcard. I tried to use 32 bit, but my sound card only supports 32 bit-float. But this created problem with sc3, (creating distortion) and I assume that this is because of -float- (it could be supposed to be integer).

Check something like this when you run jack,

ALSA: final selected sample format for capture: 32bit float little-endian

or

ALSA: final selected sample format for capture: 16bit little-endian

In order to know what card you have;

cat /proc/asound/cards

In order to know what other configuration will be possible with your soundcard, use ‘jack_control,’ which shows you all possible options for your setup, and not difficult to use.

For Realtime Scheduling

This is followed by what ‘jack’ website suggests, and it works very well. (http://jackaudio.org/linux_rt_config)

Open /etc/security/limits.d/audio.conf

Then fix as below.

# Provided by the jackd package.

#
# Changes to this file will be preserved.
#
# If you want to enable/disable realtime permissions, run
#
# dpkg-reconfigure -p high jackd
@audio - rtprio 95
@audio - memlock unlimited
#@audio - nice -19

So far, no issue when I am using SCVim, and I run Jack when I need to use it.  Hope this helps.