新建逻辑分区,识别逻辑分区,创建物理分区,扩展卷组,扩展目标分区。
点击查看代码
<-- 删除了一些错误书写 -->
[root@master ~]# fdisk -l
磁盘 /dev/sda:53.7 GB, 53687091200 字节,104857600 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000a2638
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
磁盘 /dev/mapper/centos-root:18.2 GB, 18249416704 字节,35643392 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/centos-swap:2147 MB, 2147483648 字节,4194304 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
[root@master ~]# fdisk /dev/sda //新建逻辑分区
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
命令(输入 m 获取帮助):n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p):
Using default response p
分区号 (3,4,默认 3):
起始 扇区 (41943040-104857599,默认为 41943040):
将使用默认值 41943040
Last 扇区, +扇区 or +size{K,M,G} (41943040-104857599,默认为 104857599):+10G
分区 3 已设置为 Linux 类型,大小设为 10 GiB
命令(输入 m 获取帮助):p
磁盘 /dev/sda:53.7 GB, 53687091200 字节,104857600 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000a2638
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
/dev/sda3 41943040 62914559 10485760 83 Linux
命令(输入 m 获取帮助):w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
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)
正在同步磁盘。
[root@master ~]# partprobe //识别
[root@master ~]# pvcreate /dev/sda3 //创建物理分区
Physical volume "/dev/sda3" successfully created.
[root@master ~]# 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 1qy9k5-Hcqs-I069-jA2R-Dx1L-Y63Y-2Ll6AF
"/dev/sda3" is a new physical volume of "10.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sda3
VG Name
PV Size 10.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID LuOKWS-aycL-2evL-0cHa-o42G-jjvG-4r1szh
[root@master ~]# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size <19.00 GiB
PE Size 4.00 MiB
Total PE 4863
Alloc PE / Size 4863 / <19.00 GiB
Free PE / Size 0 / 0
VG UUID us2RqC-XUJF-xAgc-iL8v-SE6J-6Hnh-beoh71
[root@master ~]# vgextend centos /dev/sda3 //扩展卷组
Volume group "centos" successfully extended
[root@master ~]# vgdisplay //查看卷组
--- 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 28.99 GiB
PE Size 4.00 MiB
Total PE 7422
Alloc PE / Size 4863 / <19.00 GiB
Free PE / Size 2559 / <10.00 GiB
VG UUID us2RqC-XUJF-xAgc-iL8v-SE6J-6Hnh-beoh71
[root@master ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 893M 0 893M 0% /dev
tmpfs 910M 0 910M 0% /dev/shm
tmpfs 910M 9.9M 900M 2% /run
tmpfs 910M 0 910M 0% /sys/fs/cgroup
/dev/mapper/centos-root 17G 17G 677M 97% /
/dev/sda1 1014M 351M 664M 35% /boot
tmpfs 182M 0 182M 0% /run/user/0
[root@master ~]# lvresize -L +10G /dev/mapper/centos-root
Insufficient free space: 2560 extents needed, but only 2559 available
[root@master ~]# lvresize -L +9G /dev/mapper/centos-root //扩展根分区大小
Size of logical volume centos/root changed from <17.00 GiB (4351 extents) to <26.00 GiB (6655 extents).
Logical volume centos/root successfully resized.
[root@master ~]# df -T
文件系统 类型 1K-块 已用 可用 已用% 挂载点
devtmpfs devtmpfs 914384 0 914384 0% /dev
tmpfs tmpfs 931404 0 931404 0% /dev/shm
tmpfs tmpfs 931404 10076 921328 2% /run
tmpfs tmpfs 931404 0 931404 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 17811456 17118916 692540 97% /
/dev/sda1 xfs 1038336 358444 679892 35% /boot
tmpfs tmpfs 186284 0 186284 0% /run/user/0
[root@master ~]# xfs_growfs /dev/mapper/centos-root //重新识别根分区
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=1113856 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=4455424, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 4455424 to 6814720
[root@master ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 893M 0 893M 0% /dev
tmpfs 910M 0 910M 0% /dev/shm
tmpfs 910M 9.9M 900M 2% /run
tmpfs 910M 0 910M 0% /sys/fs/cgroup
/dev/mapper/centos-root 26G 17G 9.7G 63% /
/dev/sda1 1014M 351M 664M 35% /boot
tmpfs 182M 0 182M 0% /run/user/0
[root@master ~]#