fdisk /dev/sda
[root@localhost ~]# 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): p //查看已分区数量
Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 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 label type: dos
Disk identifier: 0x000b61e5
Device Boot Start End Blocks Id System
/dev/sda1 * 20482099199104857683 Linux
/dev/sda2 20992004194303919921920 8e Linux LVM
Command (m forhelp): e
e: unknown command
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help): n //新增加一个分区
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): //回车,这里是选择分区类型,使用默认值,也就是主分区
Using default response p
Partition number (3,4, default 3): //回车,使用默认值即可,选择分区数量,会自己增加,如果有两个,默认就是3
First sector (41943040-104857599, default 41943040): t
First sector (41943040-104857599, default 41943040): //回车,默认值 起始扇区
Using default value 41943040
Last sector, +sectors or +size{K,M,G} (41943040-104857599, default 104857599): //回车,默认值 结束扇区
Using default value 104857599
Partition 3 of type Linux and of size 30 GiB is set
Command (m for help): t //修改分区类型
Partition number (1-3, default 3): //回车,选择默认值
Hex code (type L to list all codes): 8e //修改为LVM(8e就是LVM)
Changed type of partition 'Linux' to 'Linux LVM'
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.
---
partprobe
mkfs.ext3 /dev/sda3
---
[root@localhost ~]# lvm
lvm> pvcreate /dev/sda3 // 这是初始化刚才的分区,必须的
WARNING: ext3 signature detected on /dev/sda3 at offset 1080. Wipe it? [y/n]: y
Wiping ext3 signature on /dev/sda3.
Physical volume "/dev/sda3" successfully created.
lvm> vgextend centos /dev/sda3 //将初始化的分区加入虚拟卷组centos(卷和卷组的名字可以通过命令vgdisplay查看)
Volume group "centos" successfully extended
lvm> vgdisplay -v //查看信息
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
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 48.99 GiB
PE Size 4.00 MiB
Total PE 12542
Alloc PE / Size 4863 / <19.00 GiB
Free PE / Size 7679 / <30.00 GiB
VG UUID SmhPow-2eHv-Nj91-azuw-yiIm-H1Br-yzo4Nv
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID nuYmBV-ND69-DRnZ-L1po-Wp5D-8qQr-k2TKtR
LV Write Access read/write
LV Creation host, time localhost, 2022-01-01 17:29:54 -0500
LV Status available
# open 2
LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID GFqdAh-BKus-slss-AsbW-xgv9-Bchw-bU9IqY
LV Write Access read/write
LV Creation host, time localhost, 2022-01-01 17:29:55 -0500
LV Status available
# open 1
LV Size <17.00 GiB
Current LE 4351
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
--- Physical volumes ---
PV Name /dev/sda2
PV UUID pIcE0B-1TT5-PYnt-l46D-fKsj-m0MW-nLKE20
PV Status allocatable
Total PE / Free PE 4863 / 0
PV Name /dev/sda3
PV UUID HxR0hN-w6Dr-guQH-jqpT-lLBQ-bqHW-gxiw41
PV Status allocatable
Total PE / Free PE 7679 / 7679
lvm> lvextend -l+7679 /dev/mapper/centos-root //扩展已有卷的容量(7679是通过vgdisplay查看Free PE的大小)
Size of logical volume centos/root changed from <17.00 GiB (4351 extents) to 46.99 GiB (12030 extents).
Logical volume centos/root successfully resized.
lvm> pvdisplay //查看卷容量
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size <19.00 GiB / not usable 3.00 MiB
Allocatable yes(but full)
PE Size 4.00 MiB
Total PE 4863
Free PE 0
Allocated PE 4863
PV UUID pIcE0B-1TT5-PYnt-l46D-fKsj-m0MW-nLKE20
--- Physical volume ---
PV Name /dev/sda3
VG Name centos
PV Size 30.00 GiB / not usable 4.00 MiB
Allocatable yes(but full)
PE Size 4.00 MiB
Total PE 7679
Free PE 0
Allocated PE 7679
PV UUID HxR0hN-w6Dr-guQH-jqpT-lLBQ-bqHW-gxiw41
lvm> quit
Exiting.
---
lvextend -l +100%FREE /dev/centos/root
xfs_growfs /dev/mapper/centos-root
df -h
文章目录参考:https://blog.csdn.net/zmzdmx/article/details/112299741fdisk /dev/sda[root@localhost ~]# fdisk /dev/sdaWelcome to fdisk (util-linux 2.23.2).Changes will remain in memory only, until you decide to write them.Be careful before using the writ