赞
踩
目录
一、扩展磁盘大小
二、查看并创建系统分区
[root@node1 ~]# fdisk -l
- [root@node1 ~]# fdisk /dev/sda
- #输入m查看帮助文档
- Command (m for help): m
- 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)
- [root@node1 ~]# fdisk /dev/sda
- #输入m查看帮助文档
- Command (m for help): m
- 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): p
- Partition number (3,4, default 3): #由前面已有2个分区,所有从3开始
- First sector (20971520-62914559, default 20971520): #一路回车即可
- Using default value 20971520
- Last sector, +sectors or +size{K,M,G} (20971520-62914559, default 62914559):
- Using default value 62914559
- Partition 3 of type Linux and of size 20 GiB is set
-
- Command (m for help): w #保存退出
- The partition table has been altered!
- [root@node1 ~]# fdisk -l
-
- Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 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: 0x00009cb6
-
- Device Boot Start End Blocks Id System
- /dev/sda1 * 2048 2099199 1048576 83 Linux
- /dev/sda2 2099200 20971519 9436160 8e Linux LVM
- #sda3为新创建的分区
- /dev/sda3 20971520 62914559 20971520 83 Linux
-
- Disk /dev/mapper/centos-root: 8585 MB, 8585740288 bytes, 16769024 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/centos-swap: 1073 MB, 1073741824 bytes, 2097152 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
-
- #查看文件系统格式
- df -T -h
- #分区格式化
- mkfs.xfs /dev/sda3 #格式化为xfs格式
(注意:这一步可能会出现文件或目录不存在,可能是没有刷新造成的,会出现格式化xfs格式失败,这个时候要重启虚拟机再执行下面的命令!!!)
- #进入lvm管理
- lvm
- lvm> pvcreate /dev/sda3 #这是初始化刚才的分区3
- WARNING: ext4 signature detected on /dev/sda3 at offset 1080. Wipe it? [y/n]: y
- Wiping ext4 signature on /dev/sda3.
- Physical volume "/dev/sda3" successfully created.
- lvm> vgdisplay -v #卷和卷组的命令可以通过 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 <9.00 GiB
- PE Size 4.00 MiB
- Total PE 2303
- Alloc PE / Size 2303 / <9.00 GiB
- Free PE / Size 0 / 0
- VG UUID zy2221-18Zz-hNix-Xa40-fn2S-ymfs-QfifRi
-
- --- Logical volume ---
- LV Path /dev/centos/swap
- LV Name swap
- VG Name centos
- LV UUID ypW1dW-fdTc-qCso-7Wck-L1gH-hsOp-v4ZBey
- LV Write Access read/write
- LV Creation host, time localhost, 2021-06-25 13:10:00 +0800
- LV Status available
- # open 2
- LV Size 1.00 GiB
- Current LE 256
- 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 2IDcZo-HeDY-VzTg-FIAP-YhvQ-qU0K-cxyuBr
- LV Write Access read/write
- LV Creation host, time localhost, 2021-06-25 13:10:00 +0800
- LV Status available
- # open 1
- LV Size <8.00 GiB
- Current LE 2047
- Segments 1
- Allocation inherit
- Read ahead sectors auto
- - currently set to 8192
- Block device 253:0
-
- --- Physical volumes ---
- PV Name /dev/sda2
- PV UUID kb7rhp-Lcow-6z3W-RBYx-fJxo-pHUc-cLxYTN
- PV Status allocatable
- Total PE / Free PE 2303 / 0
-
- lvm> vgextend centos /dev/sda3 #将初始化过的分区加入到虚拟卷组centos
- Volume group "centos" successfully extended
-
通过vgdisplay再次查看,可以发现Volume group中多了Free PE / Size 5119 / <20.00 GiB一行记录
- 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 28.99 GiB
- PE Size 4.00 MiB
- Total PE 7422
- Alloc PE / Size 2303 / <9.00 GiB
- Free PE / Size 5119 / <20.00 GiB
- VG UUID zy2221-18Zz-hNix-Xa40-fn2S-ymfs-QfifRi
-
- --- Logical volume ---
- LV Path /dev/centos/swap
- LV Name swap
- VG Name centos
- LV UUID ypW1dW-fdTc-qCso-7Wck-L1gH-hsOp-v4ZBey
- LV Write Access read/write
- LV Creation host, time localhost, 2021-06-25 13:10:00 +0800
- LV Status available
- # open 2
- LV Size 1.00 GiB
- Current LE 256
- 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 2IDcZo-HeDY-VzTg-FIAP-YhvQ-qU0K-cxyuBr
- LV Write Access read/write
- LV Creation host, time localhost, 2021-06-25 13:10:00 +0800
- LV Status available
- # open 1
- LV Size <8.00 GiB
- Current LE 2047
- Segments 1
- Allocation inherit
- Read ahead sectors auto
- - currently set to 8192
- Block device 253:0
-
- --- Physical volumes ---
- PV Name /dev/sda2
- PV UUID kb7rhp-Lcow-6z3W-RBYx-fJxo-pHUc-cLxYTN
- PV Status allocatable
- Total PE / Free PE 2303 / 0
-
- PV Name /dev/sda3
- PV UUID V708hY-OO5p-IH3v-ZRlU-Torj-tXOC-ERvLr1
- PV Status allocatable
- Total PE / Free PE 5119 / 5119
- #/dev/mapper/centos-root 为根路径挂载点
- lvm> lvextend -l+5119 /dev/mapper/centos-root ##扩展已有卷的容量(5119 是通过vgdisplay查看Free PE / Size的大小)
- Size of logical volume centos/root changed from <8.00 GiB (2047 extents) to 27.99 GiB (7166 extents).
- Logical volume centos/root successfully resized.
- lvm> pvdisplay
- --- Physical volume ---
- PV Name /dev/sda2
- VG Name centos
- PV Size <9.00 GiB / not usable 3.00 MiB
- Allocatable yes (but full)
- PE Size 4.00 MiB
- Total PE 2303
- Free PE 0
- Allocated PE 2303
- PV UUID kb7rhp-Lcow-6z3W-RBYx-fJxo-pHUc-cLxYTN
-
- --- Physical volume ---
- PV Name /dev/sda3
- VG Name centos
- PV Size 20.00 GiB / not usable 4.00 MiB
- Allocatable yes (but full)
- PE Size 4.00 MiB
- Total PE 5119
- Free PE 0
- Allocated PE 5119
- PV UUID V708hY-OO5p-IH3v-ZRlU-Torj-tXOC-ERvLr1
- lvm>quit #退出
三、文件系统的扩容
以上只是做成了卷扩容,接下来做文件系统的真正扩容
- #执行df -h时根目录的挂载点
- df -h
xfs_growfs /dev/mapper/centos-root
df -h
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。