Redimensionner une partition LVM avec un minimum de coupure …
fdisk -l
Si la nouvelle taille n'apparait pas, lancer la commande suivante :
echo 1 > /sys/class/scsi_device/0\:0\:0\:0/device/rescan
Revérifier avec toujours :
fdisk -l
Ensuite il va falloir supprimer la partition et la recréer avec fdisk :
# fdisk /dev/sda
Welcome to fdisk (util-linux 2.36.1).
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/sda: 128 GiB, 137438953472 bytes, 268435456 sectors
Disk model: Virtual disk
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x868c407c
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 999423 997376 487M 83 Linux
/dev/sda2 1001470 134215679 133214210 63.5G 5 Extended
/dev/sda5 1001472 134215679 133214208 63.5G 8e Linux LVM
Command (m for help): d
Partition number (1,2,5, default 5): 2
Partition 2 has been deleted.
Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p): e
Partition number (2-4, default 2):
First sector (999424-268435455, default 999424): 1001470
Last sector, +/-sectors or +/-size{K,M,G,T,P} (1001470-268435455, default 268435455):
Created a new partition 2 of type 'Extended' and of size 127.5 GiB.
Command (m for help): p
Disk /dev/sda: 128 GiB, 137438953472 bytes, 268435456 sectors
Disk model: Virtual disk
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x868c407c
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 999423 997376 487M 83 Linux
/dev/sda2 1001470 268435455 267433986 127.5G 5 Extended
Command (m for help): n
All space for primary partitions is in use.
Adding logical partition 5
First sector (1003518-268435455, default 1003520):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (1003520-268435455, default 268435455):
Created a new partition 5 of type 'Linux' and of size 127.5 GiB.
Partition #5 contains a ext4 signature.
Do you want to remove the signature? [Y]es/[N]o: Y
The signature will be removed by a write command.
Command (m for help): p
Disk /dev/sda: 128 GiB, 137438953472 bytes, 268435456 sectors
Disk model: Virtual disk
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x868c407c
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 999423 997376 487M 83 Linux
/dev/sda2 1001470 268435455 267433986 127.5G 5 Extended
/dev/sda5 1003520 268435455 267431936 127.5G 83 Linux
Filesystem/RAID signature on partition 5 will be wiped.
Command (m for help): x
Expert command (m for help): b
Partition number (1,2,5, default 5): 5
New beginning of data (1001471-268435455, default 1003520): 1001472
Expert command (m for help): p
Disk /dev/sda: 128 GiB, 137438953472 bytes, 268435456 sectors
Disk model: Virtual disk
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x868c407c
Device Boot Start End Sectors Id Type Start-C/H/S End-C/H/S Attrs
/dev/sda1 * 2048 999423 997376 83 Linux 4/4/1 1023/254/2 80
/dev/sda2 1001470 268435455 267433986 5 Extended 939/170/1 8/7/2
/dev/sda5 1001472 268435455 267433984 83 Linux 943/175/1 8/7/2
Expert command (m for help): r
Command (m for help): p
Disk /dev/sda: 128 GiB, 137438953472 bytes, 268435456 sectors
Disk model: Virtual disk
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x868c407c
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 999423 997376 487M 83 Linux
/dev/sda2 1001470 268435455 267433986 127.5G 5 Extended
/dev/sda5 1001472 268435455 267433984 127.5G 83 Linux
Command (m for help): t
Partition number (1,2,5, default 5): 5
Hex code or alias (type L to list all): 8e
Changed type of partition 'Linux' to 'Linux LVM'.
Command (m for help): p
Disk /dev/sda: 128 GiB, 137438953472 bytes, 268435456 sectors
Disk model: Virtual disk
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x868c407c
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 999423 997376 487M 83 Linux
/dev/sda2 1001470 268435455 267433986 127.5G 5 Extended
/dev/sda5 1001472 268435455 267433984 127.5G 8e Linux LVM
Command (m for help): wr
The partition table has been altered.
Failed to update system information about partition 2: Device or resource busy
The kernel still uses the old partitions. The new table will be used at the next reboot.
Syncing disks.
Ensuite on redimensitonne la partition virtuelle :
pvresize /dev/sda5
Physical volume "/dev/sda5" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized
On peut constater avec vps :
~# pvs
PV VG Fmt Attr PSize PFree
/dev/sda5 vm-it-vg lvm2 a-- <127.52g 64.01g
et vgs :
~# vgs
VG #PV #LV #SN Attr VSize VFree
vm-it-vg 1 5 0 wz--n- <127.52g 64.01g
On extend le lvm voulu :
lvextend -l +100%FREE /dev/mapper/vm--it--vg-home
Mais ce n'est pas fini comme on peut le voir :
root@vm-it:~# df -h
Filesystem Size Used Avail Use% Mounted on
udev 1.9G 0 1.9G 0% /dev
tmpfs 392M 616K 392M 1% /run
/dev/mapper/vm--it--vg-root 12G 3.8G 7.5G 34% /
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
/dev/mapper/vm--it--vg-home 45G 138M 42G 1% /home
/dev/mapper/vm--it--vg-tmp 794M 132K 737M 1% /tmp
/dev/mapper/vm--it--vg-var 4.2G 673M 3.4G 17% /var
/dev/sda1 470M 312M 134M 70% /boot
tmpfs 392M 0 392M 0% /run/user/0
On doit redimensionner le système de fichiers :
~# resize2fs /dev/mapper/vm--it--vg-home
resize2fs 1.46.2 (28-Feb-2021)
Filesystem at /dev/mapper/vm--it--vg-home is mounted on /home; on-line resizing required
old_desc_blocks = 6, new_desc_blocks = 14
The filesystem on /dev/mapper/vm--it--vg-home is now 28653568 (4k) blocks long.
Et voilà c'est fini !