目录
新申请的ECS,磁盘一般不给挂好,非得为难我这菜鸟自己操作
磁盘挂载
查看一下现有磁盘
fdisk -l
可以看到有一块500G的磁盘/dev/vdb未使用:
Disk /dev/vda: 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: 0x000c13d8
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 1026047 512000 83 Linux
/dev/vda2 1026048 9414655 4194304 82 Linux swap / Solaris
/dev/vda3 9414656 104857599 47721472 83 Linux
Disk /dev/vdb: 536.9 GB, 536870912000 bytes, 1048576000 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: 0x42aae898
创建磁盘分区
fdisk /dev/vdb
输入n,创建新分区;大小指定为100G:
Disk /dev/vdb: 536.9 GB, 536870912000 bytes, 1048576000 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: 0x42aae898
Device Boot Start End Blocks Id System
/dev/vdb1 2048 209717247 104857600 83 Linux
Disk /dev/mapper/vg0-lv0: 107.4 GB, 107374182400 bytes, 209715200 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
创建PV(物理卷)
pvcreate /dev/vdb1
# 查看pv
pvs
PV VG Fmt Attr PSize PFree
/dev/vdb1 vg0 lvm2 a-- <100.00g 100G
如果提示没有命令,则使用命令yum -y install lvm2
安装lvm2.
创建VG(卷组)
vgcreate vg0 /dev/vdb1
# 查看
vgs
VG #PV #LV #SN Attr VSize VFree
vg0 1 1 0 wz--n- 100G 100G
创建LV(逻辑卷)
lvcreate -L 95G -n lv0 vg0
# 查看
lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
lv0 vg0 -wi-ao---- 95.00g
格式化分区
mkfs.xfs /dev/vg0/lv0
# 查看
lsblk
挂载分区
mount /dev/vg0/lv0 /apps
# 查看
df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg0-lv0 95G 33M 94G 1% /apps
挂载分配文件/etc/fstab
如果不配置,重启服务器后挂载点会丢失,还得重新挂载。容易引起不必要的恐慌。
echo '/dev/vg0/lv0 /apps xfs defaults 0 0' >> /etc/fstab
扩容逻辑分区
创建磁盘分区
fdisk /dev/vdb
输入n,创建新分区:
Disk /dev/vdb: 536.9 GB, 536870912000 bytes, 1048576000 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: 0x42aae898
Device Boot Start End Blocks Id System
/dev/vdb1 2048 209717247 104857600 83 Linux
/dev/vdb2 209717248 1048575999 419429376 83 Linux
Disk /dev/mapper/vg0-lv0: 107.4 GB, 107374182400 bytes, 209715200 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
重读分区表
partprobe /dev/vdb2
格式化分区
mkfs.xfs /dev/vdb2
扩容VG
vgextend vg0 /dev/vdb2
扩容LV
lvextend -L +5G /dev/vg0/lv0
刷新文件系统
xfs_growfs /dev/mapper/vg0-lv0
df -h
查看
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg0-lv0 100G 33M 100G 1% /apps
标签:Disk,bytes,dev,centos7,LVM,挂载,512,vg0,size
From: https://www.cnblogs.com/cheap-cabbage/p/17746487.html