Resizing Linux partitions: yes, you can!

I recently installed Ubuntu linux, and everything came up working fine. Then Ubuntu wanted to install “system updates” (all packages that have had updates since version 6.0.6 was released), so I let it go ahead and download the 200 MB of upgrades. One of those upgrades was a new linux kernel (2.6.15-28, vs. my current 2.6.15-26). To “install” this upgrade, Ubuntu attempted to write the new kernel into my /boot partition. Which lacked enough space. “Write error!” Ubuntu declared, leaving half of a kernel stuck to the end of the partition. I cleaned this off, happy to stay with my current kernel, but then I wondered. Would I ever be able to upgrade my kernel? Maybe 16 MB was too small for /boot. (Kernels are getting large and fat these days!)

After hashing this over with some friends, the solution seemed straightforward. I decided to stretch /boot out to cover 128 MB — plenty of space for several kernels and all of their friends. Now, partitions are physical divisions of your hard drive, so their position matters. My 16-MB /boot partition was first on the disk, followed by my 5-GB / partition (less than 1 GB used). Therefore, I planned to save a full copy of /boot and /, modify both partitions, then copy my data back onto the partitions.

After making and checking my full copy of this data, I turned to some man pages to acquaint myself with fdisk for the partitioning rite. Here’s where I learned something: there is a utility, parted, that will permit you to move and resize partitions! (For you geeks, this “resize” applies to both the partition and the filesystem, which is what does the trick.) Instead of destroying and re-creating them, saving and copying data, in theory I could simply shuffle them around. In theory, this is all I would need to do:

/dev/hda5 goes from 65kB to 16MB
/dev/hda6 goes from 16MB to 5256MB
So…

  1. parted /dev/hda5
  2. resize 6 128MB 5256MB
    # move and shrink /dev/hda6, which is /, to start at 128MB
  3. resize 5 65kB 128MB
    # move and grow /dev/hda5, which is /boot, to end at 128MB

In reality, parted had some tricks up its sleeve. It flat-out refused to move partition 6 anywhere above 17MB. (“Error: unable to satisfy all constraints on the partition.”) I still am not sure exactly what those constraints were, but in the end, here’s what worked:

  1. resize 6 16MB 2000MB
    # really, it's mostly empty. This was safe. I hoped.
  2. move 6 2000MB 4000MB
    # get partition 6 out of the way. Note that I couldn't just move it to start at 128MB because you "can't move a partition to overlap with itself" and it ended at 2000 MB.
  3. resize 5 65kB 128MB
    # grow partition 5
  4. resize 6 2000MB 3000MB
    # parted won't let me resize 6 back down to start at 128 MB. I can't move it there, either, because (you guessed it) it would overlap with its current position. So I had to shrink it again.
  5. move 6 128MB 1128MB
    # now I can move it down!
  6. resize 6 128MB 5256MB
    # and make it bigger.

Now I have that same post-puzzle fatigue-glow that you get after escaping Zork’s maze of twisty little passages. Puzzle completed in 6 steps. I could have done it in 5 if I’d known that I’d need to shrink partition 6 down to 1000MB from the start. Thank goodness / gave me 5 GB to mess around in — and that the shrinking steps succeeded! After rebooting, I’m back up and running, with 120 MB on /boot (not 128, possibly because partitions like to start and stop on cylinder boundaries?). Done! And I can delete that backup copy I made and never needed.

Linux upgrade: installing Ubuntu

It was time. I had let my linux desktop machine (astra) languish at home for years, neglected and barely used since I bonded with my 15″ Mac Powerbook (and then with its 15″ MacBook Pro successor). Astra’s linux distribution, Mandrake 8.2, fell further and further behind the pounding gallop of linux upgrades, until it was so out of date that I couldn’t even update its packages reliably. I finally decided that it was time to do a full upgrade and install some modern flavor of linux. After some discussions with friends and additional googling, I settled on Ubuntu. Then the fun began!

Step 1. I wanted to make a full backup of astra’s hard drives before doing anything to the OS. My backup drive (andromeda) can be accessed via firewire or USB 2.0. Astra, a cutting-edge machine from the year 2000, has neither one (but it does have USB 1.0!). So I connected astra to my Mac laptop (elysium) with an Ethernet cable and plugged andromeda into elysium’s firewire port. Getting astra and elysium to talk together was as easy as `ifconfig eth1 192.168.0.3 up` on astra and entering a manual IP (192.168.0.2) on elysium (Macs are so smart that they automatically turn Ethernet cables into crossover cables when appropriate). I then used rsync to make a full backup — interrupted intermittently when rsync failed due to two filenames on astra that differed only in case (like “Classes” and “classes”); the Mac filesystem has only a thin veneer of case-sensitivity that is easily scratched by these cases. I renamed files as needed to proceed.

