Add OS-X-related posts.
[blog.git] / posts / Humanizing_OS_X.mdwn
1 Over the past few months, my wife has gone through a number of
2 operating systems.  The Windows XP on her elderly laptop was finally
3 overrun by viruses, and we didn't have an XP install CD, so I moved
4 her over to Ubuntu.  Recent stock Ubuntu installations are not
5 particularly snappy on 300-odd MB of RAM, so after a few days I moved
6 here over to Gentoo, since I have a lot of experience running
7 stripped-down Gentoo systems on my netbook.  Unfortunately, my wife's
8 not really a big supporter of the stripped-down approach, so after the
9 second 30-MB slide show started taking down Open Office, we threw in
10 the towl and went shopping for a Mac.  The entry-level MacBook Pros
11 are reasonably priced (especially with my student discount), and she
12 gets another core and 10 times the memory and disk space.  I, on the
13 other hand, get to work the kinks out of a Unix system so I can quash
14 it into our home network.  Ready?
15
16 User switching
17 --------------
18
19 By default, there's no easy means to switch between users without
20 logging out completely.  Can't have that.  Go to
21
22     System preferences -> Accounts -> Login Options
23
24 and select `Name` (or whatever) for `Show fast user switching menu
25 as`.  This puts a widget in the toolbar near the clock which lets you
26 switch users without closing all your running applications.
27
28 SSH
29 ---
30
31 Sooner or later, your wife will come home and want to sit down in
32 front of her shiny new laptop.  Add a second keyboard by enabling
33 [[SSH]] ;).
34
35     System preferences -> Sharing -> Remote login
36
37 Kerberos
38 --------
39
40 I recently moved the home fileserver to [[Kerberos + NFSv4|Kerberos]].
41 Luckily, OS X support for Kerberos is pretty solid, and NFSv4 support
42 is just solid enough for me to mount my shares.  Copy your
43 `/etc/krb5.conf` over to `/Library/Preferences/edu.mit.Kerberos`.
44
45 You might have to edit it slightly, because Snow Leopard was ignoring
46 my DNS network name suggestion and using `.local`.  This is probably
47 what I should have used in the first place, but it's not worth
48 reworking the home system now, so use something like
49
50     [domain_realm]
51         .d.net = R.EDU
52         d.net = R.EDU
53         .local = R.EDU
54
55 If your DHCP server doesn't point out your home DNS resolver, you can
56 add it by hand in
57
58     System preferences -> Network -> AirPort -> SID -> Advanced -> DNS
59
60 Now `kinit` and company should work as expected, but with OS X, you're
61 not doing it right unless you're using a graphical interface, so they
62 provide `/System/Library/CoreServices/Ticket Viewer`.
63
64 If you want to store your password in your keychain, run
65
66     $ echo | kinit
67
68 which will pop up a password dialog with a `Remember this password...`
69 checkbox.  Find the entry in
70
71     /Application/Utilities/Keychain Access
72
73 and click on the `info` button.  Under `Access Control`, it should
74 mention that access is always allowed from `kinit`.  You can test this
75 from the command line by running
76
77     $ kinit
78
79 which will now grab a new TGT automatically (i.e. no password prompt).
80
81 For long-running NFS mounts, you might want to setup automatic ticket
82 renewal.  This is a task for [launchd][], an `rc/init/cron`
83 replacement that reads service info from `plist` files
84 (`launchd.plist(5)`).  There is a system-provided Kereberos renewal
85 service
86
87     /System/Library/LaunchAgents/com.apple.Kerberos.renew.plist
88
89 but it [has some issues][krenew].  Rather than patching the system
90 file, I just created my own alternative:
91
92     $ cat ~/Library/LaunchAgents/local.Kerberos.renew.plist
93     <?xml version="1.0" encoding="UTF-8"?>
94     <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
95     <plist version="1.0">
96     <dict>
97       <key>Label</key>
98       <string>local.Kerberos.renew.plist</string>
99       <key>Program</key>
100       <string>/usr/bin/kinit</string>
101       <key>Disabled</key>
102       <false/>
103       <key>RunAtLoad</key>
104       <true/>
105       <key>ThrottleInterval</key>
106       <integer>6000</integer>
107       <key>KeepAlive</key>
108       <dict>
109         <key>SuccessfulExit</key>
110         <true/>
111       </dict>
112     </dict>
113     </plist>
114
115 Start the service with
116
117     $ launchctl load Library/LaunchAgents/local.Kerberos.renew.plist
118
119 The `Disabled` `false` setting shouild mean that the service will
120 start automatically on the next boot.  Note that if your KDC goes down
121 and a renewal fails, the service will stop, and you'll have to restart
122 it once the KDC is back up.
123
124 NFS
125 ---
126
127 Once you've got Kerberos setup, mounting an NFS file system is just:
128
129   $ sudo mount -t nfs -o vers=4.0alpha,sec=krb5p,intr,soft my-host:/ /Volumes/my-nfs/
130
131 Note that the Apple folks are still nervous about their NFSv4
132 implementation.  From `mount_nfs(8)`:
133
134     The current NFSv4 functionality is "alpha quality" software.  Some
135     basic functionality is not yet implemented.  Use at your own risk.
136     Currently, the only way to enable NFSv4 is to specify the mount
137     option:
138
139       -o vers=4.0alpha
140
141     This special option value is only temporary and will no longer be
142     necessary (or supported) once the NFSv4 functionality is ready for
143     general use ( -o vers=4 will be sufficient ).
144
145 I haven't noticed any glitches yet, but it might be wise to restrict
146 write access from the OS X client to less critical directories, just
147 to be on the safe side.
148
149 The graphical approach to configuring NFS is
150
151     Applications -> Utilities -> Disk Utility -> File -> NFS mounts
152       Remote NFS URL: nfs://my-host/
153       Mount location: /Volumes/my-nfs
154       Advanced Mount Parameters:  vers=4.0alpha,sec=krb5p,intr,soft
155
156 After you do this, the mount should come up automatically on boot.
157 You can unmount the drive through the Finder sidebar, but I haven't
158 figured out how to remount it through the graphical interface.
159
160     $ sudo mount -a
161
162 seems to work fine though ;).
163
164 FLAC and Ogg
165 ------------
166
167 Somewhat shockingly, iTunes doesn't support [FLAC][] or [Ogg Vorbis][]
168 out of the box.  To get Ogg Vorbis support, install the [Xiph
169 Quicktime Component][xiphqt].  Their `ReadMe.rtf` explains that
170 installation is just
171
172   $ sudo cp -r Desktop/XiphQT-unpacked/XiphQT.component /Library/Components/
173
174 XiphQT gives you the ability to decode assorted xiph codecs and
175 containers, but iTunes may still need some handholding to actually
176 import the files into its library.  [Fluke][] handles that for FLAC
177 files, but the code is a bit crufty.  I've been cleaning it up a bit,
178 and I'll probably post my changes on the Google Code site over the
179 weekend.
180
181 iTunes
182 ------
183
184 Once you've got codec support in place, you should configure iTunes.
185 I unchecked `Copy files to iTunes Media folder when adding to library`
186 in
187
188   iTunes -> Preferences -> Advanced
189
190 Then get iTunes to index your NFS-mounted FLAC with
191
192   File -> Add to library
193
194 Add the FLAC with
195
196   $ flukeapp path/to/my/music/directory
197
198 Remote desktop
199 --------------
200
201 There's not much documentation online, but there is a [MS Remote
202 Desktop][rd] client available ([Microsoft page][rd-ms], [Apple
203 page][rd-a]).  The package installs into 
204
205     /Applications/Remote Desktop Connection.app
206
207 double-clicking on this from Finder will fire it up, and you can
208 configure it to log into your company's server, save the
209 configuration, and make a symlink for easy launching from the desktop:
210
211     $ ln -s ~/Documents/RDC Connections/Default.rdp ~/Desktop/WidgetsLtd.rdp
212
213 Gentoo Prefix
214 -------------
215
216 The above steps get everything setup for basic usage, but you'll
217 notice that we had to install a few applications by hand.  This just
218 consisted of unpacking a few bundled objects onto the system, but the
219 OS will not be out checking for bug fixes and upgrades to keep our
220 installations current.  I'm missing my [portage][] package manager.
221 It's ok though, there are a number of package managers designed for OS
222 X.  The major players are [Fink][] ([Debian][] tools) and [MacPorts][]
223 ([FreeBSD][] tools?), but there are fringe groups supporting the DIY
224 [Homebrew][] and my personal favorite, [Gentoo Prefix][gprefix]
225 ([Gentoo][] tools).  Pick your favorite.  The issue with any of these
226 tools will be interfacing with the underlying OS, since you don't want
227 the OS to sneakily replace your GCC without your package manager
228 knowing about it.  To deal with this, the package managers do varingly
229 complete jobs of toolchain bootstrapping to isolate their toolchain
230 from Apples [Xcode][].  Unfortunately, Xcode is not free, but if
231 you've just bought a Mac, you can probably afford the $4.99 it costs
232 for 9.3 GB of installed tools ;).
233
234 Bootstrap your Gentoo Prefix following the [MacOS docs][gp-mac]:
235
236     $ export EPREFIX="$HOME/Gentoo"
237     $ export PATH="$EPREFIX/usr/bin:$EPREFIX/bin:$EPREFIX/tmp/usr/bin:$EPREFIX/tmp/bin:$PATH"
238     $ export CHOST="x86_64-apple-darwin10"
239     $ curl 'http://overlays.gentoo.org/proj/alt/browser/trunk/prefix-overlay/scripts/bootstrap-prefix.sh?format=txt' > bootstrap-prefix.sh
240     $ chmod 755 bootstrap-prefix.sh
241     $ ./bootstrap-prefix.sh $EPREFIX tree
242     $ ./bootstrap-prefix.sh $EPREFIX/tmp make
243     $ ./bootstrap-prefix.sh $EPREFIX/tmp wget
244     $ ./bootstrap-prefix.sh $EPREFIX/tmp sed
245     $ ./bootstrap-prefix.sh $EPREFIX/tmp python
246     $ ./bootstrap-prefix.sh $EPREFIX/tmp coreutils6
247     $ ./bootstrap-prefix.sh $EPREFIX/tmp findutils
248     $ ./bootstrap-prefix.sh $EPREFIX/tmp tar15
249     $ ./bootstrap-prefix.sh $EPREFIX/tmp patch9
250     $ ./bootstrap-prefix.sh $EPREFIX/tmp grep
251     $ ./bootstrap-prefix.sh $EPREFIX/tmp gawk
252     $ ./bootstrap-prefix.sh $EPREFIX/tmp bash
253     $ ./bootstrap-prefix.sh $EPREFIX portage
254     $ hash -r
255     $ emerge --oneshot sed
256     $ emerge --oneshot --nodeps bash
257     $ emerge --oneshot pax-utils
258     $ emerge --oneshot --nodeps wget
259     $ emerge --oneshot --nodeps baselayout-prefix
260     $ emerge --oneshot --nodeps xz-utils
261     $ emerge --oneshot --nodeps m4
262     $ emerge --oneshot --nodeps flex
263     $ emerge --oneshot --nodeps bison
264     $ emerge --oneshot --nodeps binutils-config
265
266 Now check `gcc --version` to see which version of [GCC][] Xcode
267 installed.  If it's not 4.2.1, check the bootstrap docs.
268
269     $ emerge --oneshot --nodeps binutils-apple
270     $ emerge --oneshot --nodeps gcc-config
271     $ emerge --oneshot --nodeps gcc-apple
272     $ emerge --oneshot coreutils
273     $ emerge --oneshot findutils
274     $ emerge --oneshot tar
275     $ emerge --oneshot grep
276     $ emerge --oneshot patch
277     $ emerge --oneshot gawk
278     $ emerge --oneshot make
279     $ emerge --oneshot --nodeps file 
280     $ emerge --oneshot --nodeps eselect
281     $ FEATURES="-collision-protect" emerge --oneshot portage
282     $ rm -rf $EPREFIX/tmp/*
283     $ hash -r
284     $ emerge --sync
285     $ USE=-git emerge -u @system
286     $ echo 'USE="unicode nls"' >> $EPREFIX/etc/make.conf
287     $ echo 'CFLAGS="-O2 -pipe <my-cpu-flags>"' >> $EPREFIX/etc/make.conf
288     $ echo 'CXXFLAGS="${CFLAGS}"' >> $EPREFIX/etc/make.conf
289     $ emerge -e @system
290     $ cd $EPREFIX/usr/portage/scripts
291     $ ./bootstrap-prefix.sh $EPREFIX startscript
292     $ cp $EPREFIX/startscript ~/
293
294 Then run `startscript` whenever you want to start a shell from the
295 Prefix with appropriate path and environmental variables.  Use this
296 shell for future `emerge` calls.
297
298 Bootstrapping is not the most fun procedure in the world, but once
299 it's done, you don't have to worry about it ever again.  All your open
300 source packages can then be easily maintained with a mature package
301 manager, which will certainly save you some time later on.
302
303 Unfortunately, there are not as many open source devs running OS X as
304 there are running GNU/Linux, so it may take a bit of leg work to get
305 oddball packages into your package manager's repository.  I've
306 published my [[Gentoo Prefix overlay]] with assorted tools I used to
307 troubleshoot Fluke; take a look if you like [[Python]] ;).
308
309 Resources
310 ---------
311
312 OS X is certaily different from the GNU/Linux systems I've worked with
313 to date.  For example, the file system is all shuffled around, and
314 it's built on [HFS+][], which stores metadata and resource forks for
315 each file.  There are also [aliases][] (fancy symlink), bundles apps,
316 etc.  For an old-but-useful introduction to the OS from a Linux
317 perspective, check out Amit Singh's 2003 [What is Mac OS X][wmox].
318
319 [launchd]: http://www.afp548.com/article.php?story=20050620071558293
320 [krenew]: http://linsec.ca/Using_Kerberos_5_for_Single_Sign-On_Authentication#Setting_up_a_Mac_OS_X_Client
321 [FLAC]: http://flac.sourceforge.net/
322 [Ogg Vorbis]: http://www.vorbis.com/
323 [xiphqt]: https://www.xiph.org/quicktime/download.html
324 [Fluke]: https://code.google.com/p/flukeformac/
325 [rd]: http://en.wikipedia.org/wiki/Remote_Desktop_Protocol
326 [rd-ms]: http://www.microsoft.com/mac/remote-desktop-client
327 [rd-a]: http://www.apple.com/downloads/macosx/networking_security/remotedesktopconnectionclient.html
328 [portage]: http://www.gentoo.org/doc/en/handbook/handbook-x86.xml?part=2&chap=1
329 [Fink]: http://www.finkproject.org/
330 [Debian]: http://www.debian.org/
331 [MacPorts]: http://www.macports.org/
332 [FreeBSD]: http://www.freebsd.org/
333 [Homebrew]: http://mxcl.github.com/homebrew/
334 [gprefix]:  http://www.gentoo.org/proj/en/gentoo-alt/prefix/
335 [Gentoo]: http://www.gentoo.org/
336 [Xcode]: http://developer.apple.com/xcode/
337 [gp-mac]: http://www.gentoo.org/proj/en/gentoo-alt/prefix/bootstrap-macos.xml
338 [GCC]: http://gcc.gnu.org/
339 [HFS+]: http://en.wikipedia.org/wiki/HFS_Plus
340 [aliases]: http://en.wikipedia.org/wiki/Alias_%28Mac_OS%29
341 [wmox]: http://osxbook.com/book/bonus/ancient/whatismacosx/