liunx系统下的通配符起到了很大的作用,对于不确定的文档名称可以使用特殊字符表示
'*' 常用的特殊符号,表示任意多个字符
‘?’常用的特殊符号,表示任意单个字符
[0-9] #在文件名上,用来代表多个字符或者连续范围中的一个,若无则忽略
{a,b,3} #在文件名上,用来表示多组不同的字符串,全匹配
[[email protected] /]# grep -n -v '^#' /etc/fstab 1: 9:/dev/mapper/centos-root / xfs defaults 0 0 10:UUID=e6f5ab62-b4f1-4a0a-a330-e58478021804 /boot xfs defaults 0 0 11:/dev/mapper/centos-swap swap swap defaults 0 0 [[email protected] /]#
#按文件类型查找目录 [[email protected] /]# find /var/log -type d /var/log /var/log/samba /var/log/samba/old /var/log/ppp /var/log/audit /var/log/chrony /var/log/pluto /var/log/pluto/peer /var/log/glusterfs /var/log/libvirt /var/log/libvirt/qemu /var/log/speech-dispatcher /var/log/cups /var/log/gdm /var/log/tuned /var/log/sa /var/log/qemu-ga /var/log/anaconda /var/log/rhsm [[email protected] /]# #按文件名查找并指定类型为文件 [[email protected] /]# find /etc/ -name pas* -type f /etc/openldap/certs/password /etc/passwd /etc/passwd- /etc/pam.d/passwd /etc/pam.d/password-auth-ac [[email protected] /]# #查找大于10k的文件 [[email protected] /]# find /var/log -size +10k -type f /var/log/lastlog /var/log/wtmp /var/log/audit/audit.log /var/log/gdm/:0.log /var/log/sa/sa03 /var/log/sa/sa04 /var/log/sa/sa06 /var/log/sa/sa08 /var/log/sa/sa10 /var/log/sa/sa12 /var/log/sa/sa15 /var/log/anaconda/anaconda.log /var/log/anaconda/syslog /var/log/anaconda/X.log /var/log/anaconda/program.log /var/log/anaconda/packaging.log /var/log/anaconda/storage.log /var/log/anaconda/journal.log /var/log/dmesg /var/log/Xorg.9.log /var/log/Xorg.0.log /var/log/boot.log-20220812 /var/log/cron-20220812 /var/log/messages-20220812 /var/log/messages [[email protected] /]# [[email protected] /]# du -h /var/log/messages 28K /var/log/messages #大于10k并且小于25k [[email protected] /]# find /var/log -size +10k -a -size -25k -type f /var/log/wtmp /var/log/sa/sa03 /var/log/Xorg.9.log /var/log/boot.log-20220812 /var/log/cron-20220812 [[email protected] /]# #大于10k或者root用户的文件 [[email protected] /]# find /var/log -size +10k -type f -o -user root /var/log /var/log/tallylog /var/log/grubby_prune_debug /var/log/lastlog /var/log/wtmp /var/log/btmp /var/log/samba /var/log/samba/old /var/log/ppp /var/log/audit /var/log/audit/audit.log /var/log/pluto /var/log/pluto/peer /var/log/glusterfs /var/log/libvirt /var/log/libvirt/qemu /var/log/speech-dispatcher /var/log/cups/error_log /var/log/cups/page_log /var/log/cups/access_log-20220812 /var/log/cups/access_log /var/log/gdm /var/log/gdm/:0.log /var/log/gdm/:0-greeter.log /var/log/tuned /var/log/tuned/tuned.log /var/log/sa /var/log/sa/sa03 /var/log/sa/sa04 /var/log/sa/sa05 /var/log/sa/sar05 /var/log/sa/sa06 /var/log/sa/sa08 /var/log/sa/sa09 /var/log/sa/sa10 /var/log/sa/sa12 /var/log/sa/sa14 /var/log/sa/sar14 /var/log/sa/sa15 /var/log/qemu-ga /var/log/anaconda /var/log/anaconda/anaconda.log /var/log/anaconda/syslog /var/log/anaconda/X.log /var/log/anaconda/program.log /var/log/anaconda/packaging.log /var/log/anaconda/storage.log /var/log/anaconda/ifcfg.log /var/log/anaconda/ks-script-kWVo7f.log /var/log/anaconda/ks-script-zuVLNF.log /var/log/anaconda/journal.log /var/log/rhsm /var/log/boot.log /var/log/vmware-vmsvc.log /var/log/vmware-vgauthsvc.log.0 /var/log/dmesg /var/log/firewalld /var/log/Xorg.9.log /var/log/Xorg.0.log /var/log/wpa_supplicant.log /var/log/vmware-vmusr.log /var/log/yum.log /var/log/boot.log-20220812 /var/log/cron-20220812 /var/log/cron /var/log/maillog-20220812 /var/log/maillog /var/log/messages-20220812 /var/log/messages /var/log/secure-20220812 /var/log/secure /var/log/spooler-20220812 /var/log/spooler [[email protected] /]# #24小时以内的文件 [[email protected] /]# find /var/log -mtime 0 /var/log/lastlog /var/log/wtmp /var/log/audit/audit.log /var/log/cups/access_log /var/log/sa /var/log/sa/sa14 /var/log/sa/sar14 /var/log/sa/sa15 /var/log/boot.log /var/log/vmware-vmsvc.log /var/log/cron /var/log/messages /var/log/secure [[email protected] /]# ll /var/log/messages -rw-------. 1 root root 25763 8月 15 01:20 /var/log/messages #5天内修改的文件 [[email protected] /]# find /var/log -mtime -5 /var/log /var/log/lastlog /var/log/wtmp /var/log/btmp /var/log/audit/audit.log /var/log/cups /var/log/cups/access_log-20220812 /var/log/cups/access_log /var/log/sa /var/log/sa/sa12 /var/log/sa/sa14 /var/log/sa/sar14 /var/log/sa/sa15 /var/log/boot.log /var/log/vmware-vmsvc.log /var/log/boot.log-20220812 /var/log/cron-20220812 /var/log/cron /var/log/maillog /var/log/messages-20220812 /var/log/messages /var/log/secure-20220812 /var/log/secure /var/log/spooler #查找24小时之类党的文件或者目录并复制opt下面 [[email protected] /]# find /var/log/ -mtime 0 -exec cp -r {} /opt/ \; [[email protected] /]# ls /opt/ access_log boot.log lastlog sa sa15 secure wtmp audit.log cron messages sa14 sar14 vmware-vmsvc.log [[email protected] /]#
liunx独有压缩格式及命令工具(压缩比例从小到大,速度从快到慢,不支持多个文件和目录压缩)
压缩命令格式
[[email protected] opt]# gzip services [[email protected] opt]# ls services.gz [[email protected]ce opt]#
查看解压缩文件
tar命令用于在liunx下对于liunx文件或目录进行打包,使用tar程序打出来的包通常称为tar包,tar包文件通常都是一.tar结尾
tar命令格式:tar 选项 、路径/压缩包名字 被压缩文件
常用选项:
#命令选项顺序需注意否则会报错,解决办法删除命令选项前的- [[email protected] /]# cd opt/ [[email protected] opt]# tar cfz xx.tar.gz /etc/passwd /etc/fstab /home tar: 从成员名中删除开头的“/” [[email protected] opt]# ls services.gz xx.tar.gz z [[email protected] opt]# #解压 [[email protected] opt]# tar -xf xx.tar.gz -C /media/ [[email protected] opt]# ls /media/ etc home [[email protected] opt]#
添加新硬盘----分区----格式化文件系统------挂载使用
lsblk (全称list block)用于列出当前系统所有磁盘信息和分区信息
命令格式:lsblk [选项...] [设备名]
常用选项
[[email protected] ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 20G 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] sdb 8:16 0 20G 0 disk sr0 11:0 1 1024M 0 rom #sd表示SCSI接口 [[email protected] ~]# #解释 #NAME 名称 # MAJ:MIN RM 主设备号:次设备号,内核通过主次设备号识别磁盘 #RM 是否为可卸载设备:1可卸载,0不可卸载 #SIZE 设备的容量大小 #RO 设备是否为只读,0表示非只读,1表示只读 #TYPE 表示设备类型(disk为磁盘,part为分区,lvm为逻辑卷,rom只读) #MOUNTPOINT 设备挂载点 #列出指定磁盘信息 [[email protected] ~]# lsblk -d /dev/sda NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 20G 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] [[email protected] ~]# lsblk -f /dev/sda NAME FSTYPE LABEL UUID MOUNTPOINT sda ├─sda1 xfs e6f5ab62-b4f1-4a0a-a330-e58478021804 /boot └─sda2 LVM2_member cacJce-O1j4-beJh-AlCO-hZCV-VMZl-uCcJlJ ├─centos-root xfs d9283643-39ff-4d6d-a440-f3283051409f / └─centos-swap swap 2c31e219-b895-4ade-8fad-2fe7b7306f59 [SWAP] [[email protected] ~]#
df用于查看文件系统使用情况
命令格式:df [选项...] [参数...]
常用选项:
[[email protected] ~]# df -Th 文件系统 类型 容量 已用 可用 已用% 挂载点 /dev/mapper/centos-root xfs 17G 3.4G 14G 20% / devtmpfs devtmpfs 895M 0 895M 0% /dev tmpfs tmpfs 911M 0 911M 0% /dev/shm tmpfs tmpfs 911M 11M 901M 2% /run tmpfs tmpfs 911M 0 911M 0% /sys/fs/cgroup /dev/sda1 xfs 1014M 170M 845M 17% /boot tmpfs tmpfs 183M 12K 183M 1% /run/user/42 tmpfs tmpfs 183M 0 183M 0% /run/user/0 [[email protected] ~]#
du用于统计文件目录大小
命令格式:du [选项...] [参数....]
常用选型:
[[email protected] ~]# du -sh /etc/ 37M /etc/ [[email protected] ~]#
blkid显示设备属性(设备名称,设备UUID,文件系统类型)
命令格式:blkid [选项...] [参数...]
[[email protected] ~]# blkid /dev/sda1: UUID="e6f5ab62-b4f1-4a0a-a330-e58478021804" TYPE="xfs" /dev/sda2: UUID="cacJce-O1j4-beJh-AlCO-hZCV-VMZl-uCcJlJ" TYPE="LVM2_member" /dev/mapper/centos-root: UUID="d9283643-39ff-4d6d-a440-f3283051409f" TYPE="xfs" /dev/mapper/centos-swap: UUID="2c31e219-b895-4ade-8fad-2fe7b7306f59" TYPE="swap" [[email protected] ~]# blkid /dev/sda1 /dev/sda1: UUID="e6f5ab62-b4f1-4a0a-a330-e58478021804" TYPE="xfs" [[email protected] ~]#
[rootQlocaThost -]# 1s /dev hd[a-t]:IDE设备 sd[a-z]:SCSI设备 fd[0-7]:软盘驱动设备 md[0-32]:软RAID设备 loop[0-7]: 本地网环设设备 lp[0-3]:打印机设备 mem:内存设备 null:空设备,也称为黑洞,任何写入的数据配将被丢弃zero:零资源设备,任何写入的数据都将被丢弃 full:满设备,任何写入的数据都将失败 tty[0-63]:虚拟终端设备 random:随机数设备 urandom:随机数设备 port:存取I/0端口
fdisk命令用于查看磁盘使用情况和磁盘分区(MBR分区格式)
命令格式: fdisk [选项.. ] [设备路径]
常用选项: -l 列出磁盛分区表类型与分区信息
分区
[[email protected] ~]# fdisk /dev/sdb m #获取命令帮助 p #显示磁盘分区表 n #新增加一个分区 q #不保存分区退出 d #删除一个分区 w #保存分区退出 a #设置可引导标记 b #编辑bsd磁盘标签 c #设置DOS操作系统兼容标记 l #显示已知的文件系统类型,82为swap交换分区,83为Linux分区 o #建立空白DOS分区表 s #新建空白SUN磁盘标签 t #改变分区的系统ID u #改变显示记录单位 v #验证分区表 x #附加功能 #新建主分区 [[email protected] ~]# fdisk /dev/sdb 欢迎使用 fdisk (util-linux 2.23.2)。 更改将停留在内存中,直到您决定将更改写入磁盘。 使用写入命令前请三思。 Device does not contain a recognized partition table 使用磁盘标识符 0x7fe58f60 创建新的 DOS 磁盘标签。 命令(输入 m 获取帮助):p 磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区 Units = 扇区 of 1 * 512 = 512 bytes 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节 磁盘标签类型:dos 磁盘标识符:0x7fe58f60 设备 Boot Start End Blocks Id System 命令(输入 m 获取帮助):n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p 分区号 (1-4,默认 1):1 起始 扇区 (2048-41943039,默认为 2048): 将使用默认值 2048 Last 扇区, +扇区 or +size{K,M,G} (2048-41943039,默认为 41943039):+10G 分区 1 已设置为 Linux 类型,大小设为 10 GiB 命令(输入 m 获取帮助):p 磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区 Units = 扇区 of 1 * 512 = 512 bytes 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节 磁盘标签类型:dos 磁盘标识符:0x7fe58f60 设备 Boot Start End Blocks Id System /dev/sdb1 2048 20973567 10485760 83 Linux 命令(输入 m 获取帮助):w The partition table has been altered! Calling ioctl() to re-read partition table. #新建扩展分区 [[email protected] ~]# fdisk /dev/sdb 欢迎使用 fdisk (util-linux 2.23.2)。 更改将停留在内存中,直到您决定将更改写入磁盘。 使用写入命令前请三思。 命令(输入 m 获取帮助):n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): e 分区号 (2-4,默认 2): 起始 扇区 (20973568-41943039,默认为 20973568): 将使用默认值 20973568 Last 扇区, +扇区 or +size{K,M,G} (20973568-41943039,默认为 41943039):+5G 分区 2 已设置为 Extended 类型,大小设为 5 GiB 命令(输入 m 获取帮助):w The partition table has been altered! Calling ioctl() to re-read partition table. 正在同步磁盘。 #删除分区 [[email protected] ~]# fdisk /dev/sdb 欢迎使用 fdisk (util-linux 2.23.2)。 更改将停留在内存中,直到您决定将更改写入磁盘。 使用写入命令前请三思。 命令(输入 m 获取帮助):d 分区号 (1,2,默认 2):2 分区 2 已删除 命令(输入 m 获取帮助):w The partition table has been altered! Calling ioctl() to re-read partition table. 正在同步磁盘。
mkfs命令用于在分区上建立文件系统
常用文件系统类型
命令格式:
[[email protected] ~]# mkfs.xfs /dev/sdb1 meta-data=/dev/sdb1 isize=512 agcount=4, agsize=655360 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=2621440, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 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
mount文件系统挂载命令
命令格式: mount 设备路径 挂载点目录
常用选项:
[[email protected] ~]# mount /dev/sdb1 /mybak/ [[email protected] ~]# df -Th 文件系统 类型 容量 已用 可用 已用% 挂载点 /dev/mapper/centos-root xfs 17G 3.4G 14G 20% / devtmpfs devtmpfs 895M 0 895M 0% /dev tmpfs tmpfs 911M 0 911M 0% /dev/shm tmpfs tmpfs 911M 11M 901M 2% /run tmpfs tmpfs 911M 0 911M 0% /sys/fs/cgroup /dev/sda1 xfs 1014M 170M 845M 17% /boot tmpfs tmpfs 183M 12K 183M 1% /run/user/42 tmpfs tmpfs 183M 0 183M 0% /run/user/0 /dev/sdb1 xfs 10G 33M 10G 1% /mybak
umount用于卸载文件系统
命令格式:umount 挂载点
[[email protected] ~]# umount /mybak/ [[email protected] ~]# df -h 文件系统 容量 已用 可用 已用% 挂载点 /dev/mapper/centos-root 17G 3.4G 14G 20% / devtmpfs 895M 0 895M 0% /dev tmpfs 911M 0 911M 0% /dev/shm tmpfs 911M 11M 901M 2% /run tmpfs 911M 0 911M 0% /sys/fs/cgroup /dev/sda1 1014M 170M 845M 17% /boot tmpfs 183M 12K 183M 1% /run/user/42 tmpfs 183M 0 183M 0% /run/user/0
/etc/fstab用于存放文件系统信息,当系统启动时,系统会自动读取此文件信息并依次挂载
文件详解
[[email protected] ~]# tail -3 /etc/fstab /dev/mapper/centos-root / xfs defaults 0 0 UUID=e6f5ab62-b4f1-4a0a-a330-e58478021804 /boot xfs defaults 0 0 /dev/mapper/centos-swap swap swap defaults 0 0 #六字段详解 第一个字段:挂载的设备路径 第二个字段:挂载点目录 第三个字段:设备文件系统类型 第四个字段:挂载参数,参数如下 sync,async;此文件系统是否使用同步写入(sync) 或异步(async) 的内存机制,默认为异步(async) atime,noatime: 更新访问时间/不更新访问时间,访问分区时,足否更新文件的访问时间,默认为更新 ro,rw:挂载文件为只读(ro)或读写(rw),默认为rw auto,noauto:自动挂载/手动挂载,执行mount -a时,是否自动挂载/etc/fstab文件内容,默认为自动(auto) dev,nodev: 足否允许此文件系统上,可建立装置文件,默认为允许(dev) suid,nosuid: 是否允许文件系统上含有SUID与SGID特殊权限。默认为允许(SUID) exec,noexec: 是否允许文件系统上拥有可执行文件,默认为允许(exeC) user,nouser: 是否允许普通用户执行挂战操作,默认为不允许(nouser) ,只有root用户可以挂载分区 defaults默认值:代表async, rw. auto, dev, suid, exec, nouser七个选项 弟五个字段:是对文件系统进行备份,0不备份,1为备份 第六个字段:是否检查文件系统顺序,允许的数字是0,1,2 0表示不检查,1的优先权最高 #挂载 [[email protected] ~]# tail -1 /etc/fstab /dev/sdb1 /mybak xfs defaults 0 0
重新挂载文件系统,在文件系统出错的情况或者重新挂载的时候比较重要-
gdisk命令用于查看磁盘使用情况和分区使用情况
命令格式:gdisk [选项...] [设备路径]
常用选项 : -l 列出磁盘分区表类型和信息
[[email protected] ~]# gdisk /dev/sdc GPT fdisk (gdisk) version 0.8.6 #GPT版本 Partition table scan: #分区表扫描 MBR: not present #MBR分区不存在 BSD: not present #BSD分区不存在 APM: not present #APM分区不存在 GPT: not present #GPT分区不存在 Creating new GPT entries. #创建新的GPT分区 Command (? for help):? #输入?获取帮助 p #显示磁盘分区表 n #新增加一个分区 q #不保存分区退出 d #删除一个分区 w #保存分区退出 #创建新分区(总体跟MBR分区差不多) Command (? for help): n Partition number (1-128, default 1): First sector (34-20971486, default = 2048) or {+-}size{KMGTP}: Last sector (2048-20971486, default = 20971486) or {+-}size{KMGTP}: +5G Current type is 'Linux filesystem' Hex code or GUID (L to show codes, Enter = 8300): Changed type of partition to 'Linux filesystem' Command (? for help): P Disk /dev/sdc: 20971520 sectors, 10.0 GiB Logical sector size: 512 bytes Disk identifier (GUID): 1D2FD571-24F3-410B-AE27-C342688FCE0D Partition table holds up to 128 entries First usable sector is 34, last usable sector is 20971486 Partitions will be aligned on 2048-sector boundaries Total free space is 10485693 sectors (5.0 GiB) Number Start (sector) End (sector) Size Code Name 1 2048 10487807 5.0 GiB 8300 Linux filesystem Command (? for help): w #格式化并挂载 [[email protected] ~]# mkfs.xfs /dev/sdc1 meta-data=/dev/sdc1 isize=512 agcount=4, agsize=327680 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=1310720, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 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 [[email protected] ~]# mkdir /GPT [[email protected] ~]# mount /dev/sdc1 /GPT/ [[email protected] ~]#
功能 | 物理卷管理 | 卷组管理 | 逻辑卷管理 |
---|---|---|---|
scan 扫描 | pvsacn | vgscan | lvscan |
create 创建 | pvcreate | vgcreate | lvcreate |
display 显示 | pvdisplay | vgdisplay | lvdisplay |
remove 删除 | pvremove | vgremove | lvremove |
extend 扩展 | vgextenf | lvextend | |
reduce 减少 | vgreduce | lvreduce |
#卷组创建(创建卷组时分区不可格式化文件系统) [[email protected] ~]# vgcreate vg1 /dev/sdb1 /dev/sdc1 WARNING: xfs signature detected on /dev/sdb1 at offset 0. Wipe it? [y/n]: y Wiping xfs signature on /dev/sdb1. WARNING: xfs signature detected on /dev/sdc1 at offset 0. Wipe it? [y/n]: y Wiping xfs signature on /dev/sdc1. Physical volume "/dev/sdb1" successfully created. Physical volume "/dev/sdc1" successfully created. Volume group "vg1" successfully created [[email protected] ~]# #显示卷组信息 [[email protected] ~]# vgdisplay vg1 --- Volume group --- VG Name vg1 System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 2 Act PV 2 VG Size 14.99 GiB PE Size 4.00 MiB Total PE 3838 Alloc PE / Size 0 / 0 Free PE / Size 3838 / 14.99 GiB VG UUID F2FwwH-kycs-UOnT-4FBh-zQy1-vbSu-rUqAgY [[email protected] ~]# #简要显示卷组信息 [[email protected] ~]# vgs vg1 VG #PV #LV #SN Attr VSize VFree vg1 2 0 0 wz--n- 14.99g 14.99g [[email protected] ~]# #创建逻辑卷 [[email protected] ~]# lvcreate -L 10G -n lv1 vg1 Logical volume "lv1" created. [[email protected] ~]# #选项: -L 指定空间大小 -n 指定逻辑卷名 #查看逻辑卷信息 [[email protected] ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root centos -wi-ao---- <17.00g swap centos -wi-ao---- 2.00g lv1 vg1 -wi-a----- 10.00g [[email protected] ~]# lvs /dev/vg1/lv1 LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert lv1 vg1 -wi-a----- 10.00g [[email protected] ~]# #格式化逻辑卷 [[email protected] ~]# mkfs.xfs /dev/vg1/lv1 meta-data=/dev/vg1/lv1 isize=512 agcount=4, agsize=655360 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=2621440, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 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 [[email protected] ~]# #挂载逻辑卷 [email protected] ~]# mount /dev/vg1/lv1 /mybak/ [[email protected] ~]# df -h 文件系统 容量 已用 可用 已用% 挂载点 /dev/mapper/centos-root 17G 3.4G 14G 20% / devtmpfs 895M 0 895M 0% /dev tmpfs 911M 0 911M 0% /dev/shm tmpfs 911M 11M 901M 2% /run tmpfs 911M 0 911M 0% /sys/fs/cgroup /dev/sda1 1014M 170M 845M 17% /boot tmpfs 183M 12K 183M 1% /run/user/42 tmpfs 183M 0 183M 0% /run/user/0 /dev/mapper/vg1-lv1 10G 33M 10G 1% /mybak [[email protected] ~]# #逻辑卷扩容 [[email protected] ~]# lvextend -L +2G /dev/vg1/lv1 [卷组名] Size of logical volume vg1/lv1 changed from 10.00 GiB (2560 extents) to 12.00 GiB (3072 extents). Logical volume vg1/lv1 successfully resized. [[email protected] ~]# [[email protected] ~]# xfs_growfs /dev/vg1/lv1 #逻辑卷扩容后需要扩展文件系统才能使用 meta-data=/dev/mapper/vg1-lv1 isize=512 agcount=4, agsize=655360 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0 spinodes=0 data = bsize=4096 blocks=2621440, 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 2621440 to 3145728 [[email protected] ~]# #卷组扩容 [[email protected] ~]# vgextend vg1 /dev/sdc1 /dev/sdc2 Physical volume "/dev/sdc2" successfully created. WARNING: Device /dev/sdc1 has size of 8388608 sectors which is smaller than corresponding PV size of 10485760 sectors. Was device resized? Volume group "vg1" successfully extended [[email protected] ~]# vgs vg1 WARNING: Device /dev/sdc1 has size of 8388608 sectors which is smaller than corresponding PV size of 10485760 sectors. Was device resized? One or more devices used as PVs in VG vg1 have changed sizes. VG #PV #LV #SN Attr VSize VFree vg1 4 1 0 wz--n- 29.98g 14.98g #卷组减少物理卷 [[email protected] ~]# vgreduce vg1 /dev/sdc1 /dev/sdc2 WARNING: Device /dev/sdc1 has size of 8388608 sectors which is smaller than corresponding PV size of 10485760 sectors. Was device resized? One or more devices used as PVs in VG vg1 have changed sizes. Removed "/dev/sdc1" from volume group "vg1" Removed "/dev/sdc2" from volume group "vg1" #为根目录扩容 [[email protected] ~]# vgextend centos /dev/sdc1 /dev/sdc2 Volume group "centos" successfully extended [[email protected] ~]# vgs VG #PV #LV #SN Attr VSize VFree centos 3 2 0 wz--n- <27.99g 8.99g vg1 2 1 0 wz--n- 19.99g 4.99g [[email protected] ~]# df -Th 文件系统 类型 容量 已用 可用 已用% 挂载点 /dev/mapper/centos-root xfs 17G 3.4G 14G 20% / devtmpfs devtmpfs 895M 0 895M 0% /dev tmpfs tmpfs 911M 0 911M 0% /dev/shm tmpfs tmpfs 911M 11M 901M 2% /run tmpfs tmpfs 911M 0 911M 0% /sys/fs/cgroup /dev/sda1 xfs 1014M 170M 845M 17% /boot tmpfs tmpfs 183M 12K 183M 1% /run/user/42 tmpfs tmpfs 183M 0 183M 0% /run/user/0 /dev/mapper/vg1-lv1 xfs 15G 33M 15G 1% /mybak [[email protected] ~]# lvextend -L +5G /dev/mapper/ centos-root centos-swap vg1-lv1 [[email protected] ~]# lvextend -L +5G /dev/mapper/centos-root Size of logical volume centos/root changed from <17.00 GiB (4351 extents) to <22.00 GiB (5631 extents). Logical volume centos/root successfully resized. [[email protected] ~]# df -Th 文件系统 类型 容量 已用 可用 已用% 挂载点 /dev/mapper/centos-root xfs 17G 3.4G 14G 20% / devtmpfs devtmpfs 895M 0 895M 0% /dev tmpfs tmpfs 911M 0 911M 0% /dev/shm tmpfs tmpfs 911M 11M 901M 2% /run tmpfs tmpfs 911M 0 911M 0% /sys/fs/cgroup /dev/sda1 xfs 1014M 170M 845M 17% /boot tmpfs tmpfs 183M 12K 183M 1% /run/user/42 tmpfs tmpfs 183M 0 183M 0% /run/user/0 /dev/mapper/vg1-lv1 xfs 15G 33M 15G 1% /mybak [[email protected] ~]# 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 5766144 [[email protected] ~]# df -Th 文件系统 类型 容量 已用 可用 已用% 挂载点 /dev/mapper/centos-root xfs 22G 3.4G 19G 16% / devtmpfs devtmpfs 895M 0 895M 0% /dev tmpfs tmpfs 911M 0 911M 0% /dev/shm tmpfs tmpfs 911M 11M 901M 2% /run tmpfs tmpfs 911M 0 911M 0% /sys/fs/cgroup /dev/sda1 xfs 1014M 170M 845M 17% /boot tmpfs tmpfs 183M 12K 183M 1% /run/user/42 tmpfs tmpfs 183M 0 183M 0% /run/user/0 /dev/mapper/vg1-lv1 xfs 15G 33M 15G 1% /mybak [[email protected] ~]#