resizing btrfs on luks on mdadm raid10

one of my KVM VMs keeps data on BTRFS on top of encrypted LUKS drive. that drive is a block device passed from virtualization server to VM… a block device which is mdadm software RAID10. below – steps taken to resize it.

how is the block device passed to the VM? by using driver’s type=’raw’, here’s the relevant part of /etc/libvirt/qemu/myvm.xml:

  <devices>
    <emulator>/usr/bin/qemu-system-x86_64</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/mnt/kvm/myvm/myvm-disk1.qcow2'/>
      <target dev='vda' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x03' slot='0x00' function='0x0'/>
    </disk>
    <disk type='block' device='disk'>
      <driver name='qemu' type='raw'/>
      <source dev='/dev/md127'/>
      <target dev='vdb' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x05' slot='0x00' function='0x0'/>
    </disk>
    ...

that’s how block devices look like on the virtualization host:

root@virtserver ~ # lsblk
NAME      MAJ:MIN RM  SIZE RO TYPE   MOUNTPOINT
sda         8:0    0  5.5T  0 disk
├─sda1      8:1    0    1G  0 part
│ └─md0     9:0    0 1022M  0 raid1  /boot
├─sda2      8:2    0   10G  0 part
│ └─md1     9:1    0   10G  0 raid1  /
├─sda3      8:3    0    1M  0 part
└─sda4      8:4    0  2.1T  0 part
  └─md127   9:127  0  4.2T  0 raid10
sdb         8:16   0  5.5T  0 disk
├─sdb1      8:17   0    1G  0 part
│ └─md0     9:0    0 1022M  0 raid1  /boot
├─sdb2      8:18   0   10G  0 part
│ └─md1     9:1    0   10G  0 raid1  /
├─sdb3      8:19   0    1M  0 part
└─sdb4      8:20   0  2.1T  0 part
  └─md127   9:127  0  4.2T  0 raid10
sdc         8:32   0  5.5T  0 disk
└─sdc1      8:33   0  2.1T  0 part
  └─md127   9:127  0  4.2T  0 raid10
sdd         8:48   0  5.5T  0 disk
└─sdd1      8:49   0  2.1T  0 part
  └─md127   9:127  0  4.2T  0 raid10

root@virtserver ~ # parted  /dev/sda print
Model: ATA HGST HUS726060AL (scsi)
Disk /dev/sda: 6001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags: pmbr_boot

Number  Start   End     Size    File system  Name    Flags
 3      1049kB  2097kB  1049kB                       bios_grub
 1      2097kB  1076MB  1074MB                       raid
 2      1076MB  11.8GB  10.7GB                       raid
 4      11.8GB  2299GB  2287GB               backup

root@virtserver ~ # parted  /dev/sdb print
Model: ATA HGST HUS726060AL (scsi)
Disk /dev/sdb: 6001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags: pmbr_boot

Number  Start   End     Size    File system  Name    Flags
 3      1049kB  2097kB  1049kB                       bios_grub
 1      2097kB  1076MB  1074MB                       raid
 2      1076MB  11.8GB  10.7GB                       raid
 4      11.8GB  2299GB  2287GB               backup

root@virtserver ~ # parted  /dev/sdc print
Model: ATA HGST HUS726060AL (scsi)
Disk /dev/sdc: 6001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name    Flags
 1      1049kB  2287GB  2287GB               backup

root@virtserver ~ # parted  /dev/sdd print
Model: ATA HGST HUS726060AL (scsi)
Disk /dev/sdd: 6001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name    Flags
 1      1049kB  2287GB  2287GB               backup

root@virtserver ~ # cat /proc/mdstat
Personalities : [raid10] [raid1] [linear] [multipath] [raid0] [raid6] [raid5] [raid4]
md0 : active raid1 sdb1[1] sda1[0]
      1046528 blocks super 1.2 [2/2] [UU]

md1 : active raid1 sdb2[1] sda2[0]
      10476544 blocks super 1.2 [2/2] [UU]

md127 : active raid10 sda4[0] sdb4[1] sdd1[3] sdc1[2]
      4466530304 blocks super 1.2 512K chunks 2 near-copies [4/4] [UUUU]
      bitmap: 0/17 pages [0KB], 131072KB chunk

unused devices: <none>

and that’s what the myvm sees:

root@myvm:~# lsblk
NAME     MAJ:MIN RM  SIZE RO TYPE  MOUNTPOINT
vda      254:0    0  2.8G  0 disk
└─vda1   254:1    0  2.8G  0 part  /
vdb      254:16   0  4.2T  0 disk
└─backup 253:0    0  4.2T  0 crypt /mnt/backup

