[TOC]
1、执行fdisk /dev/vda命令对磁盘剩余空间进行分区;当遇到Command (m for help):时输入n,表示新建分区;然后当需要输入时,直接按Enter键;当再次遇到Command (m for help):时输入w,表示写入保存。
```
[root@host-192-168-60-16 ~]# fdisk /dev/vda
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 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):
First sector (20971520-104857599, default 20971520):
Using default value 20971520
Last sector, +sectors or +size{K,M,G} (20971520-104857599, default 104857599):
Using default value 104857599
Partition 3 of type Linux and of size 40 GiB is set
Command (m for help): 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.
```
2、执行以下命令更新磁盘分区表
```
[root@host-192-168-60-16 ~]# partprobe
```
3、查看刚刚新建的分区,发现名字为vda3,大小为40G
```
[root@host-192-168-60-16 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sr0 11:0 1 458K 0 rom
vda 252:0 0 50G 0 disk
├─vda1 252:1 0 1G 0 part /boot
├─vda2 252:2 0 9G 0 part
│ ├─centos-root 253:0 0 8G 0 lvm /
│ └─centos-swap 253:1 0 1G 0 lvm [SWAP]
└─vda3 252:3 0 40G 0 part
```
4、使用vda3分区创建一个pv
```
[root@host-192-168-60-16 ~]# pvcreate /dev/vda3
```
5、把`/dev/vda3`这个pv加入到centos这个vg中,此时vg的空间会增加40G
```
[root@host-192-168-60-16 ~]# vgextend centos /dev/vda3
```
6、查看centos这个vg的大小,发现为48.99G
```
[root@host-192-168-60-16 ~]# 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 48.99 GiB
PE Size 4.00 MiB
Total PE 12542
Alloc PE / Size 2303 / <9.00 GiB
Free PE / Size 10239 / <40.00 GiB
VG UUID JuOM4n-bUuZ-eSbn-33eU-Q01c-aXcC-8CMiMD
```
7、扩展`/dev/centos/root`
在第6步中我们看到centos这个vg的总大小为48.99GiB,Free PE为10239 ,Free Size小于40.00GiB。我们把所有Free PE都加到`/dev/centos/root`这个lv下
```
[root@host-192-168-60-16 ~]# lvextend -l +10239 /dev/centos/root
```
注意:如果只是想把`/dev/centos/root`扩展到指定大小,比如40G,那么可以执行如下命令:
```
$ lvextend -L 40G /dev/centos/root
```
8、执行以下命令使根目录生效
```
[root@host-192-168-60-16 ~]# xfs_growfs /
```
9、查看根目录大小
```
[root@host-192-168-60-16 ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 47G 1.3G 46G 3% /
devtmpfs devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs tmpfs 3.9G 8.6M 3.9G 1% /run
tmpfs tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/vda1 xfs 1014M 148M 867M 15% /boot
tmpfs tmpfs 783M 0 783M 0% /run/user/0
```
### **Reference**
* http://man.linuxde.net/lvextend
- 常用命令
- 用户与用户组
- 创建用户与用户组
- 快速脚本
- umask
- Yum源
- 基础Yum源
- Epel源
- 制作Yum源
- 同步Yum源
- 为Yum源配置代理
- 下载RPM及依赖
- 系统与内核
- 获取内核的rpm包
- 升级内核
- Iptables
- 基本语法
- 匹配条件
- 基础匹配条件
- 扩展匹配条件
- Addrtype
- Set
- TCP
- Mark
- Multiport
- 目标
- 基本目标
- 扩展目标
- DNAT
- LOG
- CT
- NOTRACK
- MARK
- IP set
- 连接追踪
- 初识连接追踪
- 连接追踪详解
- NAT
- 思路与参考汇总
- 数据结构
- FAQ
- Keepalived
- 单网卡多VIP
- 安装Keepalived
- 双网卡绑VIP
- 别名VIP和辅助VIP
- LVS
- 安装LVS
- Ipvsadm命令
- 磁盘与分区
- 基础知识
- 创建分区
- 格式化与挂载
- Fstab
- LVM
- LVM扩容
- Swap分区
- Tmpfs
- 网络相关
- 重命名网卡
- resolv.conf
- Tcpdump
- nslookup与dig
- ifcg-xxx
- 主机名
- 软件安装
- NFS
- Squid
- Redsocks
- Shadowsocks
- 时钟同步
- Chrony
- FTP
- 文件句柄
- 简介
- 设置文件句柄
- 其他
- SSH密钥登录
- 进程组-会话-终端
- X11转发
- 环境变量
- 常见问题
- 系统进程数
- 系统调用
- 系统调用FAQ
- 用户程序如何进行系统调用