# mdadm how do I shrink? [SOLVED]

## drescherjm

When builing a new file server at work I have decided to put gentoo on the raid arrays instead of its own disk as I have done many times in the past. So I partitioned 6 x 320GB drives as follows (all drives have the same partition table):

```
# sfdisk /dev/sda -l

Disk /dev/sda: 38912 cylinders, 255 heads, 63 sectors/track

Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0

   Device Boot Start     End   #cyls    #blocks   Id  System

/dev/sda1   *      0+     31      32-    257008+  fd  Linux raid autodetect

/dev/sda2         32     125      94     755055   82  Linux swap / Solaris

/dev/sda3        126   38911   38786  311548545   fd  Linux raid autodetect

/dev/sda4          0       -       0          0    0  Empty

```

Then I created a 256MB raid 1 array using the first partition of each disk. This array is /dev/md0 and I mount this as boot.

And finally I created a ~1.2TB raid 6 array with the third partition of each disk. This array is /dev/md1 and I mount this as /.

After a few problems (/dev/sdb was faulty) I was able to install amd64 gentoo 2006.0 from an installer disk (using the old manual method...) . 

Here are the drives in /etc/fstab 

```

<snip>

# NOTE: If your BOOT partition is ReiserFS, add the notail option to opts.

/dev/md0                /boot           ext2            noauto,noatime  1 2

/dev/md1                /               reiserfs        noatime         0 1

/dev/sda2               none            swap            sw              0 0

/dev/sdb2               none            swap            sw              0 0

/dev/sdc2               none            swap            sw              0 0

/dev/sdd2               none            swap            sw              0 0

/dev/sde2               none            swap            sw              0 0

/dev/sdf2               none            swap            sw              0 0

<snip>

```

But now after I have everything installed and configured I think I have made a mistake by having everything on /. I would prefer to limit / to ~50GB and make a third raid 6 array /dev/md2 from the fourth partition of each disk by shrinking /dev/md1 using mdadm. I have googled a few times but I can not find any real example of how this is done. I assume that mdadm in this config will not reduce the partition size when I shrink the array. is this correct? Then how do I calculate the exact partition size to enter into fdisk? 

Am I wasting my time with trying to shrink the array this way and instead should I just copy / to a new disk and just delete the /dev/md1 and recreate and copy everything back??

----------

## drescherjm

I believe I am going to try the second method of copying a / to a different disk. Time to get out that livecd...

----------

## drescherjm

I ended up trying both methods (made two backups of my data one with cp the other with partimage) and because I did not know that the size param in mdadm --grow is in blocks I really messed up things so I ended up deleting the raid array completly and creating the new raid6 arrays and then copying the data back with cp. A word of warning if you are going to reduce the size of a partition and use partimage reduce first as partimage will not let you put a 1.2TB reiserfs filesystem with only 4.5GB used onto a 40GB partition! 

BTW, If anyone actually wants to do this in the future I believe I now know the correct steps to do this via the madam --grow comamnd, fdisk and resize_reiserfs. 

Here goes:

WARNING, I can not gaurantee that you will not loose any data if you follow these steps.

Step 1: Use resize_reiserfs to trim your reiserfs filesystem to a size that you know will be smaller size of the new array. You can always run resize again with no params and reiserfs will make the filesystem the size of the raid array.

# resize_reiserfs -s 10G /dev/md1

Step 2: Use fdisk to reduce the the size of the partition in question on the first disk and also while your at it create a partition for the next arrray. Record the size of the partition yor resized in number of blocks (save this for step 5).

Step 3: Duplicate the partition table on all array members:

Use sfdisk -d /dev/<first_disk> | sfdisk /dev/<next_disk> 

Warning this assumes you have/want an identical partition table on all disks. 

Step 4: Repeate step 3 for all remaining disks...

Step 5: Use the number of blocks you saved from step 2 to resize the array

# mdadm -G /dev/md1 --size=<block_count>

Step 6: Run resize_reiserfs again to reize the filesystem to the size of the array (this time no size param is needed)

# resize_reiserfs /dev/md1

Step 7:

Create the array /dev/md2. If you are at this point you should have done this a few times before but here is what I did:

# mdadm -C /dev/md2 -l6 --chunk=256 -n6 /dev/sd[abcdef]4

----------

