Changing the FS Type of the Root Partition

There may be a time when you need to change the file system type used on your root partition. This might be because you want to get better performance or better stability/reliability. Or, it might be because a new release of the kernel isn't able to mount one or more of your current partitions.

For me, it was the latter event that caused me to migrate the partition used for root and a data partition from being in XFS format to using EXT3 (for the root partition) and JFS (for the data partition). I wanted to move away from XFS because at the time of this writing, the 2.6.22 kernel for Linkstations was having stability problems with XFS.

As such, you will see that the following procedure actually changes two partitions. Depending you your needs, you might not have to do all of the steps. For example, if your second partition already uses the desired FS type and has enough unused space, then Step 1 and Step 18 can be skipped. Similarly, if your current kernel does everything you need, then Step 15 can be avoided.

I chose EXT3 for the partition holding root because first it is journaled. Second, and more importantly, it is a FS type that can be mounted while in EM. This means that I can use EM as part of the process. And, once this is done, I will have a chance to use EM to fix most of the errors I might make while playing with the system in the future.

Warning: messing with the root partition is not something to be done lightly. You can get your machine into a state such that it will not boot. Fortunately I don't think you can brick your box doing this, but you can make it painful to recover.

So, please read and understand the procedure before beginning, and be sure to backup any critical data. This is not a complicated process but it is lengthy. And given that data are wiped clean from the partition at a point in the flow it will pay to not rush things.

(Thanks go to Dave and MoonMaker for helping me get the kinks out of this.)

Prerequisites

 * 1) You have to be able to get the box in and out of EM. (See EM Mode.  Note, however, that this procedure doesn't quite follow the same steps for getting into EM that's described on that page.)
 * 2) You have to be able to telnet into the box while it is in EM.
 * 3) You have to have a kernel that can mount the new FS (either compiled directly into the kernel or as a loadable module). (See HowTo Build Your Own Custom Kernel.)
 * 4) There needs to be enough space on a second partition to hold an image of the root FS. In my case this was a little over 3 GB.
 * 5) That second partition needs to be using a FS that can be mounted while in EM.
 * 6) A second machine is required that can mount a copy of this image. This means the other system has to be able to mount your current FS type.  (This was XFS in my case.)

Overview
The procedure has three core phases plus a bonus phase.


 * First, a copy of the root partition is stored as a file on a second partition.
 * Second, the file is moved to another machine where it is turned into a TAR file.
 * Third, the TAR file is brought back and written back on the newly formated partition.
 * Bonus, install a new kernel that can support a new, desired FS type.

When reformatting partitions, it is best to do things while the partition is not being actively used. This is difficult to do with the root partition.

Here's the overview. (Done while logged in as root):


 * 1) backup /dev/sda6    &larr; Start of Phase One
 * 2) format sda6 as EXT3 (to use as a staging area)
 * 3) boot into EM
 * 4) copy sda2 partition to a file on sda6
 * 5) boot normally
 * 6) copy the sda2 image file to a remote machine    &larr; Start of Phase Two
 * 7) on the remote machine, loop mount the image
 * 8) create a tar copy of the contents of that image
 * 9) copy the tar file back to the LS-Pro (to sda6)     &larr; Start of Phase Three
 * 10) boot into EM
 * 11) format sda2 as EXT3
 * 12) mount sda6 and sda2
 * 13) untar the tar file on top of sda2
 * 14) boot normally
 * 15) put the new kernel in place in /boot    &larr; Bonus Phase
 * 16) reboot
 * 17) format sda6 as JFS
 * 18) restore the contents of sda6 saved in step 1

Easier Procedure

 * 1) Format an external drive that's large enough as a file system EM can mount, such as ext3.
 * 2) Boot into EM.
 * 3) mount /dev/sda2 /mnt/disk1
 * 4) mount /dev/sdb1 /mnt/usbdisk1
 * 5) cd /mnt/disk1
 * 6) tar cvf /mnt/usbdisk1/rootfs.tar.
 * 7) cd /
 * 8) umount /dev/sda2
 * 9) Optional: Now would be a great time for Custom Partitions on the LS Pro&mdash;you'll lose all data on your partitions:
 * 10) swapoff /dev/sda5
 * 11) umount /boot
 * 12) Use fdisk or cfdisk to edit the partition table for /dev/sda
 * 13) Important: Reboot, again into EM.
 * 14) (Create the data partition with whatever filesystem you like)
 * 15) mkswap /dev/sda5
 * 16) mount /dev/sdb1 /mnt/usbdisk1
 * 17) mkfs.ext3 /dev/sda2
 * 18) mount /dev/sda2 /mnt/disk1
 * 19) cd /mnt/disk1
 * 20) tar xvf /mnt/usbdisk1/rootfs.tar
 * 21) Boot into normal mode.

