11

I have a home built NAS, and I need to slightly reconfigure some of my drive usage.

I have an mdadm RAID1 composed of two 3TB drives. Each drive has one ext3 partition that uses the entire drive. I need to shrink the ext3 partition on both drives, and add a second 8GB or so ext3 partition to one, and swap partition of equal size to the other. I think I have the steps figured out, but wanted some confirmation.

  1. Resize the mdadm RAID resize2fs /dev/md0 [size] where size is a little larger than the currently used space on the drive
  2. Remove one of the drives from the RAID mdadm /dev/md0 --fail /dev/sda1
  3. Resize the removed drive with parted
  4. Add the new partition to the drive with parted
  5. Restore the drive to the RAID mdadm -a /dev/md0 /dev/sda1
  6. Repeat 2-5 for the other device
  7. Resize the RAID to use the full partition mdadm --grow /dev/md0 -z max

Is there anything I've missed, or haven't considered?

kyork
  • 241
  • 1
  • 2
  • 5

2 Answers2

8

Yes, you missed something very important and I've learned it the hard way. http://www.zdnet.com/blog/storage/why-raid-5-stops-working-in-2009/162 points out that it becomes now statistically unavoidable to have bad sectors on the RAID array.

If you have a degraded RAID array and one of your drives hits a bad sector, mdraid will shut down the array. That will happen during the recovery when you re-add the drive, because every sector of the other drives needs to be read. I've spent quite a bit of time recovering from this, which is really tricky.\

What you should therefore do beforehand is: echo repair > /sys/block/mdX/md/sync_action

(check https://raid.wiki.kernel.org/index.php/Scrubbing)

Jarmund
  • 5,988
  • 5
  • 33
  • 57
Dirk
  • 81
  • 1
  • I can't seem to run these commands even as sudo. I am running an ubuntu server. Would you have any idea why? – J Spen Nov 10 '16 at 21:49
  • Too late for you, but to answer: The shell is running as you and sudo is not interpreting the redirection `>`. Either encapsulate everything in a subshell, or use `tee`. I prefer tee: `echo repair | sudo tee /sys/block/mdX/md/sync_action` – ibotty Jan 03 '18 at 11:02
  • 1
    1: The pointer to scrubbing is useful and appropriate; 2: It's 2018 now, 9 years past 2009. I'm operating several RAID5 arrays, of 5 8-10TB disks each, for several years now, and nothing bad has happened (apart from one of the enclosures dying...). I think the warning about RAID5 stopping to work was greatly exaggerated -- the chance of that happening is not as huge as made out to be, and can be further mitigated by paying attention to HDD error rate when you buy them; 3: You should still always have a backup of everything – Zak Feb 26 '19 at 10:21
3

Your steps look good, with two exceptions:

  1. After resize2fs, you need to shrink your mdadm array. E.g. do mdadm --grow --size xxx as step #1a.

  2. I would also suggest doing all this while booted into a rescue CD, like SystemRescueCd, and not while /dev/md0 is mounted. Follow the resize by fsck, just to make sure everything is ok.

haimg
  • 22,193
  • 16
  • 79
  • 113