很久没有学习centos的指令和操作了,最近忙于做监控,音频广播信号的项目,很少涉及服务器的项目,渐渐的远离和疏忽指令。今天对各个知识点又恶补一些,写点东西来分享。
lvm是逻辑分区意思,我记得在centos6里面有出现lvm的分区,redhat5 里面好像没有。能解答的朋友麻烦告诉我下。
xfs和ext2.3.4文件系统的不同,简单来说(抄别人的。哈哈,也可以百度吧):
xfs是一种非常优秀的日志文件系统,基于系统位数限制的文件类型,xfs是一个64位文件系统,最大支持8EB减1字节的单个文件系统,实际部署时取决于宿主操作系统的最大块限制。对于一个32位Linux系统,文件和文件系统的大小会被限制在16TB
xfs在很多方面确实做的比ext4好,ext4受限制于磁盘结构和兼容问题,可扩展性和scalability确实不如xfs,另外xfs经过很多年发展,各种锁的细化做的也比较好
ext4是第四代扩展文件系统(英语:Fourth EXtended filesystem,缩写为ext4)是linux系统下的日志文件系统,是ext3文件系统的后继版本
ext4的文件系统容量达到1EB,而文件容量则达到16TB,这是一个非常大的数字了。对一般的台式机和服务器而言,这可能并不重要,但对于大型磁盘阵列的用户而言,这就非常重要了。
ext3目前只支持32000个子目录,而ext4取消了这一限制,理论上支持无限数量的子目录
1)ext2/ext3/ext4文件系统的调整命令是resize2fs(增大和减小都支持)
lvextend -L 200G
/dev/mapper/centos-home
//
增大至200G
lvextend -L +30G
/dev/mapper/centos-home
//
增加30G
lvreduce -L 40G
/dev/mapper/centos-home
//
减小至40G
lvreduce -L -10G
/dev/mapper/centos-home
//
减小10G
resize2fs
/dev/mapper/centos-home
//
执行调整
2)xfs文件系统的调整命令是xfs_growfs(只支持增大)
lvextend -L 120G
/dev/mapper/centos-home
//
增大至120G
lvextend -L +20G
/dev/mapper/centos-home
//
增加20G
xfs_growfs
/dev/mapper/centos-home
//
执行调整
就是说:xfs文件系统只支持增大分区空间的情况,不支持减小的情况(谨记谨记谨记)。
硬要减小的话,只能在减小后将逻辑分区重新通过mkfs.xfs命令重新格式化才能挂载上,这样的话这个逻辑分区上原来的数据就丢失了。记得备份原来数据。
实例1 当系统上还有空闲的数据时候,比如系统没有划分到硬盘。(偷偷抄别人的,懒得在做一个系统盘了。)
1)查看分区空间。如下可知是xfs文件系统(
df
的-T参数就能看出文件格式)。
[root@localhost ~]
# df -hT
文件系统 类型 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root
xfs 200G 2.2G 198G 2% /
devtmpfs devtmpfs 32G 0 32G 0%
/dev
tmpfs tmpfs 32G 0 32G 0%
/dev/shm
tmpfs tmpfs 32G 49M 32G 1%
/run
tmpfs tmpfs 32G 0 32G 0%
/sys/fs/cgroup
/dev/sda1
xfs 197M 139M 59M 71%
/boot
tmpfs tmpfs 6.3G 0 6.3G 0%
/run/user/0
/dev/mapper/centos-home
xfs 628G 33M 718G 1%
/home
2)使用vgdisplay命令查看系统上的空闲空间
root@localhost ~]
# vgdisplay
--- Volume group ---
VG Name centos
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 6
VG Access
read
/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size 930.80 GiB
PE Size 4.00 MiB
Total PE 238285
Alloc PE / Size 212736 / 831.00 GiB
Free PE / Size 25549 / 99.80 GiB
//
这一项表示目前该系统上还存在99.80G的空闲空间(25549)
VG UUID a5hiAh-LB8M-9lRv-Ps1a-z35L-J4fk-sP3KrF
3) 将上面查到的空闲空间中的90G增减到
/home
分区上
[root@localhost ~]
# lvextend -L +90G /dev/mapper/centos-home //或者使用-l参数(跟PE数量),即lvextend -l +25500 /dev/mapper/centos-home
Size of logical volume centos
/home
changed from 628.00 GiB (160768 extents) to 718.00 GiB (183808 extents).
Logical volume centos
/home
successfully resized.
[root@localhost ~]
# xfs_growfs /dev/mapper/centos-home
meta-data=
/dev/mapper/centos-home
isize=512 agcount=4, agsize=41156608 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=164626432, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=80384, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 164626432 to 188219392
4)再次看着系统分区,发现home分区已经增加了90G(这种方式增加后,home分区之前的数据还不会丢失)
[root@localhost ~]
# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root
200G 2.2G 198G 2% /
devtmpfs 32G 0 32G 0%
/dev
tmpfs 32G 0 32G 0%
/dev/shm
tmpfs 32G 49M 32G 1%
/run
tmpfs 32G 0 32G 0%
/sys/fs/cgroup
/dev/sda1
197M 139M 59M 71%
/boot
tmpfs 6.3G 0 6.3G 0%
/run/user/0
/dev/mapper/centos-home
718G 33M 718G 1%
/home
虽然xfs文件系统只支持增加,不支持减少。但并不是说在xfs系统文件下不能减小,只是减小后,需要重新格式化才能挂载上。这样原来的数据就丢失了!
实例2: 这种情况只适用于系统刚安装好,逻辑分区内没有什么数据或数据不多且不重要可以删除或拷贝的情况下;计划将Home分区直接卸载,在重新从15G变成10G
root@localhost ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-LogVol05 ext4 16G 4.8G 9.9G 33% /
tmpfs tmpfs 495M 224K 495M 1% /dev/shm
/dev/sda1 ext4 485M 35M 426M 8% /boot
/dev/mapper/VolGroup-LogVol04 ext4 15G 12G 2.6G 82% /home
/dev/mapper/VolGroup-LogVol03 ext4 4.9G 583M 4.0G 13% /opt
/dev/mapper/VolGroup-LogVol06 ext4 2.4G 68M 2.2G 4% /usr/local
/dev/sr0 iso9660 4.2G 4.2G 0 100% /media/CentOS_6.5_Final
[root@localhost ~]# umount /home/
umount: /home: device is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
[root@localhost ~]# umount /home/ -f
umount2: Device or resource busy
umount: /home: device is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
#### 因为home路径下面有文件在运行,必须找文件进行删除才可以卸载掉。######
root@localhost ~]# fuser -m /home/
/home/: 2657c
[root@localhost ~]# ps -aux |grep 2657
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ
root 2657 0.0 0.1 108340 1856 pts/0 Ss+ 01:07 0:00 /bin/bash
root 2789 0.0 0.0 103252 832 pts/1 S+ 01:26 0:00 grep 2657
[root@localhost ~]# kill -9 2657
[root@localhost ~]# fuser -m /home/
[root@localhost ~]# umount /home/ ############已经成功卸载,fuser使用,底上上连接。
[root@localhost ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-LogVol05 ext4 16G 4.9G 9.8G 34% /
tmpfs tmpfs 495M 228K 495M 1% /dev/shm
/dev/sda1 ext4 485M 35M 426M 8% /boot
/dev/mapper/VolGroup-LogVol03 ext4 4.9G 583M 4.0G 13% /opt
/dev/mapper/VolGroup-LogVol06 ext4 2.4G 68M 2.2G 4% /usr/local
/dev/sr0 iso9660 4.2G 4.2G 0 100% /media/CentOS_6.5_Final
[root@localhost ~]# lvreduce -L -10G /dev/mapper/VolGroup-LogVol04 ####减小10G的空间
WARNING: Reducing active logical volume to 4.65 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce LogVol04? [y/n]: y
Reducing logical volume LogVol04 to 4.65 GiB
Logical volume LogVol04 successfully resized
[root@localhost ~]# xfs_growfs /dev/mapper/VolGroup-LogVol04 #########显然通过xfs方法减少不行,而且也卷组也不是XFS系统文件。
xfs_growfs: /dev/mapper/VolGroup-LogVol04 is not a mounted XFS filesystem
######如果-bash: mkfs.xfs: command not found,请[root@localhost ~]# yum -y install xfsprogs#####
[root@localhost ~]# mount /dev/mapper/VolGroup-LogVol04 /home/ #####在此将逻辑卷组挂载在home分区上
mount: wrong fs type, bad option, bad superblock on /dev/mapper/VolGroup-LogVol04,
missing codepage or helper program, or other error
In some cases useful info is found in syslog - try
dmesg | tail or so
[root@localhost ~]# mkfs.xfs /dev/mapper/VolGroup-LogVol04 -f ###########重新格式化
meta-data=/dev/mapper/VolGroup-LogVol04 isize=256 agcount=4, agsize=304640 blks
= sectsz=512 attr=2, projid32bit=0
data = bsize=4096 blocks=1218560, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@localhost ~]# mount /dev/mapper/VolGroup-LogVol04 /home/ ######重新在挂载一遍。
[root@localhost ~]# df -hT ###home的分区减少了10G,数据也应该不见了。
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-LogVol05 ext4 16G 4.9G 9.8G 34% /
tmpfs tmpfs 495M 228K 495M 1% /dev/shm
/dev/sda1 ext4 485M 35M 426M 8% /boot
/dev/mapper/VolGroup-LogVol03 ext4 4.9G 583M 4.0G 13% /opt
/dev/mapper/VolGroup-LogVol06 ext4 2.4G 68M 2.2G 4% /usr/local
/dev/sr0 iso9660 4.2G 4.2G 0 100% /media/CentOS_6.5_Final
/dev/mapper/VolGroup-LogVol04 xfs 4.7G 33M 4.7G 1% /home
[root@localhost ~]# mkfs.ext4 /dev/mapper/VolGroup-LogVol04 #####上面在重新格式的时候,也可以将这个格式化为ext4格式
mke2fs 1.41.12 (17-May-2010)
/dev/mapper/VolGroup-LogVol04 is mounted; will not make a filesystem here!
[root@localhost ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Wed Mar 1 17:03:43 2017
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/VolGroup-LogVol05 / ext4 defaults 1 1
UUID=afb02c3f-80b5-4dff-8dc5-50b2b44df6ef /boot ext4 defaults 1 2
/dev/mapper/VolGroup-LogVol04 /home ext4 defaults 1 2
/dev/mapper/VolGroup-LogVol03 /opt ext4 defaults 1 2
/dev/mapper/VolGroup-LogVol06 /usr/local ext4 defaults 1 2
/dev/mapper/VolGroup-LogVol01 swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
[root@localhost ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-LogVol05 ext4 16G 4.9G 9.8G 34% /
tmpfs tmpfs 495M 228K 495M 1% /dev/shm
/dev/sda1 ext4 485M 35M 426M 8% /boot
/dev/mapper/VolGroup-LogVol03 ext4 4.9G 583M 4.0G 13% /opt
/dev/mapper/VolGroup-LogVol06 ext4 2.4G 68M 2.2G 4% /usr/local
/dev/sr0 iso9660 4.2G 4.2G 0 100% /media/CentOS_6.5_Final
/dev/mapper/VolGroup-LogVol04 xfs 4.7G 33M 4.7G 1% /home
[root@localhost ~]#vgdisplay
--- Volume group ---
VG Name VolGroup
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 7
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 5
Open LV 5
Max PV 0
Cur PV 1
Act PV 1
VG Size 39.51 GiB
PE Size 4.00 MiB
Total PE 10114
Alloc PE / Size 7554 / 29.51 GiB
Free PE / Size 2560 / 10.00 GiB ###还剩下减少home分区目录下面的空间。
VG UUID aUO7Ph-kxhT-R7MQ-FCYG-yNez-IP7T-fuvKTf
###############################################################误操作,正好可以引荐,把剩余的10G分配到EXT4文件类型中了,在恢复回来。这里运用到楼上的知识,怎么增加,怎么减少。################
[root@localhost ~]# lvextend -L +10G /dev/mapper/VolGroup-LogVol03
Extending logical volume LogVol03 to 14.88 GiB
Logical volume LogVol03 successfully resized
[root@localhost ~]# xfs_growfs /dev/mapper/VolGroup-LogVol03
xfs_growfs: /dev/mapper/VolGroup-LogVol03 is not a mounted XFS filesystem
[root@localhost ~]# lvextend -L -10G /dev/mapper/VolGroup-LogVol03
Negative argument not permitted - use lvreduce
Run `lvextend --help' for more information.
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name VolGroup
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 8
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 5
Open LV 5
Max PV 0
Cur PV 1
Act PV 1
VG Size 39.51 GiB
PE Size 4.00 MiB
Total PE 10114
Alloc PE / Size 10114 / 39.51 GiB
Free PE / Size 0 / 0
VG UUID aUO7Ph-kxhT-R7MQ-FCYG-yNez-IP7T-fuvKTf
[root@localhost ~]# lvreduce -L -10G /dev/mapper/VolGroup-LogVol03 ######在重新减退回来,否则没有空的容量挂载在XFS中。
WARNING: Reducing active and open logical volume to 4.88 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce LogVol03? [y/n]: y
Reducing logical volume LogVol03 to 4.88 GiB
Logical volume LogVol03 successfully resized
########################################################
[root@localhost ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-LogVol05 ext4 16G 4.9G 9.8G 34% /
tmpfs tmpfs 495M 228K 495M 1% /dev/shm
/dev/sda1 ext4 485M 35M 426M 8% /boot
/dev/mapper/VolGroup-LogVol03 ext4 4.9G 583M 4.0G 13% /opt
/dev/mapper/VolGroup-LogVol06 ext4 2.4G 68M 2.2G 4% /usr/local
/dev/sr0 iso9660 4.2G 4.2G 0 100% /media/CentOS_6.5_Final
/dev/mapper/VolGroup-LogVol04 xfs 4.7G 33M 4.7G 1% /home
[root@localhost ~]# vgdisplay
--- Volume group ---
VG Name VolGroup
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 9
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 5
Open LV 5
Max PV 0
Cur PV 1
Act PV 1
VG Size 39.51 GiB
PE Size 4.00 MiB
Total PE 10114
Alloc PE / Size 7554 / 29.51 GiB
Free PE / Size 2560 / 10.00 GiB
VG UUID aUO7Ph-kxhT-R7MQ-FCYG-yNez-IP7T-fuvKTf
[root@localhost ~]# lvextend -L +10G /dev/mapper/VolGroup-LogVol04 #04卷才是xfs的文件系统。
Extending logical volume LogVol04 to 14.65 GiB
Logical volume LogVol04 successfully resized
[root@localhost ~]# xfs_growfs /dev/mapper/VolGroup-LogVol04 ###控制调整,格式化XFS文件。############
meta-data=/dev/mapper/VolGroup-LogVol04 isize=256 agcount=4, agsize=304640 blks
= sectsz=512 attr=2, projid32bit=0
data = bsize=4096 blocks=1218560, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=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 1218560 to 3840000
[root@localhost ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-LogVol05 ext4 16G 4.9G 9.8G 34% /
tmpfs tmpfs 495M 228K 495M 1% /dev/shm
/dev/sda1 ext4 485M 35M 426M 8% /boot
/dev/mapper/VolGroup-LogVol03 ext4 4.9G 583M 4.0G 13% /opt
/dev/mapper/VolGroup-LogVol06 ext4 2.4G 68M 2.2G 4% /usr/local
/dev/sr0 iso9660 4.2G 4.2G 0 100% /media/CentOS_6.5_Final
/dev/mapper/VolGroup-LogVol04 xfs 15G 33M 15G 1% /home
总结:XFS与EXT4文件,指令不相同也有类似的地方,合适根据文件来选择文件系统类型来选择。
这里有个疑问:为什么已经格式化成为EXT4文件了,但是在df显示中还有是Xfs文件,有大神知道,麻烦告诉我一下了。
借鉴网站:https://blog.csdn.net/lengyue1084/article/details/51477872
https://blog.csdn.net/wangkai_123456/article/details/79132333
https://blog.csdn.net/shile/article/details/52919954
https://blog.csdn.net/lengyue1084/article/details/51477872