How to Resize RAID partitions on Ubuntu Server 16.04
Recently we configured an Ubuntu 16.04 on Server. We have two 256 GBs SSDs. After a while we recognised that our main RAID partition has only 20GBs while other partition has more than 200GBs.
Here's what fdisk -l
prints out:
Disk /dev/sda: 238.5 GiB, 256060514304 bytes, 500118192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x807adac1
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 614399 612352 299M fd Linux raid autodetect
/dev/sda2 614400 1662975 1048576 512M 82 Linux swap / Solaris
/dev/sda3 1662976 43606015 41943040 20G fd Linux raid autodetect
/dev/sda4 43606016 500117503 456511488 217.7G fd Linux raid autodetect
Disk /dev/sdb: 238.5 GiB, 256060514304 bytes, 500118192 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x9a57a62a
Device Boot Start End Sectors Size Id Type
/dev/sdb1 * 2048 614399 612352 299M fd Linux raid autodetect
/dev/sdb2 614400 1662975 1048576 512M 82 Linux swap / Solaris
/dev/sdb3 1662976 43606015 41943040 20G fd Linux raid autodetect
/dev/sdb4 43606016 500117503 456511488 217.7G fd Linux raid autodetect
Disk /dev/md0: 298.7 MiB, 313196544 bytes, 611712 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/md2: 217.6 GiB, 233599664128 bytes, 456249344 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/md1: 20 GiB, 21458059264 bytes, 41910272 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
The problem is we run out of space everytime we want to install or run something new on /dev/md1 which is our main partition.
Question is though, how can we run away from this? Is there a way to use /dev/md2
beside /dev/md1
so that we don't encounter low space disk issues or even shrink /dev/md2
and grow /dev/md1
?
We followed so many tutorials but no luck resizing /dev/md1
.
Solution 1:
The recommended way to avoid the space problem in your situation is to move existing directories to the filesystem in /dev/md2
, and use symlinks to point to the new directory.
Resizing the MD device is a more complex process:
- Copy all contents of
/dev/md2
to another place - Delete the
/dev/md2
device and partitions/dev/sda4
and/dev/sdb4
which are the RAID members. - Increase the size of
/dev/sda3
and/dev/sdb3
partitions to the size you want. - Use
mdadm --grow
to increase the size of/dev/md1
to match the size of underlying partitions. - Re-create
/dev/sda4
and/dev/sdb4
partitions and create RAID array on top of them. - Copy the data back to the partitions.
The reason why you have to do all of this is because the MD devices consist of disk partitions, and partitions are single areas in the hard disk. Therefore, you have to free the space after the partition in order to increase it.
Increasing the size of filesystems would be easier if there was Logical Volume Manager (LVM) in use.