Difference between revisions of "Changing the FS Type of the Root Partition"

From NAS-Central Buffalo - The Linkstation Wiki
Jump to: navigation, search
m
Line 1: Line 1:
 +
{{Articles|LSPro}}
 
There may be a time when you need to change the file system type used on your
 
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
 
root partition.  This might be because you want to get better performance or

Revision as of 15:30, 9 October 2007

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.)

Contents

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    ← 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    ← 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)    ← 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    ← Bonus Phase
  16. reboot
  17. format sda6 as JFS
  18. restore the contents of sda6 saved in step 1

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:

# /etc/fstab: static file system information.
# <file system> <mount point>   <type>  <options>               <dump>  <pass>
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

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.

  1. backup /dev/sda6. (Use whatever technique you prefer.)
    1. scp -pr /mnt/disk1 remotehost:/temp-dir1
  2. format sda6 as EXT3 (to use as a staging area)
    1. umount /mnt/disk1
    2. mkfs.ext3 /dev/sda6
    3. change the /etc/fstab entry for /dev/sda6 to ext3
    4. /dev/sda6 /mnt/disk1 ext3 defaults,noatime,nodiratime 0 0
      (I don't know if noatime and nodiratime are appropriate for ext3)
    5. mount -t ext3 /mnt/disk1 (to make sure it works)
  3. boot into EM. (I did this rather than manually rebooting 3 times.)
    1. cd /boot
    2. mv rootfs_ok rootfs_booting
    3. echo '****' > rootfs_booting
    4. reboot
  4. copy sda2 partition to a file on sda6
    1. telnet into LS-Pro (using login 'root')
    2. mkdir temp1
    3. mount -t ext3 /dev/sda6 temp1
    4. dd if=/dev/sda2 of=temp1/part.image
  5. boot normally
    1. cd /boot
    2. mv rootfs_booting rootfs_ok
    3. echo `date` > rootfs_ok
    4. reboot
  6. copy the sda2 image file to a remote machine
    1. scp /mnt/disk1/part.image remotehost:/temp-dir2
    2. (this may take a while if the image size is large)

  7. on the remote machine, loop mount the image
    1. cd /temp-dir2
    2. mkdir temp3
    3. mount -t xfs -o loop part.image temp3
  8. create a tar copy of the contents of that image
    1. cd temp3
    2. tar pzcvf ../part.tgz .
  9. copy the tar file back to the LS-Pro (back on the LS-Pro)
    1. scp remotehost:/temp-dir2/part.tgz /mnt/disk1
  10. boot into EM
    1. cd /boot
    2. mv rootfs_ok rootfs_booting
    3. echo '****' > rootfs_booting
    4. reboot
  11. format sda2 as EXT3 (the scary part)
    1. mkfs.ext3 /dev/sda2
  12. mount sda6 and sda2
    1. mkdir temp-dir1
    2. mount -t ext3 /dev/sda6 temp-dir1
    3. mkdir temp-dir2
    4. mount -t ext3 /dev/sda2 temp-dir2
  13. untar the tar file on top of sda2
    1. cd temp-dir1
    2. gunzip part.tgz
    3. (I had to explicitly gunzip the file as the busybox tar available in EM can't do it inline)

    4. cd ../temp-dir2
    5. tar pxvf ../temp-dir1/part.tar
  14. boot normally
    1. cd /boot
    2. mv rootfs_booting rootfs_ok
    3. echo `date` > rootfs_ok
    4. reboot
  15. put the new kernel in place in /boot
    1. cd /boot
    2. cp uImage.buffalo uImage.buffalo-2.6.12.6
    3. (I left the old kernel in /boot in case I need to boot back to it)

    4. scp remotehost:/where/the/new/kernel/is uImage.buffalo-2.6.22
    5. cp uImage.buffalo-2.6.22 uImage.buffalo
    6. (Also bring over any modules you may have cross built)

    7. cd /lib/modules
    8. scp -r remotehost:/where/the/modules/are 2.6.22
  16. reboot
    1. make any offerings deemed necessary and cross fingers
    2. reboot
    3.            (Ideally you are up on the new kernel at this point)
      
  17. format sda6 as JFS
    1. apt-get install jfsutils (if the utils are not already installed)
    2. umount /mnt/disk1
    3. mkfs.jfs -c /dev/sda6
    4. (using the '-c' option made this step take several hours)

    5. modify the partition type for /dev/sda6 line in /etc/fstab
    6. /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.
    7. mount -t jfs /mnt/disk1 (to make sure it works)
  18. restore the contents of sda6 saved in step 1
      (use your favorite technique)
    1. scp -pr remotehost:/temp-dir1 /mnt/disk1

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

# /etc/fstab: static file system information.
# <file system> <mount point>   <type>  <options>               <dump>  <pass>
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