Reduce the size of a partition containing an volume

  • BE SURE TO MAKE A BACKUP
  • Either resizing or moving the physical partition may cause the raid superblock to be lost

  • Check the filesystem on mdadm raid volume
          e2fsck -f /dev/md0
          
  • Reduce the filesystem on mdadm raid volume (change volume and reduced size)
          resize2fs /dev/md0 120G
          
  • Resize the mdadm raid volume (use a size slightly larger than the filesystem)
  •       mdadm --grow /dev/md0 --size=122G
          
  • Check the filesystem on mdadm raid volume
          e2fsck -f /dev/md0
          
  • Stop the raid device
  •       mdadm /dev/md0 --stop
          
  • Resize the physical partition (use GParted to do that)
  • You may need to boot from a Live CD to do this – to use parted, you may not have to reboot to a live image
    You can also use the parted command line tool as follows:

            # apt install parted
            parted /dev/sda
            (parted) print
    
            # IMPORTANT: The END is NOT the new size - you have to add sizes of partitions before it
            (parted) resizepart
            Partition number? # Select partition number to resize
            End [10G]?        # Enter the new end of partition in bytes (remember to add sizes of partitions before it)
                              # Also, double check in GParted to make sure the size is what you expect it to be, since
                              # the parted size does not correspond to GParted size
    
            # The short sintax is (assuming partition number is 2 and you need it to resize to 125G):
            (parted) resizepart 2 125G
    
            # To continue to the next drive, use select
            (parted) select /dev/sdb
          
  • https://www.tecmint.com/parted-command-to-create-resize-rescue-linux-disk-partitions/
  • Start the raid device
  •         mdadm --examine --scan
            mdadm --assemble --scan
            #mdadm --assemble /dev/md0 /dev/sda1 /dev/sdb1
          

    In case of a raid 1 device not starting up, you might mount one of the raid partitions as a standard partition, then
    create a new raid one drive using the second partition. If that works, you can sync from the standard device to the
    new raid device and afterwords add the second partition to the raid, which will cause the raid to recover.

            # Assume /dev/sda3 and /dev/sdb3 was devices of the raid 1 array that is now broken
            mkdir /mnt/sdb3
            mount /dev/sdb3 /mnt/sdb3  # Assuming sdb3 was a raid 1 device and filesystem is still in tact.
            mdadm --create --verbose --force /dev/md1 --level=mirror --raid-devices=1 /dev/sda3
            rsync -avz /mnt/sdb3/* /mnt/md0/
            mdadm --manage /dev/md0 --add /dev/sda3
            cat /proc/mdstat
          

References