[[+content_image]]
A
A
Andrey San2016-01-13 14:59:37
linux
Andrey San, 2016-01-13 14:59:37

How to properly increase the size of a partition?

It is necessary to increase the size of disk 2.vdi /dev/sdb from 10gb to 12gb.

[[email protected] ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0    8G  0 disk
├─sda1            8:1    0  500M  0 part /boot
└─sda2            8:2    0  7.5G  0 part
  ├─centos-root 253:0    0  6.7G  0 lvm  /
  └─centos-swap 253:1    0  820M  0 lvm  [SWAP]
sdb               8:16   0   10G  0 disk
sdc               8:32   0   15G  0 disk
sr0              11:0    1 1024M  0 rom
[[email protected] ~]#
[[email protected] ~]#
[[email protected] ~]# pvcreate /dev/sdb
  Physical volume "/dev/sdb" successfully created
[[email protected] ~]# pvcreate /dev/sdc
  Physical volume "/dev/sdc" successfully created
[[email protected] ~]# vgcreate vg1 /dev/sdb /dev/sdc
  Volume group "vg1" successfully created
[[email protected] ~]# lvcreate -L 24.99G -n lv1 vg1
  Rounding up size to full physical extent 24.99 GiB
  Logical volume "lv1" created.
[[email protected] ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/vg1/lv1
  LV Name                lv1
  VG Name                vg1
  LV UUID                YHjXGf-SvIZ-3IAc-X459-SAK2-KDpj-0hzDyM
  LV Write Access        read/write
  LV Creation host, time localhost.localdomain, 2016-01-13 06:42:42 -0500
  LV Status              available
  # open                 0
  LV Size                24.99 GiB
  Current LE             6398
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2


C:\Program Files\Oracle\VirtualBox>VBoxManage modifyhd C:\Users\user1\VirtualBoxVMs\centos\2.vdi --resize 12288
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

[[email protected] ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0    8G  0 disk
├─sda1            8:1    0  500M  0 part /boot
└─sda2            8:2    0  7.5G  0 part
  ├─centos-root 253:0    0  6.7G  0 lvm  /
  └─centos-swap 253:1    0  820M  0 lvm  [SWAP]
sdb               8:16   0   12G  0 disk
└─vg1-lv1       253:2    0   25G  0 lvm
sdc               8:32   0   15G  0 disk
└─vg1-lv1       253:2    0   25G  0 lvm
sr0              11:0    1 1024M  0 rom

[[email protected] ~]# mkfs.ext4 /dev/mapper/vg1-lv1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1638400 inodes, 6551552 blocks
327577 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2155872256
200 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

[[email protected] ~]# mount /dev/mapper/vg1-lv1 /mnt/new_part


[[email protected] ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root  6.7G  4.9G  1.8G  74% /
devtmpfs                 236M     0  236M   0% /dev
tmpfs                    245M     0  245M   0% /dev/shm
tmpfs                    245M  4.3M  241M   2% /run
tmpfs                    245M     0  245M   0% /sys/fs/cgroup
/dev/sda1                497M  119M  379M  24% /boot
/dev/mapper/vg1-lv1       25G   45M   24G   1% /mnt/new_part

as we can see /dev/sdb has become 12GB, now how to increase it in LVM so that LV increases.
I do according to the article alldba.ru/index.php/stati/vmware/247-uvelichenie-r... but after a reboot, one disk is lost in LVM.

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
D
Dmitry Chervonobab, 2016-01-14
@maddimons

Let's expand our virtual disk to the sizes we need (I assume that you do this "VBoxManage modifyhd".
Now in the guest machine we expand vg1

fdisk /dev/sdb
Команда (m для справки): n
Действие команды
e расширенный
p основной раздел (1-4)
p
Номер раздела (1-4): 2
Первый цилиндр (хххх-хххх, по умолчанию ХХХХ): (по умолчанию)
Используется значение по умолчанию ХХХХ
Последний цилиндр или +size или +sizeM или +sizeK хххх-хххх, по умолчанию
ХХХХ):(по умолчанию)
Используется значение по умолчанию ХХХХ

Change fs type
Команда (m для справки): t
Номер раздела (1-4): 2 (выбираем новый раздел sdb2)
Шестнадцатеричный код (введите L для получения списка кодов): 8e
Системный тип раздела 3 изменен на 8e (Linux LVM)

Команда (m для справки): p
# должен показать ваш /dev/sdb с новым разделом sdb2 в формате lvm

save
Команда (m для справки): w
Таблица разделов была изменена!

Вызывается ioctl() для перечитывания таблицы разделов.

ПРЕДУПРЕЖДЕНИЕ: Перечитывание таблицы разделов завершилось неудачей с ошибкой
16: Устройство или ресурс занято.
Ядро все еще использует старую таблицу.
Новая таблица будет использована при следующей перезагрузке.
Синхронизируются диски.

Next, reboot (reboot|shutdown -r now)
And convert the new partition into an LVM physical volume
lvm
lvm> pvcreate /dev/sdb2
Physical volume "/dev/sdb2" successfully created

Add a new physical volume to the vg1 group
lvm> vgextend vg1 /dev/sdb2
  Volume group "vg1" successfully extended

We look at the info on vg1
And we see a new unallocated place in the line
Let's increase the size of the volume by this amount (for all available space)
Now it will show that the size has increased.
But the OS still doesn't see the new location.
You can check the size (df -h) and finally reboot the guest again.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question