Step 2. I downloaded an Ubuntu 6.0.6 ISO from the Ubuntu website and burned it to a fresh CD-ROM. (When downloading, the website forces you choose between “Ubuntu 7.0.4 with 18 months of free security updates” and “Ubuntu 6.0.6 with 3 years of free security updates.” I’m still perplexed by this, given that it’s a free and open-source OS. But I really don’t need astra to live on the bleeding edge.)

Step 3. I fiddled with my BIOS boot settings to put the CD-ROM drive ahead of the hard drive, then booted up with the Ubuntu CD-ROM. This was the first time I’ve used a “live CD”, and it performed exactly as expected. Ubuntu uncompressed itself and came up in a “test” mode, meaning that you could play around with linux and see how you like it before making the full hard-drive commitment to an installation. I wonder how many people convert to linux after playing with it running off a CD-ROM? Now granted, astra runs at just 667 MHz, but even with a modern CPU, I can’t imagine that having your OS running off the CD drive is what you would describe as a speedy experience. Astra also has only 256 MB of RAM, every bit of which I think was full of Ubuntu just to let it run without a hard drive.

Ubuntu comes with a folder called “Examples”, which includes some music, video, and Open Office (text, spreadsheet, presentation) documents. I couldn’t resist trying to open one of the spreadsheets, at which point astra froze. Out of memory? I had to reboot, but I wasn’t worried — Ubuntu was running in its own space, so no possible damage from an unexpected reboot could be done to my own hard disks; they weren’t even mounted. Therefore, imagine my surprise when I rebooted and the initial system check suddenly failed to find my primary hard drive. No problem — a second reboot and the hard drive was back.

Step 4. I was ready to install. I initiated the process, entering step 1 of a reassuringly small total of 6. The first questions were easy: username, machine name, etc. And then I came to the sweat- and nausea-inducing “set up your partition table” step. Now, you can skip this step and let Ubuntu pick the “largest contiguous free space” in which to install itself. But I didn’t have any free (unpartitioned) space because my old Mandrakian linux was still installed. Beyond that, partitioning your drives just seems like one of those nitty gritty get-your-hands-dirty experiences that you have to suffer through to really feel like you’ve installed linux. I mean, if you don’t develop a fiery, passionate opinion about the One Right Way to Partition, then how can you call yourself a geek? I opted for separate partitions for /, /boot, swap, /home, and /usr, a selection that’s fairly low on the controversy scale. I clicked my way through specifying these things, chanting “I have a full backup, I have a full backup” under my breath, especially when I was forced to check the “reformat partition” checkboxes next to… well… all of my new partitions. I hit the final “Go” button and let Ubuntu run through my hard drive, zeroing everything out (conceptually), and then unpacking itself in its new, clean home.

Step 5. I rebooted. And astra came up, all Ubuntu-ified! It worked!

Well… everything worked but the new wireless card I’d just installed, specially for astra’s new incarnation as my cutting-edge home workstation. I’ll post about how I solved that problem later. For now, here are some other interesting Ubuntu observations:

  • One does not log in as root on Ubuntu. In fact, the root user is “locked”. There is no root password! You do everything root-like via sudo. This was a bit of a shock initially (no root on my own system?), but after googling around and reading a bit of the discussion, I can see some of the reasoning for it. Interesting design choice.
  • What’s the first thing I want to do when I log in? I want a terminal shell. How do I get one? It’s not on a mouse button context menu… where… where… oh! It’s up under the “Accessories” menu. For some reason, this cracks me up, like the terminal is somehow an “extra”, optional, unneeded. For linux! Have times changed that much?
  • Ubuntu does not install anything developer-friendly with its basic install. Although I’ve encountered this before (with my Mac!), it’s still a shock to type gcc or make and get “command not found” back. Because my wireless card wasn’t working, I had to drag my machine across the house to plug it in to my router via Ethernet so that I could install these basic packages.

  • But now astra is up and running and oh-so-proud to be of use once more! Hooray!

    « Newer entries