Debian. LVM. Расширяем диск.
Устанавливаем Debian. Все по умолчанию, кроме того, что выбираем LVM.
0. В процессе потребуется утилита "partprobe" (apt-get install parted)
1. Увеличиваем размер виртуального диска.
После этого таблица разделов выглядит примерно так:
2. Для того чтобы увидеть состояние всех уровней:
pvs vgs lvs
3. Выясняем с какого сектора начинается неразмеченная область:
fdisk -l
Device Boot Start End Sectors Size Id Type /dev/xvda1 2048 499711 497664 243M 83 Linux /dev/xvda2 501758 16775167 16273410 7.8G 5 Extended /dev/xvda5 501760 16775167 16273408 7.8G 8e Linux LVM
В нашем примере это 16775167+1=16775168
4. Создаем первичный раздел в неразмеченной области:
fdisk /dev/xvda
n, p, 3, 16775168, t, 8e, p, w
5. Применяем новую разбивку диска на лету:
partprobe
6. Создаем в новом разделе физический том:
pvcreate /dev/xvda3
7. Расширяем имеющуюся группу разделов на новый pv. Имя VG можно узнать командой "pvs" (в нашем случае "testlvm-vg").
vgextend testlvm-vg /dev/xvda3
8. Расширяем логический том до максимально возможных размеров:
lvextend -l +100%FREE /dev/testlvm-vg/root
9. Проверяем расширился ли том:
lvs
10. Расширяем файловую систему:
resize2fs /dev/testlvm-vg/root
11. Проверяем что все сработало:
df -h
На всякий случай весь консольный ввод/вывод:
login as: neb
neb@192.168.0.182's password:
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
neb@testlvm:~$ su -
Password:
root@testlvm:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/dm-0 7.2G 588M 6.2G 9% /
udev 10M 0 10M 0% /dev
tmpfs 199M 4.3M 195M 3% /run
tmpfs 498M 0 498M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 498M 0 498M 0% /sys/fs/cgroup
/dev/xvda1 236M 33M 191M 15% /boot
root@testlvm:~# pvs
PV VG Fmt Attr PSize PFree
/dev/xvda5 testlvm-vg lvm2 a-- 7.76g 0
root@testlvm:~# vgs
VG #PV #LV #SN Attr VSize VFree
testlvm-vg 1 2 0 wz--n- 7.76g 0
root@testlvm:~# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root testlvm-vg -wi-ao---- 7.39g
swap_1 testlvm-vg -wi-ao---- 376.00m
root@testlvm:~# fdisk -l
Disk /dev/xvda: 12 GiB, 12884901888 bytes, 25165824 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
Disklabel type: dos
Disk identifier: 0xc0f7d9db
Device Boot Start End Sectors Size Id Type
/dev/xvda1 2048 499711 497664 243M 83 Linux
/dev/xvda2 501758 16775167 16273410 7.8G 5 Extended
/dev/xvda5 501760 16775167 16273408 7.8G 8e Linux LVM
Disk /dev/mapper/testlvm--vg-root: 7.4 GiB, 7935623168 bytes, 15499264 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 /dev/mapper/testlvm--vg-swap_1: 376 MiB, 394264576 bytes, 770048 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
root@testlvm:~# fdisk /dev/xvda
Welcome to fdisk (util-linux 2.25.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): n
Partition type
p primary (1 primary, 1 extended, 2 free)
l logical (numbered from 5)
Select (default p):
Using default response p.
Partition number (3,4, default 3): 3
First sector (499712-25165823, default 499712): 16775168
Last sector, +sectors or +size{K,M,G,T,P} (16775168-25165823, default 25165823):
Created a new partition 3 of type 'Linux' and of size 4 GiB.
Command (m for help): p
Disk /dev/xvda: 12 GiB, 12884901888 bytes, 25165824 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
Disklabel type: dos
Disk identifier: 0xc0f7d9db
Device Boot Start End Sectors Size Id Type
/dev/xvda1 2048 499711 497664 243M 83 Linux
/dev/xvda2 501758 16775167 16273410 7.8G 5 Extended
/dev/xvda3 16775168 25165823 8390656 4G 83 Linux
/dev/xvda5 501760 16775167 16273408 7.8G 8e Linux LVM
Partition table entries are not in disk order.
Command (m for help): t
Partition number (1-3,5, default 5): 3
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'.
Command (m for help): p
Disk /dev/xvda: 12 GiB, 12884901888 bytes, 25165824 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
Disklabel type: dos
Disk identifier: 0xc0f7d9db
Device Boot Start End Sectors Size Id Type
/dev/xvda1 2048 499711 497664 243M 83 Linux
/dev/xvda2 501758 16775167 16273410 7.8G 5 Extended
/dev/xvda3 16775168 25165823 8390656 4G 8e Linux LVM
/dev/xvda5 501760 16775167 16273408 7.8G 8e Linux LVM
Partition table entries are not in disk order.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Re-reading the partition table failed.: 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).
root@testlvm:~# apt-get install parted
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
libparted2
Suggested packages:
libparted-dev libparted-i18n parted-doc
The following NEW packages will be installed:
libparted2 parted
0 upgraded, 2 newly installed, 0 to remove and 1 not upgraded.
Need to get 464 kB of archives.
After this operation, 826 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://ftp.us.debian.org/debian/ jessie/main libparted2 amd64 3.2-7 [269 kB]
Get:2 http://ftp.us.debian.org/debian/ jessie/main parted amd64 3.2-7 [195 kB]
Fetched 464 kB in 10s (43.2 kB/s)
Selecting previously unselected package libparted2:amd64.
(Reading database ... 19501 files and directories currently installed.)
Preparing to unpack .../libparted2_3.2-7_amd64.deb ...
Unpacking libparted2:amd64 (3.2-7) ...
Selecting previously unselected package parted.
Preparing to unpack .../parted_3.2-7_amd64.deb ...
Unpacking parted (3.2-7) ...
Processing triggers for man-db (2.7.0.2-5) ...
Setting up libparted2:amd64 (3.2-7) ...
Setting up parted (3.2-7) ...
Processing triggers for libc-bin (2.19-18+deb8u10) ...
root@testlvm:~# partprobe
root@testlvm:~# pvcreate /dev/xvda3
Physical volume "/dev/xvda3" successfully created
root@testlvm:~# pvs
PV VG Fmt Attr PSize PFree
/dev/xvda3 lvm2 --- 4.00g 4.00g
/dev/xvda5 testlvm-vg lvm2 a-- 7.76g 0
root@testlvm:~# vgextend testlvm-vg /dev/xvda3
Volume group "testlvm-vg" successfully extended
root@testlvm:~# vgs
VG #PV #LV #SN Attr VSize VFree
testlvm-vg 2 2 0 wz--n- 11.76g 4.00g
root@testlvm:~# lvextend -l +100%FREE /dev/testlvm-vg/root
Size of logical volume testlvm-vg/root changed from 7.39 GiB (1892 extents) to 11.39 GiB (2916 extents).
Logical volume root successfully resized
root@testlvm:~# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root testlvm-vg -wi-ao---- 11.39g
swap_1 testlvm-vg -wi-ao---- 376.00m
root@testlvm:~# resize2fs /dev/testlvm-vg/root
resize2fs 1.42.12 (29-Aug-2014)
Filesystem at /dev/testlvm-vg/root is mounted on /; on-line resizing required
old_desc_blocks = 1, new_desc_blocks = 1
The filesystem on /dev/testlvm-vg/root is now 2985984 (4k) blocks long.
root@testlvm:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/dm-0 12G 638M 10G 6% /
udev 10M 0 10M 0% /dev
tmpfs 199M 4.3M 195M 3% /run
tmpfs 498M 0 498M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 498M 0 498M 0% /sys/fs/cgroup
/dev/xvda1 236M 33M 191M 15% /boot
root@testlvm:~#
