REHL 7之xfs和resize2fs扩展根目录大小

我在REHL7.0下安装oracle12c的时候提示根目录/下空间不足,于是想直接扩下根目录,网上搜索都是通过
[root@redhat6-3 ~]# resize2fs /dev/mapper/vg_redhat63-lv_root

resize2fs 1.41.12 (17-May-2010)

Filesystem at /dev/mapper/vg_redhat63-lv_root is mounted on /; on-line resizing required

old desc_blocks = 2, new_desc_blocks = 2

Performing an on-line resize of /dev/mapper/vg_redhat63-lv_root to 4859904 (4k) blocks.

The filesystem on /dev/mapper/vg_redhat63-lv_root is now 4859904 blocks long.

resize2fs来做,(具体案例很多,大家一搜就有)可以在线挂硬盘,但是扩根目录文件夹的时候一直提示如下:

[root@rac2 ~]# resize2fs /dev/hel/
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/rhel/root
Couldn’t find valid filesystem superblock.
[root@rac2 ~]#
重启也好,啥法都是试了就是一直提示,有的说umout目录,但是根目录不可能umout的,ext2online也试不行。
第三天查网帖的时候找到一篇《CentOS6、7 LVM逻辑卷分区自动扩容Shell脚本》,本来看到resize2fs感觉没啥新意,突然发现xfs_growfs ,赶紧仔细研读,(由于CentOS6和CentOS7在默认根文件系统的文件系统格式存在差异,需要判断是否为xfs,如果是xfs则应该使用xfs_growfs而不是一味的使用resize2fs。)
一句话惊醒梦中人啊,查阅了几篇xfs的用法后,在系统下一试果然好使,

