Linux中的存储设备管理(设备识别,挂载,分区,磁盘配额)

本文详细介绍了Linux系统中如何管理存储设备,包括设备名称识别、查看命令如fdisk和lsblk,设备挂载与卸载操作,磁盘分区(MBR类型),文件系统的部署,swap分区的作用,以及磁盘配额的设置,帮助读者全面理解Linux存储管理。
摘要由CSDN通过智能技术生成

1、设备名称的识别

find 参数
-name 名字
-user 用户
-group
-type 类型 f:文件 l:符号连接 d:目录 c:字符设备 b:块设备 s:套接字
exec 执行
-maxdepth 最大深度
-mindepth 最小深度
-cmin 最近更改的文件 1 :1分钟, +1:大于1分钟, -1:1分钟之内
-o 或者
-a 而且
not 相反
size 大小

实验环境:

[root@node1 mnt]# useradd lee
[root@node1 mnt]# chown westos.lee westosfile1
[root@node1 mnt]# chown westos.westos westosfile2
[root@node1 mnt]# chown lee.lee westosfile3
[root@node1 mnt]# ll
total 0
-rw-r--r--. 1 westos lee    0 Oct 18 14:39 westosfile1
-rw-r--r--. 1 westos westos 0 Oct 18 14:39 westosfile2
-rw-r--r--. 1 lee    lee    0 Oct 18 14:39 westosfile3
-rw-r--r--. 1 root   root   0 Oct 18 14:39 westosfile4
-rw-r--r--. 1 root   root   0 Oct 18 14:39 westosfile5

实验:

[root@node1 mnt]# find /mnt/ -name "*westos*"  查找文件
/mnt/westosfile1
/mnt/westosfile2
/mnt/westosfile3
/mnt/westosfile4
/mnt/westosfile5
[root@node1 mnt]# mkdir westosdir  
[root@node1 mnt]# touch westosdir/westosfile1
[root@node1 mnt]# find /mnt/ -name westosfile1  查找目录里面的,和子目录里面的文件都能查找到
/mnt/westosfile1
/mnt/westosdir/westosfile1
[root@node1 mnt]# find /mnt/ -maxdepth 1 -name westosfile1   最大深度为1层
/mnt/westosfile1
[root@node1 mnt]# find /mnt/ -maxdepth 2 -name westosfile1 最大深度为2层
/mnt/westosfile1
/mnt/westosdir/westosfile1
[root@node1 mnt]# find /mnt/ -mindepth 2 -maxdepth 2 -name westosfile1 指定第2层
/mnt/westosdir/westosfile1
[root@node1 mnt]# find /mnt/ -type f  查看文件
/mnt/westosfile1
/mnt/westosfile2
/mnt/westosfile3
/mnt/westosfile4
/mnt/westosfile5
/mnt/westosdir/westosfile1
[root@node1 mnt]# find /mnt/ -type d 查看目录
/mnt/
/mnt/westosdir
[root@node1 mnt]# find /mnt/ -user lee 查看用户
/mnt/westosfile3
[root@node1 mnt]# find /mnt/ -user lee -o -user westos  -o表示或者 ,查询多个用户文件
/mnt/westosfile1
/mnt/westosfile2
/mnt/westosfile3
[root@node1 mnt]# find /mnt/ -user lee -a -user lee   -a 表示并且 ,-a也可以不加
/mnt/westosfile3
[root@node1 mnt]# find /mnt/ -user westos  -group westos  用户和组都是westos
/mnt/westosfile2
[root@node1 mnt]# find /mnt/ -user westos  -not -group westos  用户是westos,组不是westos
/mnt/westosfile1

用文件大小查找文件

制作指定文件大小

