Resizing an iSCSI EXT3 disk, partition, and file system

A client of mine uses an iSCSI target to back up databases on Oracle Enterprise Linux production machines.

Great concept - until the disk runs out of space and the admins want to take down the server to fix that. Ahum? Take the server offline for a backup drive? Come on, there's got to be a better way. And there is.

The admins' way was:

  1. create a new iSCSI target and connect to it
  2. move the data from the old mounted drive to the new one
  3. mount the new drive as /u04

That took ages (moving a few TB just takes a while - especially if the iSCSI target is a not-overl;y-fast device... it's for backups, you know, so why spend the money)

I figured there had to be a faster way. And there is (we'll use /dev/sdc1 with /u04 as mount point in our example):

  1. unmount the iSCSI device: 
    > umount /u04

  2. turn off journalling on the partition, making it a ext2 partition
    > tune2fs -O ^has_journal /dev/sdc1

  3. disconnect from it
    > iscsiadm -m node -T <iscsi target path> -p <iscsi host> --logout
  4. resize the target on the target system (ie. in the SAN console)

  5. log back into the iscsi target

  6. use fdisk to delete and recreate the partition table (scary, I know)
    > fdisk /dev/sdc
    Command (m for help): p
    => write down start- and end-cylinder of the existing partition
    => now delete the partition (1, in our case):

    Command (m for help): d
    Partition number (1-5): 1

    => Now we re-create the partition (phew!)
    Command (m for help): n
    Command action
       l   logical (5 or over)
       p   primary partition (1-4)
    Partition number (1-4): 1

    First cylinder (1-32267, default 1): 1
    => take the first cylinder from what your wrote down. Most likely it'll be "1"

    Last cylinder or +size or +sizeM or +sizeK (1-32268, default 32268): 32268
    => depends on what you want, but usually you'll want the default here (largest)

    Now make sure that you set up the right things:

    Command (m for help): p

    Command (m for help): p

    Disk /dev/sdc: 268.7 GB, 268703891456 bytes
    255 heads, 63 sectors/track, 32668 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes

    Device Boot Start End Blocks Id System
    /dev/sdc1 1 32668 262405678+ 83 Linux

    Looking good? Then write the partition table changes to disk.

    Command (m for help): w
    The partition table has been altered!

    FDisk will complain about the re-reading the table, but we'll work around that in a minute so we don't need a reboot (that WAS the objective right?!)

  7.  Repeat steps 3 and 5 (the --logout / --login steps) to get the disk re-read

  8.  Run fsck to check the filesystem for errors (needs to be done)
    > fsck -n /dev/sdc1

  9. use resize2fs to resize the partition's file system
    >resize2fs /dev/sdc1

  10. turn journalling back on
    >tune2fs -j /dev/sdc1
  11. pray
    >Root Admin, whou thou art at the keyboard, protect this humble consultant's butt, etc etc
  12. mount the partition (we're lazy, so we'll do a -a)
    >mount -a

 Admittedly - a lot more steps, but without the moving of data, it's a heck of a lot faster.