Изменения размера раздела
Complete Steps and Explanation
ssh to server, sudo -i to become root
Confirm there is a limited amount of disk space. In the output below, note the / (root) volume only has 3.9 GB disk space:
xxxxxxxxxxuser@server:~$
df -hFilesystem Size Used Avail Use% Mounted onudev 1.9G 0 1.9G 0% /devtmpfs 394M 1.1M 393M 1% /run/dev/mapper/ubuntu--vg-ubuntu--lv 3.9G 3.2G 489M 87% /tmpfs 2.0G 0 2.0G 0% /dev/shmtmpfs 5.0M 0 5.0M 0% /run/locktmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup/dev/loop0 89M 89M 0 100% /snap/core/7270/dev/sda2 976M 77M 833M 9% /boot/dev/loop1 90M 90M 0 100% /snap/core/7713tmpfs 394M 0 394M 0% /run/user/1000Next confirm in Linux that there is actually a lot more space available. As you will see from the output below, there is 24G on the /dev/sda3 volume. The other 1GB is used in the boot volume and the BIOS boot
xxxxxxxxxxuser@server:~#
fdisk -lDisk /dev/loop0: 88.5 MiB, 92778496 bytes, 181208 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/loop1: 89 MiB, 93327360 bytes, 182280 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytes...Disk /dev/sda: 25 GiB, 26843545600 bytes, 52428800 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 4096 bytesI/O size (minimum/optimal): 4096 bytes / 4096 bytesDisklabel type: gptDisk identifier: ED41F7A6-5D09-457B-A55C-C7F1E30DE419Device Start End Sectors Size Type/dev/sda1 2048 4095 2048 1M BIOS boot/dev/sda2 4096 2101247 2097152 1G Linux filesystem/dev/sda3 2101248 52426751 50325504 24G Linux filesystemDisk /dev/mapper/ubuntu--vg-ubuntu--lv: 4 GiB, 4294967296 bytes, 8388608 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 4096 bytesI/O size (minimum/optimal): 4096 bytes / 4096 bytesThe one set of instructions referred to starting this process using parted, so parted log is below. The instructions as per Stack read something like:
“First you need to run parted and use its resizepart command to expand the partition to use the whole disk, then run pvresize to tell LVM about the new space, then run lvresize to grow the logical volume, and finally resize2fs on the logical volume to grow the filesystem to use the new space. This can be done without a reboot.”
Please note however I diverted slightly from these steps. The first command I learnt / used in parted, was just used to print the partition information:
xxxxxxxxxxuser@server:~#
partedGNU Parted 3.2Using /dev/sdaWelcome to GNU Parted! Type 'help' to view a list of commands.(parted) printModel: Msft Virtual Disk (scsi)Disk /dev/sda: 26.8GBSector size (logical/physical): 512B/4096BPartition Table: gptDisk Flags:Number Start End Size File system Name Flags1 1049kB 2097kB 1049kB bios_grub2 2097kB 1076MB 1074MB ext43 1076MB 26.8GB 25.8GB(parted) quitThis was followed by me checking and re-checking information using fdisk and df -h to make sure I was understanding the current situation.
Then I finally started the procedure:
xxxxxxxxxxuser@server:~#
partedGNU Parted 3.2Using /dev/sdaWelcome to GNU Parted! Type 'help' to view a list of commands.(parted) resizepartPartition number? 3End? [26.8GB]?(parted) quitInformation: You may need to update /etc/fstab.…
xxxxxxxxxxuser@server:~#
pvresize /dev/sda3Physical volume "/dev/sda3" changed1 physical volume(s) resized / 0 physical volume(s) not resizedAt this point I tried using lvresize but couldn’t get it to work. It appears there is both lvresize and lvextend. As per the “microhowto.info” article:
“The difference is that lvextend can only increase the size of a volume, whereas lvresize can increase or reduce it.”
The first attempt at specifying 24GB did not work. After I completed the procedure I found that you can also specify a flag 100%, but unfortunately, I didn’t get that information in time and just ended up specifying 23GB. If I have the time I might try and use the 100% flag. For reference, the flag is lvextend -l +100%FREE /dev/VGNAME/LVNAME
Below first attempt but insufficient space:
xxxxxxxxxxuser@server:~#
lvextend --size 24G /dev/mapper/ubuntu--vg-ubuntu--lvInsufficient free space: 5120 extents needed, but only 5119 availableSecond attempt reducing space to allocate:
xxxxxxxxxxuser@server:~#
lvextend --size 23G /dev/mapper/ubuntu--vg-ubuntu--lvSize of logical volume ubuntu-vg/ubuntu-lv changed from 4.00 GiB (1024 extents) to 23.00 GiB (5888 extents).Logical volume ubuntu-vg/ubuntu-lv successfully resized.After lvextend, one has to use resize2fs. This was kind of scary because it appeared I was going to work on a live disk, but it went quick.
xxxxxxxxxxuser@server:~#
resize2fs /dev/mapper/ubuntu--vg-ubuntu--lvresize2fs 1.44.1 (24-Mar-2018)Filesystem at /dev/mapper/ubuntu--vg-ubuntu--lv is mounted on /; on-line resizing requiredold_desc_blocks = 1, new_desc_blocks = 3The filesystem on /dev/mapper/ubuntu--vg-ubuntu--lv is now 6029312 (4k) blocks long.TADA! The disk is now 23G big as seen by df-h output below:
xxxxxxxxxxuser@server:~# df -hFilesystem Size Used Avail Use% Mounted onudev 1.9G 0 1.9G 0% /devtmpfs 394M 1.1M 393M 1% /run/dev/mapper/ubuntu--vg-ubuntu--lv 23G 3.2G 19G 15% /tmpfs 2.0G 0 2.0G 0% /dev/shmtmpfs 5.0M 0 5.0M 0% /run/locktmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup/dev/loop0 89M 89M 0 100% /snap/core/7270/dev/sda2 976M 77M 833M 9% /boot/dev/loop1 90M 90M 0 100% /snap/core/7713tmpfs 394M 0 394M 0% /run/user/1000user@server:~#И еще
В Centos 7 файловая система по умолчанию- xfs .
поддержка файловой системы xfs только расширяется, а не уменьшается. Поэтому, если вы хотите изменить размер файловой системы, используйте xfs_growfs, а не resize2fs.
xxxxxxxxxxxfs_growfs /dev/root_vg/root Примечание: Для использования файловой системы ext4
xxxxxxxxxxresize2fs /dev/root_vg/root