KVM увеличить диск

Материал из poiuty wiki
Перейти к: навигация, поиск

Выключаем виртуальную машину.

virsh shutdown kvm2

Проверяем, что она действительно выключена.

# virsh list
 Id    Name                           State
----------------------------------------------------

Увеличиваем размер диска.

cd /vm
qemu-img resize kvm2.qcow2 +80GB

Включаем виртуальную машину.

virsh start kvm2

Заходим по SSH и увеличиваем partition size.
Запускаем fdisk и смотрим разделы.

# fdisk /dev/vda

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): p
Disk /dev/vda: 100 GiB, 107374182400 bytes, 209715200 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: 0x00036fc3

Device     Boot  Start      End  Sectors  Size Id Type
/dev/vda1  *      2048   499711   497664  243M 83 Linux
/dev/vda2       501758 41940991 41439234 19.8G  5 Extended
/dev/vda5       501760 41940991 41439232 19.8G 8e Linux LVM

Удаляем второй и пятый раздел.

Command (m for help): d
Partition number (1,2,5, default 5): 5

Partition 5 has been deleted.

Command (m for help): d
Partition number (1,2, default 2): 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): 2
First sector (499712-209715199, default 499712):
Last sector, +sectors or +size{K,M,G,T,P} (499712-209715199, default 209715199):

Created a new partition 2 of type 'Extended' and of size 99.8 GiB.

Command (m for help): n
Partition type
   p   primary (1 primary, 1 extended, 2 free)
   l   logical (numbered from 5)
Select (default p): l

Adding logical partition 5
First sector (501760-209715199, default 501760):
Last sector, +sectors or +size{K,M,G,T,P} (501760-209715199, default 209715199):

Created a new partition 5 of type 'Linux' and of size 99.8 GiB.

Поменяем тип у пятого раздела.

Command (m for help): t
Partition number (1,2,5, default 5): 5
Hex code (type L to list all codes): 8e

Changed type of partition 'Linux' to 'Linux LVM'.

Проверим.

Command (m for help): p
Disk /dev/vda: 100 GiB, 107374182400 bytes, 209715200 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: 0x00036fc3

Device     Boot  Start       End   Sectors  Size Id Type
/dev/vda1  *      2048    499711    497664  243M 83 Linux
/dev/vda2       499712 209715199 209215488 99.8G  5 Extended
/dev/vda5       501760 209715199 209213440 99.8G 8e Linux LVM

Запишем изменения и выйдем из fdisk.

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).

Чтобы изменения вступили в силу - нужно перезагрузиться.

shutdown -r now

А можно и не перезагружаться.

apt-get install parted
partprobe

Сделаем resize the physical volume

# pvresize /dev/vda5
  Physical volume "/dev/vda5" changed
  1 physical volume(s) resized / 0 physical volume(s) not resized

Увеличиваем раздел lvm раздела.

# lvextend -l +100%FREE /dev/p2pool/root
Size of logical volume p2pool/root changed from 18.91 GiB (4840 extents) to 98.91 GiB (25320 extents).
Logical volume root successfully resized

Проверяем.

# lvs
  LV     VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root   p2pool -wi-ao----  98.91g
  swap_1 p2pool -wi-ao---- 872.00m

Осталось сделать resize

# resize2fs /dev/p2pool/root
resize2fs 1.42.12 (29-Aug-2014)
Filesystem at /dev/p2pool/root is mounted on /; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 7
The filesystem on /dev/p2pool/root is now 25927680 (4k) blocks long.

Готово.

# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/p2pool-root   98G  7.4G   86G   8% /
udev                      10M     0   10M   0% /dev
tmpfs                    397M  248K  397M   1% /run
tmpfs                    5.0M     0  5.0M   0% /run/lock
tmpfs                    793M     0  793M   0% /run/shm
/dev/vda1                232M   48M  172M  22% /boot
tmpfs                    793M     0  793M   0% /tmp