[root@rac2 ~]# xfs_info /dev/rhel/root
meta-data=/dev/mapper/rhel-root isize=256 agcount=4, agsize=1147392 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=4589568, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@rac2 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 18G 3.0G 15G 17% /
devtmpfs 905M 0 905M 0% /dev
tmpfs 914M 164K 914M 1% /dev/shm
tmpfs 914M 9.0M 905M 1% /run
tmpfs 914M 0 914M 0% /sys/fs/cgroup
/dev/sda1 497M 120M 377M 25% /boot
/dev/sr0 3.5G 3.5G 0 100% /run/media/root/RHEL-7.0 Server.x86_64
[root@rac2 ~]# xfs_growfs /dev/rhel/root
meta-data=/dev/mapper/rhel-root isize=256 agcount=4, agsize=1147392 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=4589568, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
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 4589568 to 9046016
[root@rac2 ~]# xfs_growfs /dev/rhel/root
xfs_info /dev/rhel/root
meta-data=/dev/mapper/rhel-root isize=256 agcount=8, agsize=1147392 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=9046016, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@rac2 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 35G 3.0G 32G 9% /
devtmpfs 905M 0 905M 0% /dev
tmpfs 914M 164K 914M 1% /dev/shm
tmpfs 914M 9.0M 905M 1% /run
tmpfs 914M 0 914M 0% /sys/fs/cgroup
/dev/sda1 497M 120M 377M 25% /boot
/dev/sr0 3.5G 3.5G 0 100% /run/media/root/RHEL-7.0 Server.x86_64
[root@rac2 ~]#
困扰了三天的问题终于解决了,晚上可以好梦了。赶紧分享大家以飨。
以下贴出扩展swap和根目录的过程,欢迎大家交流
初始状态
[root@rac1 ~]# free -m
total used free shared buffers cached
Mem: 1826 919 907 9 0 324
-/+ buffers/cache: 594 1232
Swap: 2047 0 2047
[root@rac1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 18G 5.0G 13G 29% /
devtmpfs 908M 0 908M 0% /dev
tmpfs 914M 164K 914M 1% /dev/shm
tmpfs 914M 9.0M 905M 1% /run
tmpfs 914M 0 914M 0% /sys/fs/cgroup
/dev/sda1 497M 96M 401M 20% /boot
/dev/sr0 3.5G 3.5G 0 100% /run/media/root/RHEL-7.0 Server.x86_64
[root@rac1 ~]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x000aa76d

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 41943039 20458496 8e Linux LVM

Disk /dev/mapper/rhel-root: 18.8 GB, 18798870528 bytes, 36716544 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 /dev/mapper/rhel-swap: 2147 MB, 2147483648 bytes, 4194304 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

一块20个硬盘,2G的swap,18G的根目录
[root@rac1 ~]# vgdisplay -v
Finding all volume groups
Finding volume group “rhel”
— Volume group —
VG Name rhel
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.51 GiB
PE Size 4.00 MiB
Total PE 4994
Alloc PE / Size 4994 / 19.51 GiB
Free PE / Size 0 / 0
VG UUID cnpKO5-HowL-pwbZ-PGvi-81fk-3JXF-u5Uqte

— Logical volume —
LV Path /dev/rhel/root
LV Name root
VG Name rhel
LV UUID 8JfkKC-nnvl-KhHD-e5wx-yISp-O3Ys-xxnVWD
LV Write Access read/write
LV Creation host, time localhost, 2015-04-29 17:10:28 +0800
LV Status available

open 1

LV Size 17.51 GiB
Current LE 4482
Segments 1
Allocation inherit
Read ahead sectors auto

  • currently set to 256
    Block device 253:0

— Logical volume —
LV Path /dev/rhel/swap
LV Name swap
VG Name rhel
LV UUID H14cCa-ignp-pPag-G9QU-sWjc-WoB3-XklFXu
LV Write Access read/write
LV Creation host, time localhost, 2015-04-29 17:10:29 +0800
LV Status available

open 2

LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto

  • currently set to 256
    Block device 253:1

— Physical volumes —
PV Name /dev/sda2
PV UUID wRff8C-8kkz-0E1N-CKLh-YnBu-7qAf-DBa8KF
PV Status allocatable
Total PE / Free PE 4994 / 0

[root@rac1 ~]# pvdisplay -v
Scanning for physical volume names
— Physical volume —
PV Name /dev/sda2
VG Name rhel
PV Size 19.51 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 4994
Free PE 0
Allocated PE 4994
PV UUID wRff8C-8kkz-0E1N-CKLh-YnBu-7qAf-DBa8KF
一个卷组rhel,一个pv是/dev/sda2

[root@rac2 ~]# echo “- - -” > /sys/class/scsi_host/host0/scan
[root@rac1 ~]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x000aa76d

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 41943039 20458496 8e Linux LVM

Disk /dev/sdb: 16.1 GB, 16106127360 bytes, 31457280 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 /dev/mapper/rhel-root: 18.8 GB, 18798870528 bytes, 36716544 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 /dev/mapper/rhel-swap: 2147 MB, 2147483648 bytes, 4194304 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

在线添加一块16G的硬盘。
[root@rac1 ~]# pvcreate /dev/sdb
Physical volume “/dev/sdb” successfully created
[root@rac1 ~]# pvdisplay
— Physical volume —
PV Name /dev/sda2
VG Name rhel
PV Size 19.51 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 4994
Free PE 0
Allocated PE 4994
PV UUID wRff8C-8kkz-0E1N-CKLh-YnBu-7qAf-DBa8KF

“/dev/sdb” is a new physical volume of “15.00 GiB”
— NEW Physical volume —
PV Name /dev/sdb
VG Name
PV Size 15.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID XkelY2-zsv3-1Cpu-GRkJ-RmqZ-CKTs-XmHVkR

[root@rac1 ~]# pvscan
PV /dev/sda2 VG rhel lvm2 [19.51 GiB / 0 free]
PV /dev/sdb lvm2 [15.00 GiB]
Total: 2 [34.51 GiB] / in use: 1 [19.51 GiB] / in no VG: 1 [15.00 GiB]
[root@rac1 ~]# vgextend rhel /dev/sdb
Volume group “rhel” successfully extended
[root@rac1 ~]# pvdisplay
— Physical volume —
PV Name /dev/sda2
VG Name rhel
PV Size 19.51 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 4994
Free PE 0
Allocated PE 4994
PV UUID wRff8C-8kkz-0E1N-CKLh-YnBu-7qAf-DBa8KF

— Physical volume —
PV Name /dev/sdb
VG Name rhel
PV Size 15.00 GiB / not usable 4.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 3839
Free PE 3839
Allocated PE 0
PV UUID XkelY2-zsv3-1Cpu-GRkJ-RmqZ-CKTs-XmHVkR
创建PV,加入VG
[root@rac1 ~]# swapoff -v /dev/sdb
swapoff /dev/sdb
swapoff: /dev/sdb: swapoff failed: Invalid argument
[root@rac1 ~]# swapoff -v /dev/rhel/swap
swapoff /dev/rhel/swap
[root@rac1 ~]# lvresize -L+1.5G /dev/rhel/swap
Extending logical volume swap to 3.50 GiB
Logical volume swap successfully resized
[root@rac1 ~]# mkswap /dev/rhel/swap
mkswap: /dev/rhel/swap: warning: wiping old swap signature.
Setting up swapspace version 1, size = 3670012 KiB
no label, UUID=6323ca9b-e968-4c0e-8852-51aee7c93407
[root@rac1 ~]# swapon /dev/rhel/swap
[root@rac1 ~]# free -m
total used free shared buffers cached
Mem: 1826 937 889 9 0 326
-/+ buffers/cache: 610 1216
Swap: 3583 0 3583
[root@rac1 ~]#
swap扩展到3.5G
[root@rac1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 18G 5.0G 13G 29% /
devtmpfs 908M 0 908M 0% /dev
tmpfs 914M 164K 914M 1% /dev/shm
tmpfs 914M 9.0M 905M 1% /run
tmpfs 914M 0 914M 0% /sys/fs/cgroup
/dev/sda1 497M 96M 401M 20% /boot
/dev/sr0 3.5G 3.5G 0 100% /run/media/root/RHEL-7.0 Server.x86_64
[root@rac1 ~]# lvextend -L +5G /dev/mapper/rhel-root
Extending logical volume root to 22.51 GiB
Logical volume root successfully resized
[root@rac1 ~]# xfs_growfs /dev/rhel/root
meta-data=/dev/mapper/rhel-root isize=256 agcount=4, agsize=1147392 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0
data = bsize=4096 blocks=4589568, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
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 4589568 to 5900288
[root@rac1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 23G 5.0G 18G 22% /
devtmpfs 908M 0 908M 0% /dev
tmpfs 914M 164K 914M 1% /dev/shm
tmpfs 914M 9.0M 905M 1% /run
tmpfs 914M 0 914M 0% /sys/fs/cgroup
/dev/sda1 497M 96M 401M 20% /boot
/dev/sr0 3.5G 3.5G 0 100% /run/media/root/RHEL-7.0 Server.x86_64
[root@rac1 ~]#
根目录扩展到23G,大功告成。

你可能感兴趣的:(REHL 7之xfs和resize2fs扩展根目录大小)