Thursday, April 29, 2010

Ubuntu 10.04 on Mac Mini

This post describes a short procedure for installing Ubuntu 10.04 on a Mac mini. The instructions were initially written (and should still work) for older Ubuntu versions, down to 8.10. However, I haven't tested the old versions for a long time.

The process is roughly the same as my previous instructions for Ubuntu 8.04, but the write-up is more detailed to address the questions I have received last time. So don't the post length scare you!

Outline
The article starts with a warning describing the shortcomings of installing Ubuntu on the newest Mac Mini model. That is followed by a step-by-step guide for installing Ubuntu which should work on any Mac (tested only on Minis though). The post ends with instructions on how to restore your dual-boot solution if Mac updates break it, and a list of (community-contributed) tricks for getting some hardware to work on the latest Mini.

Warning (skip if you're sure you want Ubuntu)
Ubuntu will not work seamlessly on the new Mac mini (model MacMini3,1 with 5 USB ports). This is based on the release version of Ubuntu 10.04.

Wireless does not work right after installation, so Ethernet is needed, at least for bootstrapping. Once the system gains Internet access, it offers to install a Broadcom STA wireless driver which offers good performance. Grub 2 will get stuck and not show the boot menu about one times in five. This is uncomfortable if you're planning to use your Mini as a server that sits somewhere far away. For desktop usage, you'll probably want to install the nVidia proprietary drivers. On the open-source nouveau drivers, my screen doesn't get recognized when using mini-Display Port, but it works reasonably well when connected via the mini-DVI port. Sound doesn't work out of the box, and you'll need to hack your configuration files to get it to work (see below).

Method
  1. Use a Leopard or Snow Leopard (Desktop or Server) install disc to get your Mac in pristine form. This step is intended to undo anything that might have gone wrong in your previous attempts. You can skip it if you have a fresh install.
  2. Use Software Update to ensure you have all your updates installed. Update and reboot until there are no updates left.
  3. Start up Boot Camp Assistant (press Apple+Space to open Spotlight, then start typing the name until the application appears) and create a "Windows" partition.
  4. Do not let Boot Camp Assistant reboot your computer. Use Apple+Q to quit once it's done partitioning.
  5. Download and install the latest version of rEFIt (0.14 at the time of this writing) from http://refit.sourceforge.net/
  6. Open up Terminal (use Spotlight if you don't have it on your dock) and type the following commands:
    cd /efi/refit
    ./enable-always.sh
  7. Insert your Ubuntu CD, and shut down the computer, then power it back up.
  8. You should see the rEFIt boot screen.
  9. Select the Ubuntu CD (it should have a penguin on it) and go through the normal installation process. If rEFIt doesn't recognize the Ubuntu CD, power-cycle your Mac, and use Bootcamp to boot the Ubuntu CD - press and hold the Alt key as soon as the computer starts up, until the BootCamp screen shows up; select the CD image.
  10. When you have to do partitioning, choose Manual. Remove the Windows partition (the big FAT32 partition at the end). Create an ext4 partition (be sure to to allow for swap space) and set it to mount to /, then create a swap partition. If you're unfamiliar with partitioning a Linux system, read the recommendations below.
    • Click on the FAT32 partition, then click the Delete Partition button.
    • Click on the free space entry at the bottom, then click the New partition button. Select Ext4 journaling file system under Use as:, check the Format the partition: box and select / as the Mount point:. Now subtract twice your RAM size from the partition size. For example, if your partition size is 53575 Mb and you have 1Gb of RAM, you would write in 51527, which is 53575 - 2*1024. Press OK when you're done.
    • Click on the free space entry at the bottom, then click the New partition button. Select swap area under Use as: then press OK.
  11. Unless you know what you're doing, do not change the Advanced settings on the last installation screen. Specifically, don't change the default Grub installation location (hd0).
  12. When the installation is done, the Mac will reboot (if you're lucky) or beep multiple times. If it beeps, turn it off (press the power button for 4 seconds) then turn it back on.
  13. When you get the rEFIt boot screen, go to Partitioning Tool (bottom row, second icon from the left). It will prompt you if you want to update the MBR to reflect the GPT. Press Y, and watch the system reboot.
  14. Power down the system by pulling the power cord. Then power up again.
  15. Select Macintosh HD, and make sure you can boot into OSX. If it doesn't boot after 2 minutes, power cycle (see previous step) again.
  16. Optionally, switch the boot default to Linux. Open up /efi/refit/refit.conf in TextEdit, and uncomment the line saying #legacyfirst (at the bottom of the file).
  17. Reboot your Mac mini, and enjoy choice!
OSX software updates might remove your ability to dual-boot. The colorful boot menu will disappear, and your computer will boot into Mac OSX. If that happens, you can restore dual-booting with the following commands (step 6 from the guide above):
  • Open up Terminal (use Spotlight if you don't have it on your dock) and type the following commands:
    cd /efi/refit

    ./enable-always.sh
Hint: you can bookmark this post to have the solution handy. I won't mind :)

Getting Hardware to Work (community-contributed)
The tips here should help if you want to go beyond Ubuntu's out-of-the-box hardware support. These were contributed by others, and I just put them together on one page.
Sound (by nonspeaking) - not needed after Ubuntu 9.10 Beta
To get the sound working, add the following line to /etc/modprobe.d/alsa-base.conf
options snd-hda-intel model=imac24

Motivation
If you're curious, the following reasons determined me to write this post
  • My readers commented on my installation method for Ubuntu 8.04, and said it doesn't work for 8.10. Takeaway: please do comment! I listen :)
  • I got a new Mac Mini (MB464LL/A, 5 USB ports) to replace the one that was stolen from me.
Enjoy Ubuntu on your Mac!
Please leave a comment if you find a shorter way, or if something is not working for you.

Wednesday, April 21, 2010

Rails 3 Development Setup for Ubuntu

This post describes the steps needed to set up a fresh Ubuntu installation so you can start playing with Rails 3 and contribute to it

Method
This method isn't the most conventional way of developing on Ubuntu (I do replace the Ubuntu-supplied RubyGems binaries, so that I can get the latest version, and get gem binaries on my path). It also is not the most secure method (you will create install a ton of packages and create some random users on your database servers). It's quite fast and effective for development, though.

I have tested the steps below on Ubuntu 10.04 (Lucid Lynx), and I have good reasons to believe that they will work on Ubuntu 9.04 (Karmic Koala) as well.

Start off by installing some Ubuntu packages:
sudo apt-get update; sudo apt-get dist-upgrade
sudo apt-get install ruby rubygems ri ruby-dev libopenssl-ruby build-essential mysql-client mysql-server libmysqlclient-dev postgresql postgresql-client libpq-dev sqlite3 libsqlite3-dev curl git-core git-completion git-doc git-gui

Override Ubuntu's crippled RubyGems with the proper version:
sudo gem install rubygems-update
gem env | grep 'EXECUTABLE DIRECTORY'
sudo `gem env | grep 'EXECUTABLE DIRECTORY' | ruby -e "puts gets.split(': ', 2).last"`/update_rubygems

Create the rails user in MySQL:
echo "GRANT ALL ON *.* TO 'rails'@'localhost';" | mysql -uroot

Create a superuser in PostgreSQL:
sudo -u postgres createuser --superuser $USER
echo "\\password $USER" | sudo -u postgres psql

Install rvm:
sudo gem install rvm
rvm-install
echo "if [[ -s /home/$USER/.rvm/scripts/rvm ]] ; then source /home/$USER/.rvm/scripts/rvm ; fi" | cat - /home/$USER/.bashrc > /home/$USER/.bashrc2
rm /home/$USER/.bashrc; mv /home/$USER/.bashrc2 /home/$USER/bashrc


Install the Rails-preferred VM and create a clean gem set:
rvm install 1.8.7
rvm use 1.8.7
rvm gemset create rails3
rvm gemset use rails3
gem install bundler mocha

Prepare to work on Rails (do this every time you start a shell):
rvm use 1.8.7
rvm gemset use rails3

Check out Rails and install its dependencies:
git clone git://github.com/rails/rails.git
cd rails
bundle install
rake mysql:build_databases
rake postgresql:build_databases

Run the Rails test suite. If it passes, your environment is all set up. 
rake  # This should be run in the rails directory.

If you want to create a test application, then you should install the gems from the edge Rails:
rake install  # This should be run in the rails directory.

Happy hacking!

Motivation
At one of Boston.rb's hackfests, Dan Pickett held a workshop on contributing to Rails 3. I think I was the only one in the room not using OS X, and I had to follow a slightly different sequence of steps to get my setup working. I figured it's nice to summarize all the steps for future reference.

Conclusion
Thank you for reading! I hope the post above has been helpful, and hope you'll have fun playing with Rails 3. I look forward to your comments and suggestions for improving the method outlined here.