Running CDE on FreeBSD on a Mac Mini

Intro

Just for fun I installed FreeBSD on a Mac Mini 3.1 (early 2009), and installed compiled CDE as desktop environment.
Here's a screenshot of my desktop:

Installation

These are the key steps to do so:

  1. Download the memstick image of FreeBSD 11.0 Release for amd64
  2. Write the uncompressed image to an USB thumb drive of at least 1 GB by using dd
  3. Boot the Mac Mini from that USB drive by holding either CMD and u during boot, or by holding ALT and then selecting the USB drive in the upcoming menu
  4. Install FreeBSD as usual, i.e. I let the installer choose the ZFS partitioning scheme, and activated sshd, ntpd, and a local unbound (caching nameserver) during system boot
  5. Log in as root
  6. Edit /etc/ssh/sshd_config, set PermitRootLogin to without-password, and add your public key to /root/.ssh/authorized_keys
  7. Update FreeBSD to the latest patch level:
    # freebsd-update fetch install
    # shutdown -r now
    
  8. Install bash and tmux:
    # pkg install bash tmux
    
  9. Change root's shell to bash (not strictly needed, but I prefer bash):
    # pw usermod root -s /usr/local/bin/bash
    
  10. Start a new tmux session:
    # tmux
    
  11. In order to compile CDE, you'll need these packages:
    # pkg install xorg git bdftopcf open-motif ksh93
    
  12. Of course we'll need an appropriate graphics driver:
    # pkg install nvidia-driver-340 nvidia-settings
    
  13. Finally, some useful tools:
    # pkg install vim chromium gimp qmmp vlc pstree xmmix
    
  14. Now, while still in a tmux session, clone the CDE repository:
    # git clone git://git.code.sf.net/p/cdesktopenv/code cdesktopenv-code
    
  15. Now you might follow loosely the CDE wiki for FreeBSD. I did steps #4 (just edit /etc/rc.conf, no need to reboot yet), #7 (make symlinks), #9 (attempt to build), #10 (install cde), and #11 (create directory for ToolTalk). There was no need to install gcc47 nor libXp, and I had not to edit the Xm/Xm.h include file
  16. Create /usr/local/etc/X11/xorg.conf:
    Section "ServerLayout"
    	Identifier     "X.org Configured"
    	Screen      0  "Screen0" 0 0
    	InputDevice    "Mouse0" "CorePointer"
    	InputDevice    "Keyboard0" "CoreKeyboard"
    EndSection
    
    Section "Files"
    	ModulePath   "/usr/local/lib/xorg/modules"
    	FontPath     "/usr/local/share/fonts/misc/"
    	FontPath     "/usr/local/share/fonts/TTF/"
    	FontPath     "/usr/local/share/fonts/OTF/"
    	FontPath     "/usr/local/share/fonts/Type1/"
    	FontPath     "/usr/local/share/fonts/100dpi/"
    	FontPath     "/usr/local/share/fonts/75dpi/"
    EndSection
    
    Section "Module"
    	Load  "dbe"
    	Load  "dri"
    	Load  "dri2"
    	Load  "extmod"
    	Load  "record"
    	Load  "glx"
    EndSection
    
    Section "InputDevice"
    	Identifier  "Keyboard0"
    	Driver      "kbd"
    EndSection
    
    Section "InputClass"
    	Identifier	"KeyboardDefaults"
    	MatchIsKeyboard	"on"
    	Driver		"keyboard"
    	Option		"XkbLayout" "de"
    EndSection
    
    Section "InputDevice"
    	Identifier  "Mouse0"
    	Driver      "mouse"
    	Option	    "Protocol" "auto"
    	Option	    "Device" "/dev/sysmouse"
    	Option	    "ZAxisMapping" "4 5 6 7"
    EndSection
    
    Section "Monitor"
    	Identifier   "Monitor0"
    	VendorName   "Monitor Vendor"
    	ModelName    "Monitor Model"
    EndSection
    
    Section "Device"
    	Identifier  "Card0"
    	Driver      "nvidia"
    	BusID       "PCI:2:0:0"
    EndSection
    
    Section "Screen"
    	Identifier "Screen0"
    	Device     "Card0"
    	Monitor    "Monitor0"
    	SubSection "Display"
    		Depth     24
    		Modes     "1600x1200"
    	EndSubSection
    EndSection
    
  17. As the nvidia kernel module seems not to be loaded during system when added to /boot/loader.conf, I added this to /etc/rc.conf:
    kld_list="nvidia"
    
  18. To make the rear audio jack work I had to add this to /etc/sysctl.conf:
    dev.hdaa.0.gpio_config="0=set 1=set"
    hw.snd.default_auto=2
    hw.snd.default_unit=2
    
  19. Add this to /etc/rc.conf to save and restore audio mixer levels during system reboot:
    mixer_enable="YES"
    
  20. Every host needs to have the correct time. Thus set it with ntpdate and ntpd in /etc/rc.conf when the system boots:
    ntpdate_enable="YES"
    ntpd_sync_on_start="YES"
    ntpd_enable="YES"
    
    Don't forget to set your preferred NTP server(s) in /etc/ntp.conf.
  21. If you prefer a graphical login, create (or add the following line to) /etc/rc.local:
    #!/bin/sh
    
    /usr/dt/bin/dtlogin -daemon
    
    Make it executable by running chmod 0755 /etc/rc.local
  22. Reboot the Mac Mini
  23. If you did not add dtlogin to /etc/rc.local, then login as normal user, and either start /usr/dt/bin/Xsession manually. Or add /usr/dt/bin/Xsession to your ~/.xinitrc, and simply start X by calling startx
  24. You might want to consider setting up a simple local firewall, e.g. add this to /etc/rc.conf:
    firewall_enable="YES"
    firewall_type="workstation"
    firewall_myservices="22/tcp"
    firewall_allowservices="192.168.0.0/24"   # or whatever your trusted net is!
    

Notes

Bluetooth worked out of the box. Thus I could simply follow the Bluetooth section of the FreeBSD handbook:

  1. Verify that the kernel detected the bluetooth hardware and loaded the appropriate driver:
    # dmesg | grep ubt
    
  2. Scan for nearby bluetooth devices:
    # hccontrol -n ubt0hci inquiry
    
  3. Query a remote device for its name, e.g. your mobile phone:
    # hccontrol -n ubt0hci remote_name_request XX:XX:XX:XX:XX:XX
    

Todo