Friday, 30 January 2015

Ports updates for FreeBSD: Minecraft, HFS reading, and more…

I have been spending my time lately doing some maintenance with Ports, updating and fixing the software packages I use. I've submitted a couple of PRs to the FreeBSD team and hopefully my changes will be merged very soon.

Minecraft (games/minecraft-client)
The minecraft-runtime script wasn't working, and the JAVA_VERSION was, in my opinion incorrectly, bumped to 1.8 when it runs perfectly well on 1.7. I have submitted PR 197063 to rectify these issues, and additionally more correctly replace variables in the script templates.
HFSExplorer (sysutils/hfsexplorer)
The current version in Ports no longer exists on SourceForge, as they have moved to GitHub. With the move came a new release that brings some new features and enhanced compatibility. I have submitted PR 197209 to update the distfile location and version.
LWJGL (games/lwjgl)
This library, used by Minecraft, does not currently build with openjdk8. I am currently ironing out this bug so that I can submit a patch either upstream or to FreeBSD (or perhaps both), whichever one is necessary. I'll note further progress on this here on my blog.
Symbola (x11-fonts/symbola)
Elly has submitted PR 197090 to add the Symbola Unicode 7.0 font to FreeBSD. Look for this coming soon.

An article about more MacBook stuff is coming shortly, but for now I'm still working out some issues. Until then, happy hacking everyone!

Saturday, 24 January 2015

FreeBSD on Apple MacBook Pro 8,2: Now with more features

As an update to my last post, I have been able to make more of the features of my 13" Late 2011 MacBook Pro work on FreeBSD 11.0-CURRENT.

Sensor Readings.

Simple: kldload coretemp. To have on boot, add coretemp_load="YES" in /boot/loader.conf.

Cool Temperatures and Power Saving.

You will need to ensure i915kms is loaded and add drm.i915.enable_rc6=7 to your /boot/loader.conf. This was pointed out by the FreeBSD wiki which I could not find, so thank you Elly for helping me find these docs.

Additionally, you can add hw.pci.do_power_nodriver=3 to power down unused PCI cards. They re-enable when you kldload the modules, so this will help if you do not use the SD card reader or FireWire port very much.

Touchpad Gestures.

The atp(4) driver is flaky, but does work. Just add atp_load="YES" to /boot/loader.conf. Two fingers = right-click, three fingers = middle-click. Three finger tap is somehow hilariously much more reliable than two fingers, but with a little persistence they work. Two-finger scroll is a bit wonky and scrolls at unpredictable speeds, but I have a feeling this is a sysctl that may be fixable.


This actually does work right out of the box. I can pair with my phone and use the nifty obexapp utility to transfer files to my Android phone, an HTC One (M8). Unfortunately I was unable to transfer any files or pictures from the phone; obexapp consistently reported "0 bytes streamed in 2 seconds". I think it may be a permissions error as I able to upload files to my phone's Download/ directory correctly but no other directory.

To establish a Bluetooth connection (with an Android phone at least), you have to do the following:

  1. Add your phone to /etc/bluetooth/hcsecd.conf. The examples are quite good. Remember your PIN.
  2. Enable hcsecd in /etc/rc.conf and set flags to ubt0.
  3. Enable sdpd in /etc/rc.conf.
    Your /etc/rc.conf should now have at least the following lines:
  4. Start both services...
    /etc/rc.d/hcsecd start
    /etc/rc.d/sdpd start
  5. Now run obexapp -a phone:bluetooth:mac -C FTRN. Your phone will ask you for the PIN you specified in /etc/bluetooth/hcsecd.conf. Enter it, and you can see files on your FreeBSD computer!

Some More Bumps.

With all of these things fixed, I have had two more snags. One was that my tilde key (the ~ next to the 1 key) on my MacBook's internal keyboard was not working. This was fixed by adding the following line to ~/.xmodmaprc and running xmodmap ~/.xmodmaprc:

keycode 94 = grave asciitilde

My other new bump is that when I plug in headphones, the sound still comes out of the external speakers (and there is no sound in the headphones). This is probably due to some weirdness in the Apple HDA and I will have to take a closer look at this.

In conclusion, I am still quite happy with this change and am looking forward to fixing the rest of these issues.

Friday, 23 January 2015

