Installing Windows 7 SP1 on chainloaded Windows

The Problem

When I try to install Windows 7 Service Pack 1 (SP1) on my dual-booting computer, installation fails every time with the error 0x800F0A12.

My Setup

Drive 0

Drive 0 has Windows 7 installed. In the setup wizard, I just deleted all partitions, clicked the blank drive, clicked Next and let Windows handle the partition scheme, boot options, etc. the way it wanted. So there is no GRUB config or code here.

Drive 1

Drive 1 has Ubuntu installed with my preferred partition scheme. GRUB is installed to this drive and there is an entry for Windows 7 on Drive 0.

BIOS

In BIOS, I boot Drive 1 by default and just select Windows from the GRUB menu when I want to use Windows.

The Cause

If you can believe it, Windows was cranky because I was using GRUB to chainload Windows’ own bootloader!

The Solution

So the solution was to select my boot device at boot time (F12 during POST on my board) and boot from Drive 0 directly. SP1 is now installing without a hitch.

O_O

Once the installation is complete, you can continue chainloading Windows’ bootloader with GRUB. It’s only the SP1 installation that gums it up.

References

I found these articles to be most helpful on my journey.

Posted in Windows | Tagged , , , , , , , | 1 Comment

Enable Hibernate on the System76 Lemur Ultra (lemu4)

I got a System76 Lemur Ultra (codename lemu4), and I love it! The build quality is a little so-so (the faux-metal plastic is kind of bendy, and, well, plastic), but I wasn’t expecing a MacBook.

One of my favorite things as a long-time Linux laptop user is that this thing supports hibernation out of the box! Whoa whoa whoa—before you get too excited, I said supports. You have to enable it yourself, and this is not a simple checkbox. That’s stupid. System76 should do this for you, but whatever. Here are the simple steps to get full hibernate (suspend to disk) support in your System76 Lemur Ultra.

Enable Hibernation

sudo tee /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla <<EOF
[Enable hibernation]
Identity=unix-user:*
Action=org.freedesktop.upower.hibernate
ResultActive=yes
EOF

Enable Resume

No copypasta here. The format of /etc/default/grub and the lack of support for sourcing other files makes it a poor candidate for that. Just edit the file.

  1. Add this to /etc/default/grub: GRUB_CMDLINE_LINUX="resume=/dev/sda5"
  2. sudo update-grub

That’s it! Yeah, it’s kind of stupid that System76 doesn’t configure this for you before they ship the computer, but at least the hardware fully supports this fairly fundamental but somehow rare convenience.

Posted in quickies, tutorials | Tagged , , , , , , , | Leave a comment

The “Easy Way” to Add Custom DNS Servers in Ubuntu

Goal

Just add a goddamned nameserver to Ubuntu. I have lxc, and I want to ssh to my containers without knowing their IPs or starting them in the foreground. Is that so hard?!

Solution

Install dnsmasq.

sudo apt-get install -y dnsmasq

Add the DNS server. Call the file whatever you like. For my purposes, I’m adding my lxc DNS server, so I call it lxc-dns.

sudo tee /etc/dnsmasq.d/lxc-dns <<EOF
server=10.3.0.1
EOF

Restart dnsmasq

sudo /etc/init.d/dnsmasq restart

“That’s it.” dnsmasq will notify resolvconf that you’re running a local caching DNS server, so just letting dnsmasq know what your nameservers are is sufficient to use them.

Editor’s Note

You may have noticed a lot of sarcastic quotes here. This is really, really sloppy and fucking stupid. Adding a DNS server didn’t used to mean running your own private caching DNS server. You used to add a line to a config file. I’m not saying that making a backend to maintain a database of DNS servers and enable notification and interoperation with other services is stupid (OK, maybe I am), but they could at least make it as simple as allowing you to append a custom IP to a file in /etc/resolvconf/! Seriously, what the fuck?!.

Posted in tutorials, Uncategorized | Tagged , , , , , , | 3 Comments

Installing XBMC on Ubuntu 12.04 on an Acer Aspire Revo 1600

Install Nvidia Current Updates

