Installing Ubuntu on an HP Stream Mini PC

c04526282When I heard the news a few weeks ago that HP was introducing a cute little blue mini PC that would only cost $180, my first thought was, “I want one!” And when I heard that the Stream Mini would ship with Windows 8.1 preinstalled, my second thought was, “And when I get it the first thing I’m going to do is install Ubuntu on it.”

Easier said than done.

The actual process of installing Ubuntu is not difficult. The difficulty proved to be in simply getting the Stream Mini to boot from a USB stick.

tl;dr

The HP Stream Mini has UEFI boot. If you hit F12 at boot, you get the UEFI boot selector screen, but that’s no good because it won’t show the USB stick. For HP devices like this you need to hit F10 on boot to access the UEFI/BIOS configuration tools. From this point I trust you can find the settings to change the boot order. Just put your USB stick ahead of the hard drive in the order and you’re set.

Actually, I do prefer to read the whole thing, no matter how long it is

Now, for those of you who want the full story, here’s how it goes. I’ll say up front that I primarily use a Mac, so my instructions for preparing the USB stick are Mac-only.

Actually, not quite true. Most of what I’m describing is done at the UNIX command line, so for a UNIX/Linux system, the experience should be similar to this, but you don’t have to convert the .iso file. Also, for the first couple of steps I’m using the Mac-only command diskutil. The instructions on the Raspberry Pi page mentioned in step 2 use the generic UNIX equivalents.

For Windows… you’re on your own. It involves crappy third-party apps you have to download and, well, yuck. I started out all of this trying to get it set up using the Windows 8.1 install that came on the HP Stream Mini, but I quickly gave up and switched to my Mac. (The official Ubuntu docs have instructions for Windows that I read before giving up.)

Step 1: Download Ubuntu

There are many options (including other Linux distros), but if you’re undecided, you probably want to get yourself a copy of the latest version (or latest LTS [Long Term Support] version) of Ubuntu Desktop. Be sure to go for the 64-bit version. At the time of this writing, Ubuntu 14.04.1 LTS is the latest and greatest.

Step 2: Prepare your USB stick

Déjà vu? No, I really have written about this before. More or less. While there are some minor differences, this is basically the same process I described for preparing an SD card with Raspbian for a Raspberry Pi using a Mac.

You can read the even lengthier details there, but basically, you want to:

1) Insert a USB stick (I recommend at least 2 GB, but who can even find one under 4 GB these days?) into a USB port on the Mac. Make sure you don’t care about losing all of the data on this USB stick, because you will.

2) Open Terminal and save yourself some extra typing in the immediate future by starting with: sudo -s

3) Type diskutil list and press Enter to see a list of volumes. Look for your USB stick and note what it says at the right under IDENTIFIER. There’s a good chance it’s going to be disk1s1 but it could be something else. You just need to know the disk1 part. Don’t worry about the s1. Remember this for later.

4) Unmount the disk. Enter this command: diskutil unmountDisk /dev/disk1 being sure to replace the 1 with whatever number you saw in the previous step.

5) Find your Ubuntu installer image. It’s probably in your Downloads folder. Type cd ~/Downloads and press Enter. Then type ls -al and look for the Ubuntu filename, which likely ends with .iso. You’re going to need to convert this into a .img file.

6) Run this command: hdiutil convert input.iso -format UDRW -o output.img but be sure to replace input.iso with the actual filename of your Ubuntu .iso file. You can also change output.img to whatever you want… or at least the output part. This is the filename for the new .img file.

7) Run ls -al again. Mac OS X probably “helpfully” stuck a .dmg extension on your .img file, so run this: mv output.img.dmg output.img replacing both instances of output as appropriate.

OK, now we are actually ready to write Ubuntu onto the USB stick. Run this command:

dd bs=1m if=output.img of=/dev/rdisk1

Be sure to use the correct name for your .img file, and the correct disk number in that rdisk1 bit. Note that the r I added stands for “raw” and it just makes the process go a bit faster.

