How to resize an OCFS2 filesystem on Linux

The post outlines the steps to resize an OCFS2 filesystem on Linux. The procedure should first be tested in test before being performed against a production environment.

1. Backup all data on the filesystem

Repartitioning a disk/device is a destructive process that may result in complete loss of volume data. Backup the contents of the volume to be resized before proceeding.

2. Globally unmount the filesystem to be resized

OCFS2 filesystem resize can only be performed with the filesystem unmounted from all cluster nodes. Unmount the filesystem to be resized on all cluster nodes. Use the mounted.ocfs2 command to verify if any nodes still have the volume mounted e.g.:

# mounted.ocfs2 -f
Device    FS    Nodes
/dev/sdb1 ocfs2 node01, node02
/dev/sdc1 ocfs2 node01, node02
/dev/sdg1 ocfs2 node01, node02
# mounted.ocfs2 -f
Device FS Nodes
/dev/sdb1 ocfs2 Not mounted
/dev/sdc1 ocfs2 Not mounted
/dev/sdg1 ocfs2 Not mounted

3. Perform a filesystem check

Before resizing the device or filesystem, perform a filesystem check. Be sure to correct/address any issues before proceeding.

# fsck.ocfs2 -fn /dev/sdb1
Checking OCFS2 filesystem in /dev/sdb1:
label: resizer
uuid: 21 bd e3 16 a6 a6 4e 95 89 23 77 c9 0d 9e 24 02 
number of blocks: 1048265
bytes per block: 4096
number of clusters: 1048265
bytes per cluster: 4096
max slots: 6

/dev/sdb1 was run with -f, check forced.
Pass 0a: Checking cluster allocation chains
Pass 0b: Checking inode allocation chains
Pass 0c: Checking extent block allocation chains
Pass 1: Checking inodes and blocks.
Pass 2: Checking directory entries.
Pass 3: Checking directory connectivity.
Pass 4a: checking for orphaned inodes
Pass 4b: Checking inodes link counts.
All passes succeeded.

4. Resize the underlying device/partition

The underlying LUN/device/partition upon which the filesystem resides must first be resized before the filesystem itself can be resized. The method, and therefore the commands required, to resize the device will differ depending upon the storage solution used. Note, as of OCFS2 version available at the time of writing this post, OCFS2 volumes may be resized larger, but not smaller.

In the following example, the OCFS2 partition to be resized resides on partition /dev/sdb1 (an iSCSI target) that is resized from 4Gb to 8Gb.

# df -kl /cfs03
Filesystem   1K-blocks Used     Available  Use%  Mounted on
/dev/sdb1    4193060   1578984  2614076    38%   /cfs03
# mount -t ocfs2
...
/dev/sdb1 on /cfs03 type ocfs2 (rw,_netdev,heartbeat=local)

Before Resize

# cat /proc/partitions | grep sdb
8  16  4194304 sdb
8  17  4194288 sdb1

During Resize (LUN resized, but not partition)

# cat /proc/partitions | grep sdb
8  16  8388608 sdb
8  17  4194288 sdb1

When using OCFS2 filesystems on partitioned devices, always ensure to recreate the partition using the original Start cylinder and larger End cylinder.

# fdisk /dev/sdb

The number of cylinders for this disk is set to 8192.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)

Command (m for help): p

Disk /dev/sdb: 8589 MB, 8589934592 bytes
64 heads, 32 sectors/track, 8192 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        4096     4194288   83  Linux

Command (m for help): d
Selected partition 1

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-8192, default 1): 
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-8192, default 8192): 
Using default value 8192

Command (m for help): p

Disk /dev/sdb: 8589 MB, 8589934592 bytes
64 heads, 32 sectors/track, 8192 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        8192     8388592   83  Linux

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

Calling ioctl() to re-read partition table.
Syncing disks.
Note: If using device sizes greater than 2Tb, use the parted utilty instead of fdisk to manage partitions.

After device/partition resize, ensure that all cluster nodes’ operating systems detect the new sizing of the device/partition before proceeding. The following utilities/methods can be used to dynamically detect device/partition changes; partprobe, sfdisk, blockdev, cluster-wide node reboot. Use with caution, for example:

# /sbin/partprobe /dev/sdb

OR

# /sbin/sfdisk -R /dev/sdb

OR

# /sbin/blockdev --rereadpt /dev/sdb

Verify the kernel sees the modified device partition sizing. After Resize (both LUN and partition resized):

# cat /proc/partitions | grep sdb
8 16 8388608 sdb
8 17 8388592 sdb1

Note, depending on the kernel device naming scheme employed (udev, dm, EMC PowerPath etc.), the device file name used to refer to the device on one node may differ to that on other nodes and/or change to a different name – this is normal and expected.

5. Resize the OCFS2 filesystem

Once the device/partition has been resized and it’s new size visible to all cluster nodes, resize the OCFS2 filesystem using the tunefs.ocfs2 command. For example:

# tunefs.ocfs2 -S /dev/sdb1
tunefs.ocfs2 1.2.4
Changing volume size from 1048572 blocks to 2097148 blocks
Proceed (y/N): y
Resized volume
Wrote Superblock

6. Perform filesystem check

Having resized the OCFS2 partition, perform another filesystem check before attempting to mount the resized volume.

# fsck.ocfs2 -fn /dev/sdb1
Checking OCFS2 filesystem in /dev/sdb1:
  label:              resizer
  uuid:               22 02 bb 51 b2 90 4a 4d 82 30 13 5d cc dd 05 bc 
  number of blocks:   2097148
  bytes per block:    4096
  number of clusters: 2097148
  bytes per cluster:  4096
  max slots:          6

/dev/sdb1 was run with -f, check forced.
Pass 0a: Checking cluster allocation chains
Pass 0b: Checking inode allocation chains
Pass 0c: Checking extent block allocation chains
Pass 1: Checking inodes and blocks.
Pass 2: Checking directory entries.
Pass 3: Checking directory connectivity.
Pass 4a: checking for orphaned inodes
Pass 4b: Checking inodes link counts.
All passes succeeded.

7. Mount the resized OCFS2 volume

Remount the resized OCFS2 filesystem on all cluster nodes.

# mounted.ocfs2 -f
Device FS Nodes
/dev/sdc1 ocfs2 node01, node02
/dev/sdf1 ocfs2 node01, node02
/dev/sdb1 ocfs2 node01, node02
# mount -t ocfs2
/dev/sdb1 on /cfs03 type ocfs2 (rw,_netdev,heartbeat=local)
...
# df -kl /cfs03
Filesystem   1K-blocks Used     Available Use% Mounted on
/dev/sdb1    8388592   1579120  6809472   19%  /cfs03
posted @ 2021-09-22 12:10  雪竹子  阅读(280)  评论(0编辑  收藏  举报