You want the Nvidia binary blob drivers to squeeze every bit of performance out of this Ion LE chipset so you can watch videos in 1080p on a $200 turd computer.

sudo apt-get install -y nvidia-current-updates

Disable Compositing for Nvidia Display Drivers

You want to disable compositing or the video will tear so very, very much. I’m very thankful that I found this article. This forum post says that you can just toggle a setting in Compiz Config Settings Manager, but that didn’t work for me.

sudo nvidia-xconfig --no-composite

Reboot or restart your display server.

Install XBMC on Ubuntu the Right Way

sudo add-apt-repository ppa:team-xbmc/ppa && sudo apt-get update && sudo apt-get install -y xbmc

Now you can run XBMC by launching it with Dash or by typing xbmc at a prompt.

Install lirc for Windows MCE USB IR receiver

This is optional. I have a Windows Media Center Edition-style USB IR receiver that I use with a Logitech Harmony remote. If you don’t do this step, the remote will move the cursor in XBMC, but that’s pretty much it.

sudo apt-get install -y lirc

When prompted, select Windows Media Center Remote. When prompted for an IR tranmitter, choose “none.”

Posted in XBMC | Tagged , , , , , , , , , | Leave a comment

Quickie: Fix Missing “Downloads” Icons in Chrome/Chromium

Have you run across this bug? It’s not a huge deal, but in Ubuntu, you generally get broken icons on the Chrome/Chromium Downloads tab.

Missing Chrome Downloads icons

Missing Chrome Downloads icons

There are related bug reports here and here, but I don’t see any movement on this. The quick fix is to install gnome-icon-theme-full

sudo apt-get install -y gnome-icon-theme-full
Posted in quickies, Uncategorized | Tagged , , , , , , , | Leave a comment

Prevent Virtual Machines from Saving Network Interface udev Rules

I use a lot of VirtualBox VMs. A problem that I have frequently is that when cloning an Ubuntu VM and changing its MAC address is that it won’t be able to initialize the network (as seen in a previous post). I found a permanent fix for this!

Before you clone your VM, you can block the creation of the udev rule that remembers your MAC address/interface bindings.

rules='/etc/udev/rules.d/70-persistent-net.rules'
sudo rm $rules && sudo mkdir $rules

That’s it! Clone away. Now that there is a directory where the udev rule is normally written, the rule won’t be written. It will just fail silently, and the bindings (e.g. MAC address 00:11:22:33:44:55 maps to eth0) will be generated dynamically upon boot. The MAC address won’t change, and the order of your interfaces won’t change, so there’s really no drawback.

Posted in virtualization | Tagged , , , , | 6 Comments

Compacting a VMDK (Virtual Machine Disk Format image)

Compacting a VMDK file (.vmdk) is a good idea if you want to share or reuse it, such as with Vagrant. If you’ve tinkered with your VM a bit, deleting cached files isn’t enough. The space in the filesystem is marked as free, but isn’t erased. It still contains the data, so it doesn’t compress as well. Here, I’ll describe how to zero that free space and shrink that image.

How much it helps depends on your disk content, but for what it’s worth, my VMDK with an Ubuntu Maverick 64 install shrank from 2.0GB to 1.6GB, and gzipped they are now 679MB and 425MB, respectively. That’s a nice savings when you’re talking about shipping the image around between computers and using it as a Vagrant base box multiple times.

Zero Free Space

If you zero the free space, it can be efficiently compressed.

Note: If you can, defrag the volume. You can’t really defrag ext4 (you can, but it’s sketchy), so I’m not going into that.

You want to use the VirtualBox GUI to change the boot media for your VM to a lightweight live Linux like Finnix and boot from it.

Then install zerofree

sudo apt-get update && sudo apt-get install -y zerofree

Then zero the free space on your partition. Mine’s sda1, so it looks like

sudo zerofree -v /dev/sda1

Then shut down the VM

sudo poweroff

Clone the VMDK

VirtualBox only lets you compact VDIs, but if we clone a VMDK we get a compressed copy. So find your disk image

cd $VirtualBox_VMs_dir/$vm_dir

If you don’t have any snapshots, just

VBoxManage clonehd $disk_name.vmdk clone.vmdk

