I was shocked to discover that converting one’s filesystem is simple as pie and totally safe. The process goes like this:
- Remove cruft from your system (optional)
- Reboot into a LiveCD environment (optional if the partition you want to convert can be mounted read-only without rebooting)
- Mount the partition you want to convert in read-only mode
- Copy the contents of the partition somewhere temporarily (ex. another partition, external drive, DVD, etc.)
- Unmount the copied partition
- Format the partition with your desired filesystem
- Mount the formatted partition and copy all the files back
- Edit /etc/fstab to reflect the new filesystem
- 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“.)
- 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 - 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. - Mount the partition I want to convert in read-only mode.
mkdir /mnt/slice mount -r /dev/sda1 /mnt/slice
- Copy the contents of the partition somewhere temporarily
mkdir /root/backup cp -dPRp /mnt/slice /root/backup
- Unmount the copied partition
umount /dev/sda1 - Format the partition with my desired filesystem, XFS
mkfs.xfs -f /dev/sda1
- Mount the formatted partition and copy all the files back
mount /dev/sda1 /mnt/slice cp -dPRp /root/backup/slice /mnt
- Edit /etc/fstab to reflect the new filesystem
nano /mnt/slice/etc/fstabMy new /etc/fstab reads:
/dev/sda1 / xfs defaults 0 1
- Exit Rescue Mode, reboot.
- Install the appropriate utilities for fscking your filesystem. Ex. for XFS, I need xfsprogs.
emerge -va xfsprogs
I did not include the “noatime” mount option because it might actually decrease performance for XFS systems (source).
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!


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