Jump to contentJump to page navigation: previous page [access key p]/next page [access key n]
documentation.suse.com / SUSE Linux Enterprise Server-Dokumentation / Storage Administration Guide / Software RAID / Resizing Software RAID Arrays with mdadm
Applies to SUSE Linux Enterprise Server 15 SP2

11 Resizing Software RAID Arrays with mdadm

This section describes how to increase or reduce the size of a software RAID 1, 4, 5, or 6 device with the Multiple Device Administration (mdadm(8)) tool.

Resizing an existing software RAID device involves increasing or decreasing the space contributed by each component partition. The file system that resides on the RAID must also be able to be resized to take advantage of the changes in available space on the device. In SUSE Linux Enterprise Server, file system resizing utilities are available for file systems Btrfs, Ext2, Ext3, Ext4, and XFS (increase size only). Refer to Chapter 2, Resizing File Systems for more information.

The mdadm tool supports resizing only for software RAID levels 1, 4, 5, and 6. These RAID levels provide disk fault tolerance so that one component partition can be removed at a time for resizing. In principle, it is possible to perform a hot resize for RAID partitions, but you must take extra care for your data when doing so.

Warning
Warning: Back Up your Data Before Resizing

Resizing any partition or file system involves some risks that can potentially result in losing data. To avoid data loss, ensure that you back up your data before you begin any resizing task.

Resizing the RAID involves the following tasks. The order in which these tasks are performed depends on whether you are increasing or decreasing its size.

Table 11.1: Tasks Involved in Resizing a RAID

Tasks

Description

Order If Increasing Size

Order If Decreasing Size

Resize each of the component partitions.

Increase or decrease the active size of each component partition. You remove only one component partition at a time, modify its size, then return it to the RAID.

1

2

Resize the software RAID itself.

The RAID does not automatically know about the increases or decreases you make to the underlying component partitions. You must inform it about the new size.

2

3

Resize the file system.

You must resize the file system that resides on the RAID. This is possible only for file systems that provide tools for resizing.

3

1

The procedures in the following sections use the device names shown in the following table. Ensure that you modify the names to use the names of your own devices.

Table 11.2: Scenario for Increasing the Size of Component Partitions

RAID Device

Component Partitions

/dev/md0

/dev/sda1

/dev/sdb1

/dev/sdc1

11.1 Increasing the Size of a Software RAID

Increasing the size of a software RAID involves the following tasks in the given order: increase the size of all partitions the RAID consists of, increase the size of the RAID itself and, finally, increase the size of the file system.

Warning
Warning: Potential Data Loss

If a RAID does not have disk fault tolerance, or it is simply not consistent, data loss results if you remove any of its partitions. Be very careful when removing partitions, and ensure that you have a backup of your data available.

11.1.1 Increasing the Size of Component Partitions

Apply the procedure in this section to increase the size of a RAID 1, 4, 5, or 6. For each component partition in the RAID, remove the partition from the RAID, modify its size, return it to the RAID, then wait until the RAID stabilizes to continue. While a partition is removed, the RAID operates in degraded mode and has no or reduced disk fault tolerance. Even for RAIDs that can tolerate multiple concurrent disk failures, do not remove more than one component partition at a time. To increase the size of the component partitions for the RAID, proceed as follows:

  1. Open a terminal.

  2. Ensure that the RAID array is consistent and synchronized by entering

    > cat /proc/mdstat

    If your RAID array is still synchronizing according to the output of this command, you must wait until synchronization is complete before continuing.

  3. Remove one of the component partitions from the RAID array. For example, to remove /dev/sda1, enter

    > sudo mdadm /dev/md0 --fail /dev/sda1 --remove /dev/sda1

    To succeed, both the fail and remove actions must be specified.

  4. Increase the size of the partition that you removed in the previous step by doing one of the following:

    • Increase the size of the partition, using a disk partitioner such as the YaST Partitioner or the command line tool parted. This option is the usual choice.

    • Replace the disk on which the partition resides with a higher-capacity device. This option is possible only if no other file systems on the original disk are accessed by the system. When the replacement device is added back into the RAID, it takes much longer to synchronize the data because all of the data that was on the original device must be rebuilt.

  5. Re-add the partition to the RAID array. For example, to add /dev/sda1, enter

    > sudo mdadm -a /dev/md0 /dev/sda1

    Wait until the RAID is synchronized and consistent before continuing with the next partition.

  6. Repeat these steps for each of the remaining component devices in the array. Ensure that you modify the commands for the correct component partition.

  7. If you get a message that tells you that the kernel could not re-read the partition table for the RAID, you must reboot the computer after all partitions have been resized to force an update of the partition table.

  8. Continue with Section 11.1.2, “Increasing the Size of the RAID Array”.