Gathering Information
First, before getting started, let's gather some information to make doubly sure that we are playing with the correct partitions. If you look at the /etc/fstab file you might see something like:

proc           /proc      proc    defaults                            0 0 none           /dev/pts   devpts  gid=5,mode=20                       0 0 tmpfs          /tmp       tmpfs   size=10M,mode=1777                  0 0 /dev/sda5      swap       swap    defaults                            0 0 /dev/sda1      /boot      ext3    defaults,noatime,errors=remount-ro  0 1 /dev/sda6      /mnt/disk1 xfs     defaults,noatime,nodiratime         0 0
 * 1) /etc/fstab: static file system information.

Here we can see that /dev/sda6 currently is being mounted using XFS. We will have to reformat this partition since we want to use this partition as the holding place for the copy of the root partition. (If this partition is formated as EXT3, then you will not have to reformat it.)

Note that this fstab file does not specify the partition to be mounted at /.

If you type "mount" you should see something like:

rootfs on / type rootfs (rw) /dev/root.old on /initrd type ext2 (rw) /dev/root on / type xfs (rw,data=ordered) tmpfs on /lib/init/rw type tmpfs (rw,nosuid) proc on /proc type proc (rw,nosuid,nodev,noexec) sysfs on /sys type sysfs (rw,nosuid,nodev,noexec) usbfs on /proc/bus/usb type usbfs (rw,nosuid,nodev,noexec) /dev/root on /dev/.static/dev type xfs (rw,data=ordered) tmpfs on /dev type tmpfs (rw) tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev) devpts on /dev/pts type devpts (rw,nosuid,noexec) tmpfs on /tmp type tmpfs (rw) /dev/sda1 on /boot type ext3 (rw,noatime,data=ordered) /dev/sda6 on /mnt/disk1 type xfs (rw,noatime,nodiratime) nfsd on /proc/fs/nfsd type nfsd (rw) rpc_pipefs on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)

From this, you can see that the /dev/root (corresponding to /dev/sda2) partition is being mounted with type XFS. This is what we are looking to change.

Step by Step
Note, because my system is using FreeLink, this procedure has a Debian flavor to it. It should be relatively easy to adapt this to other firmware families (such as GenLink).

Again, this procedure is done as root.

 backup /dev/sda6. (Use whatever technique you prefer.)  scp -pr /mnt/disk1 remotehost:/temp-dir1  