[root@node1 mnt]# dd if=/dev/zero of=/mnt/westosfile1 bs=1M count=10  bs 表示拷贝块的大小 ,count表示有多少块,dd:用指定大小的块拷贝一个文件 if=模板文件
10+0 records in
10+0 records out
10485760 bytes (10 MB, 10 MiB) copied, 0.0484184 s, 217 MB/s
[root@node1 mnt]# dd if=/dev/zero of=/mnt/westosfile2 bs=1M count=20
20+0 records in
20+0 records out
20971520 bytes (21 MB, 20 MiB) copied, 0.0120816 s, 1.7 GB/s
[root@node1 mnt]# dd if=/dev/zero of=/mnt/westosfile3 bs=1M count=30
30+0 records in
30+0 records out
31457280 bytes (31 MB, 30 MiB) copied, 0.0175175 s, 1.8 GB/s
[root@node1 mnt]# du -sh westosfile1
10M	westosfile1
[root@node1 mnt]# du -sh westosfile2
20M	westosfile2
[root@node1 mnt]# du -sh westosfile3
30M	westosfile3
[root@node1 mnt]# find /mnt/ -size 20M  等于20M
/mnt/westosfile2
[root@node1 mnt]# find /mnt/ -size -20M  小于20M
/mnt/
/mnt/westosfile1
/mnt/westosfile4
/mnt/westosfile5
/mnt/westosdir
/mnt/westosdir/westosfile1
[root@node1 mnt]# find /mnt/ -size +20M 大与20M
/mnt/westosfile3

时间查找文件

[root@node1 mnt]# touch westosfile6
[root@node1 mnt]# find /mnt/ -cmin 1 分钟
/mnt/
/mnt/westosfile6
[root@node1 mnt]# find /mnt/ -cmin -1 1分钟以内的
/mnt/
/mnt/westosfile6
[root@node1 mnt]# find /mnt/ -cmin +1 大于1分钟的
/mnt/westosfile1
/mnt/westosfile2
/mnt/westosfile3
/mnt/westosfile4
/mnt/westosfile5
/mnt/westosdir
/mnt/westosdir/westosfile1

权限查找文件

[root@node1 mnt]# chmod g-r /mnt/westosfile2 
[root@node1 mnt]# chmod o-r /mnt/westosfile3 
[root@node1 mnt]# ll
total 61440
drwxr-xr-x. 2 root   root         25 Oct 18 15:12 westosdir
-rw-r--r--. 1 westos lee    10485760 Oct 18 16:41 westosfile1
-rw----r--. 1 westos westos 20971520 Oct 18 16:41 westosfile2
-rw-r-----. 1 lee    lee    31457280 Oct 18 16:41 westosfile3
-rw-r--r--. 1 root   root          0 Oct 18 14:39 westosfile4
-rw-r--r--. 1 root   root          0 Oct 18 14:39 westosfile5
-r-r--r--. 1 root   root          0 Oct 18 17:12 westosfile6
[root@node1 mnt]# find /mnt/ -perm 444  表示u位,g位,o位都必须只是r权限
/mnt/westosfile6
[root@node1 mnt]# find /mnt/ -perm -444  -444表示u 位,g位,o位都开启r权限
/mnt/
/mnt/westosfile1
/mnt/westosfile4
/mnt/westosfile5
/mnt/westosdir
/mnt/westosdir/westosfile1
/mnt/westosfile6
[root@node1 mnt]# find /mnt/ -perm /444  /444表示u位或者g位或者o位开启了r权限
/mnt/
/mnt/westosfile1
/mnt/westosfile2
/mnt/westosfile3
/mnt/westosfile4
/mnt/westosfile5
/mnt/westosdir
/mnt/westosdir/westosfile1
/mnt/westosfile6
[root@node1 mnt]# find /mnt/ -perm /755  总共7个条件 rwxr-xr-x 或的关系
/mnt/
/mnt/westosfile1
/mnt/westosfile2
/mnt/westosfile3
/mnt/westosfile4
/mnt/westosfile5
/mnt/westosdir
/mnt/westosdir/westosfile1
/mnt/westosfile6
[root@node1 mnt]# find /mnt/ -perm /777  总管9个条件
/mnt/
/mnt/westosfile1
/mnt/westosfile2
/mnt/westosfile3
/mnt/westosfile4
/mnt/westosfile5
/mnt/westosdir
/mnt/westosdir/westosfile1
/mnt/westosfile6
[root@node1 mnt]# find /mnt/ -perm -002 表示o位有写的权限
[root@node1 mnt]# chmod 777 westosfile5 
[root@node1 mnt]# ll
-rwxrwxrwx. 1 root   root          0 Oct 18 14:39 westosfile5
[root@node1 mnt]# find /mnt/ -perm -002 -exec chmod u-w {} \;   \表示转译符 注释分号的作用  ,-exec表示可以执行的动作
[root@node1 mnt]# find /mnt/ -name \*westos\* -exec rm -fr {} \;  删除带有westos的文件;  {}表示find命令查找的结果
find: ‘/mnt/westosdir’: No such file or directory

