[Linux Raid] mdadm raid 1 resizing partition

In order to resize the raid file system from small capacity to larger one, we should reset the raid size and file system size to new setting.
Here are two simple case studies to increase and reduce raid size.
Case 1: Increase the size of /dev/md4 from 4GB to 8GB

  • pre-check the file system
  • increase the raid capacity
  • resize file system capacity
  • pro-check
  • mount and use

Case 2: Reduce the size of /dev/md4 from 8GB to 6GB

  • umount the file system
  • pre-check
  • reduce the file system capacity
  • reduce the raid capacity
  • pro-check
  • mount and use

Reference: HowToForge

Case 1: Increase the size of /dev/md4 from 4GB to 8GB

Show details of /dev/md4
mdadm --detail /dev/md4

/dev/md4:
Version : 0.90
Creation Time : Sat Jan 15 11:06:08 2011
Raid Level : raid1
Array Size : 4194304 (4.00 GiB 4.29 GB)
Used Dev Size : 4194304 (4.00 GiB 4.29 GB)
Raid Devices : 2
Total Devices : 2
Preferred Minor : 4
Persistence : Superblock is persistent

Update Time : Sat Jan 15 11:19:47 2011
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0

UUID : 844af06e:0f8604d5:375c0a47:1d95493b
Events : 0.18

Number   Major   Minor   RaidDevice State
0      22        1        0      active sync   /dev/hdc1
1      22       65        1      active sync   /dev/hdd1

Pre-check the raid is health before resizing
e2fsck -f /dev/md4

/dev/md4: recovering journal
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/md4: 11/524288 files (9.1% non-contiguous), 54384/1048576 blocks

Increate the raid 1 from 4G to 8G
(8G = 8 * 1024 * 1024 = 8388608K)
(Increase the raid size (just like the container size) before file system size)
mdadm --grow /dev/md4 --size=8388608

Resize the filesystem to 8G
(Increase the file system size)
resize2fs /dev/md4 8G

resize2fs 1.39 (29-May-2006)
Filesystem at /dev/md4 is mounted on /mnt; on-line resizing required
Performing an on-line resize of /dev/md4 to 2097152 (4k) blocks.
The filesystem on /dev/md4 is now 2097152 blocks long.

Pro-check the filesystem is good to use.
e2fsck -f /dev/md4

If everything is ok, then mount and use it.
mount /dev/md4 /somewhere_you_like/
Show whether resizing takes effective
df -h

Case 2: Reduce the size of /dev/md4 from 8GB to 6GB

Umount the file system before resizing as online reduce file system size is not allow.
umount /somewhere_you_mount_before/
Pre-check the filesystem is good.
e2fsck -f /dev/md4
Resize the file system to 6GB
resize2fs /dev/md4 6G

Reduce the raid 1 from 8G to 6G
(6G = 6 * 1024 * 1024 = 6291456K)
mdadm --grow /dev/md4 --size=6291456
Pro-check the filesystem is good to use.
e2fsck -f /dev/md4
mount and use it.
mount /dev/md4 /somewhere_you_like/
Show whether resizing takes effective
df -h

Leave a Reply

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.