Now, wait. It shouldn’t take too long, but it might be a minute or so. Once you get the # command prompt again, your USB stick is ready to go. You’ll probably also get a system dialogue box warning you that the disk you inserted is unreadable. Just ignore that. Remove the USB stick from your Mac and insert it into the (powered down) HP Stream Mini.

Step 3: Boot the HP Stream Mini and access the UEFI/BIOS configuration

With the USB stick in one of the HP Stream Mini’s USB ports, power on, then immediately press and hold (or, if you like, frantically tap repeatedly) the F10 key on your keyboard. This should bring up the UEFI/BIOS configuration tool.

hp01

First, go to the Storage menu and choose Boot Order. The dialogue below will appear.

hp02

I recommend disabling UEFI Boot Sources as shown here. Then under Legacy Boot Sources look for your USB stick (not shown here because I didn’t have one inserted when I took the photo). Follow the instructions in the lower right of the box to select and change the order of the boot devices. Make sure your USB stick is above Hard Drive in the list. Press F10 to confirm.

hp03

Now go to the File menu and choose Save Changes and Exit. The computer will now proceed to boot up from the USB stick.

Step 4: Run the Ubuntu installer

This is pretty straightforward. Unlike earlier Linux distributions, Ubuntu these days has a very polished installer program that should feel very familiar to anyone who’s ever installed Windows or Mac OS X on a computer before. There are several steps such as picking your language, location and keyboard layout, but just follow the on-screen instructions and wait for the process to complete, which in my experience took about 20 minutes.

After installation is complete, the system will ask you to reboot, then remove the USB stick and press Enter. Follow those instructions and in less than a minute you should be up and running with a clean install of Ubuntu!

Very useful WordPress tip for editing systemwide options

In the process of searching for a solution to a very specific WordPress problem (getting the “Add Media” overlay to default to “none” for the link — no one I know ever wants it to default to inserting a link), I came upon a very useful general tip for WordPress.

WordPress stores a ton of settings in the wp_options data table. But a lot of those settings are not directly accessible for editing in WordPress admin. Or so I thought.

Turns out, it’s not linked anywhere in the admin interface, but if you have the Administrator role, you can access an All Settings page that allows you to edit any record in that table (except serialized data) by going to this URL:

http://YOUR_URL/wp-admin/options.php

Watch out… you have the potential to really mess things up here, which is why it’s not easier to get to. But it’s a handy way to easily update an option, if you know what you’re doing, without having to log into the database directly.

Oh… and if you want to fix the specific problem I was trying to solve at the beginning of this post, look for image_default_link_type and set it to “none”.

A couple of quick steps to improve the Yosemite UI on non-Retina Macs

I’m guessing most Mac users running a Mac that can handle it have already updated to Yosemite, or will soon. I’m the kind of user who always runs OS updates whenever they’re available.

I’m not a huge fan of Apple’s decision to make Helvetica Neue the new system font in Yosemite. I like Helvetica, but I don’t love it. I prefer something with a little more personality, a little less ubiquity. That said, I do prefer geometric and Grotesque-type fonts over humanist fonts… and I was really sick of Lucida Grande, which I never really liked in the first place.

My first reaction when I tried the Yosemite beta was that it looked half-assed. The final version is a bit more polished, but it still feels poorly thought out. Or, at least, it did until last weekend when I was at an Apple Store and I saw Yosemite on a Retina MacBook Pro for the first time.

Wow.

Retina is clearly what this interface was designed for, and eventually that’s how we’ll all be experiencing it. But for now, and for a while to come, most of us will probably be stuck with non-Retina Macs and the inferior presentation of Yosemite’s refined UI that they deliver.

That said, there are a couple of things you can do to improve the experience. Part of why Yosemite doesn’t look great on a non-Retina Mac is that there’s too much subtle stuff going on that just kind of gets mucked up when you don’t have that precise definition on letters and icons. You can improve this aspect of the UI immensely by reducing its use of transparency. Open up System Preferences and switch to Accessibility. Check the box labeled Reduce transparency.

