Chapter IX disk storage and file system management

Keywords: Linux Operation & Maintenance architecture DevOps Cloud Native

2.3 mount

Mount: the act of associating an additional file system with an existing directory in the root file system, so that this directory can be used as an access to other files

Uninstall: the process of releasing this association

Associate a device with a mount Point: mount Point

The original files under the mount point will be temporarily hidden after mounting. Therefore, the directory of the mount point is generally empty

The device in use by the process cannot be uninstalled

2.3.1 mount file system

Format:

mount [-fnrsvw] [-t vfstype] [-o options] device mountpoint

Device: indicates the device to mount

  • Device file: for example: / dev/sda5
  • Volume LABEL: - L 'LABEL', e.g. - L 'MYDATA'
  • UUID: - U 'UUID': for example - U '0c50523c-43f1-45e7-85c0-a126711d406e'
  • Pseudo file system name: proc, sysfs, devtmpfs, configfs

**mountpoint: * * the mount point directory must exist in advance. It is recommended to use an empty directory

mount common command options

-t fstype Specifies the file system type on the device to mount,as:ext4,xfs
-r readonly,Read only mount
-w read and write, Read write mount
-n Do not update/etc/mtab,mount invisible
-a Auto mount all devices that support auto mount(Defined in/etc/fstab In the file and in the mount option
auto function)
-L 'LABEL' Specify the mount device with the volume label
-U 'UUID' with UUID Specify the device to mount
-B, --bind Bind directory to another directory

-o options: (Options for mounting file systems),Multiple options are separated by commas
    async Asynchronous mode,When memory changes,Write cache buffer,Writing to disk after a period of time is efficient but not safe
    sync Synchronous mode,When the memory changes, write to the disk at the same time, which is safe but inefficient
    atime/noatime Contains directories and files
    diratime/nodiratime Access timestamp of the directory
    auto/noauto Whether it supports automatic mount after startup, and whether it supports-a option
    exec/noexec Does it support running applications on the file system
    dev/nodev Are device files supported on this file system
    suid/nosuid Is it supported suid and sgid jurisdiction
    remount Remount
    ro/rw Read only, read-write
    user/nouser Allow ordinary users to mount this device,/etc/fstab use
    acl/noacl Enable on this file system acl function
    loop use loop equipment
    _netdev Mount network resources only when the network is available, such as: NFS file system
    defaults amount to rw, suid, dev, exec, auto, nouser, async

Mounting rules:

  • A mount point can mount only one device at a time
  • If multiple devices are mounted on a mount point at the same time, only the data of the last device can be seen, and the data on other devices will be hidden
  • A device can be mounted to multiple mount points at the same time
  • Generally, the mount point is an empty directory that already exists

2.3.2 unmount the file system umount

When uninstalling: you can use the device or the mount point

umount Device name|Mount point

2.3.3 viewing mounting

View mount

#Display all currently mounted devices by viewing the / etc/mtab file
mount
#View all mounted devices tracked by the kernel
cat /proc/mounts

View the mount point

findmnt MOUNT_POINT|device

View the processes that are accessing the specified file system

lsof MOUNT_POINT
fuser -v MOUNT_POINT

Terminates all processes that are accessing the specified file system

fuser -km MOUNT_POINT

2.3.4 persistent mount

Save the mount in / etc/fstab to enable the mount automatically the next time you power on

/Help in etc/fstab format:

man 5 fstab

Each line defines a file system to mount, including 6 items in total

  • Device or pseudo file system to mount
    Equipment file
    LABEL: LABEL=""
    UUID: UUID=""
    Pseudo file system name: proc, sysfs
  • Mount point: must be a pre-existing directory
  • File system type: ext4, xfs, iso9660, nfs, none
  • Mount options: defaults, acl, bind
  • Dump frequency: 0: no backup 1: dump every day 2: dump every other day
  • fsck checks the order of file systems: the allowed numbers are 0 1 2
    0: no self inspection, 1: self inspection first; Generally, only rootfs is used. 2: non rootfs is used

To add a new mount item, you need to execute the following command to take effect

mount -a

example:

[root@rocky8 ~]#  mkdir /mnt/sdb{1,2}
[root@rocky8 ~]# ls /mnt
sdb1  sdb2
[root@rocky8 ~]# ls /mnt/sdb1
[root@rocky8 ~]# touch /mnt/sdb1/sdb1.txt
[root@rocky8 ~]# touch /mnt/sdb2/sdb2.txt
/mnt
├── sdb1
│   └── sdb1.txt
└── sdb2
    └── sdb2.txt

2 directories, 2 files

[root@rocky8 ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs          382688       0    382688   0% /dev
tmpfs             400580       0    400580   0% /dev/shm
tmpfs             400580    5744    394836   2% /run
tmpfs             400580       0    400580   0% /sys/fs/cgroup
/dev/sda2      104806400 2633816 102172584   3% /
/dev/sda3       52403200  398404  52004796   1% /data
/dev/sda1        1038336  191796    846540  19% /boot
tmpfs              80116       0     80116   0% /run/user/0
/dev/sdb2        2086912   47636   2039276   3% /mnt
[root@rocky8 ~]# touch /mnt/sdb1/sdb1-2.txt
[root@rocky8 ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs          382688       0    382688   0% /dev
tmpfs             400580       0    400580   0% /dev/shm
tmpfs             400580    5744    394836   2% /run
tmpfs             400580       0    400580   0% /sys/fs/cgroup
/dev/sda2      104806400 2633816 102172584   3% /  
/dev/sda3       52403200  398404  52004796   1% /data
/dev/sda1        1038336  191796    846540  19% /boot
tmpfs              80116       0     80116   0% /run/user/0
/dev/sdb2        2086912   47636   2039276   3% /mnt #The first file created, used, is still 47636 

[root@rocky8 ~]# touch /mnt/sdb1/sdb1-3.txt
[root@rocky8 ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs          382688       0    382688   0% /dev
tmpfs             400580       0    400580   0% /dev/shm
tmpfs             400580    5744    394836   2% /run
tmpfs             400580       0    400580   0% /sys/fs/cgroup
/dev/sda2      104806400 2633816 102172584   3% /  
/dev/sda3       52403200  398404  52004796   1% /data
/dev/sda1        1038336  191796    846540  19% /boot
tmpfs              80116       0     80116   0% /run/user/0
/dev/sdb2        2086912   47636   2039276   3% /mnt #The second file created, used, is still 47636 

[root@rocky8 ~]# ll /mnt/sdb1/*
-rw-r--r-- 1 root root 0 Oct 15 22:46 /mnt/sdb1/sdb1-2.txt
-rw-r--r-- 1 root root 0 Oct 15 22:48 /mnt/sdb1/sdb1-3.txt
-rw-r--r-- 1 root root 0 Oct 15 22:45 /mnt/sdb1/sdb1.txt
[root@rocky8 ~]# echo > /mnt/sdb1/sdb1-4.txt
[root@rocky8 ~]# ll /mnt/sdb1/sdb1-4.txt
-rw-r--r-- 1 root root 1 Oct 15 22:51 /mnt/sdb1/sdb1-4.txt

[root@rocky8 ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs          382688       0    382688   0% /dev
tmpfs             400580       0    400580   0% /dev/shm
tmpfs             400580    5744    394836   2% /run
tmpfs             400580       0    400580   0% /sys/fs/cgroup
/dev/sda2      104806400 2633816 102172584   3% /
/dev/sda3       52403200  398404  52004796   1% /data
/dev/sda1        1038336  191796    846540  19% /boot
tmpfs              80116       0     80116   0% /run/user/0
/dev/sdb2        2086912   47660   2039252   3% /mnt #Writing data to a file takes up 4k, because a file takes up a minimum of 4k

[root@rocky8 ~]# du /mnt/sdb1
4	/mnt/sdb1
[root@rocky8 ~]# echo > /mnt/sdb1/sdb1-5.txt
[root@rocky8 ~]# du /mnt/sdb1
8	/mnt/sdb1
#It takes 4k to create a new file

[root@rocky8 ~]# xfs_info /dev/sda2
meta-data=/dev/sda2              isize=512    agcount=4, agsize=6553600 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=26214400, imaxpct=25 #Block size 4096
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=12800, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

[root@rocky8 ~]# mount /dev/sdb1 /mnt/sdb1 #Mount mount
[root@rocky8 ~]# ls /mnt/sdb1
lost+found
#After mounting, the original data is invisible and hidden

[root@rocky8 ~]# echo > /mnt/sdb1/a.txt
[root@rocky8 ~]# echo > /mnt/sdb1/b.txt
[root@rocky8 ~]# ls /mnt/sdb1
a.txt  b.txt  lost+found
[root@rocky8 ~]# du -sh /mnt/sdb1
4.0K	/mnt/sdb1

[root@rocky8 ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs          382688       0    382688   0% /dev
tmpfs             400580       0    400580   0% /dev/shm
tmpfs             400580    5744    394836   2% /run
tmpfs             400580       0    400580   0% /sys/fs/cgroup
/dev/sda2      104806400 2633816 102172584   3% /
/dev/sda3       52403200  398404  52004796   1% /data
/dev/sda1        1038336  191796    846540  19% /boot
tmpfs              80116       0     80116   0% /run/user/0
/dev/sdb2        2086912   47644   2039268   3% /mnt
/dev/sdb1        1031836    2821    972491   1% /mnt/sdb1 #2821 disk space has been used

[root@rocky8 ~]# echo > /mnt/sdb1/c.txt
[root@rocky8 ~]# du -sh /mnt/sdb1
5.0K	/mnt/sdb1
[root@rocky8 ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs          382688       0    382688   0% /dev
tmpfs             400580       0    400580   0% /dev/shm
tmpfs             400580    5744    394836   2% /run
tmpfs             400580       0    400580   0% /sys/fs/cgroup
/dev/sda2      104806400 2633816 102172584   3% /
/dev/sda3       52403200  398404  52004796   1% /data
/dev/sda1        1038336  191796    846540  19% /boot
tmpfs              80116       0     80116   0% /run/user/0
/dev/sdb2        2086912   47644   2039268   3% /mnt
/dev/sdb1        1031836    2822    972490   1% /mnt/sdb1 #New files add 1k space

[root@rocky8 ~]# ls /mnt/sdb1/ -a
.  ..  a.txt  b.txt  c.txt  lost+found
[root@rocky8 ~]# umount /mnt/sdb1/
[root@rocky8 ~]# ls /mnt/sdb1/ -a
.  ..  sdb1-2.txt  sdb1-3.txt  sdb1-4.txt  sdb1-5.txt  sdb1.txt
#After uninstalling the partition mount, you can see the data on the original root partition

#As a mount point folder, the first folder must exist and the second folder should be an empty folder

[root@rocky8 ~]# ls /mnt/sdb2
sdb2.txt
[root@rocky8 ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs          382688       0    382688   0% /dev
tmpfs             400580       0    400580   0% /dev/shm
tmpfs             400580    5744    394836   2% /run
tmpfs             400580       0    400580   0% /sys/fs/cgroup
/dev/sda2      104806400 2633816 102172584   3% /
/dev/sda3       52403200  398404  52004796   1% /data
/dev/sda1        1038336  191796    846540  19% /boot
tmpfs              80116       0     80116   0% /run/user/0
/dev/sdb2        2086912   47644   2039268   3% /mnt
[root@rocky8 ~]# mount /dev/sdb2 /mnt/sdb2
[root@rocky8 ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs          382688       0    382688   0% /dev
tmpfs             400580       0    400580   0% /dev/shm
tmpfs             400580    5744    394836   2% /run
tmpfs             400580       0    400580   0% /sys/fs/cgroup
/dev/sda2      104806400 2633816 102172584   3% /
/dev/sda3       52403200  398404  52004796   1% /data
/dev/sda1        1038336  191796    846540  19% /boot
tmpfs              80116       0     80116   0% /run/user/0
/dev/sdb2        2086912   47644   2039268   3% /mnt
#As long as the partition is mounted, it can be seen with df

[root@rocky8 ~]# ls /mnt/sdb2
sdb1  sdb2
#xfs file system takes up more space than ext4 metadata

[root@rocky8 ~]# xfs_info /dev/sdb2
meta-data=/dev/sdb2              isize=512    agcount=4, agsize=131072 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=524288, 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
#df views data in 1k by default

[root@rocky8 ~]# ls /mnt/sdb2
sdb1  sdb2
[root@rocky8 ~]# echo > /mnt/sdb2/x.txt
[root@rocky8 ~]# ls /mnt/sdb2
sdb1  sdb2  x.txt
[root@rocky8 ~]# du -sh /mnt/sdb2
12K	/mnt/sdb2
[root@rocky8 ~]# echo > /mnt/sdb2/y.txt
[root@rocky8 ~]# du -sh /mnt/sdb2
16K	/mnt/sdb2

[root@rocky8 ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs          382688       0    382688   0% /dev
tmpfs             400580       0    400580   0% /dev/shm
tmpfs             400580    5744    394836   2% /run
tmpfs             400580       0    400580   0% /sys/fs/cgroup
/dev/sda2      104806400 2633816 102172584   3% /
/dev/sda3       52403200  398404  52004796   1% /data
/dev/sda1        1038336  191796    846540  19% /boot
tmpfs              80116       0     80116   0% /run/user/0
/dev/sdb2        2086912   47652   2039260   3% /mnt

[root@rocky8 ~]# mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
devtmpfs on /dev type devtmpfs (rw,nosuid,size=382688k,nr_inodes=95672,mode=755)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
bpf on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,relatime,mode=700)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpu,cpuacct)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/rdma type cgroup (rw,nosuid,nodev,noexec,relatime,rdma)
cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls,net_prio)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
none on /sys/kernel/tracing type tracefs (rw,relatime)
configfs on /sys/kernel/config type configfs (rw,relatime)
/dev/sda2 on / type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=2M)
mqueue on /dev/mqueue type mqueue (rw,relatime)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=37,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=22459)
fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime)
/dev/sda3 on /data type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
/dev/sda1 on /boot type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,size=80116k,mode=700)
/dev/sdb2 on /mnt type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
/dev/sdb2 on /mnt/sdb2 type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
#Mount can also view mount information

[root@rocky8 ~]# mount /dev/sdb1 /mnt/sdb2
[root@rocky8 ~]# ls /mnt/sdb2
a.txt  b.txt  c.txt  lost+found
#A directory can only mount one partition. If multiple partitions are mounted, the files in the original mounted partition will be hidden. You can't see them unless you uninstall the currently mounted partition

[root@rocky8 ~]# umount /mnt/sdb2
[root@rocky8 ~]# ls /mnt/sdb2
sdb1  sdb2  x.txt  y.txt
#Unloaded, the original is back

[root@rocky8 ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs          382688       0    382688   0% /dev
tmpfs             400580       0    400580   0% /dev/shm
tmpfs             400580    5744    394836   2% /run
tmpfs             400580       0    400580   0% /sys/fs/cgroup
/dev/sda2      104806400 2633816 102172584   3% /
/dev/sda3       52403200  398404  52004796   1% /data
/dev/sda1        1038336  191796    846540  19% /boot
tmpfs              80116       0     80116   0% /run/user/0
/dev/sdb2        2086912   47652   2039260   3% /mnt
[root@rocky8 ~]# mkdir /mnt/sdb2-2
[root@rocky8 ~]# mount /dev/sdb2 /mnt/sdb2-2
[root@rocky8 ~]# ls /mnt/sdb2-2
sdb1  sdb2  sdb2-2  x.txt  y.txt
#A partition can mount multiple mount points, but the data in it is the same

[root@rocky8 ~]# mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
devtmpfs on /dev type devtmpfs (rw,nosuid,size=382688k,nr_inodes=95672,mode=755)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
bpf on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,relatime,mode=700)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpu,cpuacct)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/rdma type cgroup (rw,nosuid,nodev,noexec,relatime,rdma)
cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls,net_prio)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
none on /sys/kernel/tracing type tracefs (rw,relatime)
configfs on /sys/kernel/config type configfs (rw,relatime)
/dev/sda2 on / type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=2M)
mqueue on /dev/mqueue type mqueue (rw,relatime)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=37,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=22459)
fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime)
/dev/sda3 on /data type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
/dev/sda1 on /boot type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,size=80116k,mode=700)
/dev/sdb2 on /mnt type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
/dev/sdb2 on /mnt/sdb2 type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
/dev/sdb2 on /mnt/sdb2-2 type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
#reltime delays updating the read time. Only when the read time reaches more than one day, or when the read time is older than the write time, can it be updated. Only when the file is added, can it appear that the read time is earlier than the modification time. Only at this time can the read time be updated

#You can add noatime and nodiratime when you mount it, and it will not update the read time, but if you touch the file, it will still update the read time

[root@rocky8 ~]# touch /mnt/sdb2/xx.txt
[root@rocky8 ~]# cd /mnt/sdb2
#If someone is accessing the directory
[root@rocky8 sdb2]# umount /mnt/sdb2
umount: /mnt/sdb2: target is busy.
#You cannot unmount the mounted partition now

[root@rocky8 sdb2]# fuser -v /mnt/sdb2 #fuser -v see who is accessing this directory
                     USER        PID ACCESS COMMAND
/mnt/sdb2:           root     kernel mount /mnt
                     root        917 ..c.. bash

[root@rocky8 sdb2]# fuser -mk /mnt/sdb2 #fuser -mk can force users using this directory out
/mnt/sdb2:             917c

Connection closed.

Disconnected from remote host(rocky8.4-172.31.1.8) at 23:07:17.

Type `help' to learn how to use Xshell prompt.
[C:\~]$ 
Reconnecting in 1 seconds. Press any key to exit local shell.
.

Connecting to 172.31.1.8:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.

WARNING! The remote SSH server rejected X11 forwarding request.
Last login: Fri Oct 15 19:09:34 2021 from 172.31.0.1
[root@rocky8 ~]# 
#The user who kicks the access will log out

[root@rocky8 ~]# fuser -v /mnt/sdb2
                     USER        PID ACCESS COMMAND
/mnt/sdb2:           root     kernel mount /mnt
#No one is visiting now

[root@rocky8 ~]# umount /mnt/sdb2
#Just cancel the mount now

[root@rocky8 ~]# mount  /dev/sdb2 /mnt/sdb2
[root@rocky8 ~]# mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
devtmpfs on /dev type devtmpfs (rw,nosuid,size=382688k,nr_inodes=95672,mode=755)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
bpf on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,relatime,mode=700)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpu,cpuacct)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/rdma type cgroup (rw,nosuid,nodev,noexec,relatime,rdma)
cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls,net_prio)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
none on /sys/kernel/tracing type tracefs (rw,relatime)
configfs on /sys/kernel/config type configfs (rw,relatime)
/dev/sda2 on / type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=2M)
mqueue on /dev/mqueue type mqueue (rw,relatime)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=37,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=22459)
fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime)
/dev/sda3 on /data type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
/dev/sda1 on /boot type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
/dev/sdb2 on /mnt type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
/dev/sdb2 on /mnt/sdb2-2 type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,size=80116k,mode=700)
/dev/sdb2 on /mnt/sdb2 type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)

[root@rocky8 ~]# mount -o remount,ro /mnt/sdb2
#Remount with mount -o remount without kicking the user who is accessing

[root@rocky8 ~]# mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
devtmpfs on /dev type devtmpfs (rw,nosuid,size=382688k,nr_inodes=95672,mode=755)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
bpf on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,relatime,mode=700)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpu,cpuacct)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/rdma type cgroup (rw,nosuid,nodev,noexec,relatime,rdma)
cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls,net_prio)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
none on /sys/kernel/tracing type tracefs (rw,relatime)
configfs on /sys/kernel/config type configfs (rw,relatime)
/dev/sda2 on / type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=2M)
mqueue on /dev/mqueue type mqueue (rw,relatime)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=37,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=22459)
fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime)
/dev/sda3 on /data type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
/dev/sda1 on /boot type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
/dev/sdb2 on /mnt type xfs (ro,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
/dev/sdb2 on /mnt/sdb2-2 type xfs (ro,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,size=80116k,mode=700)
/dev/sdb2 on /mnt/sdb2 type xfs (ro,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota) #This is already read-only

[root@rocky8 ~]# touch /mnt/sdb2/yy.txt
touch: cannot touch '/mnt/sdb2/yy.txt': Read-only file system
#You can't write files in now

[root@rocky8 ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs          382688       0    382688   0% /dev
tmpfs             400580       0    400580   0% /dev/shm
tmpfs             400580    5744    394836   2% /run
tmpfs             400580       0    400580   0% /sys/fs/cgroup
/dev/sda2      104806400 2633912 102172488   3% /
/dev/sda3       52403200  398404  52004796   1% /data
/dev/sda1        1038336  191796    846540  19% /boot
/dev/sdb2        2086912     336   2086576   1% /mnt
tmpfs              80116       0     80116   0% /run/user/0
[root@rocky8 ~]# lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda       8:0    0  200G  0 disk 
├─sda1    8:1    0    1G  0 part /boot
├─sda2    8:2    0  100G  0 part /
├─sda3    8:3    0   50G  0 part /data
├─sda4    8:4    0    1K  0 part 
└─sda5    8:5    0    2G  0 part [SWAP]
sdb       8:16   0   20G  0 disk 
├─sdb1    8:17   0    1G  0 part 
├─sdb2    8:18   0    2G  0 part /mnt/sdb2
├─sdb3    8:19   0  512B  0 part 
├─sdb5    8:21   0    2G  0 part 
└─sdb6    8:22   0    3G  0 part 
sdc       8:32   0   10G  0 disk 
├─sdc1    8:33   0    1G  0 part 
└─sdc2    8:34   0    2G  0 part 
sr0      11:0    1  9.2G  0 rom  
nvme0n1 259:0    0   10G  0 disk 

[root@rocky8 ~]#  umount /boot
[root@rocky8 ~]#  umount /data
[root@rocky8 ~]#  umount /
umount: /: target is busy.
#/The root partition cannot be unmounted

[root@rocky8 ~]# mount -a
[root@rocky8 ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs          382688       0    382688   0% /dev
tmpfs             400580       0    400580   0% /dev/shm
tmpfs             400580    5744    394836   2% /run
tmpfs             400580       0    400580   0% /sys/fs/cgroup
/dev/sda2      104806400 2633932 102172468   3% /
/dev/sdb2        2086912     336   2086576   1% /mnt
tmpfs              80116       0     80116   0% /run/user/0
/dev/sda1        1038336  191796    846540  19% /boot
/dev/sda3       52403200  398404  52004796   1% /data

[root@rocky8 ~]# findmnt /data
TARGET SOURCE    FSTYPE OPTIONS
/data  /dev/sda3 xfs    rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota
#findmnt view mount status

[root@rocky8 ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs          382688       0    382688   0% /dev
tmpfs             400580       0    400580   0% /dev/shm
tmpfs             400580    5744    394836   2% /run
tmpfs             400580       0    400580   0% /sys/fs/cgroup
/dev/sda2      104806400 2633912 102172488   3% /
/dev/sdb2        2086912     336   2086576   1% /mnt
tmpfs              80116       0     80116   0% /run/user/0
/dev/sda1        1038336  191796    846540  19% /boot
/dev/sda3       52403200  398404  52004796   1% /data  
[root@rocky8 ~]# cat /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Wed Oct  6 11:16:34 2021
#
# 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.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
UUID=57f3a077-bb67-42c3-9e6c-bc8a0fed3776 /                       xfs     defaults        0 0
UUID=c72110fc-5dae-470c-9940-97ba978c7dc7 /boot                   xfs     defaults        0 0
UUID=02ae6744-8c28-4c86-b85b-e113c06a834f /data                   xfs     defaults        0 0
UUID=4f387202-0a81-4202-9e12-90d04af4d308 none                    swap    defaults        0 0

[root@rocky8 ~]# lsblk -f
NAME    FSTYPE  LABEL                UUID                                 MOUNTPOINT
sda                                                                       
├─sda1  xfs                          c72110fc-5dae-470c-9940-97ba978c7dc7 /boot
├─sda2  xfs                          57f3a077-bb67-42c3-9e6c-bc8a0fed3776 /
├─sda3  xfs                          02ae6744-8c28-4c86-b85b-e113c06a834f /data
├─sda4                                                                    
└─sda5  swap                         4f387202-0a81-4202-9e12-90d04af4d308 [SWAP]
sdb                                                                       
├─sdb1  ext4                         f7d5345f-5f29-417d-a044-37508852e80f 
├─sdb2  xfs                          8a2c8fdf-9294-4030-b10c-edc8a7b3e78f /mnt/sdb2
├─sdb3                                                                    
├─sdb5                                                                    
└─sdb6                                                                    
sdc                                                                       
├─sdc1                                                                    
└─sdc2                                                                    
sr0     iso9660 Rocky-8-4-x86_64-dvd 2021-06-20-16-16-21-00               
nvme0n1 

[root@rocky8 ~]# blkid /dev/sdb1
/dev/sdb1: UUID="f7d5345f-5f29-417d-a044-37508852e80f" BLOCK_SIZE="1024" TYPE="ext4" PARTUUID="a62c9118-01"

[root@rocky8 ~]# vim /etc/fstab
#Add the following
UUID=f7d5345f-5f29-417d-a044-37508852e80f /mnt/sdb1              ext4     ro,noatime,nodiratime  0 0 

[root@rocky8 ~]# mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
devtmpfs on /dev type devtmpfs (rw,nosuid,size=382688k,nr_inodes=95672,mode=755)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
bpf on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,relatime,mode=700)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpu,cpuacct)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/rdma type cgroup (rw,nosuid,nodev,noexec,relatime,rdma)
cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls,net_prio)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
none on /sys/kernel/tracing type tracefs (rw,relatime)
configfs on /sys/kernel/config type configfs (rw,relatime)
/dev/sda2 on / type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=2M)
mqueue on /dev/mqueue type mqueue (rw,relatime)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=37,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=22459)
fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime)
/dev/sdb2 on /mnt type xfs (ro,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
/dev/sdb2 on /mnt/sdb2-2 type xfs (ro,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,size=80116k,mode=700)
/dev/sdb2 on /mnt/sdb2 type xfs (ro,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
/dev/sda1 on /boot type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
/dev/sda3 on /data type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
#Now / dev/sdb1 is not mounted

[root@rocky8 ~]# mount -a #mount -a mount now
[root@rocky8 ~]# mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
devtmpfs on /dev type devtmpfs (rw,nosuid,size=382688k,nr_inodes=95672,mode=755)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
bpf on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,relatime,mode=700)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpu,cpuacct)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/rdma type cgroup (rw,nosuid,nodev,noexec,relatime,rdma)
cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls,net_prio)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
none on /sys/kernel/tracing type tracefs (rw,relatime)
configfs on /sys/kernel/config type configfs (rw,relatime)
/dev/sda2 on / type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=2M)
mqueue on /dev/mqueue type mqueue (rw,relatime)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=37,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=22459)
fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime)
/dev/sdb2 on /mnt type xfs (ro,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
/dev/sdb2 on /mnt/sdb2-2 type xfs (ro,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,size=80116k,mode=700)
/dev/sdb2 on /mnt/sdb2 type xfs (ro,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
/dev/sda1 on /boot type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
/dev/sda3 on /data type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
/dev/sdb1 on /mnt/sdb1 type ext4 (ro,noatime,nodiratime)
#Now / dev/sdb1 is mounted

[root@rocky8 ~]# cd /mnt/sdb1
[root@rocky8 sdb1]# ls
a.txt  b.txt  c.txt  lost+found
[root@rocky8 sdb1]# rm -f a.txt
rm: cannot remove 'a.txt': Read-only file system
#Because it is mounted read-only, the files in it cannot be deleted now

[root@rocky8 sdb1]# vim /etc/fstab
UUID=f7d5345f-5f29-417d-a044-37508852e80f /mnt/sdb1              ext4     noatime,nodiratime  0 0
#Delete ro, and the default is rw

[root@rocky8 sdb1]# mount -a
[root@rocky8 sdb1]# mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
devtmpfs on /dev type devtmpfs (rw,nosuid,size=382688k,nr_inodes=95672,mode=755)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
bpf on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,relatime,mode=700)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpu,cpuacct)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/rdma type cgroup (rw,nosuid,nodev,noexec,relatime,rdma)
cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls,net_prio)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
none on /sys/kernel/tracing type tracefs (rw,relatime)
configfs on /sys/kernel/config type configfs (rw,relatime)
/dev/sda2 on / type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=2M)
mqueue on /dev/mqueue type mqueue (rw,relatime)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=37,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=22459)
fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime)
/dev/sdb2 on /mnt type xfs (ro,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
/dev/sdb2 on /mnt/sdb2-2 type xfs (ro,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,size=80116k,mode=700)
/dev/sdb2 on /mnt/sdb2 type xfs (ro,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
/dev/sda1 on /boot type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
/dev/sda3 on /data type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
/dev/sdb1 on /mnt/sdb1 type ext4 (ro,noatime,nodiratime)
#mount -a does not take effect immediately

[root@rocky8 sdb1]# mount -o remount /dev/sdb1 #remount must be remounted

[root@rocky8 sdb1]# mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
devtmpfs on /dev type devtmpfs (rw,nosuid,size=382688k,nr_inodes=95672,mode=755)
securityfs on /sys/kernel/security type securityfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
tmpfs on /run type tmpfs (rw,nosuid,nodev,mode=755)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
pstore on /sys/fs/pstore type pstore (rw,nosuid,nodev,noexec,relatime)
bpf on /sys/fs/bpf type bpf (rw,nosuid,nodev,noexec,relatime,mode=700)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpu,cpuacct)
cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/rdma type cgroup (rw,nosuid,nodev,noexec,relatime,rdma)
cgroup on /sys/fs/cgroup/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_cls,net_prio)
cgroup on /sys/fs/cgroup/blkio type cgroup (rw,nosuid,nodev,noexec,relatime,blkio)
cgroup on /sys/fs/cgroup/freezer type cgroup (rw,nosuid,nodev,noexec,relatime,freezer)
cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids)
cgroup on /sys/fs/cgroup/hugetlb type cgroup (rw,nosuid,nodev,noexec,relatime,hugetlb)
cgroup on /sys/fs/cgroup/memory type cgroup (rw,nosuid,nodev,noexec,relatime,memory)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
none on /sys/kernel/tracing type tracefs (rw,relatime)
configfs on /sys/kernel/config type configfs (rw,relatime)
/dev/sda2 on / type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime,pagesize=2M)
mqueue on /dev/mqueue type mqueue (rw,relatime)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=37,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=22459)
fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime)
/dev/sdb2 on /mnt type xfs (ro,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
/dev/sdb2 on /mnt/sdb2-2 type xfs (ro,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,size=80116k,mode=700)
/dev/sdb2 on /mnt/sdb2 type xfs (ro,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
/dev/sda1 on /boot type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
/dev/sda3 on /data type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
/dev/sdb1 on /mnt/sdb1 type ext4 (rw,noatime,nodiratime)
#It takes effect now

#If mount -a has never existed in / etc/fstab, the new one will take effect immediately. If it already exists, the changed one will not take effect immediately

[root@rocky8 sdb1]# cd /mnt/sdb1
[root@rocky8 sdb1]# ls
a.txt  b.txt  c.txt  lost+found
[root@rocky8 sdb1]# rm -rf lost+found/
[root@rocky8 sdb1]# ls
a.txt  b.txt  c.txt
#Now you can delete the files or folders inside. The lost+found folder is a feature of ext2, ext3 and etx4, which is equivalent to a shelter

[root@rocky8 sdb1]# stat b.txt
  File: b.txt
  Size: 1         	Blocks: 2          IO Block: 1024   regular file
Device: 811h/2065d	Inode: 13          Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2021-10-15 22:55:26.196775264 +0800
Modify: 2021-10-15 22:55:26.196775264 +0800
Change: 2021-10-15 22:55:26.196775264 +0800
 Birth: -

[root@rocky8 sdb1]# cat b.txt

[root@rocky8 sdb1]# stat b.txt
  File: b.txt
  Size: 1         	Blocks: 2          IO Block: 1024   regular file
Device: 811h/2065d	Inode: 13          Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2021-10-15 22:55:26.196775264 +0800
Modify: 2021-10-15 22:55:26.196775264 +0800
Change: 2021-10-15 22:55:26.196775264 +0800
 Birth: -
#Cat atime is not modified

[root@rocky8 sdb1]# touch b.txt
[root@rocky8 sdb1]# stat b.txt
  File: b.txt
  Size: 1         	Blocks: 2          IO Block: 1024   regular file
Device: 811h/2065d	Inode: 13          Links: 1
Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2021-10-15 23:21:03.783761878 +0800
Modify: 2021-10-15 23:21:03.783761878 +0800
Change: 2021-10-15 23:21:03.783761878 +0800
 Birth: -
#Forced touch, atime is modified

[root@rocky8 sdb1]# reboot
[root@rocky8 ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs          382688       0    382688   0% /dev
tmpfs             400580       0    400580   0% /dev/shm
tmpfs             400580    5748    394832   2% /run
tmpfs             400580       0    400580   0% /sys/fs/cgroup
/dev/sda2      104806400 2632648 102173752   3% /
/dev/sda3       52403200  398404  52004796   1% /data
/dev/sda1        1038336  192152    846184  19% /boot
/dev/sdb1        1031836    2821    972491   1% /mnt/sdb1
tmpfs              80116       0     80116   0% /run/user/0
#After reboot, / dev/sdb1 is automatically mounted

[root@rocky8 ~]# vim /etc/fstab
UUID=f7d5345f-5f29-417d-a044-37508852e800 /mnt/sdb1              ext4     noatime,nodiratime  0 0
#If the UUID is written incorrectly during setting, the system cannot start normally after restarting

[root@rocky8 ~]# reboot


#It will enter the fault state and enter the root password


#Check that / dev/sdb1 is not mounted


#Enter configuration file


#Note out the line of attaching the wrong disk first


#Restart


#Now the system can start normally

[root@rocky8 ~]# vim /etc/fstab
/dev/sdb1 /mnt/sdb1              ext4     noatime,nodiratime  0 0

[root@rocky8 ~]# mount -a
[root@rocky8 ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs          382688       0    382688   0% /dev
tmpfs             400580       0    400580   0% /dev/shm
tmpfs             400580    5744    394836   2% /run
tmpfs             400580       0    400580   0% /sys/fs/cgroup
/dev/sda2      104806400 2632880 102173520   3% /
/dev/sda3       52403200  398404  52004796   1% /data
/dev/sda1        1038336  192152    846184  19% /boot
tmpfs              80116       0     80116   0% /run/user/0
/dev/sdb1        1031836    2821    972491   1% /mnt/sdb1

Example: the UUID of centos7,8 / etc / fstab partition is wrong and cannot be started

Automatic entry emergency mode,input root password
#cat /proc/mounts can be viewed / mounted in rw mode
#vim /etc/fstab
#reboot

Example: the UUID of centos 6 /etc/fstab partition is wrong and cannot be started

#If the mount device of / etc/fstab fails, such as file system failure, and the file system detection item (i.e. item 6 is non-0), it will fail to start

#Automatically enter emergency mode and enter the root password
#cat /proc/mounts can be viewed / mounted in ro mode, and the configuration file cannot be modified directly
#mount -o remount,rw /
#vim /etc/fstab
#Modify the last item of the fault line, i.e. item 6, to 0. The health of the mounted equipment will not be detected during startup, so as to ignore the error and realize startup

Example: / etc/fstab format

[root@centos8 ~]#cat /etc/fstab
UUID=cb7cae1e-d227-4f64-872b-cd6cce20c911 /data/mysql ext4 noatime
0 0
/disk.img data/disk xfs defaults
0 0
/etc /mnt/etc none bind
0 0

[root@centos6 ~]#cat /etc/fstab
/disk.img /mnt/disk ext4 loop 0 0

2.4 processing exchange files and partitions

2.4.1 introduction to swap

Swap swap partition is a supplement to system RAM. Swap partition supports virtual memory. When there is not enough ram to save the data processed by the system, the data will be written to the swap partition. When the system lacks swap space, the kernel will terminate the process due to the depletion of RAM memory. Configuring too much swap space will cause the storage device to be allocated but idle, resulting in waste. Too much swap space will also cover up memory leakage

Note: to optimize performance, swap can be stored in distributed storage or high-performance disk storage

Official recommendation system swap space

https://access.redhat.com/documentation/zh-cn/red_hat_enterprise_linux/7/html/installation_guide/sect-disk-partitioning-setup-ppc#sect-recommended-partitioning-scheme-ppc

Amount of RAM in the systemRecommended swap spaceRecommended swap space size to allow hibernation
Less than 2 GB2 times the amount of RAMThree times the RAM capacity
2 GB - 8 GBEqual to the amount of RAMMultiple of RAM
8 GB - 64 GB4 GB to 0.5 times RAM capacity1.5 times RAM capacity
Over 64 GBIndependent load (at least 4GB)Hibernation is not recommended

example:

[root@rocky8 ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:          782Mi       178Mi       396Mi       5.0Mi       207Mi       470Mi
Swap:         2.0Gi          0B       2.0Gi
#If the memory is full and there is no virtual memory, an OOM error will appear. OOM is out of memory. The memory is full

[root@rocky8 ~]# dd if=/dev/zero of=/dev/null bs=8G count=1
dd: memory exhausted by input buffer of size 8589934592 bytes (8.0 GiB)
#If you use 8G of memory immediately, you will report that there is insufficient memory

[root@rocky8 ~]# dd if=/dev/zero of=/dev/null bs=4G count=1
dd: memory exhausted by input buffer of size 4294967296 bytes (4.0 GiB)

[root@rocky8 ~]# dd if=/dev/zero of=/dev/null bs=100M count=1
1+0 records in
1+0 records out
104857600 bytes (105 MB, 100 MiB) copied, 0.0722939 s, 1.5 GB/s

[root@rocky8 ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 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: 0xa62c9118

Device     Boot    Start      End  Sectors Size Id Type
/dev/sdb1           2048  2099199  2097152   1G 83 Linux
/dev/sdb2        2099200  6293503  4194304   2G 83 Linux
/dev/sdb3        6293504 41943039 35649536  17G  5 Extended
/dev/sdb5        6295552 10489855  4194304   2G 83 Linux
/dev/sdb6       10491904 16783359  6291456   3G 8e Linux LVM

[root@rocky8 ~]# lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda       8:0    0  200G  0 disk 
├─sda1    8:1    0    1G  0 part /boot
├─sda2    8:2    0  100G  0 part /
├─sda3    8:3    0   50G  0 part /data
├─sda4    8:4    0    1K  0 part 
└─sda5    8:5    0    2G  0 part [SWAP]
sdb       8:16   0   20G  0 disk 
├─sdb1    8:17   0    1G  0 part /mnt/sdb1
├─sdb2    8:18   0    2G  0 part 
├─sdb3    8:19   0    1K  0 part 
├─sdb5    8:21   0    2G  0 part 
└─sdb6    8:22   0    3G  0 part 
sdc       8:32   0   10G  0 disk 
├─sdc1    8:33   0    1G  0 part 
└─sdc2    8:34   0    2G  0 part 
sr0      11:0    1  9.2G  0 rom  
nvme0n1 259:0    0   10G  0 disk 

[root@rocky8 ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs          382688       0    382688   0% /dev
tmpfs             400580       0    400580   0% /dev/shm
tmpfs             400580    5744    394836   2% /run
tmpfs             400580       0    400580   0% /sys/fs/cgroup
/dev/sda2      104806400 2632880 102173520   3% /
/dev/sda3       52403200  398404  52004796   1% /data
/dev/sda1        1038336  192152    846184  19% /boot
tmpfs              80116       0     80116   0% /run/user/0
/dev/sdb1        1031836    2821    972491   1% /mnt/sdb1

[root@rocky8 ~]# 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.


Command (m for help): t
Partition number (1-3,5,6, default 6): 5
Hex code (type L to list all codes): L

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris        
 1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden or  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx         
 5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data    
 6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility   
 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt         
 9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access     
 a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O        
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor      
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi ea  Rufus alignment
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         eb  BeOS fs        
 f  W95 Ext'd (LBA) 54  OnTrackDM6      a6  OpenBSD         ee  GPT            
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        ef  EFI (FAT-12/16/
11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f0  Linux/PA-RISC b
12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f1  SpeedStor      
14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f4  SpeedStor      
16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      f2  DOS secondary  
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fb  VMware VMFS    
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fc  VMware VMKCORE 
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fd  Linux raid auto
1c  Hidden W95 FAT3 75  PC/IX           bc  Acronis FAT32 L fe  LANstep        
1e  Hidden W95 FAT1 80  Old Minix       be  Solaris boot    ff  BBT            
Hex code (type L to list all codes): 82

Changed type of partition 'Linux' to 'Linux swap / Solaris'.

Command (m for help): p
Disk /dev/sdb: 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: 0xa62c9118

Device     Boot    Start      End  Sectors Size Id Type
/dev/sdb1           2048  2099199  2097152   1G 83 Linux
/dev/sdb2        2099200  6293503  4194304   2G 83 Linux
/dev/sdb3        6293504 41943039 35649536  17G  5 Extended
/dev/sdb5        6295552 10489855  4194304   2G 82 Linux swap / Solaris #Change / dev/sdb5 to swap
/dev/sdb6       10491904 16783359  6291456   3G 8e Linux LVM

Command (m for help): w
The partition table has been altered.
Syncing disks.

[root@rocky8 ~]# fdisk -l  /dev/sdb
Disk /dev/sdb: 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: 0xa62c9118

Device     Boot    Start      End  Sectors Size Id Type
/dev/sdb1           2048  2099199  2097152   1G 83 Linux
/dev/sdb2        2099200  6293503  4194304   2G 83 Linux
/dev/sdb3        6293504 41943039 35649536  17G  5 Extended
/dev/sdb5        6295552 10489855  4194304   2G 82 Linux swap / Solaris
/dev/sdb6       10491904 16783359  6291456   3G 8e Linux LVM

[root@rocky8 ~]# mkswap /dev/sdb5 #mkswap create swap partition
Setting up swapspace version 1, size = 2 GiB (2147479552 bytes)
no label, UUID=9a3b3cde-e94d-4f62-9c7e-069d2e3e400b

[root@rocky8 ~]# blkid
/dev/sda2: UUID="57f3a077-bb67-42c3-9e6c-bc8a0fed3776" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="43d7507d-02"
/dev/sda1: UUID="c72110fc-5dae-470c-9940-97ba978c7dc7" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="43d7507d-01"
/dev/sda3: UUID="02ae6744-8c28-4c86-b85b-e113c06a834f" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="43d7507d-03"
/dev/sda5: UUID="4f387202-0a81-4202-9e12-90d04af4d308" TYPE="swap" PARTUUID="43d7507d-05"
/dev/sdb1: UUID="f7d5345f-5f29-417d-a044-37508852e80f" BLOCK_SIZE="1024" TYPE="ext4" PARTUUID="a62c9118-01"
/dev/sdb2: UUID="8a2c8fdf-9294-4030-b10c-edc8a7b3e78f" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="a62c9118-02"
/dev/sdb5: UUID="9a3b3cde-e94d-4f62-9c7e-069d2e3e400b" TYPE="swap" PARTUUID="a62c9118-05"
/dev/sdb6: PARTUUID="a62c9118-06"
/dev/sdc1: PARTLABEL="Linux filesystem" PARTUUID="7a7090a5-623a-45a0-b7e7-2c613355b7ea"
/dev/sdc2: PARTLABEL="Linux LVM" PARTUUID="cb838081-f185-4983-ad7e-6eea78c54565"
/dev/sr0: BLOCK_SIZE="2048" UUID="2021-06-20-16-16-21-00" LABEL="Rocky-8-4-x86_64-dvd" TYPE="iso9660" PTUUID="4a14a4ee" PTTYPE="dos"

[root@rocky8 ~]# vim /etc/fstab
UUID=9a3b3cde-e94d-4f62-9c7e-069d2e3e400b swap                    swap    defaults        0 0 

[root@rocky8 ~]# swapon -a #Effective immediately
[root@rocky8 ~]# swapon -s #View swap
Filename				Type		Size	Used	Priority
/dev/sda5                              	partition	2097148	0	-2
/dev/sdb5                              	partition	2097148	0	-3
#-2, - 3 is the priority. The smaller the number, the higher the priority. It is used first

[root@rocky8 ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:          782Mi       179Mi       391Mi       5.0Mi       210Mi       469Mi
Swap:         4.0Gi          0B       4.0Gi
#swap increased by 2G

#To delete swap, ensure that the deleted partition is not used

[root@rocky8 ~]# vim /etc/fstab
UUID=9a3b3cde-e94d-4f62-9c7e-069d2e3e400b swap                    swap    pri=100         0 0
#pre=100 is to set the priority. The set positive priority is higher than the system default negative priority

[root@rocky8 ~]# swapoff /dev/sdb5
[root@rocky8 ~]# swapon -a
[root@rocky8 ~]# swapon -s
Filename				Type		Size	Used	Priority
/dev/sda5                              	partition	2097148	0	-2
/dev/sdb5                              	partition	2097148	0	100

#Delete swap
[root@rocky8 ~]# swapoff /dev/sdb5 #Close / dev/sdb5 and swap first

[root@rocky8 ~]# vim /etc/fstab
#Delete the following
UUID=9a3b3cde-e94d-4f62-9c7e-069d2e3e400b swap                    swap    pri=100         0 0

[root@rocky8 ~]# 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.


Command (m for help): d
Partition number (1-3,5,6, default 6): 5

Partition 5 has been deleted.

Command (m for help): w
The partition table has been altered.
Syncing disks.
#delete a partition

[root@rocky8 ~]# lsblk
NAME    MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda       8:0    0  200G  0 disk 
├─sda1    8:1    0    1G  0 part /boot
├─sda2    8:2    0  100G  0 part /
├─sda3    8:3    0   50G  0 part /data
├─sda4    8:4    0    1K  0 part 
└─sda5    8:5    0    2G  0 part [SWAP]
sdb       8:16   0   20G  0 disk 
├─sdb1    8:17   0    1G  0 part /mnt/sdb1
├─sdb2    8:18   0    2G  0 part 
├─sdb3    8:19   0    1K  0 part 
└─sdb5    8:21   0    3G  0 part 
sdc       8:32   0   10G  0 disk 
├─sdc1    8:33   0    1G  0 part 
└─sdc2    8:34   0    2G  0 part 
sr0      11:0    1  9.2G  0 rom  
nvme0n1 259:0    0   10G  0 disk 

[root@rocky8 ~]# swapon -s
Filename				Type		Size	Used	Priority
/dev/sda5                              	partition	2097148	0	-2
[root@rocky8 ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:          782Mi       181Mi       333Mi       5.0Mi       267Mi       467Mi
Swap:         2.0Gi          0B       2.0Gi

[root@rocky8 ~]# swapoff /dev/sda5 #Remove what / dev/sda5 is using
[root@rocky8 ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:          782Mi       179Mi       336Mi       5.0Mi       266Mi       468Mi
Swap:            0B          0B          0B
#Now the memory usage becomes larger and the swap partition is gone

2.4.2 implementation process of switching partition

  1. Create swap partition or file
  2. Write special signatures using mkswap
  3. Add the appropriate entry in the / etc/fstab file
  4. Activate swap space with swapon -a

Enable swap partition

swapon [OPTION]... [DEVICE]

Options:

-a: Activate all switched partitions
-p PRIORITY: Specify priority, or/etc/fstab Specify in column 4: pri=value

Example: create swap partition

[root@rocky8 ~]# echo -e 'n\np\n\n\n+2G\nt\n82\nw\n' | fdisk /dev/sdc

[root@rocky8 ~]# mkswap /dev/sdc1
Setting up swapspace version 1, size = 2 GiB (2147479552 bytes)
no label, UUID=d3140a7a-65b7-4cb7-8a2b-12d38aa98c6f

[root@rocky8 ~]# blkid /dev/sdc1
/dev/sdc1: UUID="d3140a7a-65b7-4cb7-8a2b-12d38aa98c6f" TYPE="swap"
PARTUUID="b094d43d-01

[root@rocky8 ~]# vim /etc/fstab
UUID=d3140a7a-65b7-4cb7-8a2b-12d38aa98c6f swap swap defaults,pri=100 0
0

[root@rocky8 ~]# swapon -a

[root@rocky8 ~]# free -h
total used free shared buff/cache available
Mem: 3.7Gi 264Mi 3.2Gi 9.0Mi 261Mi 3.2Gi
Swap: 4.0Gi 0B 4.0Gi

[root@rocky8 ~]# cat /proc/swaps
Filename Type Size Used Priority
/dev/sda5 partition 2097148 0 -2
/dev/sdc1 partition 2097148 0 100

Disable swap partition:

swapoff [OPTION]... [DEVICE]

Example: disable swap partition

[root@rocky8 ~]# sed -i.bak '/swap/d' /etc/fstab
[root@rocky8 ~]# swapoff -a

Priority of SWAP
You can specify the priority of swap partitions 0 to 32767. The higher the value, the higher the priority

If the user does not specify a priority, the core will automatically assign a priority to the swap, starting from - 1. Each time a new swap without a priority specified by the user is added, the priority will be reduced by one

The default priority of the first added swap is relatively high, unless the user specifies a priority, and the priority specified by the user (a positive number) is always higher than the priority specified by the core default (a negative number)

2.4.3 usage strategy of swap

/The value of proc/sys/vm/swappiness determines the space of swap partition when the memory consumption reaches a certain percentage

example:

[root@centos8 ~]# cat /proc/sys/vm/swappiness
30
[root@rhel5 ~]# cat /proc/sys/vm/swappiness
60

Note: when the memory is used to 100-30 = 70%, swap partitions begin to be used. Simply put, this parameter defines the system's tendency to use swap. The default value is 30. The larger the value, the more inclined it is to use swap. It can be set to 0, which will not prohibit the use of swap, but minimize the possibility of using swap

example:

[root@rocky8 ~]# cat /proc/sys/vm/swappiness 
30
[root@rocky8 ~]# echo "vm.swappiness=0" >> /etc/sysctl.conf
[root@rocky8 ~]# sysctl -p
vm.swappiness = 0
[root@rocky8 ~]# cat /proc/sys/vm/swappiness
0

2.5 common disk tools

2.5.1 file system space occupation and other information viewing tools df

df [OPTION]... [FILE]...

Common options

-H Unit: 10
-T file system type
-h human-readable
-i inodes instead of blocks
-P with Posix Compatible format output

example:

[[root@rocky8 ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
devtmpfs          382688       0    382688   0% /dev
tmpfs             400580       0    400580   0% /dev/shm
tmpfs             400580    5740    394840   2% /run
tmpfs             400580       0    400580   0% /sys/fs/cgroup
/dev/sda2      104806400 2633380 102173020   3% /
/dev/sda3       52403200  398404  52004796   1% /data
/dev/sda1        1038336  192152    846184  19% /boot
/dev/sdb1        1031836    2821    972491   1% /mnt/sdb1
tmpfs              80116       0     80116   0% /run/user/0
[root@rocky8 ~]# df -h 
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        374M     0  374M   0% /dev
tmpfs           392M     0  392M   0% /dev/shm
tmpfs           392M  5.7M  386M   2% /run
tmpfs           392M     0  392M   0% /sys/fs/cgroup
/dev/sda2       100G  2.6G   98G   3% /
/dev/sda3        50G  390M   50G   1% /data
/dev/sda1      1014M  188M  827M  19% /boot
/dev/sdb1      1008M  2.8M  950M   1% /mnt/sdb1
tmpfs            79M     0   79M   0% /run/user/0
[root@rocky8 ~]# df -Th #-T display file system
Filesystem     Type      Size  Used Avail Use% Mounted on
devtmpfs       devtmpfs  374M     0  374M   0% /dev
tmpfs          tmpfs     392M     0  392M   0% /dev/shm
tmpfs          tmpfs     392M  5.7M  386M   2% /run
tmpfs          tmpfs     392M     0  392M   0% /sys/fs/cgroup
/dev/sda2      xfs       100G  2.6G   98G   3% /
/dev/sda3      xfs        50G  390M   50G   1% /data
/dev/sda1      xfs      1014M  188M  827M  19% /boot
/dev/sdb1      ext4     1008M  2.8M  950M   1% /mnt/sdb1
tmpfs          tmpfs      79M     0   79M   0% /run/user/0

example:

[root@rhel5 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
99415464 2084776 92199220 3% /
/dev/sda1 101086 12056 83811 13% /boot
tmpfs 517536 0 517536 0% /dev/shm
[root@rhel5 ~]# df -P
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/mapper/VolGroup00-LogVol00 99415464 2084776 92199220 3% /
/dev/sda1 101086 12056 83811 13% /boot
tmpfs

2.5.2 view the overall space occupancy of a directory du

du [OPTION]... DIR

Common options

-h human-readable
-s summary
    --max-depth=# Specify the maximum directory level
    -x, --one-file-system #Ignore directories that are not on the same file system

example:

[root@rocky8 ~]# du /data
4	/data
[root@rocky8 ~]# echo a>/data/a.txt
[root@rocky8 ~]# du /data
8	/data
[root@rocky8 ~]# du -h /data
8.0K	/data

[root@rocky8 ~]# mkdir /data/dir{1,2}
[root@rocky8 ~]# echo b >/data/dir1/b.txt
[root@rocky8 ~]# echo c >/data/dir2/c.txt
[root@rocky8 ~]# du  /data
4	/data/dir1
4	/data/dir2
16	/data
[root@rocky8 ~]# du -sh /data
16K	/data
#-s displays only the / data directory information

2.5.3 tools dd

dd command: convert and copy a file

Format:

dd if=/PATH/FROM/SRC of=/PATH/TO/DEST bs=# count=#

Common options

if=file Read from the named file instead of from standard input
of=file Write to the named file instead of to standard output
bs=size block size, Specify block size (yes ibs Also obs)
cbs=size Primary conversion size individual byte
skip=blocks Ignore from beginning blocks individual ibs Block size
seek=blocks Ignore from beginning blocks individual obs Block size
count=n copy n individual bs
conv=conversion[,conversion...] Converts the file with the specified parameters

conversion Conversion parameters:
ascii transformation EBCDIC by ASCII
ebcdic transformation ASCII by EBCDIC
lcase Convert uppercase characters to lowercase characters
ucase Convert lowercase characters to uppercase characters
nocreat Do not create output file
noerror Don't stop on error
notrunc Do not truncate output files
sync Fill each input block into ibs Bytes, and the insufficient part is empty(NUL)Character complement
fdatasync The output file is physically written before writing is complete

example:

#skip is the number of skips when inputting from the if target
#seek is the number of skips when outputting from the of target

[root@rocky8 ~]# dd of=/data/a.txt conv=ucase #Convert case
abc
xyz
0+2 records in
0+1 records out
8 bytes copied, 24.516 s, 0.0 kB/s
#ctrl+d end
[root@rocky8 ~]# cat /data/a.txt 
ABC
XYZ

[root@rocky8 ~]# cat >f1.txt <<EOF
abcdef
EOF
[root@rocky8 ~]# cat >f2.txt <<EOF
123456789
EOF
[root@rocky8 ~]# dd if=f1.txt of=f2.txt bs=1 count=2 skip=3 seek=4
2+0 records in
2+0 records out
2 bytes copied, 8.4238e-05 s, 23.7 kB/s
[root@rocky8 ~]# cat f2.txt 
1234de
# bs=1 reads 1 byte each time, count=2 reads 2 times, skip=3 skips 3 from f1.txt, seek=4 skips 4 from f2.txt, and outputs to f2.txt. The last F of f1.txt is truncated, and the 789 of f2.txt is truncated, so it doesn't exist. The final result is 1234de.

[root@rocky8 ~]# cat >f2.txt <<EOF
123456789
EOF
[root@rocky8 ~]# cat f1.txt 
abcdef
[root@rocky8 ~]# cat f2.txt 
123456789
[root@rocky8 ~]# dd if=f1.txt of=f2.txt bs=1 count=2 skip=3 seek=4 conv=notrunc
2+0 records in
2+0 records out
2 bytes copied, 9.5318e-05 s, 21.0 kB/s
[root@rocky8 ~]# cat f2.txt 
1234de789
#conv=notrunc this is not truncation

[root@rocky8 ~]# dd if=/dev/zero of=/data/disk.img bs=1M count=0 seek=1024
0+0 records in
0+0 records out
0 bytes copied, 3.1539e-05 s, 0.0 kB/s
[root@rocky8 ~]# du /data/disk.img 
0	/data/disk.img
#What is created is a sparse file, or an empty file

example:

#Backup MBR
dd if=/dev/sda of=/tmp/mbr.bak bs=512 count=1
#Destroy bootloader in MBR
dd if=/dev/zero of=/dev/sda bs=64 count=1 seek=446

2.6 practice

1. Create a 2G file system with a block size of 2048byte and 1% of the available space reserved. The file system is ext4 and the volume label is test. This partition is required to be automatically mounted to the / test directory after startup, and the acl mount option is available by default
2. Write a script to complete the following functions:
(1) Lists all disk devices recognized by the current system
(2) If the number of disks is 1, its space usage information is displayed
Otherwise, space usage information on the last disk is displayed
3. Merge the CentOS-6.10-x86_64-bin-DVD1.iso and CentOS-6.10-x86_64-bin-DVD2.iso files of CentOS6 into a CentOS-6.10-x86_64-Everything.iso file, and configure it as a yum source

Posted by Strings on Tue, 02 Nov 2021 19:00:24 -0700