给linux虚拟机硬盘扩容(LVM分区)

2020-12-29  本文已影响0人  082e63dc752b

1.关闭虚拟机,调整磁盘容量大小。


image.png

2.开启虚拟机,查看磁盘分区信息。

root@graylog-preview:~# fdisk -l
Disk /dev/sda: 150 GiB, 161061273600 bytes, 314572800 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: 0x1a970210

Device     Boot    Start       End  Sectors  Size Id Type
/dev/sda1  *        2048  40957951 40955904 19.5G 8e Linux LVM
/dev/sda2       40957952 104857599 63899648 30.5G 83 Linux


Disk /dev/mapper/graylog--preview--vg-root: 49 GiB, 52655292416 bytes, 102842368 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/graylog--preview--vg-swap_1: 980 MiB, 1027604480 bytes, 2007040 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@graylog-preview:~# lsblk
NAME                            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
fd0                               2:0    1    4K  0 disk 
sda                               8:0    0  150G  0 disk 
├─sda1                            8:1    0 19.5G  0 part 
│ ├─graylog--preview--vg-root   253:0    0   49G  0 lvm  /
│ └─graylog--preview--vg-swap_1 253:1    0  980M  0 lvm  [SWAP]
└─sda2                            8:2    0 30.5G  0 part 
  └─graylog--preview--vg-root   253:0    0   49G  0 lvm  /

3.创建新分区

root@graylog-preview:~# fdisk /dev/sda

Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): m

Help:

  DOS (MBR)
   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   u   change display/entry units
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table


Command (m for help): n
Partition type
   p   primary (2 primary, 0 extended, 2 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (3,4, default 3): 
First sector (104857600-314572799, default 104857600): 
Last sector, +sectors or +size{K,M,G,T,P} (104857600-314572799, default 314572799): 

Created a new partition 3 of type 'Linux' and of size 100 GiB.

Command (m for help): w
The partition table has been altered.
Syncing disks.

4.重新读取分区

root@graylog-preview:~# partprobe /dev/sda

5.创建物理卷

root@graylog-preview:~# pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created.

6.查看卷组名称,以及卷组使用情况

root@graylog-preview:~# vgdisplay
  --- Volume group ---
  VG Name               graylog-preview-vg
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               <50.00 GiB
  PE Size               4.00 MiB
  Total PE              12799
  Alloc PE / Size       12799 / <50.00 GiB
  Free  PE / Size       0 / 0   
  VG UUID               DyyKU1-gQ4j-Udo6-mPC8-Ogh1-fwRD-XJ9w4b

7.将物理卷扩展到卷组

root@graylog-preview:~# vgextend graylog-preview-vg /dev/sda3
  Volume group "graylog-preview-vg" successfully extended

8.查看当前逻辑卷的空间状态

root@graylog-preview:~# lvdisplay
  --- Logical volume ---
  LV Path                /dev/graylog-preview-vg/root
  LV Name                root
  VG Name                graylog-preview-vg
  LV UUID                VIavCO-3GyX-YO3E-WEu9-wyqp-B5Ko-Mv2GYp
  LV Write Access        read/write
  LV Creation host, time graylog-preview, 2020-11-05 19:44:54 +0000
  LV Status              available
  # open                 1
  LV Size                <49.04 GiB
  Current LE             12554
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
   
  --- Logical volume ---
  LV Path                /dev/graylog-preview-vg/swap_1
  LV Name                swap_1
  VG Name                graylog-preview-vg
  LV UUID                7PBtOy-6qBY-vok1-9fHB-YfCy-hrDs-VVDzSU
  LV Write Access        read/write
  LV Creation host, time graylog-preview, 2020-11-05 19:44:54 +0000
  LV Status              available
  # open                 2
  LV Size                980.00 MiB
  Current LE             245
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

9.将卷组中的空闲空间扩展到根分区逻辑卷

root@graylog-preview:~# lvextend -l +100%FREE /dev/graylog-preview-vg/root 
  Size of logical volume graylog-preview-vg/root changed from <49.04 GiB (12554 extents) to <149.04 GiB (38153 extents).
  Logical volume graylog-preview-vg/root successfully resized.

10.执行

root@graylog-preview:~# resize2fs /dev/graylog-preview-vg/root 
resize2fs 1.44.1 (24-Mar-2018)
Filesystem at /dev/graylog-preview-vg/root is mounted on /; on-line resizing required
old_desc_blocks = 7, new_desc_blocks = 19
The filesystem on /dev/graylog-preview-vg/root is now 39068672 (4k) blocks long.

11.查看扩展之后磁盘使用情况

root@graylog-preview:~# df -h
Filesystem                             Size  Used Avail Use% Mounted on
udev                                   2.0G     0  2.0G   0% /dev
tmpfs                                  395M  756K  394M   1% /run
/dev/mapper/graylog--preview--vg-root  147G  3.7G  137G   3% /
tmpfs                                  2.0G     0  2.0G   0% /dev/shm
tmpfs                                  5.0M     0  5.0M   0% /run/lock
tmpfs                                  2.0G     0  2.0G   0% /sys/fs/cgroup
tmpfs                                  395M     0  395M   0% /run/user/1000
root@graylog-preview:~# lsblk
NAME                            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
fd0                               2:0    1    4K  0 disk 
sda                               8:0    0  150G  0 disk 
├─sda1                            8:1    0 19.5G  0 part 
│ ├─graylog--preview--vg-root   253:0    0  149G  0 lvm  /
│ └─graylog--preview--vg-swap_1 253:1    0  980M  0 lvm  [SWAP]
├─sda2                            8:2    0 30.5G  0 part 
│ └─graylog--preview--vg-root   253:0    0  149G  0 lvm  /
└─sda3                            8:3    0  100G  0 part 
  └─graylog--preview--vg-root   253:0    0  149G  0 lvm  /
上一篇 下一篇

猜你喜欢

热点阅读