Centos系统 LVM 扩容根分区
LVM 扩容根分区
硬盘太小,不够用,LVM扩容根分区
增加一块硬盘,如下图所示:
二、
[root@tmp ~]# mount #通过mount命令让我们知道/dev/mapper/vg_tmp-lv_root 文件系统为ext4
/dev/mapper/vg_tmp-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
[root@tmp ~]# lsblk #通过lsblk 可看出vg_tmp-lv_root 就是挂载到 / sdb这块硬盘100G未使用
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 500M 0 part /boot
└─sda2 8:2 0 19.5G 0 part
├─vg_tmp-lv_root (dm-0) 253:0 0 17.6G 0 lvm /
└─vg_tmp-lv_swap (dm-1) 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 100G 0 disk
sr0 11:0 1 395M 0 rom
[root@tmp ~]# mkfs.ext4 /dev/sdb #格式化/dev/sdb 为ext4
[root@tmp ~]# pvcreate /dev/sdb #把/dev/sdb 创建成一个pv
Physical volume "/dev/sdb" successfully created
[root@tmp ~]# vgs # vgs 命令可以查看卷组,一个一卷组vg_tmp
VG #PV #LV #SN Attr VSize VFree
vg_tmp 1 2 0 wz--n- 19.51g 0
[root@tmp ~]# vgextend vg_tmp /dev/sdb #把/dev/sdb 加到vg_tmp 这个卷组上
Volume group "vg_tmp" successfully extended
[root@tmp ~]# vgdisplay #vgdisplay 命令可以看出free pe 有100G
--- Volume group ---
VG Name vg_tmp
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 119.50 GiB
PE Size 4.00 MiB
Total PE 30593
Alloc PE / Size 4994 / 19.51 GiB
Free PE / Size 25599 / 100.00 GiB
VG UUID yxzyS0-iYIh-BuLX-n3hc-M5Bh-U8IL-BdBjwC
[root@tmp ~]# lvextend -L +99.95G /dev/mapper/vg_tmp-lv_root #99.95G 挂载到/dev/mapper/vg_tmp-lv_root,如果写100G可能会不成功,块大小等!
Rounding size to boundary between physical extents: 99.95 GiB
Size of logical volume vg_tmp/lv_root changed from 17.57 GiB (4498 extents) to 117.52 GiB (30086 extents).
Logical volume lv_root successfully resized [root@tmp ~]# resize2fs /dev/mapper/vg_tmp-lv_root
[root@tmp ~]# resize2fs /dev/mapper/vg_tmp-lv_root #更新/dev/mapper/vg_tmp-lv_root 分区大小
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/vg_tmp-lv_root is mounted on /; on-line resizing required
old desc_blocks = 2, new_desc_blocks = 8
Performing an on-line resize of /dev/mapper/vg_tmp-lv_root to 30689280 (4k) blocks.
The filesystem on /dev/mapper/vg_tmp-lv_root is now 30689280 blocks long.
[root@tmp ~]# df –h #查看根分区是否扩容
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_tmp-lv_root
116G 795M 109G 1% /
tmpfs 491M 0 491M 0% /dev/shm
/dev/sda1 477M 30M 422M 7% /boot