È un'attività comune ridimensionare/espandere il file system btrfs poiché btrfs è ampiamente utilizzato in CentOS/RHEL 7 e anche come driver di archiviazione back-end di Docker. Questo post illustra 2 procedure comuni per espandere un volume di root btrfs:
- Espandi per utilizzare lo spazio disponibile sul disco originale
- Aggiungi un nuovo disco nello stesso volume btrfs
1. Ridimensionamento della partizione per utilizzare lo spazio disponibile sul disco originale
1. Verifica il tuo spazio su disco e la dimensione della partizione corrente con fdisk o parted se il tuo disco è più grande di 2 terabyes:
# fdisk -l /dev/xvda Disk /dev/xvda: 53.7 GB, 53687091200 bytes, 104857600 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x00087895 Device Boot Start End Blocks Id System /dev/xvda1 * 2048 1030143 514048 83 Linux /dev/xvda2 1030144 9418751 4194304 82 Linux swap / Solaris /dev/xvda3 9418752 31457279 11019264 83 Linux [root@host0 ~]# lsblk -f /dev/xvda NAME FSTYPE LABEL UUID MOUNTPOINT xvda ├─xvda1 xfs /boot 049e257e-25b1-4f46-80aa-ffaa27a21022 /boot ├─xvda2 swap SWAP-VM 0406d7df-68b6-47cb-8ea9-195ac7ef7497 [SWAP] └─xvda3 btrfs btr_pool 1e72a30b-d59d-458f-b04f-59bf8bdec35d /
2. fdisk non supporta il ridimensionamento della partizione, quindi è necessario eliminare la vecchia partizione che si desidera modificare e crearne una nuova.
# fdisk /dev/xvda Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): p Disk /dev/xvda: 53.7 GB, 53687091200 bytes, 104857600 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x00087895 Device Boot Start End Blocks Id System /dev/xvda1 * 2048 1030143 514048 83 Linux /dev/xvda2 1030144 9418751 4194304 82 Linux swap / Solaris /dev/xvda3 9418752 31457279 11019264 83 Linux Command (m for help): d Partition number (1-3, default 3): 3 Partition 3 is deleted
3. Creiamo ora una nuova partizione.
Command (m for help): n Partition type: p primary (2 primary, 0 extended, 2 free) e extended Select (default p): p Partition number (3,4, default 3): 3 First sector (9418752-104857599, default 9418752): Using default value 9418752 Last sector, +sectors or +size{K,M,G} (9418752-104857599, default 104857599): Using default value 104857599 Partition 3 of type Linux and of size 45.5 GiB is set Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) Syncing disks.
4. Verifica la partizione appena creata usando "fdisk -l".
# fdisk -l /dev/xvda Disk /dev/xvda: 53.7 GB, 53687091200 bytes, 104857600 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x00087895 Device Boot Start End Blocks Id System /dev/xvda1 * 2048 1030143 514048 83 Linux /dev/xvda2 1030144 9418751 4194304 82 Linux swap / Solaris /dev/xvda3 9418752 104857599 47719424 83 Linux
5. Devi far sapere al kernel Linux la modifica che hai apportato a /dev/xvda usando il comando "partprobe":
# partprobe Error: Partition(s) 3 on /dev/xvda have been written, but we have been unable to inform the kernel of the change, probably because it/they are in use. As a result, the old partition(s) will remain in use. You should reboot now before making further changes.
6. Poiché viene utilizzato il file system di root, è necessario riavviare il sistema operativo per consentire al kernel di vedere la modifica. Se non è un filesystem di root, puoi saltare questo passaggio.
# shutdown -r now
Espansione del filesystem btfrs
1. Ora puoi espandere il file system radice di btrfs.
# btrfs filesystem resize +10g / Resize '/' of '+10g'
2. Verifica la nuova dimensione del filesystem nell'output del comando "df -h".
# df -h / Filesystem Size Used Avail Use% Mounted on /dev/xvda3 21G 2.5G 17G 14% /
Puoi anche utilizzare tutto lo spazio sul disco, se lo desideri. Usa l'opzione "max" con il comando "btrfs filesystem resize".
# btrfs filesystem resize max / Resize '/' of 'max'
# df -h / Filesystem Size Used Avail Use% Mounted on /dev/xvda3 46G 2.5G 42G 6% /
2. Aggiungi un nuovo disco al volume btrfs
1. È possibile aggiungere un nuovo disco al sistema presentando una nuova LUN o collegando un nuovo disco virtuale se si esegue una macchina virtuale. Potrebbe essere necessario eseguire lo script sottostante per eseguire la scansione del nuovo LUN/disco.
# rescan-scsi-bus.sh -a
o riavviare il sistema per rendere il nuovo disco visibile al sistema operativo,
2. Verificare che il nuovo disco possa essere visualizzato dal sistema operativo utilizzando i comandi “sblk -f” o “fdisk -l”. Ad esempio /dev/xvdb è il nuovo disco per l'esempio in questo post.
# lsblk -f NAME FSTYPE LABEL UUID MOUNTPOINT xvda ├─xvda1 xfs /boot 049e257e-25b1-4f46-80aa-ffaa27a21022 /boot ├─xvda2 swap SWAP-VM 0406d7df-68b6-47cb-8ea9-195ac7ef7497 [SWAP] └─xvda3 btrfs btr_pool 1e72a30b-d59d-458f-b04f-59bf8bdec35d / xvdb
# fdisk -l /dev/xvdb Disk /dev/xvdb: 10.7 GB, 10737418240 bytes, 20971520 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes
3. Aggiungi il nuovo disco /dev/xvdb al volume di root
# btrfs device add /dev/xvdb /
4. Distribuisci i metadati dal primo disco /dev/xvda al secondo disco /dev/xvdb.
# btrfs filesystem balance / WARNING: Full balance without filters requested. This operation is very intense and takes potentially very long. It is recommended to use the balance filters to narrow down the balanced data. Use 'btrfs balance start --full-balance' option to skip this warning. The operation will start in 10 seconds. Use Ctrl-C to stop it. 10 9 8 7 6 5 4 3 2 1 Starting balance without any filters. Done, had to relocate 9 out of 9 chunks
5. Verifica la nuova dimensione del filesystem usando “df -h”.
# df -h / Filesystem Size Used Avail Use% Mounted on /dev/xvda3 56G 2.5G 52G 5% /
Puoi vedere che il file system di root è aumentato di altri 10G che è la dimensione di /dev/xvdb.
Come creare e montare il file system Btrfs (spiegato con esempi)