Screen Shot 2014-11-06 at 12.11.23 PM

Another optional change you may wish to make is to darken the menu bar and Dock. This is more of a matter of taste, but personally I like the darker look. Switching this on essentially inverts the colors, so your menu bar has a nearly black background with white text, and the Dock becomes translucent dark gray, instead of translucent white.

Once again in System Preferences go to General and check Use dark menu bar and Dock.

Screen Shot 2014-11-06 at 12.11.16 PM

Now enjoy your new OS!

Responsive images with srcset in WordPress

As a developer, I am somewhat conservative. I believe strongly in the importance of web standards, and I am reluctant to be an early adopter of any new techniques or, even worse, non-standard workarounds for limitations in existing standards. I’d rather live with the limitations until a proper standard — or at least a de facto standard — takes hold.

One of the latest issues to challenge my approach has been responsive images. I’ve settled into a pattern of going with “1.5x” quality images, trying to strike a balance between quality on large high-res displays and a reasonable file size. But it really doesn’t do either very well.

Today’s issue of A List Apart features an exciting article:

Responsive Images in Practice

Yes! In practice! Let’s do this!

There have been a couple of competing proposals for handling responsive image sets, and I am pleased to see the srcset attribute begin to emerge as the winner. The biggest plus it has for me is that it degrades gracefully for older browsers that don’t support it.

Well, before I had even finished reading the article I started thinking about how I could leverage the build-in image sizing mechanism in WordPress to use srcset. I haven’t looked around — I’m sure someone else has already created a plugin that perfectly nails what I am attempting to do here. And, to be honest, I haven’t extensively tested this code yet, although I did drop it into a site I’m currently working on, just to be sure it doesn’t throw a fatal error and that it actually does render the HTML <img> tag as advertised.

function img_with_srcset($attachment_id, $default_size='medium', $echo=true) {
  $output = null;

  // Get image metadata
  $image = wp_get_attachment_metadata($attachment_id);

  // Set upload directory for image URLs
  $upload_dir = wp_upload_dir();
  $upload_url = $upload_dir['baseurl'] . '/' . dirname($image['file']) . '/';

  // Build array of sizes for srcset attribute
  $sizes = array();
  foreach ($image['sizes'] as $size) {
    $sizes[$size['width']] = $upload_url . $size['file'] . ' ' . $size['width'] . 'w';
  }
  
  // Sort sizes, largest first
  krsort($sizes);

  // Get image alt text
  $image_alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true);

  // Generate output <img> tag
  if (!empty($sizes)) {
    $output =  '<img srcset="' . implode(', ', $sizes) . '" ' .
               'src="' . $upload_url . $image['sizes'][$default_size]['file'] . '" ' .
               'alt="' . esc_html($image_alt) . '" />';
  }
  
  // Return/echo output
  if ($echo) {
    echo $output;
    return true;
  }
  else {
    return $output;
  }
}

Let’s just examine what’s going on here.

The function takes three input parameters. An attachment ID, a default size (for the old school src attribute), and a boolean for whether to echo the output or just return it.

First, we get the attachment metadata and put it into $image. You can see more about what the wp_get_attachment_metadata() function does here.

Next, we set up the $upload_url variable to be the full base URL to the WordPress uploads directory. That’s because the metadata output only includes the filename of each sized image, not its full URL.

Then we loop through all of the sizes in the metadata output, generating a series of strings containing the image URL and its width, for use in the srcset attribute. We put these into an array because we need to manipulate the list a bit: we need to sort it so the largest images come first, and then later we need to implode() this into a comma-separated string.

Of course we also need the image’s alt text, so we grab that with get_post_meta() which you can read more about here.

Finally, assuming we actually have some size data, we build the <img> tag, complete with srcset attribute! Then we either echo or return it, as determined by the $echo input parameter.

Something else I’d like to try with this is taking it a step further by adding a filter that processes page content, looking for <img> tags, and automatically inserts the appropriate srcset attribute.

