# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 300G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 39G 0 part ├─centos-root 253:0 0 35.1G 0 lvm / └─centos-swap 253:1 0 3.9G 0 lvm [SWAP] sr0 11:0 1 1024M 0 rom
新建 LVM 分区
使用 fsdik 在 /dev/sda 上新建分区。
1 2 3 4 5 6 7 8
# fdisk /dev/sda Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them. Be careful before using the write command.
Command (m forhelp): n
根据提示, 一直 Enter 采用默认设置即可,直到出现类似以下输出:
1
Partition 3 of type Linux and of size 260 GiB is set
之后,键入 t 进行分区类型设置,依次输入 3、8e 设置 LVM 分区:
1 2 3 4
Command (m forhelp): t Partition number (1-3, default 3): 3 Hex code (type L to list all codes): 8e Changed type of partition 'Linux' to 'Linux LVM'
然后,键入 w 保存分区。
1 2 3 4 5 6 7 8 9
Command (m forhelp): w The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: 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) Syncing disks.
使用以下命令扫描出新创建的分区:
1 2
# partprobe -s /dev/sda: msdos partitions 1 2 3
或者如下命令扫描:
1
# partx -v -a /dev/sda
此时,查看块设备详情可以看到新建的 /dev/sda3 分区:
1 2 3 4 5 6 7 8 9
# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 300G 0 disk ├─sda1 8:1 0 1G 0 part /boot ├─sda2 8:2 0 39G 0 part │ ├─centos-root 253:0 0 35.1G 0 lvm / │ └─centos-swap 253:1 0 3.9G 0 lvm [SWAP] └─sda3 8:3 0 260G 0 part sr0 11:0 1 1024M 0 rom
使用新分区扩容 LV
在磁盘分区的基础上创建物理卷:
1 2
# pvcreate /dev/sda3 Physical volume "/dev/sda3" successfully created
使用新建的物理卷扩展卷组:
1 2
# vgextend centos /dev/sda3 Volume group "centos" successfully extended
扩容逻辑卷:
1 2 3
# lvextend /dev/centos/root /dev/sda3 Size of logical volume centos/root changed from 35.12 GiB (8991 extents) to <295.12 GiB (75550 extents). Logical volume centos/root successfully resized.