Linux: August 2006 Archives

Manually re-writing the MBR

| | Comments (0)

The other day, I resized my NTFS partition from taking the entire disk, and made some others: a 100MB partition at the beginning of the drive, and then 15GB at the end. The 15GB was split into 1GB/14GB. I'm sure that most of you can imagine what each partition was for: /boot, swap, and /.

I popped in my gentoo livecd, fired up gentoo-nofb, and went to work installing gentoo. Firing up fdisk, I saw that my partition table was out of order. And hey, it was! I had only resized my existing partition, not made additional ones. Likewise, the large NTFS partition sitting in the middle of the drive had partition ID #1, and the 100MB before it had ID #2. "Why not" I said, and told fdisk to fix the partition table order for me. Which, hey, it did, and did perfectly.

Recall from previous posts that Window's boot loader (NTLDR) is a little finicky. It was installed to the first partition, likewise, when starting Windows, it tried to load files from partition one.

Which, was now 100MB in size and formatted ext2.

To complicate the matter, I had left my CD binder at a friend's house the day before, preventing me from popping in the XP CD and hitting the "Repair" option. I also needed to boot into Windows (hey, don't judge me!), and by fixing the problem, I had broken it. I recall a small bit of IRC chat that occured while I was trying to fix this:

him: iirc, fdisk has a fix partition order option, maybe that'll help?
me: That's what I used, I need it in it's broken state to work
him: oh, okay.

So, fdisk is not of use, and I need to change my partition table entry. Luckily, the MBR (which houses the partition table) is only 512 bytes in length, and the partition table is an even smaller subset of that. So, what do you do when you have a linux livecd to repair your partition table?

Google, `dd`, and `echo`.

  1. Google the partition table format and location
  2. Use fdisk to dump the current partition table (it dumps it so that I can see offsets, enter fdisk and then press 'x', 'd' to see what I mean)
  3. Backup the current MBR (dd if=/dev/hda of=MBR.bin bs=512 count=1; scp MBR.bin user@host:~/)
  4. Use a combination of `echo blah > file` and `dd if=file of=/dev/hda bs=1 count=1 seek=blah` to change the partition table order.
  5. Reboot and hope that it works at all.

And guess what?

It worked, first try.

I might have gone absolutely nuts once I saw that it worked.

I wound up deleting the initial /boot partition, and resizing the
NTFS partition to take that initial hundred megs. I'm booting without a /boot partition, but hey, it isn't exactly required.

Of course, an hour later, I realized that I could have just:

  1. Deleted the /boot partition
  2. Deleted the swap partition
  3. Made a new /boot partition, numbered one, after the number two (NTFS) partition
  4. Re-fix the partition order (again)

Oh well. At least I can say that I've manually re-written an MBR now using echo and dd.

Bad idea: changing hostname/domainname while X is running

| | Comments (0)

For anyone who thinks to themselves, "You know, changing the domainname is fine while the system is running [X]", think again.

Change the domainname while X is running causes X to die in horrible, horrible ways.

Taking your glibc compile along with it. Oops. So much for the past half-hour.

About this Archive

This page is a archive of entries in the Linux category from August 2006.

Linux: July 2006 is the previous archive.

Linux: September 2006 is the next archive.

Find recent content on the main index or look in the archives to find all content.

Powered by Movable Type 4.0