11.1.2 Increasing the Size of the RAID Array

After you have resized each of the component partitions in the RAID (see Section 11.1.1, “Increasing the Size of Component Partitions”), the RAID array configuration continues to use the original array size until you force it to be aware of the newly available space. You can specify a size for the RAID or use the maximum available space.

The procedure in this section uses the device name /dev/md0 for the RAID device. Ensure that you modify the name to use the name of your own device.

  1. Open a terminal.

  2. Ensure that the RAID array is consistent and synchronized by entering

    > cat /proc/mdstat

    If your RAID array is still synchronizing according to the output of this command, you must wait until synchronization is complete before continuing.

  3. Check the size of the array and the device size known to the array by entering

    > sudo mdadm -D /dev/md0 | grep -e "Array Size" -e "Dev Size"
  4. Do one of the following:

    • Increase the size of the array to the maximum available size by entering

      > sudo mdadm --grow /dev/md0 -z max
    • Increase the size of the array to the maximum available size by entering

      > sudo mdadm --grow /dev/md0 -z max --assume-clean

      The array uses any space that has been added to the devices, but this space will not be synchronized. This is recommended for RAID 1 because the synchronization is not needed. It can be useful for other RAID levels if the space that was added to the member devices was pre-zeroed.

    • Increase the size of the array to a specified value by entering

      > sudo mdadm --grow /dev/md0 -z SIZE

      Replace SIZE with an integer value in kilobytes (a kilobyte is 1024 bytes) for the desired size.

  5. Recheck the size of your array and the device size known to the array by entering

    > sudo mdadm -D /dev/md0 | grep -e "Array Size" -e "Dev Size"
  6. Do one of the following:

11.1.3 Increasing the Size of the File System

After you increase the size of the array (see Section 11.1.2, “Increasing the Size of the RAID Array”), you are ready to resize the file system.

You can increase the size of the file system to the maximum space available or specify an exact size. When specifying an exact size for the file system, ensure that the new size satisfies the following conditions:

  • The new size must be greater than the size of the existing data; otherwise, data loss occurs.

  • The new size must be equal to or less than the current RAID size because the file system size cannot extend beyond the space available.

Refer to Chapter 2, Resizing File Systems for detailed instructions.

11.2 Decreasing the Size of a Software RAID

Decreasing the Size of a Software RAID involves the following tasks in the given order: decrease the size of the file system, decrease the size of all partitions the RAID consists of, and finally decrease the size of the RAID itself.

Warning
Warning: Potential Data Loss

If a RAID does not have disk fault tolerance, or it is simply not consistent, data loss results if you remove any of its partitions. Be very careful when removing partitions, and ensure that you have a backup of your data available.

Important
Important: XFS

Decreasing the size of a file system formatted with XFS is not possible, since such a feature is not supported by XFS. As a consequence, the size of a RAID that uses the XFS file system cannot be decreased.

11.2.1 Decreasing the Size of the File System

When decreasing the size of the file system on a RAID device, ensure that the new size satisfies the following conditions:

  • The new size must be greater than the size of the existing data; otherwise, data loss occurs.

  • The new size must be equal to or less than the current RAID size because the file system size cannot extend beyond the space available.

