I have a 2 disk mdadm RAID 0 volume, 4TB total, created in Ubuntu 14.04 server. The volume is less than half full and I'm looking to unraid the disks, keeping the data so that I can use one of the disks in another machine.

Ideally I'd like to be able to do this without buying another drive for data copy.



If the raid array is partitioned, then you can use gparted to shrink and/or move the filesystems within it until the second half of the disk is unused. If it is not partitioned, then you need to shrink the filesystem with resize2fs ( assuming it is ext[234] ). Give yourself a little extra room just to be sure. Then you can convert the raid0 into a degraded raid4, which supports reshaping ( raid0 does not, but a degraded raid4 is essentially the same thing as a raid0 ). Then you can reshape the array down to only one disk, and remove the second disk.

resize2fs /dev/md2 2800M  # 2 3gb drives, left an extra 200mb of margin
mdadm -G /dev/md2 -l raid4
mdadm -G /dev/md2 -Z 2900M
e2fsck -f /dev/md2 # make sure you didn't break things
mdadm -G /dev/md2 -n 2 --backup=backup
mdadm -D /dev/md2 # watch until it is done reshaping
mdadm -G /dev/md2 -l raid0 # drop the second disk and go back to ( single disk ) raid0
mdadm -G /dev/md2 -Z max
resize2fs /dev/md2  # maximize the fs to use the full disk

In the process of testing this, I found that resize2fs would not let me shrink the fs to half of its original size even though it was only 33% used. I have submitted a patch to fix this minimum size calculation bug.

|improve this answer|||||
  • I'm trying to do this with a /dev/md0 device that contains a /dev/md0p1 ext4 partition and a /dev/md0p2 linux-swap partition. When I resize the array (-Z option), the partitions disappear. They come back with -Z max. Any way to get rid of a disk with a setup like mine? – Jakob Kruse Sep 5 '16 at 18:37
  • @JakobKruse, you follow the instructions in the answer? – psusi Oct 7 '16 at 17:58
  • I did, and it didn't work. Breaks on step 3. I ended up imaging the ext4 partition to an external drive, zapping everything and then restoring the image. – Jakob Kruse Oct 12 '16 at 6:29
  • @JakobKruse, oh I see, you partitioned your raid array. I don't do that. In that case you would need to shrink/move the partitions in the array before you shrink the array itself. – psusi Oct 20 '16 at 23:21
  • Nice, wasn't aware about the raid4 reshaping feature, that's awesome. Well explained too. – John Jan 8 at 2:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.