Linux – How to resize mdadm partition with extended partition at the end

debianlinuxmdadmpartitionraid

I have several VMs on mdadm partitions, and I need to add another VM, but I habe no more space left on the mdadm RAID.
So I wanted to shrink one of the partitions (which does not need much HDD space) and use the gained space for the new VM.
Debian defaults to create an extended partition at the end for swapping, so I can't just resize the root partition and create a md7.
I understand, that I could just resize md6p1 and use the space afterwards, but I need to separate the partitions to md6 and md7.

Here's the partition (fdisk -l of host system):

Disk /dev/md6: 100 GiB, 107302879232 bytes, 209575936 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos

Device     Boot     Start       End   Sectors  Size Id Type
/dev/md6p1 *         2048 200996863 200994816 95.9G 83 Linux
/dev/md6p2      200998910 209573887   8574978  4.1G  5 Extended
/dev/md6p5      200998912 209573887   8574976  4.1G 82 Linux swap / Solaris

One of the RAID devices:

/dev/sda8       716193792 925900799 209707008  100G 83 Linux

What is the proper way of doing that?

Best Answer

I would go with the suggestions Sven already helpfully provided in the comment. Though I wouldn't see a need to use lvm. Also using image files is not slower than using partitions, or at least not noticeably slower and it has the added benefit of being more versatile and easier to manage, copy, backup...

To go with your example you could remove the swap partition and then expand /dev/md6p1 to use the whole disk.

Then when you have /dev/md7 in place you could first create a small swap partition (or use a swap file instead), then create one or more partitions to fill the rest of the disk. Mount these partitions to places inside the /dev/md6p1 partition which I assume is the root filesystem. Mount points such as /usr and /home are good candidates.

Also take a look at /usr/share/doc/mdadm/README.recipes.gz. It has some examples on how to expand a raid. It may be a good idea to replace the disks one by one with larger disks and expand the raid that way. Then either create new partitions or expand the existing one(s).

Related Topic