I setup my Raid-0 mdadm raid array a few years ago when I setup my arch install following this guide https://wiki.archlinux.org/title/RAID#Installation while also googling and asking questions elsewhere to get it right for my exact setup.

I want to shrink the portion of the raid-0 array allocated to my OS, and create a new partition with the free space, and install a different linux OS on that partition.

Will I have to re setup the array during the installation of that OS? As I understand it this is a software raid, and I believe I remember my OS partition having some config for the loading of the array.

I've tried use mdadm --grow /dev/md127 --size=3T (Shrinking from 3.4T to 3T so I can install OS on the other 400GB). This yields the following error: mdadm: Cannot set device size in this type of array.

I've tried using other software like fdisk, but do not want to write an action that will accidentally corrupt my array.

1 Answer 1


I don't use RAID-0 much (not at all), so I'm not actually sure why mdadm does not support shrinking RAID-0. The alternative seems to re-create the array, but for mdadm --create to work, you have to specify the disk order, data offset, level, layout, etc. correctly.

The error message itself is a generic one, it does not specifically mention RAID-0 at all (there's actually another message in the code Component size change is not supported for RAID0, which is not reached here). The manpage does mention that RAID 0 array size cannot be changed.

It can still be done indirectly, by temporarily converting RAID-0 to RAID-4 (or RAID-5 using --layout=parity-last). This conversion should happen instantly without changing on-disk data, since RAID-0 and RAID-4 (with missing parity disk) happen to be identical. Shrinking works then, since md RAID-4/5/6 supports it.

However, I'm sure almost nobody ever tests doing it this way, so... there might still be some risk involved.

Here's an example with the level and layout change.

Setup RAID-0:

# head -c 100M /dev/urandom > a.img
# losetup --find --show a.img

# head -c 100M /dev/urandom > b.img
# losetup --find --show b.img

# mdadm --create /dev/md42 --level=0 --raid-devices=2 /dev/loop0 /dev/loop1
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md42 started.

# head -c 42M /dev/md42 | md5sum
fff6e815ae3979b190e1a84f1b9fd776  -

Shrink RAID-0 via RAID-4:

# mdadm --grow /dev/md42 --size=21M
mdadm: Cannot set device size in this type of array.

# mdadm --grow /dev/md42 --level=4
mdadm: level of /dev/md42 changed to raid4
# mdadm --grow /dev/md42 --size=21M
mdadm: component size of /dev/md42 has been set to 21504K
# mdadm --grow /dev/md42 --level=0
mdadm: level of /dev/md42 changed to raid0

# echo 3 > /proc/sys/vm/drop_caches
# md5sum /dev/md42
fff6e815ae3979b190e1a84f1b9fd776  /dev/md42

Note that the --size does not account for the data offset, so each component must remain at least component size plus data offset large.

# mdadm --examine /dev/loop0
Avail Dev Size : 43008 sectors (21.00 MiB 22.02 MB)
Data Offset : 4096 sectors

So in this example, the device size must be at least 43008 + 4096 = 47104 sectors large. If your array was larger, the default data offset picked by mdadm may be much larger too, so do be careful not to shrink your partitions by too much.

Also note that raid0 has some corner cases (with devices of different size) where this method may not work. This answer assumes you're using same-sized drives with mdadm 1.2 metadata.

  • Decided to go ahead and try to shrink raid-0 by first converting it to Raid 4. Once converted to RAID 4, i am still unable to shrink/"grow" the array. Md127 is a 3.4T raid4 array, and when i run mdadm --grow /dev/md127 --size=3T it says "mdadm: Cannot set device size for /dev/md127. No Space left on device". Assuming it's using the syntax of expansion I try to plug in a negative number after size, which also doesn't work. Commented Apr 23 at 16:56
  • --size is "amount of space to use from each drive" (data offset not included). check mdadm --examine for Avail/Used/Array Size and Data Offset. Commented Apr 23 at 17:57
  • Also for mdadm, T means TiB not TB. Commented Apr 23 at 18:03
  • Was able to resize the mdadm array /dev/md127, and it's size is displaying correctly in lsblk as 2.9T. However, it's partition, md127p1, is still sized as 3.4T. How do I resize this? Commented Apr 23 at 18:45
  • Was unable to resize the md127p1, and ended up unable to boot after restart. Before restarting I also did a cat /proc/Mdstat into my /etc/mdadm.conf. Booting yields many errors and I am met with an emergency root shell after everything fails. Commented Apr 23 at 19:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .