5 Linux 存储的基本管理 7.23

1 设备识别

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

设备文件名称:

SATA/SAS/USB      /dev/sda,/dev/sdb      ##s=SATA(硬盘), d=DISK a=第几块

IDE                            /dev/hd0,/dev/hd1      ##h=hard

VIRTIO-BLOCK       /dev/vda,/dev/vdb       ##v=virtio

M2(SSD)            /dev/nvme0,/dev/nvme1    ##nvme=m2

SD/MMCEMMC(卡)      /dev/mmcblk0,/dev/mmcblk1     ##mmcblk=mmc卡

光驱                          /dev/cdrom,/dev/sr0./dev/sr1

设备查看

fdisk -l                  ##查看磁盘分区情况(看到的最全的)

lsblk                     ##设备使用情况

blkid                      ##设备管理方式及设备id

df               df -H    df -h           ##查看正在被系统挂载的设备

cat /proc/partitions        ##查看系统识别设备

 磁盘进行分盘

搭建实验环境 搭建一个虚拟机(重置虚拟机进行网络配置)真机下连接虚拟机

进行分盘
[root@westoslinux ~]# cat /proc/partitions   ##分盘前查看磁盘分区情况
major minor  #blocks  name

 253        0   20971520 vda
 253        1    1048576 vda1
 253        2    2097152 vda2
 253        3   17824768 vda3

[root@dhcp_server ~]# virt-manager  ##切换至真机进行分盘

[root@westoslinux ~]# cat /proc/partitions  ##切换至真机下的虚拟机进行查看磁盘分区情况
major minor  #blocks  name

 253        0   20971520 vda
 253        1    1048576 vda1
 253        2    2097152 vda2
 253        3   17824768 vda3
 253       16    5242880 vdb

cat /proc/partitions   查看硬盘

虚拟机reset 
新建ip 
  nmcli  connection   reload 
  nmcli connection  up ens3
  nmcli connection show   查看网卡
真机 切换root超级用户  
virt-manager  打开虚拟机设置

fdisk -l ##查看磁盘分区情况
lsblk    ##设备使用情况
blkid    ##设备管理方式及设备id
df      ##查看正在被系统挂载的设备
cat /proc/partitions  ##查看系统识别设备
df -h     df -H


[root@westoslinux ~]# fdisk -l      ##查看磁盘分区情况
Disk /dev/vda: 20 GiB, 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
Disklabel type: dos
Disk identifier: 0x34fd8722

Device     Boot   Start      End  Sectors Size Id Type
/dev/vda1  *       2048  2099199  2097152   1G 83 Linux
/dev/vda2       2099200  6293503  4194304   2G 82 Linux swap / Solaris
/dev/vda3       6293504 41943039 35649536  17G 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@westoslinux ~]# lsblk        ##设备使用情况
NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda    253:0    0  20G  0 disk 
├─vda1 253:1    0   1G  0 part /boot
├─vda2 253:2    0   2G  0 part [SWAP]
└─vda3 253:3    0  17G  0 part /
vdb    253:16   0   5G  0 disk 

[root@westoslinux ~]#  blkid     ##设备管理方式及设备id
/dev/vda1: UUID="5640a252-d218-4377-917b-f7857918682a" TYPE="xfs" PARTUUID="34fd8722-01"
/dev/vda2: UUID="e79a5f1b-345e-4f76-be18-3f0a069fc81c" TYPE="swap" PARTUUID="34fd8722-02"
/dev/vda3: UUID="62f69d75-abe0-4c6b-a59c-dd69b6f80965" TYPE="xfs" PARTUUID="34fd8722-03"


[root@westoslinux ~]# cat /proc/partitions       ##查看系统识别设备
major minor  #blocks  name

 253        0   20971520 vda
 253        1    1048576 vda1
 253        2    2097152 vda2
 253        3   17824768 vda3
 253       16    5242880 vdb


[root@westoslinux ~]# df      ##查看正在被系统挂载的设备
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs          403532       0    403532   0% /dev
tmpfs             419132       0    419132   0% /dev/shm
tmpfs             419132    6672    412460   2% /run
tmpfs             419132       0    419132   0% /sys/fs/cgroup
/dev/vda3       17814528 3325008  14489520  19% /
/dev/vda1        1038336  173172    865164  17% /boot
tmpfs              83824    1180     82644   2% /run/user/42
tmpfs              83824      32     83792   1% /run/user/0