2、设备的查看命令

设备接入系统后都是以文件的形式存在

设备名称 #######
SATA/SAS/USB /dev/sda,/dev/sdb s=STAT ,d=DISK ,a=第几块
IDE /dev/hd0,/dev/hsd1 ##h=hard
VIRTIO-BLOCK /dev/vda, /dev/vdb #v=virtio
M2 (SSD) /dev/nvme0,.dev/nvme1 #nvme=m2
SD/MMC/EMMC(卡) /dev/mmcblk0,/dev/mmcblk1 # mmcblk=mmc卡
光驱 /dev/cdrom,/dev/sr0,/dev/sr1

2.1设备查看

fdisk -l :查看磁盘分区情况 (真实存在的设备)
lsblk:设备使用情况
blkid:设备管理方式及设备id
df:查看正在被系统挂载的设备
cat /proc/partitions:查看系统识别设备 (系统识别的设备与系统识别的设备存在差异,没有uuid。无驱动,需要被提醒,)

[root@node1 mnt]# fdisk -l  查看磁盘分区情况 
Disk /dev/vda: 8 GiB, 8589934592 bytes, 16777216 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
Disklabel type: dos
Disk identifier: 0x657e7edc

Device     Boot   Start      End  Sectors  Size Id Type
/dev/vda1  *       2048  1026047  1024000  500M 83 Linux
/dev/vda2       1026048  2050047  1024000  500M 82 Linux swap / Solaris
/dev/vda3       2050048 16777215 14727168    7G 83 Linux


Disk /dev/vdb: 5 GiB, 5368709120 bytes, 10485760 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
[root@node1 mnt]# lsblk   查看系统中识别设备
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
vda    253:0    0    8G  0 disk 
├─vda1 253:1    0  500M  0 part /boot
├─vda2 253:2    0  500M  0 part [SWAP]
└─vda3 253:3    0    7G  0 part /
vdb    253:16   0    5G  0 disk 
[root@node1 mnt]# lsblk 
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
vda    253:0    0    8G  0 disk 
├─vda1 253:1    0  500M  0 part /boot
├─vda2 253:2    0  500M  0 part [SWAP]
└─vda3 253:3    0    7G  0 part /
vdb    253:16   0    5G  0 disk 
[root@node1 mnt]# cat /proc/partitions 查看系统中识别设备
major minor  #blocks  name

 253        0    8388608 vda
 253        1     512000 vda1
 253        2     512000 vda2
 253        3    7363584 vda3
 253       16    5242880 vdb
[root@node1 mnt]# df  系统中被使用挂载的设备
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs          907424       0    907424   0% /dev
tmpfs             935220       0    935220   0% /dev/shm
tmpfs             935220    9336    925884   1% /run
tmpfs             935220       0    935220   0% /sys/fs/cgroup
/dev/vda3        7353344 4372764   2980580  60% /
/dev/vda1         506528  218600    287928  44% /boot
tmpfs             187044    1180    185864   1% /run/user/42
tmpfs             187044       4    187040   1% /run/user/0
[root&
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小莫细说linux

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值