Convert your Linux filesystem safely and easily (even on a VPS)

I was shocked to discover that converting one’s filesystem is simple as pie and totally safe. The process goes like this:

  1. Remove cruft from your system (optional)
  2. Reboot into a LiveCD environment (optional if the partition you want to convert can be mounted read-only without rebooting)
  3. Mount the partition you want to convert in read-only mode
  4. Copy the contents of the partition somewhere temporarily (ex. another partition, external drive, DVD, etc.)
  5. Unmount the copied partition
  6. Format the partition with your desired filesystem
  7. Mount the formatted partition and copy all the files back
  8. Edit /etc/fstab to reflect the new filesystem
  9. Reboot and profit

Thanks to Slicehost’s wonderful Rescue Mode with a 2GB Rescue Slice, I was able to use this method to convert my Gentoo VPS from ext3 to XFS. Here’s a step-by-step account. These steps were performed on a 256MB VPS at Slicehost. YMMV.

(Why XFS? Good performance and reliability, reasonable CPU load, maximization of disk space. See “Filesystems (ext3, reiser, xfs, jfs) comparison” and “Serverwide Performance Benchmarking“.)

  1. Make sure my slice is smaller than 1.4GB.
    I am using the Rescue Slice (with only about 1.4GB free) as the temporary storage location, so my slice must be smaller than 1.4GB or it wouldn’t fit. (It might be possible to backup and restore over the Internet, but copying to the Rescue Slice and back is definitely the simplest, so plan to perform these steps early in your slice’s life.)
    Some tricks to slim down my slice (all optional):
    eclean-dist -d“, “eclean-pkg -d” and delete the rest of /usr/portage/distfiles if necessary
    in /usr/portage, “rm -rf a* dev-* g* k* m* n* perl-* r* sci-* sec-* sys-* w* x*
    emerge -a –depclean” and “revdep-rebuild
    localepurge
    use “df -h” and “du -h /dirname” to help

  2. Boot into a Rescue Slice environment.
    Go to the SliceManager, and the Rescue panel of your slice. Click “Enter Rescue Mode”. Use the provided temp root password to log into the Rescue Slice.
  3. Mount the partition I want to convert in read-only mode.
    mkdir /mnt/slice
    mount -r /dev/sda1 /mnt/slice
  4. Copy the contents of the partition somewhere temporarily
    mkdir /root/backup
    cp -dPRp /mnt/slice /root/backup
  5. Unmount the copied partition
    umount /dev/sda1
  6. Format the partition with my desired filesystem, XFS
    mkfs.xfs -f /dev/sda1
  7. Mount the formatted partition and copy all the files back
    mount /dev/sda1 /mnt/slice
    cp -dPRp /root/backup/slice /mnt
  8. Edit /etc/fstab to reflect the new filesystem
    nano /mnt/slice/etc/fstab

    My new /etc/fstab reads:

    /dev/sda1               /               xfs             defaults        0 1
  9. I did not include the “noatime” mount option because it might actually decrease performance for XFS systems (source).

  10. Exit Rescue Mode, reboot.
  11. Install the appropriate utilities for fscking your filesystem. Ex. for XFS, I need xfsprogs.
    emerge -va xfsprogs

I now have a spiffy Gentoo VPS on XFS. Yay!

If your Gentoo VPS fails to boot with a fatal error about /proc being already mounted, don’t panic. You did nothing wrong; this is a known Gentoo bug. Read this article for how to fix it easily.

Credit:
HOWTO Convert Filesystems

If you liked this post, please subscribe to my feed. Thanks for visiting!

Related posts

0 Responses to “Convert your Linux filesystem safely and easily (even on a VPS)”


  1. No Comments

Leave a Reply