Converting a root filesystem from Reiserfs to XFS





This is a section of my adventures into install Linux on a laptop. This page is meant to explain how I converted from a Reiserfs root filesystem to an XFS root filesystem on a system with limited disk space.

After my installation of Debian GNU/Linux with Reiserfs support I ended up with a disk layout of :

hda1        /boot     ext2         7MB
hda5        /         reiserfs     2GB
hda6        -swap-                96MB

After installing and looking into other peoples experiences with laptop and also information about Reiserfs I came to the conclusion that I would like to preserve battery power on my laptop as long as possible but the noflushd daemon would not work along side the reiserfs filesystem so I decided to look for an alternative filesystem. I could have gone for ext2 but seeing as this laptop is a bit of an experiment/toy I thought I would try out XFS.

Steps of conversion

  1. Make a XFS kernel I first needed to create a new kernel with XFS support. I found some Debian packages for XFS tools and also some kernel patch packages. I installed all these but the kernel patches didn't seem to work. Looking on the SGI website I found three patches to download for stable release 1.0.1. Unfortunately these were for 2.4.5 so I had to take a step back on the kernel I was using. All these patches applied ok and the XFS option appeared in the filesystem section.

  2. Reduce the root filesystem I then needed to copy my root filesystem somewhere so I could change it to a xfs partition. s I had no free disk space but I was only using about 30% of my current root filesystem so I had to 'chop it up'. I used resize_reiserfs to shrink my filesystem to under 1GB. I then needed to shrink the partition as well, I decided to use cfdisk for this, I just deleted the hda5 partition and redefined it at just over 1Gb. I added a new partition in the gap and made this an ext2 partition. I edited my /etc/fstab as my swap partition had changed from hda6 to hda7. My new layout looked like this:
    hda1        /boot     ext2           7MB
    hda5        /         reiserfs     1.1GB
    hda6        /         ext2         0.9GB
    hda7        -swap-                  96MB
    

  3. Copy root filesytem to spare partition For this I rebooted into single user mode with Linux single at the LiLo prompt and did :
    mount -t ext2 /dev/hda6 /mnt
    cd /
    tar lvcf - . | (cd /mnt ; tar xpvf -)
    
    This obviously took a while. After it had finished I edited my lilo.conf and /etc/fstab to change instances of hda5 to hda6, not forgetting to change /mnt/etc/fstab as well!! Also changing the filesystem of / in the fstab to ext2.

  4. Convert root filesystem to XFSAfter rebooting in single user mode again and verifying that everything is ok and the root partition being used is the copy on hda6, I went ahead and converted the reiserfs to xfs. I did this with :
    mkfs_xfs -f /dev/hda5    (-f to force overwrite of reiserfs)
    mount -t xfs /dev/hda5 /mnt
    

  5. Copy everything back to XFS filesystem Did this using the same command as before:
    cd /
    tar lvcf - . | (cd /mnt ; tar xpvf -)
    
    Then I checked my lilo.conf and fstab (only /mnt/etc/fstab) change the root filesystem line to
    /dev/hda2	/	xfs	defaults 	1    1
    
    Then I rebooted again, first in single user just to check it worked ok then in full.

  6. Putting the disk back to normal It just remained for me to put my disk layout back how I wanted it. I have decided to add a small fat16 partition for use with hibernation mode of the laptop. So I deleted the hda6 partition and created another hda6 of about 40MB at the end of the free space. Then I deleted the hda5 (root) partition and redefined it using all the free space. So the disk ended up looking like:
    hda1        /boot     ext2         7MB
    hda5        /         xfs        1.9GB
    hda5        -dos-     fat16       40MB
    hda6        -swap-                96MB
    
    I'm not going to worry about mounting the fat16 partition so I didn't need to change the fstab. I double checked the lilo.conf and re-ran lilo just to be sure then rebooted in single user mode and grew the xfs filesystem to use the whole partition:
    xfs_growfs /dev/hda5
    

    After that it was just a reboot into usual full mode.

Still to do

What I need to do is create a rescue disk with XFS support so I can boot off floppy and mount the root filesystem if I need to.

Disclaimer

I did all this without doing any backups of my current setup. I had only recently installed a fairly plain Debian system so didn't have much to lose if I screwed it all up. I advise anyone else doing this to backup their data first.




Helpfull links





Neil Cheshire - created - 25th July 2001