There you have it. I welcome anyone who’s reading this to give the function a try in your WordPress site, and let me know how it goes!

Follow-up on my post about getting an iPhone 5c on the eve of the iPhone 6 announcement

So, a few weeks back, just 4 days before the iPhone 6 announcement to be specific, I wrote here that I wanted an iPhone 5c. I had been coveting the funky colors and unashamed plastic of them since they’d been announced, and I’d seen enough leaked photos and specs for the iPhone 6 that I already knew, if it lived up to the rumors, that I didn’t really want one.

The day after I wrote that blog post, I went for it. We went to the Apple Store and bought no fewer than three iPhone 5c’s, in fact — two 32 GB units and one 16 GB unit for the boy, who’s now in middle school and needs a way to communicate with us given his newfound independence — and switched from Verizon to T-Mobile in the process.

The rationale: regardless of what they did keep, I knew (or at least reasonably assumed) Apple would be discontinuing the 32 GB 5c once the 6 was announced, and I also knew that 32 GB was the “sweet spot” for my iPhone storage capacity needs. My faltering iPhone 5 had 64 GB of storage, and I had never used more than about 35 GB of that… and even then only by unnecessarily carrying around a half dozen full-length, HD movies on the device.

So it was that on the weekend before the iPhone 6 announcement, I became the proud owner of a gaudy, banana-yellow iPhone 5c. And it was good.

T-Mobile, so far, has been great. The guys at the T-Mobile store where I had to go the next day to activate my phone were fast and knew what they were doing, and T-Mobile’s service has been outstanding, with voice call clarity and LTE reliability I could never even have imagined possible with Verizon, at a little over half the cost.

But my joy didn’t last long. Not because the iPhone 6 surprised me — it didn’t. At all. But because less than 24 hours after I took my iPhone 5c out of the box, it fell out of my pocket as I got out of the car in our garage, and suffered a permanent ding in the plastic on the lower right corner. Fortunately it was very, very small. But it was big enough to consume a significant portion of my attention for the next two weeks. I touched it constantly. I stared closely at it, willing it to disappear.

It did not disappear.

On the night we bought the iPhones, I rationalized the obviously ludicrous purchase by noting Apple’s 14-day return policy. That gave me until the day after the iPhone 6 would go on sale to change my mind.

As it happens, a coworker had preordered the iPhone 6, and it arrived at the studio on Friday. I took a look at it. I held it. I even put it in my pocket. It was not bad… definitely not as obnoxiously big as I had expected. But I still didn’t want it. I would live with my iPhone 5c, scratch and all, for a year at least, until the next round of updates.

But then, the next morning, 14 days after my purchase, and therefore the last day I could return the 5c to the Apple Store, I was idly browsing Apple’s website.

The first thing I noticed was that the 5c, now the lowest-end iPhone, is now only available in an 8 GB size. I had assumed they’d keep the 16 GB around. 8 GB is just stupid now. But whatever. I had my 32 GB unit. I was happy.

Of course I was aware that the 5s had been bumped down to the mid-range level previously occupied by the 5c. Which meant that if I’d just waited a few days, I could’ve gotten a 5s for the price of a 5c. I didn’t really care. I knew it was faster, had a slightly better camera, and had TouchID, which I didn’t think I wanted. I was fine with my banana-colored 5c.

Until I looked at the price. The 32 GB 5s was now $50 cheaper than what I had paid for the two 32 GB 5c’s we had bought 14 days earlier. That meant we could take them back, upgrade to 5s’s, and get $100 back! Hell yes.

Not only that, I could get rid of the ding in the plastic that had plagued my mind for two weeks.

So later that afternoon, we trekked back to the Apple Store, past all of the people queued up outside to get iPhone 6’s, and straight to a blue-shirted employee who was more than happy to work with us and never once even glanced in the direction of the ding. 15 minutes later, we had exchanged our 5c’s for 5s’s and had gotten a big credit back to our bank account.

I used part of my $50 refund to buy a bright yellow case for my “space gray” iPhone 5s.