format sda6 as EXT3 (to use as a staging area)  umount /mnt/disk1 mkfs.ext3 /dev/sda6 change the /etc/fstab entry for /dev/sda6 to ext3
 * /dev/sda6 /mnt/disk1 ext3 defaults,noatime,nodiratime 0 0
 * (I don't know if noatime and nodiratime are appropriate for ext3)

mount -t ext3 /mnt/disk1 (to make sure it works)</li> </ol> </li>

boot into EM. (I did this rather than manually rebooting 3 times.)  cd /boot</li> mv rootfs_ok rootfs_booting</li> echo '****' > rootfs_booting</li> reboot</li> </ol> </li>

copy sda2 partition to a file on sda6  telnet into LS-Pro (using login 'root')</li> mkdir temp1</li> mount -t ext3 /dev/sda6 temp1</li> dd if=/dev/sda2 of=temp1/part.image</li> </ol> </li>

boot normally  cd /boot</li> mv rootfs_booting rootfs_ok</li> <li>echo `date` > rootfs_ok</li> <li>reboot</li> </ol> </li>

<li>copy the sda2 image file to a remote machine <ol style="list-style-type:lower-alpha"> <li>scp /mnt/disk1/part.image remotehost:/temp-dir2</li> (this may take a while if the image size is large) </ol> </li>

<li>on the remote machine, loop mount the image <ol style="list-style-type:lower-alpha"> <li>cd /temp-dir2</li> <li>mkdir temp3</li> <li>mount -t xfs -o loop part.image temp3</li> </ol> </li>

<li>create a tar copy of the contents of that image <ol style="list-style-type:lower-alpha"> <li>cd temp3</li> <li>tar pzcvf ../part.tgz .</li> </ol> </li>

<li>copy the tar file back to the LS-Pro (back on the LS-Pro) <ol style="list-style-type:lower-alpha"> <li>scp remotehost:/temp-dir2/part.tgz /mnt/disk1</li> </ol> </li>

<li>boot into EM <ol style="list-style-type:lower-alpha"> <li>cd /boot</li> <li>mv rootfs_ok rootfs_booting</li> <li>echo '****' > rootfs_booting</li> <li>reboot</li> </ol> </li>

<li>format sda2 as EXT3 (the scary part) <ol style="list-style-type:lower-alpha"> <li>mkfs.ext3 /dev/sda2</li> </ol> </li>

<li>mount sda6 and sda2 <ol style="list-style-type:lower-alpha"> <li>mkdir temp-dir1</li> <li>mount -t ext3 /dev/sda6 temp-dir1</li> <li>mkdir temp-dir2</li> <li>mount -t ext3 /dev/sda2 temp-dir2</li> </ol> </li>

<li>untar the tar file on top of sda2 <ol style="list-style-type:lower-alpha"> <li>cd temp-dir1</li> <li>gunzip part.tgz</li> (I had to explicitly gunzip the file as the busybox tar available in EM can't do it inline) <li>cd ../temp-dir2</li> <li>tar pxvf ../temp-dir1/part.tar</li> </ol> </li>

<li>boot normally <ol style="list-style-type:lower-alpha"> <li>cd /boot</li> <li>mv rootfs_booting rootfs_ok</li> <li>echo `date` > rootfs_ok</li> <li>reboot</li> </ol> </li>

<li>put the new kernel in place in /boot <ol style="list-style-type:lower-alpha"> <li>cd /boot</li> <li>cp uImage.buffalo uImage.buffalo-2.6.12.6</li> (I left the old kernel in /boot in case I need to boot back to it) <li>scp remotehost:/where/the/new/kernel/is uImage.buffalo-2.6.22</li> <li>cp uImage.buffalo-2.6.22 uImage.buffalo</li> (Also bring over any modules you may have cross built) <li>cd /lib/modules</li> <li>scp -r remotehost:/where/the/modules/are 2.6.22</li> </ol> </li>

<li>reboot <ol style="list-style-type:lower-alpha"> <li>make any offerings deemed necessary and cross fingers</li> <li>reboot</li> (Ideally you are up on the new kernel at this point) </ol> </li>

<li>format sda6 as JFS <ol style="list-style-type:lower-alpha"> <li>apt-get install jfsutils (if the utils are not already installed)</li> <li>umount /mnt/disk1</li> <li>mkfs.jfs -c /dev/sda6</li> (using the '-c' option made this step take several hours) <li>modify the partition type for /dev/sda6 line in /etc/fstab</li>
 * /dev/sda6 /mnt/disk1 jfs defaults,noatime,nodiratime 0 2
 * (here too, I'm not sure if noatime and nodiratime are appropriate for JFS)
 * It is important to specify '2' for the 'pass' parameter. This will allow the partition to mount properly at boot.

<li>mount -t jfs /mnt/disk1 (to make sure it works)</li> </ol> </li>

<li>restore the contents of sda6 saved in step 1 <ol style="list-style-type:lower-alpha"> (use your favorite technique) <li>scp -pr remotehost:/temp-dir1 /mnt/disk1</li> </ol> </li> </ol>

And now your /etc/fstab file should look something like:

proc           /proc      proc    defaults                            0 0 none           /dev/pts   devpts  gid=5,mode=20                       0 0 tmpfs          /tmp       tmpfs   size=10M,mode=1777                  0 0 /dev/sda5      swap       swap    defaults                            0 0 /dev/sda1      /boot      ext3    defaults,noatime,errors=remount-ro  0 1 /dev/sda6      /mnt/disk1 jfs     defaults,noatime,nodiratime         0 2
 * 1) /etc/fstab: static file system information.