Score:1

How to re-organize partition sizes on a Software RAID on Ubuntu?

tj flag

I have an existing Software RAID consisting of 4 partitions on a Server running Ubuntu 22. I want to decrease the size of the md2 partition and increase the size of the md3 partition.

How do achieve that without data loss? The partition to be decreased in size has sufficient space to do so.

root@Ubuntu-2204-jammy-arm64-base ~ # cat /proc/mdstat
Personalities : [raid1] [raid6] [raid5] [raid4] [linear] [multipath] [raid0] [raid10]
md3 : active raid6 nvme0n1p5[0] nvme1n1p5[1] nvme2n1p5[2] nvme3n1p5[3]
      5378365440 blocks super 1.2 level 6, 512k chunk, algorithm 2 [4/4] [UUUU]
      [==========>..........]  resync = 50.1% (1347715200/2689182720) finish=105.4min speed=212018K/sec
      bitmap: 21/21 pages [84KB], 65536KB chunk

md2 : active raid6 nvme2n1p4[2] nvme0n1p4[0] nvme1n1p4[1] nvme3n1p4[3]
      2111567872 blocks super 1.2 level 6, 512k chunk, algorithm 2 [4/4] [UUUU]
        resync=DELAYED
      bitmap: 8/8 pages [32KB], 65536KB chunk

md0 : active raid1 nvme0n1p2[0] nvme3n1p2[3] nvme1n1p2[1] nvme2n1p2[2]
      4189184 blocks super 1.2 [4/4] [UUUU]

md1 : active raid1 nvme1n1p3[1] nvme0n1p3[0] nvme2n1p3[2] nvme3n1p3[3]
      1046528 blocks super 1.2 [4/4] [UUUU]

Disk sizes:

root@Ubuntu-2204-jammy-arm64-base ~ # df -h
Filesystem      Size  Used Avail Use% Mounted on
tmpfs            26G  2.4M   26G   1% /run
/dev/md2        2.0T  2.1G  1.9T   1% /
tmpfs           126G     0  126G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
/dev/md1        989M  129M  810M  14% /boot
/dev/nvme3n1p1  256M  340K  256M   1% /boot/efi
/dev/md3        5.0T   25G  4.7T   1% /home
tmpfs            26G     0   26G   0% /run/user/0
tmpfs            26G     0   26G   0% /run/user/1000
Score:1
ca flag

What you are trying to do is quite complex. I suggest a careful reading of mdadm manpage (especially the "Size Changes" and "RAID-Devices Changes" sections) before doing anything.

If unsure, seek for professional help.

To accomplish what you want, you need to:

  • shrink the filesystem on top of md2 (xfs can not be shrunk so, if you are using it, then stop now)
  • shrink the array with mdadm --grow
  • reduce the backing partitions (p4)
  • use partprobe to notify the kernel about the change
  • now, enlarge the partitions (p5) backing md3
  • re-run partprobe
  • grow the array with mdadm --grow
  • expand the filesystem

As you can see, there are many steps to follow. Any errors and your data are lost.

Again, if unsure, seek for qualified help.

delete avatar
tj flag
Thank you. I now understand the principles of what needs to be done, which helped me a lot. However, I will give this in professional hands.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.