Dual boot Windows 7 and Ubuntu, fix Windows MBR issue [solved]

I went through a heck of a time getting Windows 7 and Ubuntu (actually eeebuntu) to dual boot on my new Asus Eee PC. Either would work fine alone but liked to overwrite the other’s boot loader.

I’ve read that it’s easier to install Windows first and Ubuntu later, but even though I installed Ubuntu later, Windows failed to boot after I installed it.

My first lesson through all of this: Don’t customize, save any documents, or install any software until both OS’s are installed and dual booting. I went through two windows installs and 3 ubuntu installs to get it all to work.

You can use either Windows or Ubuntu’s installer to partition the drive. I formatted 40 GB in NTFS for Windows 7, 10 GB as ext3 for Eeebuntu, 2 GB for Eeebuntu swap, and 5 GB in Fat32 for a shared partition between the two drives.

Even though I was careful not to format, resize or overwrite the windows drive, Windows 7 booted into a startup repair, and failed with the message “startup repair cannot repair this computer automatically”. My additional info was StartuprepairOffline and CorruptRegistry. I ended up having to reinstall Windows.

In hindsight, I would have installed Ubuntu first and then Windows. Windows is more picky when its boot record is overwritten, and ubuntu’s is easier to fix.

I tried a couple of solutions first – this article, “How to fix your windows MBR with an ubuntu live CD”, has been mirrored everywhere, and no longer works. ms-sys is no longer included with Ubuntu, is not available in the Ubuntu software repositories, and when I tried downloading and compiling from source I got missing libraries errors.

My efforts to use Super Grub Disk also failed. Supposedly Super Grub Disk makes it easy to edit your master boot records and boot menu, but it only runs from windows. After I reinstalled windows, and installed Auto Super Grub Disk, when I tried booting and chose it as an option, I simply got to a DOS-based menu screen saying Windows cannot start normally. I’m also finding it hard to uninstall super grub disk.

What finally worked was installing Ubuntu, installing Windows, booting from an Ubuntu live disk, reinstalling grub, booting into Ubuntu, and editing the Grub menu to make Windows 7 active (“makeactive”) again. No special software required, just some command line editing. This tutorial from the Ubuntu site walked me through it.

Finally, the steps:

1. Install Ubuntu (partition the drives first)
2. Install Windows into one of the partitions (format it as NTFS)
3. Boot into the Ubuntu live CD. In terminal (Accessories > Terminal) run these commands:

sudo grub
find /boot/grub/stage1
root (hd0,0) [or whatever the find command listed]
setup (hd0)

4. Reboot back into Ubuntu (not the live CD)
5. Open terminal again, and edit your boot menu:

sudo gedit /boot/grub/menu.lst

Add an entry for Windows 7 above this line:


Here is my entry:

title Windows 7
rootnoverify (hd0,0)
chainloader +1

Your (hd0,0) may be different.

Towards the top of the file, I also changed my timeout from 10 to 5, so that it only takes 5 seconds to choose a custom default OS to boot.

I also deleted the other entry at the end of the file, below the lines:


# This is a divider, added to separate the menu items below from the Debian
# ones.

because that entry didn’t work anyway. It’s similar to the Windows entry we added but uses savedefault instead of makeactive; I believe makeactive is what Windows needed to make it work correctly.

That’s it! Now you should be able to boot into both OSes.

Edit: I got super grub disk to stop showing in my boot menu in Windows by running this in a command prompt:

bcdedit /enum

That lists the identifiers in your menu. Then:

bcdedit /delete {super grub disk's super long identifier string with curly braces}

That got Windows to boot normally again.

Choose a random winner or randomize a list with terminal and PHP [solved]

I wrote this for my class, which needed to have a randomized order of presentations:

php -r '$order = array("person1","person2","person3","person4","person5","person6","person7","person8","person9","person10");shuffle($order);foreach($order as $number=>$name){echo $number+1 . " $name\n";}'

To run it, open up terminal (in OS X) and paste it in.

I’ve also had to choose a random winner for gift certificates before:
php -r '$order = array("person1","person2","person3","person4","person5","person6","person7","person8","person9","person10");shuffle($order);echo "$order[0]\n";'

mod_security won’t let you post [solved]

In my last post, I kept getting this error when I clicked Publish in wordpress:

Error 406, Not Acceptable. An appropriate representation of the requested resource /wp-admin/post.php could not be found on this server.

It turned out my host was running mod_security and there are certain phrases it won’t let you publish. It’s censorship, but I understand why they do it. I was talking about the most dangerous command you can run in unix:

sudo rm -rf

That’s what triggered it. I had to obfuscate the text in that entry and this one just to be able to post it. (View the source of this page to see what I mean).

If you’ve been able to post normally and suddenly you can’t and are getting this error, check for weird linux commands or files in your post that could be triggering this.

Triple Boot on an Intel iMac (OSX, Ubuntu, XP/Vista on Intel iMac) [solved]

Triple Booting (Mac OSX, Ubuntu 7.04, Windows Vista) on an Intel 24″ iMac (Core 2 Duo)

Boot Camp is all spiffy and whatnot, but for some reason, it only supports two OSes. If you’re like me, you’ve got to go a little bit further and install three. While all of the following is documented online in various places, I didn’t find one consolidated FAQ to explain the entire process. Plus, I wanted to remind myself how to do it incase it ever came up again. So this is the general process to install three OSes on an Intel iMac.

Things you’ll need:

  • An Intel iMac (other macs use a different type of boot loader/partition table, which I do not address)
  • A fast internet connection (to get the next two items)
  • Bootcamp (see below)
  • Ubuntu: (or whatever flavor of Unix you want to run)
  • A Windows Vista (XP) full install disk. (Apparently you need a SP2 version of XP.)
  • several hours of time (you’re installing two complete OSes, among other things)
  • if your iMac has a wireless keyboard and mouse, like mine, you’ll need a USB keyboard and mouse during the Ubuntu install later.


Back up -everything-. You never know what might happen. After all, you’re resizing your partition, messing with the boot record, and generally getting very intimate with your machine.

Download Bootcamp ( Install and run. Burn the Mac Drivers disk for Windows. This is really the only reason to get Bootcamp at all. You don’t need it for what follows.

In a terminal, run ‘diskutil’ to repartition your (Mac) drive. Something like the following:
diskutil resizevolume disk0s2 190G “Linux” Ubuntu 10G “MS-DOS FAT32” Windows 32G
My iMac has a 250 GB drive. Here I chose to resize it to 190GB and create a Linux-type partition of 10GB and a FAT32-type partition of 32GB. Do whatever you want size-wise. The basic idea here is that you’re re-sizing the existing partition (which was the full size of the hard drive) to something less and creating two new partitions, one for Ubuntu (Linux), the other for Windows. The command “diskutil list” is a good place to start and “diskutil resizevolume” will describe the syntax of that option.

This was the step that gave me the most trouble of the whole process. I ran diskutil several times and each time got some message about there not being enough space, though I had some 80GB free on the drive. After seeing something online, I shlepped my Parallels harddrive files (each 10-25GB) off to an external drive. After that and an Empty Trash, diskutil ran without a hitch. I don’t really understand whether macs actually do not get fragmented, but freeing up another 60GB of space (for a total of about 130GB) did the trick.

I choose to go with rEFIt ( instead of the Bootcamp loader. It looks good, is customizable (can change the icons and timeout, etc.) and handles three OSes well.

Install rEFIt. Very straight-forward, just run the package installed.

Put your Windows Vista (XP) disk in and reboot. Hold down “c” after the boot chime to boot from the CD/DVD drive.

Install Vista as you would normally, except be sure to choose the correct partition. If you followed my diskutil suggestion, it will be the fourth partition. Go by the size of the partitions. It’s the fourth because there were already two partitions on your original computer, the first being some 200 MB and containing the EFI (mac boot loader junk).

Insert the Mac Drivers disk that you created using Bootcamp. Run it and reboot. Now your mac keyboard and whatever else (iSight camera?) should work splendidly with Vista.

Have your way with your new Vista system (install updates, play games, admire Aero effects, whatever). You should be up and running with it now.

Eject the Mac Drivers disk and insert your Ubuntu disk. Reboot and hold down “c” again. You should boot into the Ubuntu Live CD system.

Install Ubuntu.

It’s possible that at some point the rEFIt loader gets hosed. Scary, yes, but nothing was lost for me. Just reboot into OSX (hold down “alt/option” at boot to get the Mac disc selector and choose your OSX disc) and re-install rEFIt. It’s very light-weight and easy to put back.

Reboot, choosing Mac OSX now. There is some little bug whereby Ubuntu won’t boot the first time. From the rEFIt menu, you select the Penguin (Ubuntu), it dims, and then the system hangs. Someone pointed out that this resolves itself after you boot into OSX and/or turn the computer off. I didn’t identify the issue because it indeed disappeared when I did those two things. So goof around in OSX (look, you haven’t hosed your original OSX system!), then reboot.

On this boot, select the Ubuntu drive from the rEFIt menu. (Once the Dim Penguin problem goes away, you will be able to boot into Ubuntu from then on.)

Ubuntu isn’t too bright about some of the iMac hardware, so this part’s a pain. Depending on your priorities, you’ll want to do the following in whatever order. This is where you’ll need that USB keyboard and mouse.

Ubuntu doesn’t install Bluetooth by default so plug in a USB keyboard and mouse (if you’re really dorky, or strapped, you might be able to do this with just a mouse). Initially, your wireless keyboard and mouse aren’t supported, so even though the system is up and running, you’ll be dead in the water. You will need to use the package manager to get “bluez-utils” installed and activated. [–terminal command to enable bluetooth and the edit to the config file to enable it at boot–]

The display will default to VESA 800×600 (which drives me batty). You want to run “dpkg-reconfigure xserver-xorg” in a terminal and choose the right driver for your display. On my 24″ iMac, it’s Nvidia, so I chose “nv” ( This is key, as the VESA driver can’t display above 1024×800. Then just choose the display modes that your screen supports (I went back into OSX and wrote them down from the Display preferences, since no one seems to have this documented online). For my 24″ intel imac, they are as follows: 640×480, 800×500, 800×600, 960×600, 1024×640, 1024×768, 1280×800, 1280×960, 1344×840, 1344×1008, 1600x1000x 1600×1200, and 1920×1200

That’s pretty much it! You’re up and running with whichever OS you choose at the rEFIt menu at boot time.

Download packages and wordpress plugins with wget and SSH [solved]

If you’re a typical web designer, when you install web packages like phpBB or wordpress or plugins like bad behavior or spam karma, you probably go to the web page that hosts the file, download it to your computer, unzip it, FTP to your host, and upload the directory to install the package.

Well, if your host has SSH access, there’s an easier way:

Go to the webpage of the file you want to download and right click and copy the link instead of downloading it.

Get putty and connect to your host via SSH on port 22, using your FTP login and password.

cd to the directory you want to download the file to (such as cd public_html/wordpress/wp-content/plugins/).

Type in this command:

wget [URL]

Where [URL] is the link to the downloaded file. For instance:


You can right click to paste in putty, so just type wget, hit space and then right click and hit enter.
Voila! Now you’ve downloaded the package right to your host. It’s way faster too.

Wget also works great for anonymous FTP files, just paste in the URL in the same way.

After you’re done downloading, to unzip a .zip file you just type:

unzip []

To gunzip and untar a .tar.gz file you can type:

tar -xvzf [nameoffile.tar.gz]

Voila! Then follow the instructions to continue installing your package (such as logging into wordpress, clicking on plugins and activating your plugin).

Is the directory named something different than you want? Just use mv:

mv [nameofdirectory] [newnamefordirectory]

Does the unzipped directory have an unwanted subdirectory? cd into the directory/subdirectory and then move everything down a level:

cd [directory]/[unwantedsubdirectory]/

mv * ..

This is a no brainer for your typical linux guru, but a great trick for your average web developer!

Repetitive arrow keying in linux [solved]

So, who knew that a lot of the keyboard shortcuts you miss in windows and mac are actually possible in the linux command line too. This digg story links to a great article on Bash shortcuts. Mac users and other SSH users, if the alt shortcuts don’t work, try hitting escape instead (don’t hold it down).
My favorites:
Ctrl + a – Jump to the start of the line
Ctrl + e – Jump to the end of the line
Ctrl + l – Clear the screen
Alt + ? – Show current completion list
“2T” means Press TAB twice:
2T – All available commands(common)
$2T – All Sys variables
/2T – Entire directory structure including Hidden ones

Extra tip:
In mac terminal, open terminal > window settings, and choose emulation. Choose ‘option click to position cursor,’ and click ‘use settings as defaults.’ Now when you hold down option and click, your cursor jumps to where you clicked! No more repetitive arrow keying!

read more | digg story