doc:appunti:linux:sa:raid_shrink
Shrinking a RAID0 volume to add a smaller device to it
Must add the resize2fs operation!
Suppose we have:
- /dev/md3 is the RAID0 device, running in degraded mode.
- /dev/sda7 is the surviving component of md0, 921GB in size.
- /dev/sdb7 is the new component to be added to md0, 451GB in size.
Get the size of the new component sdb7
Get the exact size (in kb) of the /dev/sdb7 partition. Using parted and display sizes in sector units:
parted /dev/sdb (parted) unit s (parted) print ... Sector size (logical/physical): 512B/4096B ... 7 95703040s 976773119s 881070080s home raid
so the size of /dev/sdb7 is 881070080 / 2 = 440535040 kb.
Get the size of the running component sda7 and RAID device md3
Get the size (in kb) of the /dev/sda7 partition:
parted /dev/sda (parted) unit s (parted) print ... Sector size (logical/physical): 512B/4096B ... 7 95703040s 1894920191s 1799217152s home raid
The size is 1799217152 / 2 = 899608576 kb.
Get the size of the /dev/md0 RAID volume:
mdadm -D /dev/md3 ... Array Size : 899476480 (857.81 GiB 921.06 GB) ...
The overhead of the RAID volume is 899608576 - 899476480 = 132096 kb. For safety we allow an extra space of 128 kb for the RAID superblock.
Calcluate the new array size
So we can calculate the new array size:
new_array_size = new_component_size - raid_overhead - raid_superblock_size
440535040 - 132096 - 128 = 440402816
It is now possibile to shrink the existing array /dev/md3 to the new smaller size:
mdadm --grow /dev/md3 -z 440402816
Finally we can add the new component to the shrinked array:
mdadm /dev/md3 --add /dev/sdb7
doc/appunti/linux/sa/raid_shrink.txt · Last modified: 2025/01/07 09:45 by niccolo