Refer to Chapter 2, Resizing File Systems for detailed instructions.

11.2.2 Decreasing the Size of the RAID Array

After you have resized the file system (see Section 11.2.1, “Decreasing the Size of the File System”), the RAID array configuration continues to use the original array size until you force it to reduce the available space. Use the mdadm --grow mode to force the RAID to use a smaller segment size. To do this, you must use the -z option to specify the amount of space in kilobytes to use from each device in the RAID. This size must be a multiple of the chunk size, and it must leave about 128 KB of space for the RAID superblock to be written to the device.

The procedure in this section uses the device name /dev/md0 for the RAID device. Ensure that you modify commands to use the name of your own device.

  1. Open a terminal.

  2. Check the size of the array and the device size known to the array by entering

    > sudo mdadm -D /dev/md0 | grep -e "Array Size" -e "Dev Size"
  3. Decrease the array’s device size to a specified value by entering

    > sudo mdadm --grow /dev/md0 -z SIZE

    Replace SIZE with an integer value in kilobytes for the desired size. (A kilobyte is 1024 bytes.)

    For example, the following command sets the segment size for each RAID device to about 40 GB where the chunk size is 64 KB. It includes 128 KB for the RAID superblock.

    > sudo mdadm --grow /dev/md2 -z 41943168
  4. Recheck the size of your array and the device size known to the array by entering

    > sudo mdadm -D /dev/md0 | grep -e "Array Size" -e "Device Size"
  5. Do one of the following:

11.2.3 Decreasing the Size of Component Partitions

After you decrease the segment size that is used on each device in the RAID (see Section 11.2.2, “Decreasing the Size of the RAID Array”), the remaining space in each component partition is not used by the RAID. You can leave partitions at their current size to allow for the RAID to grow at a future time, or you can reclaim this now unused space.

To reclaim the space, you decrease the component partitions one at a time. For each component partition, you remove it from the RAID, reduce its partition size, return the partition to the RAID, then wait until the RAID stabilizes. To allow for metadata, you should specify a slightly larger size than the size you specified for the RAID in Section 11.2.2, “Decreasing the Size of the RAID Array”.

While a partition is removed, the RAID operates in degraded mode and has no or reduced disk fault tolerance. Even for RAIDs that can tolerate multiple concurrent disk failures, you should never remove more than one component partition at a time. To decrease the size of the component partitions for the RAID, proceed as follows:

  1. Open a terminal.

  2. Ensure that the RAID array is consistent and synchronized by entering

    > cat /proc/mdstat

    If your RAID array is still synchronizing according to the output of this command, you must wait until synchronization is complete before continuing.

  3. Remove one of the component partitions from the RAID array. For example, to remove /dev/sda1, enter

    > sudo mdadm /dev/md0 --fail /dev/sda1 --remove /dev/sda1

    To succeed, both the fail and remove actions must be specified.

  4. Decrease the size of the partition that you removed in the previous step to a size that is slightly larger than the size you set for the segment size. The size should be a multiple of the chunk size and allow 128 KB for the RAID superblock. Use a disk partitioner such as the YaST partitioner or the command line tool parted to decrease the size of the partition.

  5. Re-add the partition to the RAID array. For example, to add /dev/sda1, enter

    > sudo mdadm -a /dev/md0 /dev/sda1

    Wait until the RAID is synchronized and consistent before continuing with the next partition.

  6. Repeat these steps for each of the remaining component devices in the array. Ensure that you modify the commands for the correct component partition.

  7. If you get a message that tells you that the kernel could not re-read the partition table for the RAID, you must reboot the computer after resizing all of its component partitions.

  8. (Optional) Expand the size of the RAID and file system to use the maximum amount of space in the now smaller component partitions and increase the size of the file system afterward. Refer to Section 11.1.2, “Increasing the Size of the RAID Array” for instructions.