centos文件系统扩容命令成功记录
[zhangbingbing07@192 ~]$ su root
密码:
[root@192 zhangbingbing07]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 16K 1.9G 1% /dev/shm
tmpfs 1.9G 13M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root 17G 12G 5.2G 70% /
/dev/sda1 1014M 347M 668M 35% /boot
tmpfs 378M 32K 378M 1% /run/user/1000
[root@192 zhangbingbing07]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 30G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sr0 11:0 1 1024M 0 rom
[root@192 zhangbingbing07]# fdisk /dev/sda
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
命令(输入 m 获取帮助):p
磁盘 /dev/sda:32.2 GB, 32212254720 字节,62914560 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000acdd2
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
命令(输入 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-62914559,默认为 41943040):
将使用默认值 41943040
Last 扇区, +扇区 or +size{K,M,G} (41943040-62914559,默认为 62914559):
将使用默认值 62914559
分区 3 已设置为 Linux 类型,大小设为 10 GiB
命令(输入 m 获取帮助):p
磁盘 /dev/sda:32.2 GB, 32212254720 字节,62914560 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x000acdd2
设备 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@192 zhangbingbing07]# partprobe /dev/sda
[root@192 zhangbingbing07]# pvcreate /dev/sda3
WARNING: dos signature detected on /dev/sda3 at offset 510. Wipe it? [y/n]: y
Wiping dos signature on /dev/sda3.
Physical volume "/dev/sda3" successfully created.
[root@192 zhangbingbing07]# 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 D1I2TL-j420-KfTY-pK0a-CV2I-9gdf-T6apQ9
[root@192 zhangbingbing07]# vgextend centos /dev/sda3
Volume group "centos" successfully extended
[root@192 zhangbingbing07]# 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 D1I2TL-j420-KfTY-pK0a-CV2I-9gdf-T6apQ9
[root@192 zhangbingbing07]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 16K 1.9G 1% /dev/shm
tmpfs 1.9G 13M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root 17G 12G 5.2G 70% /
/dev/sda1 1014M 347M 668M 35% /boot
tmpfs 378M 32K 378M 1% /run/user/1000
[root@192 zhangbingbing07]# /dev/mapper/centos-root
bash: /dev/mapper/centos-root: 权限不够
[root@192 zhangbingbing07]# lvextend -L+10G /dev/mapper/centos-root
Insufficient free space: 2560 extents needed, but only 2559 available
[root@192 zhangbingbing07]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 16K 1.9G 1% /dev/shm
tmpfs 1.9G 13M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root 17G 12G 5.2G 70% /
/dev/sda1 1014M 347M 668M 35% /boot
tmpfs 378M 32K 378M 1% /run/user/1000
[root@192 zhangbingbing07]# lvextend -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@192 zhangbingbing07]# lvextend -L+1G /dev/mapper/centos-root
Insufficient free space: 256 extents needed, but only 255 available
[root@192 zhangbingbing07]# 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 IV9ke0-j0ro-rvt8-Ek2N-2Pdq-PuNx-UeHSAF
--- Physical volume ---
PV Name /dev/sda3
VG Name centos
PV Size 10.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 2559
Free PE 255
Allocated PE 2304
PV UUID f7wHrk-70fS-y5o9-pnIb-Ff20-0GEe-CpZzTj
[root@192 zhangbingbing07]# cat /etc/fstab |grep centos-root
/dev/mapper/centos-root / xfs defaults 0 0
[root@192 zhangbingbing07]# xfs_growfs /dev/mapper/centos-roog
xfs_growfs: /dev/mapper/centos-roog is not a mounted XFS filesystem
[root@192 zhangbingbing07]# 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@192 zhangbingbing07]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 16K 1.9G 1% /dev/shm
tmpfs 1.9G 13M 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/mapper/centos-root 26G 12G 15G 46% /
/dev/sda1 1014M 347M 668M 35% /boot
tmpfs 378M 32K 378M 1% /run/user/1000
[root@192 zhangbingbing07]#