as you can see on each of the physical drives – sda-sdd – there’s over 3700GB of unallocated space. my aim is to use some of that space and increase size of /dev/mapper/backup on myvm by enlarging /dev/md127 on the virtualization server.

#1 – shut down the myvm virtual machine. possibly unnecessarily.

#2 – resize the sda4, sdb4, sdc1, sdd1 by adding 2000GB of space to each:

root@virtserver ~ # parted /dev/sda
GNU Parted 3.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: ATA HGST HUS726060AL (scsi)
Disk /dev/sda: 6001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags: pmbr_boot

Number  Start   End     Size    File system  Name    Flags
 3      1049kB  2097kB  1049kB                       bios_grub
 1      2097kB  1076MB  1074MB                       raid
 2      1076MB  11.8GB  10.7GB                       raid
 4      11.8GB  2299GB  2287GB               backup

(parted) resizepart 4
End?  [2299GB]? 4299GB
(parted)
Information: You may need to update /etc/fstab.

root@virtserver ~ # parted /dev/sdb
GNU Parted 3.2
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: ATA HGST HUS726060AL (scsi)
Disk /dev/sdb: 6001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags: pmbr_boot

Number  Start   End     Size    File system  Name    Flags
 3      1049kB  2097kB  1049kB                       bios_grub
 1      2097kB  1076MB  1074MB                       raid
 2      1076MB  11.8GB  10.7GB                       raid
 4      11.8GB  2299GB  2287GB               backup

(parted) resizepart 4
End?  [2299GB]? 4299GB
(parted)
Information: You may need to update /etc/fstab.

root@virtserver ~ # parted /dev/sdc
GNU Parted 3.2
Using /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: ATA HGST HUS726060AL (scsi)
Disk /dev/sdc: 6001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name    Flags
 1      1049kB  2287GB  2287GB               backup

(parted) resizepart 1
End?  [2287GB]? 4287GB
(parted)
Information: You may need to update /etc/fstab.

root@virtserver ~ # parted /dev/sdd
GNU Parted 3.2
Using /dev/sdd
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: ATA HGST HUS726060AL (scsi)
Disk /dev/sdd: 6001GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name    Flags
 1      1049kB  2287GB  2287GB               backup

(parted) resizepart 1
End?  [2287GB]? 4287GB
(parted)
Information: You may need to update /etc/fstab.

#3 resize mdadm raid on top of sda4, sdb4, sdc1, sdd1:

root@virtserver ~ # dmesg
[32503.362525] md127: detected capacity change from 4573727031296 to 8573726752768
[32503.405402] md: resync of RAID array md127
root@virtserver ~ # cat /proc/mdstat
Personalities : [raid10] [raid1] [linear] [multipath] [raid0] [raid6] [raid5] [raid4]
md0 : active raid1 sdb1[1] sda1[0]
      1046528 blocks super 1.2 [2/2] [UU]

md1 : active raid1 sdb2[1] sda2[0]
      10476544 blocks super 1.2 [2/2] [UU]

md127 : active raid10 sda4[0] sdb4[1] sdd1[3] sdc1[2]
      8372780032 blocks super 1.2 512K chunks 2 near-copies [4/4] [UUUU]
      [==========>..........]  resync = 54.5% (4567488064/8372780032) finish=310.4min speed=204265K/sec
      bitmap: 15/32 pages [60KB], 131072KB chunk

unused devices: <none>

#4 start the myvm VM again

root@virtserver ~ # virsh start myvm

#5 on myvm – open the luks container and resize it

root@myvm:~# cryptsetup luksOpen /dev/vdb backup
Enter passphrase for /dev/vdb:
root@myvm:~# cryptsetup resize backup -v
Enter passphrase for /dev/vdb:
Key slot 0 unlocked.
Command successful.
root@myvm:~# mount /dev/mapper/backup /mnt/backup/
root@myvm:~# btrfs filesystem resize max /mnt/backup/
Resize '/mnt/backup/' of 'max'
root@myvm:~# dmesg
[  130.727318] BTRFS info (device dm-0): new size for /dev/mapper/backup is 8573709975552
root@myvm:~# lsblk
NAME     MAJ:MIN RM  SIZE RO TYPE  MOUNTPOINT
vda      254:0    0  2.8G  0 disk
└─vda1   254:1    0  2.8G  0 part  /
vdb      254:16   0  7.8T  0 disk
└─backup 253:0    0  7.8T  0 crypt /mnt/backup

there we have it – more space available for the /mnt/backup!

Leave a Reply

Your email address will not be published. Required fields are marked *

(Spamcheck Enabled)