March 6, 2007
Root Filesystem Conversion
Ed: This post was originally written on 2006/08/03, but for some reason I missed publishing it. As I believe the information is useful, I'm publishing it now.
On my home workstation, I used LVM for the one 160GB hard drive. When I first built the box (in May of 2004), I installed Fedora Core 2 for x86_64; it's a dual AMD Opteron 242 (1.6GHz). I created four partitions:
- 100MB
/boot/ - 2GB swap (there's 1GB RAM, but I can expand to 8GB)
- remainder (~96GB) LVM
- 60GB Windows XP Professional
For a couple of weeks, I have been unable to install any updates to FC5. When I run yum update, I get a series of error messages telling me that yum needs additional disk space on the root partition in order to install packages. Strangely enough, almost none of those packages have files that end up in the root partition.
The root filesystem was a 512MB ext3 LVM logical volume. Sure, I could make it bigger, but I shouldn't have to. In fact, I should be able to have it be only about 256MB and still have a completely usable system. I have /home/, /tmp/, /usr/, /var/ and even /opt/ all split off onto their own LVs, so there's not that much stuff left on the root volume. In fact, running du -sx / shows that there is just barely 200MB of data present. However, running df / shows that it is 99% full (about 508MB used). Clearly, ext3 is not an efficient choice for a root partition when the bulky filesystems are split out like this.
So, I decided to "convert" to another filesystem type. I chose to use XFS for the root volume. Converting the root partition can be a little bit tricky, as the initrd needs to have the right drivers to work with it. Here's my step-by-step (assuming that the volume group is named system):
- Create a new volume and format it with the new filesystem type (the size could be smaller, if desired):
# lvcreate -L 512MB -n newroot system # mkfs.xfs /dev/system/newroot
- Mount the new root volume and remount the current root volume read-only:
# mkdir /mnt/temp # mount /dev/system/newroot /mnt/temp/ # mount -o remount,ro /
- Copy the contents of just the root volume to the new root volume (the
-xswitch is very important):# cp -ax /* /mnt/temp/
- Unmount the new root volume:
# umount /mnt/temp/
- Run
uname -rand record the value. This will be needed later when runningmkinitrd. - Reboot the system into a rescue environment. In order to be able to boot with the new root partition, it is necessary to recreate the initrd. You could hand edit the existing one(s) to fix things up, but this will be quite a bit easier. Use a CD or a network bootable rescue environment for your distro (FC5 in my case).
- If you let the setup for the rescue environment mount your partitions/volumes, that's fine, just make sure to unmount everything so you can switch root partitions. If you don't let it mount up the parts, that's fine too; just use the LVM commands for your rescue environment to activate LVM.
- Rename the old root volume out of the way and rename the new one into place (this only works while the volumes are not mounted):
# lvrename system root oldroot # lvrename system newroot root
- Mount the (new) root volume and at least
/boot/and/usr/on top of that: - It's time to recreate the initrd. This is easiest when done
chroot'ed into the system environment found on your hard drive (assuming your new root volume was mounted at/mnt/system/):# chroot /mnt/system/
- Run
mkinitrd. Depending on which distribution is installed, this could require quite a different set of switches than what I'm showing you here. In my case, it was Fedora, so I used themkinitrdcommand found in the/sbin/new-kernel-pkgscript, which is run as part of the post-install scripts from every Red Hat kernel RPM (just open up/sbin/new-kernel-pkgand find the right command to run, replacing "something" with the correct kernel version string recorded earlier from theuname -rcommand):# /sbin/mkinitrd --allow-missing -f /boot/initrd-2.6.something 2.6.something
- Leave the
chrootenvironment and unmount everything (yes, if you just cleanly exit the rescue environment, it should cleanly unmount everything, but let's just be sure it happens right, shall we?):# exit # umount /mnt/system/usr/ # umount /mnt/system/boot/ # umount /mnt/system/
- Reboot. The system should come up with your root volume in use with a new filesystem type.
# mkdir /mnt/system/ # mount /dev/system/root /mnt/system/ # mount /dev/sda1 /mnt/system/boot/ # mount /dev/system/usr /mnt/system/usr/
That's it. That wasn't so difficult, was it?
The entire thing could be done from within the rescue environment, including copying the contents of the root volume to the new root volume, if you like.
Posted by lamontp at March 6, 2007 5:23 PM
Trackback Pings
TrackBack URL for this entry:
http://blogs.gurulabs.com/cgi-bin/mt-tb.cgi/45