一,Centos为硬盘新增容量分区并挂载到根目录
1.查看硬盘的情况。
可以看到硬盘新增了大小,但是没有被用起来。
下面我要做的其实就是lvm扩展
[root@Slave2 ~]# 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 for help): p
Disk /dev/sda: 429.5 GB, 429496729600 bytes, 838860800 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: 0x0001784c
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 33554431 15727616 8e Linux LVM
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): 3
First sector (33554432-838860799, default 33554432): 33554432
Last sector, +sectors or +size{K,M,G} (33554432-838860799, default 838860799): 838860799
Partition 3 of type Linux and of size 384 GiB is set
Command (m for help): p
Disk /dev/sda: 429.5 GB, 429496729600 bytes, 838860800 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: 0x0001784c
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 33554431 15727616 8e Linux LVM
/dev/sda3 33554432 838860799 402653184 83 Linux
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.
[root@Slave2 ~]#
用 partprobe /dev/sda3 没有启作用,重启后生效
可以看到sda3为刚刚新增的分区。
开始扩容:
创建物理卷:
[root@Slave2 ~]# lvm
lvm> pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created.
lvm>
查看物理卷和卷组:
lvm> pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name centos
PV Size <15.00 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 3839
Free PE 0
Allocated PE 3839
PV UUID VZ9vj7-442j-SGbv-3ZRj-gdDs-kQuK-YIPcEj
"/dev/sda3" is a new physical volume of "384.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sda3
VG Name
PV Size 384.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID TRQMxO-ouRd-E4GM-mL60-R4Ub-3FsX-BjiXZF
lvm>
将物理卷加入到卷组:
lvm> vgextend centos /dev/sda3
Volume group "centos" successfully extended
lvm> 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 398.99 GiB
PE Size 4.00 MiB
Total PE 102142
Alloc PE / Size 3839 / <15.00 GiB
Free PE / Size 98303 / <384.00 GiB
VG UUID e6v5QC-dUMm-yUWn-KSy7-5eOx-ttq6-5eyDID
lvm>
将卷组剩余空间添加到逻辑卷组/dev/centos/root
lvm> lvextend -l +100%FREE /dev/centos/root
Size of logical volume centos/root changed from 13.39 GiB (3429 extents) to 397.39 GiB (101732 extents).
Logical volume centos/root successfully resized.
lvm>
同步到文件系统
lvm> exit
Exiting.
[root@Slave2 ~]# xfs_growfs /dev/centos/root
meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=877824 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=3511296, 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 3511296 to 104173568
[root@Slave2 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 8.8M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/mapper/centos-root 398G 9.9G 388G 3% /
/dev/sda1 1014M 150M 865M 15% /boot
tmpfs 1.6G 0 1.6G 0% /run/user/0
[root@Slave2 ~]#