[root@westoslinux ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        395M     0  395M   0% /dev
tmpfs           410M     0  410M   0% /dev/shm
tmpfs           410M  6.6M  403M   2% /run
tmpfs           410M     0  410M   0% /sys/fs/cgroup
/dev/vda3        17G  3.2G   14G  19% /
/dev/vda1      1014M  170M  845M  17% /boot
tmpfs            82M  1.2M   81M   2% /run/user/42
tmpfs            82M   32K   82M   1% /run/user/0


[root@westoslinux ~]# df -H
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        414M     0  414M   0% /dev
tmpfs           430M     0  430M   0% /dev/shm
tmpfs           430M  6.9M  423M   2% /run
tmpfs           430M     0  430M   0% /sys/fs/cgroup
/dev/vda3        19G  3.5G   15G  19% /
/dev/vda1       1.1G  178M  886M  17% /boot
tmpfs            86M  1.3M   85M   2% /run/user/42
tmpfs            86M   33k   86M   1% /run/user/0

2  设备挂载

设备临时挂载

在系统中有设备id的设备是可以被系统使用的

挂载命令:

mount    -o   挂载参数     device  挂载地址

umount               设备 | 挂载点

mount                                                                  ##查看挂载参数

mount -o rw /dev/vda1   /westos                

mount -o remount,ro /westos                               ##转换挂载参数  由rw变为r

在卸载时出现正忙:

fuser -Kvm  设备 | 挂载点                                 ## -K 结束进程,-v 现实详细信息, -m 显示进

“注意:以上设备挂载都是临时挂载”

  临时挂载

  108  mount -o rw /dev/sda1 /mnt   ##挂载u盘到 /mnt/,并指定权限dw
  109  cd /mnt
  110  ls
  111  cd ~112  umount /mnt                 ##卸载时若显示系统繁忙,则进行查看还在运行进程
  117  lsof /dev/sda1                       ##查看还在运行进程        
  119  fuser -Kvm /dev/sda1                 ##查看还在运行进程 并结束进程
  120  umount /mnt                          ##再次卸载

    3 设备中文件的查找

find

        -name

         -user

        -group

        -type    f    d    s    b    l

        -perm 222  (必须是)  /222(有一个满足就可)   -222(都得有)

        -exec

        -maxdepth  1

         -mindepth   1

         -cmin   1    +1    -1

         -size    +1  -1     1M

          -o   #或者

           -a    #所有

           -not   # 不是它

[root@westoslinux mnt]# touch westosfile{1..5}
[root@westoslinux mnt]# ls
westosfile1  westosfile2  westosfile3  westosfile4  westosfile5
[root@westoslinux mnt]# ls -l
total 0
-rw-r--r--. 1 root root 0 Jul 23 11:13 westosfile1
-rw-r--r--. 1 root root 0 Jul 23 11:13 westosfile2
-rw-r--r--. 1 root root 0 Jul 23 11:13 westosfile3
-rw-r--r--. 1 root root 0 Jul 23 11:13 westosfile4
-rw-r--r--. 1 root root 0 Jul 23 11:13 westosfile5
[root@westoslinux mnt]# mkdir westosdir 
[root@westoslinux mnt]# ls -l
total 0
drwxr-xr-x. 2 root root 6 Jul 23 11:14 westosdir
-rw-r--r--. 1 root root 0 Jul 23 11:13 westosfile1
-rw-r--r--. 1 root root 0 Jul 23 11:13 westosfile2
-rw-r--r--. 1 root root 0 Jul 23 11:13 westosfile3
-rw-r--r--. 1 root root 0 Jul 23 11:13 westosfile4
-rw-r--r--. 1 root root 0 Jul 23 11:13 westosfile5
[root@westoslinux mnt]# useradd lee
[root@westoslinux mnt]# chown westos.lee westosfile1
[root@westoslinux mnt]# chown westos.westos westosfile2
[root@westoslinux mnt]# chown lee.westos westosfile3
[root@westoslinux mnt]# chown lee.lee westosfile4
[root@westoslinux mnt]# ls -l
total 0
drwxr-xr-x. 2 root   root   6 Jul 23 11:14 westosdir
-rw-r--r--. 1 westos lee    0 Jul 23 11:13 westosfile1
-rw-r--r--. 1 westos westos 0 Jul 23 11:13 westosfile2
-rw-r--r--. 1 lee    westos 0 Jul 23 11:13 westosfile3
-rw-r--r--. 1 lee    lee    0 Jul 23 11:13 westosfile4
-rw-r--r--. 1 root   root   0 Jul 23 11:13 westosfile5
[root@westoslinux mnt]# find /mnt -user lee
/mnt/westosfile3
/mnt/westosfile4
[root@westoslinux mnt]# find /mnt -user lee -o -user westos
/mnt/westosfile1
/mnt/westosfile2
/mnt/westosfile3
/mnt/westosfile4
[root@westoslinux mnt]# find /mnt -user lee -group westos
/mnt/westosfile3
[root@westoslinux mnt]# find /mnt -user lee -not  -group westos   ##不是它的组

 

###################################################################################
-maxdepth 对大查看几层     -mindepth  最少几层

[root@westoslinux mnt]# find /mnt -maxdepth 1 -name westosfile1  ##查看1层
/mnt/westosfile1
[root@westoslinux mnt]# find /mnt -maxdepth 2 -name westosfile1   ##查看2层
/mnt/westosfile1
/mnt/westosdir/westosfile1

[root@westoslinux mnt]# find /mnt  -mindepth 2 -maxdepth 2 -name westosfile1  ##最大查看和最小2层
/mnt/westosdir/westosfile1

########################################################################
-size -20M +20M  ##内容大小

[root@westoslinux mnt]# dd if=/dev/zero of=/mnt/westosfile1 bs=1M count=10
10+0 records in
10+0 records out
10485760 bytes (10 MB, 10 MiB) copied, 0.00948289 s, 1.1 GB/s
[root@westoslinux 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.0197436 s, 1.1 GB/s
[root@westoslinux 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.0483176 s, 651 MB/s
[root@westoslinux mnt]# find /mnt -size 20M
/mnt/westosfile2
[root@westoslinux mnt]# find /mnt -size -20M
/mnt
/mnt/westosfile1
/mnt/westosfile4
/mnt/westosfile5
/mnt/westosdir
/mnt/westosdir/westosfile1
[root@westoslinux mnt]# find /mnt -size +20M
/mnt/westosfile3
##################################################################################

-cmin 分钟      -1 小于1分钟的内容    +1大于1分钟的内容

[root@westoslinux mnt]# touch westosfile6
[root@westoslinux mnt]# find /mnt -cmin 1
/mnt
/mnt/westosfile6
[root@westoslinux mnt]# find /mnt -cmin -1
/mnt
/mnt/westosfile6
[root@westoslinux mnt]# find /mnt -cmin +1
/mnt/westosfile1
/mnt/westosfile2
/mnt/westosfile3
/mnt/westosfile4
/mnt/westosfile5
/mnt/westosdir
/mnt/westosdir/westosfile1
#########################################################################

-perm 权限 -444 必须满足r只读权限    /444  u g o 中任意一个满足权限就可以

drwxr-xr-x. 2 root   root         25 Jul 23 11:27 westosdir
-rw-r--r--. 1 westos lee    10485760 Jul 23 11:37 westosfile1
-rw-r--r--. 1 westos westos 20971520 Jul 23 11:37 westosfile2
-rw-r--r--. 1 lee    westos 31457280 Jul 23 11:37 westosfile3
-rw-r--r--. 1 lee    lee           0 Jul 23 11:13 westosfile4
-rw-r--r--. 1 root   root          0 Jul 23 11:13 westosfile5
-rw-r--r--. 1 root   root          0 Jul 23 11:40 westosfile6


[root@westoslinux mnt]# chmod o-r westosfile1
[root@westoslinux mnt]# chmod g-r westosfile2
[root@westoslinux mnt]# ll
total 61440
drwxr-xr-x. 2 root   root         25 Jul 23 11:27 westosdir
-rw-r-----. 1 westos lee    10485760 Jul 23 11:37 westosfile1
-rw----r--. 1 westos westos 20971520 Jul 23 11:37 westosfile2
-rw-r--r--. 1 lee    westos 31457280 Jul 23 11:37 westosfile3
-rw-r--r--. 1 lee    lee           0 Jul 23 11:13 westosfile4
-rw-r--r--. 1 root   root          0 Jul 23 11:13 westosfile5
-rw-r--r--. 1 root   root          0 Jul 23 11:40 westosfile6

[root@westoslinux mnt]# find /mnt -perm -444
/mnt
/mnt/westosfile3
/mnt/westosfile4
/mnt/westosfile5
/mnt/westosdir
/mnt/westosdir/westosfile1
/mnt/westosfile6
[root@westoslinux mnt]# find /mnt -perm /444
/mnt
/mnt/westosfile1
/mnt/westosfile2
/mnt/westosfile3
/mnt/westosfile4
/mnt/westosfile5
/mnt/westosdir
/mnt/westosdir/westosfile1
/mnt/westosfile6
####################################################################
   -exec 执行的意思
[root@westoslinux mnt]# chmod 777 westosfile6   ##权限全部打开

[root@westoslinux mnt]# find /mnt -perm -002 -exec chmod o-w {} \;   ##查找-002权限的文件 进行更改
[root@westoslinux mnt]# ll
total 61440
drwxr-xr-x. 2 root   root         25 Jul 23 11:27 westosdir
-rw-r-----. 1 westos lee    10485760 Jul 23 11:37 westosfile1
-rw----r--. 1 westos westos 20971520 Jul 23 11:37 westosfile2
-rw-r--r--. 1 lee    westos 31457280 Jul 23 11:37 westosfile3
-rw-r--r--. 1 lee    lee           0 Jul 23 11:13 westosfile4
-rw-r--r--. 1 root   root          0 Jul 23 11:13 westosfile5
-rwxrwxr-x. 1 root   root          0 Jul 23 11:40 westosfile6
#######################################################################################

udevadm settle     同步分区     -K不对空的格式化处理

#4.分区#

#MBR分区方式:##
主分区
主分区表记录分区的信息并可以直接使用的分区
扩展分区
主分区表记录的分区,不可直接使用,只是逻辑分区容器
逻辑分区
扩展分区之上划分的分区叫做逻辑分区
#分区方法#
ot@rhel8_node1 mnt]# fdisk
/dev/sdb
Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x4018d2a4.

Command (m for help): m        ##获得帮助
d        ##删除
l        ##列出所有分区类型
n        ##新建
p        ##显示分区表
t        ##更改分区类型
w        ##保存更改
q        ##退出
g        ##设定分区方式为GPT
o        ##设定分区方式为mbr

Command (m for help):         n#新建
Partition type
p primary (0 primary, 0 extended, 4 free)        ##主分区

e extended (container for logical partitions)        ##扩展分区

Select (default p): p        ##建立主分区
Partition number (1-4, default 1):1        ##分区表位置
First sector (2048-20971519, default 2048):        ##分区起始位置推荐使用默认
Last sector, +sectors or +size{K,M,G,T,P} (2048-20971519, default 20971519): +100M        ##分区结束
位置
Command (m for help):wq        ##退出保存,如果直接q表示退出不保存
udevadm settle        ##同步分区表
mkfs.xfs -K /dev/sdb1        ##格式化设备为xfs文件系统(相当与在/dev/sda1上安装设备管理软件)
                                                ##-K 不丢弃空数据块
mount /dev/sdb1 /mnt/westos        ##mount命令挂在为临时挂在,如果需要永久挂在需要编写/etc

 #parted#

parted /dev/vdb mklabel msdos
parted /dev/vdb mkpart primary 1 100
parted /dev/vdb rm 2

#常用文件系统对比#

#####设备删除######

dd if=/dev/zero of=/dev/sdb bs=1M count=1

#mbr分区方式转换成GPT#

parted /dev/sda
(parted) mklabel
New disk label type? gpt
Warning: The existing disk label on /dev/sda will be destroyed and all data on this disk will be
lost.
Do you want to continue?
Yes/No? yes
(parted) quit

在RHEL8中可以直接使用fdisk /dev/sdb

g        ##g表示把/dev/sdb设备的分区方式调整为GPT

5.swap分区

作用:
程序在运行时所有数据是在RAM
当RAM使用量超过了限额
为了使系统更加稳定
我们在硬盘上划分一部分空间来作内存缓冲区swap
当内存使用超过限额,内核会把内存中闲置的数据存放到swap中
当程序需要swap分区中的数据时内核将swap分区中的数据在交还给内存进程处理

swap分区大小建议:
内存大小        swap分区建议大小        当允许HIBERNATE

2GiB以下                内存两倍                               内存3倍
2-8GiB                        等于物理内存                      物理内存2倍
8-64GiB                        4GiB                                   1.5倍物理内存
64GiB以上                   4GiB                                    HIBERNATE不开

swap管理
swapon -s       ##查看swap分区信息
创建swap分区
创建分区并设定分区的类型为Linuxswap

6.磁盘配额#

作用:
设定用户能写入指定设备的最大额度

设定方法:
mount /dev/sda1 /pub/ -o usrquota        ##挂载设备并激活配额参数
quotaon -uv /dev/sda1        ##激活配额
edquota -u lee        ##设定用户lee配额
Disk quotas for user lee (uid 1001):

永久开启配额
vim /etc/fstab
/dev/sda1        /pub        xfs        defaults,usrquota 0 0

测试:
su - lee
cd /pub
dd if=/dev/zero of=/pub/leefile bs=1M count=22 ##截取数据失败只能写入20M数据

关闭配额:
quotaoff -uv /dev/sda1
vim /etc/fstab ##去掉配额参数usrquota

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值