MDADM: Resize underlying partitions in mdadm RAID1

  1. Boot into a rescue CD, like SystemRescueCd, /dev/mdX is not mounted. Use fsck, just to make sure everything is ok with filesystem before any actions.
  2. Make scrabbing of target partition and repairing if will be need.
    A RAID array can suffer from sleeping bad blocks. i.e. blocks that you cannot read, but normally you never do (because they haven’t been allocated to a file yet). When a drive fails, and you are recovering the data onto a spare, hitting that sleeper can kill your array. For this reason it is good to regularly (daily, or weekly, maybe monthly) read through the entire array making sure everything is OK. In 2.6.16 (with complete functionality in 2.6.17) you will be able to trigger a background read-test of the whole array:

    1
    echo check > /sys/block/mdX/md/sync_action

    If you were to create an array with –assume-clean, then whenever you run this it will report lots of errors, though you can fix them with

    1
    echo repair > /sys/block/mdX/md/sync_action

    If you are going to be doing that (and I would recommend it) then you may as well allow the initial sync, especially as you can quite happily ignore the fact that it is happening.

  3. Resize filesystem on the mdadm RAID:
    1
    resize2fs /dev/md0 [size]

    where size is a little larger than the currently used space on the drive in filesystem

  4. After resize2fs, you need to shrink your mdadm array. For example, shrink /dev/md2 to 30GB. The –size value must be in KiBytes (30 x 1024 x 1024 = 31457280); make sure it can be divided by 64:
    1
    2
    mdadm --grow /dev/md2 --size=31457280
    (size FS <-> MD size <-> New partition size)
  5. Remove one of the drives from the RAID:
    1
    mdadm /dev/md0 --fail /dev/XXX1
  6. Resize the removed drive with parted. Add the new partition to the drive with parted
  7. Restore the drive to the RAID:
    mdadm -a /dev/mdX /dev/XXX1
  8. Repeat steps for the other device
  9. Resize the RAID to use the full partition:
    1
    mdadm --grow /dev/mdX -z max
  10. Next we grow the file system to the largest possible value (if you don’t specify a size, resize2fs will use the largest possible value) and check:
    1
    2
    resize2fs /dev/mdX
    e2fsck -f /dev/mdX
Scroll to top