Otherwise, find the snapshot you want. I just want the newest one, so I

ls -lt Snapshots

And I get something like this at the top (newest file is on top):

-rw------- 1 force force 721092608 Jul 12 10:13 {11f18f3d-9a0b-4e98-b680-a108ac31a0aa}.vmdk

The 11f18f3d... is the UUID. So I want to use that to clone the disk.

VBoxManage clonehd 11f18f3d-9a0b-4e98-b680-a108ac31a0aa clone.vmdk

Attach the newly shrunk disk to the VM

Just use the VirtualBox GUI to edit the VM and attach your newly cloned disk instead of the original one. You’re done!

Posted in tutorials | Tagged , , , , , , , | 1 Comment

Render a template from a hash in Ruby

A hash is a great way to manage a list of key/value pairs, and templates are a great way to render content. So here’s a simple way to render a template from a hash.

template.erb

My favorite color is <%= favorite_color %>.

render.rb

require 'erb'
require 'ostruct'

opts = OpenStruct.new({
  :favorite_color => ARGV[0]
})

template = open('template.erb', 'r') {|f| f.read}
puts ERB.new(template).result(opts.instance_eval {binding})

So running

ruby render.rb blue

will output this

My favorite color is blue.

Which is cool. The interesting parts (and the reason I’m writing this) are that you need to instantiate a new OpenStruct from your hash so that its members can be accessed as methods, and then you have to set the binding for ERB by saying opts.instance_eval {binding}. This runs binding in the context of the opts object, so then calls to methods like favorite_color made by ERB in this context will evaluate to the values of our hash.

Posted in ruby | Tagged , , , , , , , | Leave a comment

Clone Ubuntu VMs in VirtualBox

Update: I found a permanent workaround for the udev ethernet interface problem. See this post.

I installed Ubuntu from mini.iso and I want to make several copies. What are the potential pitfalls? Well, the only real problem is that if we’re not careful they’ll all have the same MAC address. There’s a checkbox to avoid this in VirtualBox,

Reinitialize the MAC address checkbox

What a convenient checkbox!

which gets you halfway there, but when you boot your new system it will still remember that eth0 was that old MAC address. What’s worse is it will stall for over a minute while booting and tell you it’s waiting for network configuration…

Waiting up to 60 more seconds for network configuration

AAAAHHHHHHHHHHH!!!!

Update: I found a permanent workaround for the udev ethernet interface problem. See this post.

The easiest way to get through this is just to wait it out. Eventually you’ll get a login prompt. When you do, log in. Now you want to edit your udev rules so that you’re newly generated MAC address maps to eth0. That’ll fix everything.

sudo vi /etc/udev/rules.d/*-persistent-net.rules

Mine looks like this

# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:11:7c:8b", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:03:8e:5a", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"

I’m just going to delete the old eth0 entry (the first one) and change the name of the new one to eth0.

# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:03:8e:5a", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

A quick reboot and everything’s shiny. :)

Posted in VirtualBox | Tagged , , , | 7 Comments

Depaginate Phoronix Articles

I sketched this for Phoronix, but you could easily adapt it to any site that uses pagination. I think it’s an interesting problem, so if you want to see another site depaginated, just ask me in a comment and I’ll check it out.

Here’s the script. It’s also available as a Gist if you want to tinker with it.

/**
 * Depaginate Phoronix articles
 *
 * Script by Justin Force, 2012. Released to the public domain.
 *
 * Stick this in whatever user scripts you have. I keep an unpacked Chrome
 * extension. You could also use this with GreaseMonkey or something as long as
 * you load jQuery first.
 */


$(function () {
  $.each($('.phxcms_navigation_format a').filter(function () {
    return $(this).attr('href').match(/&num=/) && !$(this).text().match(/Next Page/);
  }), function () {
    var div = $('<div>');
    div.load($(this).attr('href') + ' #phxcms_content_phx', function () {
      div.find('.phxcms_navigation_format').remove();
    });
    $('#phxcms_content_phx').append(div);
  });
});
Posted in javascript, quickies | Tagged , , , , , , , , | Leave a comment