FreeBSD on Apple MacBook Pro (13", Late 2011): Initial thoughts


I rely on my laptop, an Apple MacBook Pro 8,2 (13", Late 2011), for most of my work. For the past year or so I have been using Gentoo Linux on it. Gentoo is probably the best distribution of Linux out there today, but that isn't really saying a lot about it. Underneath the beautiful and easy-to-use Portage system lies the same glibc, the same turmoil over a switch to a less-than-ideal init system, and the same kernel-level bugs that bring my productivity down.

I had considered sticking it out, and possibly even picking up maintaining OpenRC if it is abandoned as some people seem to want. However, I have been having many glibc-related bugs lately:

  • Almost all GTK apps keep locking up in waitpid.
  • gdb locks up when I try to attach to processes - even after checking /proc/sys/kernel/yama/ptrace_scope and the like (no error, just hang).
  • Starting VirtualBox VMs cause the entire machine to lock up for up to two minutes before returning to normal. This isn't from starting the VM either; it occurs before the VM can even begin.

I don't take system-level changes lightly, but it was time to try something else. Trying to rebuild everything against something like musl seemed like an interesting idea, but it still wouldn't solve the eventuality of systemd. Additionally, there are still other compatibility issues using musl. And if I was having to rebuild everything anyway, I might as well try something completely different…

Enter FreeBSD.

I have been playing around with FreeBSD on my UltraSPARC system, as I wrote earlier. It is pretty snappy on there, even though it is a very old and slow system. Therefore, I decided to research about FreeBSD on MacBooks. There are a few requirements I have with a primary OS:

  • It absolutely must boot natively via EFI. I do not have the time to wait 90+ seconds for BIOS boot, and some of the hardware in the MacBook won't even perform correctly under that mode; the DVD drive and the Bluetooth are very fickle, at least in my experience.
  • It must be able to run a performant virtualisation solution, like VirtualBox, which is my go-to system emulator. I use virtualisation heavily, so this is a requirement.
  • It must work with the hardware components I use on my computer. This is primarily Gigabit Ethernet, FireWire, the SD card reader, and the Bluetooth radio.

I had enough disk space free on my Mac OS X partition to resize it down and give FreeBSD a "comfortable" 64 GB. Since this is just for testing, I left my Gentoo install and its LVM PV alone. I resized the Mac OS X partition and moved down the LVM PV to put FreeBSD in the middle (otherwise the space would be oddly divided) using GParted running on the Gentoo install. I was horrified when it, too, was locked in waitpid. I waited over three hours before it finally became responsive again, and hilariously enough, it reported that the operations completed in just 49 minutes.

I created a 300MB HFS+ partition used for the EFI loader, since Apple's firmware really likes having EFI code on HFS+. This also allows it to show up native in Chooser. You can also use FAT16 or FAT32, but I prefer to use HFS+ for this since it is just a single file. The rest of the 64 GB was given to a single FreeBSD UFS partition.

Next, I did something that I absolutely do not recommend for any reason unless you are willing to accept permanent data loss: I ran a Qemu instance with /dev/sda as the virtual hard disk. This allowed me to manipulate the disk directly from Qemu, which was convenient since the FreeBSD UEFI USB install image does not yet support Apple's firmware. However, if I typed even one letter or number wrong, this could have erased my entire drive so please do not do this! I fetched the sets manually from FreeBSD's FTP archive and extracted them to the new FreeBSD UFS partition on my disk. I shut down the Qemu instance after I configured /etc/rc.conf to my liking.

Finally, back in Gentoo, I copied the /boot/boot1.efi file from the FreeBSD UFS partition to the HFS+ partition, using the name boot.efi. The directory tree on the HFS+ partition, to boot natively and show up in Chooser (and Startup Disk in Mac OS X), is as follows:

  • /mach_kernel - 0 byte file, must be present to show in Startup Disk.
  • /EFI - copy this directory from the ESP. It contains the encrypted firmware used to start the computer's components.
  • /System/Library/CoreServices/boot.efi - this is the FreeBSD /boot/boot1.efi file.
  • /System/Library/CoreServices/SystemVersion.plist - this is an XML file that you can put the details of your FreeBSD install into to show what version it is and such. This file isn't strictly necessary but adds a very nice touch of professionalism to the install.

Booting the FreeBSD: EFI on the First Try!

I snuck in a /.VolumeIcon.icns file with the FreeBSD Beastie head logo, then rebooted my system. I waved goodbye to Gentoo, but wasn't sure if my FreeBSD installation was fully successful. Lo and behold!

I pressed RETURN and hoped for the best... and the best is what I received!

I was overjoyed to see how fast it boots; under 20 seconds from Chooser to a login prompt. I spent the rest of the night installing binary packages using pkg for software which I could tolerate the default options, but actually installed most things from the Ports system. Xorg support was native and flawless, including DRM for acceleration using my laptop's Intel HD Graphics 3000. The next morning I had the entire KDE 4 base system built and working in just two hours! KWin's compositing looks just as good as it did in Linux, but now uses much less CPU and memory - the entire thing boots up (using KDM4 to start my KDE session) using just 290 MB RAM, and will actually idle at 0.0% CPU (Linux would idle around 1.1-1.5%).

Some Issues.

While FreeBSD appears to be a panacea for everything I had wrong in Gentoo Linux, all is not immediately well. Of course, as with any new system, there are some more things I need to fix and figure out:

These will need some configuring and driver twiddling, but I have high hopes based on what I read on the very useful FreeBSD forums and mailing lists.
Ext2FS crashes
I backed up my system before installing FreeBSD, of course, but my backup disk (along with my primary disk which was unharmed) is formatted as ext4 (Linux FS). FreeBSD has a module to be able to read it, but when I try and access almost any file, it has a kernel panic. I am currently looking in to what is causing this and how to fix it.
Sensor readings
Currently, my laptop thinks it is -273.1 °C. This is quite obviously impossible, so I will need to investigate how to fix KDE's system monitor widget :)
While the FreeBSD kernel has a great touchpad driver merged in to 11.0-CURRENT, and it shows up in my kernel log as I boot up, Xorg only sees my mouse as having one button with no gesture support either. This means no scrolling on the side or with two fingers, no right clicking, no middle click for pasteboards, and so on. This will also need some fixing.

Overall Thoughts.

FreeBSD is very performant on this hardware, and seems to be doing a good job driving it. There are some quirks to it, but this is a new system and the kernel I am running is a beta anyway, so it of course will not be perfect. I am happy with this switch though and probably will not go back to Linux any time soon unless they can sort out their issues. I hope they can, because the Linux kernel itself is actually decent, and has a lot of commercial support which is good for open-source going forward. However, FreeBSD's performance is amazing and gives me renewed hope for the quality of systems that can be made in open-source communities.

Now playing: Devil in a New Dress - Kanye West

Double entendre... FreeBSD's logo is Beastie, and my laptop is a devil of a computer wearing a new dress with FreeBSD.

Sunday, 11 January 2015

FreeBSD 10.1 on UltraSPARC Sun Ultra 60: Booting and initial packages

As noted in my previous article, my friend Madeline and I set out yesterday to fix my Sun Ultra 60's boot problems so that it could run FreeBSD. The issue ended up being that the disk alias in OpenBoot had been scrambled (probably from the NVRAM reset I did to force it to boot), and was reading from a SCSI target that did not exist. I fixed this and it instantly booted up FreeBSD!

Now comes the fun part. I would really like to use pkg-ng and avoid building packages on a 360MHz computer if at all possible. Even though the UltraSPARC-II's 360MHz is closer to an Intel's 800-1000MHz, it's still a pretty poor platform for compiling some of the things I plan to use on it. I would like to run things like CMake and the new Clang 3.5 vs the very old, broken GCC 4.2.1 that FreeBSD on sparc64 ships.

I plan on setting up a buildbox on amd64 that will cross-compile ports for sparc64. There is only a single reference I can find for setting up such a system, and the instructions aren't too clear to me, so I will be writing up my experiences. For now, I have built ports-mgmt/pkg from source and it works. Unfortunately FreeBSD runs no mirrors, so I will have the "honour" of setting up my own local pkg mirror. If I'm able to make it work and compile enough useful ports I may make it public.

Saturday, 10 January 2015

FreeBSD 10.1 on UltraSPARC Sun Ultra 60: The adventure begins

Today begins a new adventure for me. After trying to like Solaris 8 and finding it too old, and trying to like Solaris 11 and finding it too Enterprisey EnterpriseWare™, and unsuccessfully trying to boot Linux plenty of times, I am going to install FreeBSD 10.1 on my Sun Ultra 60. Some specs...

  • UltraSPARC-II 360MHz (supposedly equivalent to a Pentium III, which at the time was huge)
  • 512MB RAM (again, at the time it was released, this was more than anyone would ever need)
  • 18.6GB Fujitsu SCSI disk, which doesn't give me a whole lot of room but is sufficient (I've run FreeBSD 9 on a P4 with a 20GB disk, with KDE and X, so...)
  • Creator 3D UPA graphics - full 1080p, with 3D and 2D acceleration - in 1999.
  • OpenBoot 3.31

You may be asking why I would use this computer. I have a few reasons. One is that I love utilising different CPU architectures and computers for what they do best. I'm thinking about playing around with some older graphics demos and seeing what I can get OpenGL/SDL2 to do with this. Considering that at the time it was 10x more powerful than any PC around, it may be enough to get some small-ish demos running at good speed. Another reason is that it's just a fun project, and another big-endian architecture besides PowerPC that I can use for endianness testing. I also am looking forward to porting SuperGameHerm to the SPARC architecture if I am able.

I'll be blogging about using and maintaining this system as I continue to use it, but for now, some installation notes!

Booting the System.

This computer is notoriously fickle to boot. I had to hold the STOP+N keys to clear the NVRAM to be able to see video at all. STOP+D is also a useful key combo, as it turns on the POSTs and ensures all the devices are working properly. All devices passed in my unit, so I proceeded at the OpenBoot "

" prompt to type boot cdrom and watched the system boot up.

Booting the Kernel.

I watched with glee as the system booted the FreeBSD 10.1 kernel, but the glee quickly turned to dismay as I saw...

cd0: cd present [269120 x 2048 byte records]
Trying to mount root from cd9660:/dev/iso9660/10_1_RELEASE_SPARC64_CD [ro]...
warning: no time-of-day clock registered, system time will not be set accurately

No disk activity. The CD drive was quiet. The fans weren't even spun up, so there was no CPU activity. It was quiet... Too quiet... Eerily quiet for what was supposed to be a noisy, happy FreeBSD install. I pressed STOP+A to try and break into OpenBoot. The system was locked solid and it would not respond. Fortunately, it seems to be a glitch, and resetting the system (power down and power up) fixed this issue.

Installing the FreeBSD.

Since the Linux install failed and I already saved the contents of the SPARC slices, I used the Automatic Disk partitioning, which created a 17 GB / and 800 MB swap slice. This should be enough for most builds. It may not be enough for Qt, but I will probably not build Qt on here anyway. Now the fun part: Installing the distributions (somewhat akin to package sets on Linux, I guess). I downloaded the full Disc 1 ISO and burned it to a CD so I did not have to configure the network or wait for the - sadly only 10Mbit - Happy Meal Ethernet to download any files. It verified the checksums and immediately began installing to my local disk drive.

Note that I saw a few odd errors: "sym0: unexpected disconnect". This didn't seem to affect the installation any, so I'm not sure what exactly is going on here.

After that was finished, it was time to set up the devices. I configured networking (v4 + v6), added users for myself and my partner in crime, and then set out to install pkg-ng, the FreeBSD package management tool that makes FreeBSD so amazing and easy to use. Sadly, it does not support SPARC64, only the Intel x86 family of systems. The first order of business, then, is making a pkg-ng server for myself. I will cover that later, when I'm able to get that going. For now, it's ports (building from source) only.

Booting into the FreeBSD!

And now, everything is finished. Eject the CD and reset the system. This is going to be wonder----ful?

Luckily, one of my friends is an experienced SPARC sysadmin so she is going to help me fix it. Later today I will post the resolution, but first we have to find it. Until then, happy hacking!

Thursday, 1 January 2015

Not having "resolutions" this New Years

Okay, I understand that many people like to make up "resolutions" for New Years. Stop me if you've heard this one before:

  • "This is the year I start eating healthier."
  • "This is the year I go the gym ALL THE DAYS."
  • "This is the year I volunteer to ALL THE CAUSES."
  • "This is the year I will change (some basic trait) and instead (do something seen as better by society)!"

Right, that never works. And here's why: the motivations are completely wrong. "New Year's Day" is, by the by, just another day. It's another day that is usually felt hung over, but still it is just another day. This is not a catalyst with which to make a large change, for yourself or for anyone else. What matters is not when you start something, but how and why you start it. Why do you want to eat healthier? Is it because it's the "in" thing to do, or is it because you genuinely want to be healthy? Do you really only want to be healthy because it's a new year?

I realise that many people view a new year as a "new beginning"; whilst a happy sentiment, and one that can sell a lot of greeting cards and party hats, it is nothing more than just that - a sentiment. The boundary of a year is an invented one. If you truly want to be healthy, you should do it because you want to be healthy, not because you want "this year to be different". When you inevitably slip up — don't be ashamed of yourself, we all do at one point or another — you can simply say "I still want to be healthy and I'll keep at it" instead of "oh well, this year isn't being different, I'll try again next year". You'll eventually run out of next years with which to try again.

So what are my goals for this year? I'd like to move to a better locale than I live now and finally finish my schooling. However, these aren't new goals I pulled out of my rear for the new year; I have been working at them for months now and I plan to achieve them this year. Plan ahead and don't stop for the bumps. Be inspired to smooth over the next ones!

I suppose my major point to this is that the best thing you can do this New Years is enjoy it with your friends and family. And if you want to change something besides your wall calendar, you need to have the right reasons for it. You are definitely worth your own investment of time and energy. You just have to see yourself that way, and then it will pay off in dividends.

Now playing: ♫ Skyfall - Adele