1. 程式人生 > 其它 >最長迴文串

最長迴文串

Linux磁碟管理

在Linux系統中,如何有效地對儲存空間加以使用和管理,是一項非常重要的技術。

1、檢視磁碟或者目錄的容量

檢視硬碟分配 -------- df
“df” 檢視已掛載磁碟的總容量、使用容量、剩餘容量等,可以不加任何引數,預設單位“KB”
GB、MB、KB就是指電腦裡面檔案檔案大小的單位
GB是最大的單位,然後是MB...就是常說的兆,KB是最小的單位
1GB=1024MB 1MB=1024KB 1KB=1024B
[root@localhost ~]# df
Filesystem              1K-blocks    Used Available Use% Mounted on
devtmpfs                   485864       0    485864   0% /dev
tmpfs                      497872       0    497872   0% /dev/shm
tmpfs                      497872    7768    490104   2% /run
tmpfs                      497872       0    497872   0% /sys/fs/cgroup
/dev/mapper/centos-root  17811456 4173720  13637736  24% /
/dev/sda1                 1038336  139260    899076  14% /boot
tmpfs                       99576       0     99576   0% /run/user/0

第一列是分割槽的名字,第二列為該分割槽總共的容量,第三列為已經使用了多少,第四列為還剩下多少,
第五列為已經使用百分比,如果這個數值到達90%以上,那麼你就應該關注了,磁碟分割槽滿了可不是什
麼好事情,會引起系統崩潰的。最後一列為掛載點。

“df” 的引數
-a 顯示所有檔案系統的磁碟使用情況,包括0塊(block)的檔案系統,如/proc檔案系統。
-k 以k位元組為單位顯示。
-i 顯示i節點資訊,而不是磁碟塊。
-t 顯示各指定型別的檔案系統的磁碟空間使用情況。
-x 列出不是某一指定型別檔案系統的磁碟空間使用情況(與t選項相反)。
-T 顯示檔案系統型別
df” 常用選項有 “-i” “-h” “-k” “-m”

檢視inodes使用狀況 --------使用引數“-i”
[root@localhost ~]# df -i
Filesystem               Inodes IUsed   IFree IUse% Mounted on
devtmpfs                 121466   392  121074    1% /dev
tmpfs                    124468     1  124467    1% /dev/shm
tmpfs                    124468   732  123736    1% /run
tmpfs                    124468    16  124452    1% /sys/fs/cgroup
/dev/mapper/centos-root 8910848 78139 8832709    1% /
/dev/sda1                524288   326  523962    1% /boot
tmpfs                    124468     1  124467    1% /run/user/0

使用合適的單位顯示 ---------引數“-h”
[root@localhost ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 475M     0  475M   0% /dev
tmpfs                    487M     0  487M   0% /dev/shm
tmpfs                    487M  7.6M  479M   2% /run
tmpfs                    487M     0  487M   0% /sys/fs/cgroup
/dev/mapper/centos-root   17G  4.0G   14G  24% /
/dev/sda1               1014M  136M  879M  14% /boot
tmpfs                     98M     0   98M   0% /run/user/0

以K為單位顯示 --------引數“-k”
tmpfs                     98M     0   98M   0% /run/user/0
[root@localhost ~]# df -k
Filesystem              1K-blocks    Used Available Use% Mounted on
devtmpfs                   485864       0    485864   0% /dev
tmpfs                      497872       0    497872   0% /dev/shm
tmpfs                      497872    7768    490104   2% /run
tmpfs                      497872       0    497872   0% /sys/fs/cgroup
/dev/mapper/centos-root  17811456 4173620  13637836  24% /
/dev/sda1                 1038336  139260    899076  14% /boot
tmpfs                       99576       0     99576   0% /run/user/0

以M為單位顯示 --------引數“-m”
[root@localhost ~]# df -m
Filesystem              1M-blocks  Used Available Use% Mounted on
devtmpfs                      475     0       475   0% /dev
tmpfs                         487     0       487   0% /dev/shm
tmpfs                         487     8       479   2% /run
tmpfs                         487     0       487   0% /sys/fs/cgroup
/dev/mapper/centos-root     17394  4076     13319  24% /
/dev/sda1                    1014   136       879  14% /boot
tmpfs                          98     0        98   0% /run/user/0
檢視某個目錄或檔案所佔空間大小
“du” 用來檢視某個目錄或檔案所佔空間大小.
語法 :du[-abckmsh][檔案或者目錄名]
[root@localhost mnt]# du centos/   檢視centos目錄大小
0       centos/
“-a” 全部檔案與目錄大小都列出來
[root@localhost etc]# du -a adjtime / |head  通過管道符“|”進行輸出前10行資料
4       adjtime
0       /boot/efi/EFI/centos
0       /boot/efi/EFI
0       /boot/efi
4       /boot/grub2/device.map
8       /boot/grub2/i386-pc/gcry_rmd160.mod
12      /boot/grub2/i386-pc/acpi.mod
4       /boot/grub2/i386-pc/gcry_rsa.mod
4       /boot/grub2/i386-pc/adler32.mod
16      /boot/grub2/i386-pc/gcry_seed.mod

如果du不指定單位,預設顯示單位為KB.
“-b” 列出的值以bytes為單位輸出。
“-k” 以KB為單位輸出,和預設不加任何選項的輸出值是一樣的。
“-m” 以MB為單位輸出
“-h” 系統自動調節單位
“-c” 最後加總
“-s” 只列出總和

2、磁碟分割槽格式化

在磁碟分割槽前必須現新建一塊硬碟

fdisk
fdisk 是Linux下硬碟的分割槽工具,但fdisk只能劃分小於2T的分割槽。
語法 :fdisk[-l][裝置名稱]選項只有一個。
“-l” 後邊不跟裝置名會直接列出系統中所有的磁碟裝置以及分割槽表,加上裝置名會列出該裝置的分割槽表。

[root@localhost etc]# fdisk -l

Disk /dev/sda: 21.5 GB, 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
Disk label type: dos
Disk identifier: 0x000c2a41

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    41943039    19921920   8e  Linux LVM

Disk /dev/sdb: 21.5 GB, 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


Disk /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 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


Disk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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@localhost etc]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

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
Building a new DOS disklabel with disk identifier 0xb584e0a0.


‘m’ 會列出常用的命令  幫助文件
Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)
   
   “p” 列印當前磁碟的分割槽情況
   Command (m for help): p

Disk /dev/sdb: 21.5 GB, 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
Disk label type: dos
Disk identifier: 0xb584e0a0

   Device Boot      Start         End      Blocks   Id  System

“n” 建立一個新的分割槽
‘w’ 儲存操作
‘q’ 退出
‘d’ 刪除一個分割槽
建立分割槽
Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
   Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-41943039, default 2048): 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +5G
Partition 1 of type Linux and of size 5 GiB is set
使用 ‘n’ 命令新建分割槽,它會提示是要 ‘e’ (擴充套件分割槽) 還是 ‘p’ (主分割槽)[1]筆者的選擇是 ‘p’,
於是輸入 ‘p’ 然後回車,輸入 ‘p’ 後,會提示分割槽數,這裡筆者寫 ‘1’, 因為是第一個分割槽,當然你也
可以寫 ‘2’ 或 ‘3’, 如果你直接回車的話,會繼續提示你必須輸入一個數字,接著又提示第一個柱面從哪
裡開始,預設是 ‘1’, 你可以寫一個其他的數字,不過這樣就浪費了空間,所以還是寫 ‘1’ 吧,或者你直
接回車也會按 ‘1’ 處理,接著是讓輸入最後一個柱面的數值,也就是說你需要給這個分割槽分多大空間,關
於柱面是多大筆者不再細究,你只需要掌握筆者教給你的方法即可,即寫 “+5G”, 這樣即方便又不容易出錯。
用 ‘p’ 檢視已經多出了一個分割槽。

Command (m for help): p

Disk /dev/sdb: 21.5 GB, 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
Disk label type: dos
Disk identifier: 0xb584e0a0

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    10487807     5242880   83  Linux
繼續上面的操作,一直建立主分割槽到4, 然後再一次建立分割槽的時候則會提示你輸入e,
建立擴充套件分割槽sdb4
Command (m for help): n
Partition type:
   p   primary (3 primary, 0 extended, 1 free)
   e   extended
Select (default e): e
Selected partition 4
First sector (31459328-41943039, default 31459328): 31459328
Last sector, +sectors or +size{K,M,G} (31459328-41943039, default 41943039): 
Using default value 41943039
Partition 4 of type Extended and of size 5 GiB is set
這是因為,在Linux中最多隻能建立4個主分割槽,那如果你想多建立幾個分割槽如何做?很容易,在建立完第三
個分割槽後,建立第四個分割槽時選擇擴充套件分割槽。擴充套件分割槽,在最後一列顯示為 “Extended”, 接下來繼續建立分
區。

Command (m for help): p

Disk /dev/sda: 21.5 GB, 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
Disk label type: dos
Disk identifier: 0x000c2a41

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *        2048     2099199     1048576   83  Linux
/dev/sdb2         2099200    12584959     5242880   83  Linux
/dev/sdb3        12584960    23070719     5242880   83  Linux
/dev/sdb4        23070720    41943039     9436160    5  Extended

下面再進行建立分割槽時,是基於擴充套件分割槽的容量來進行分割槽
建立sdb5 分割槽
Command (m for help): p

Disk /dev/sda: 21.5 GB, 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
Disk label type: dos
Disk identifier: 0x000c2a41

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *        2048     2099199     1048576   83  Linux
/dev/sdb2         2099200    12584959     5242880   83  Linux
/dev/sdb3        12584960    23070719     5242880   83  Linux
/dev/sdb4        23070720    41943039     9436160    5  Extended
/dev/sdb5        23072768    41943039     9435136   83  Linux

這時候再分割槽和以前有區別了,不再選擇是主分割槽還是擴充套件分割槽了,而是直接定義大小。有一點筆者要講一下,
當分完三個主分割槽後,第四個擴充套件分割槽需要把剩餘的磁碟空間全部劃分給擴充套件分割槽,不然的話剩餘的空間會浪
費,因為分完擴充套件分割槽後,再劃分新的分割槽時是在已經劃分的擴充套件分割槽裡來分的。其中/dev/sdb4為擴充套件分割槽
,這個分割槽是不可以格式化的,你可以把它看成是一個空殼子,能使用的為/dev/sdb5, 其中/dev/sdb5為
/dev/sdb4的子分割槽,這個子分割槽叫做邏輯分割槽。
刪除分割槽
使用d刪除sdb1分割槽
Command (m for help): d  
Partition number (1-5, default 5): 1
Partition 1 is deleted

Command (m for help): p

Disk /dev/sda: 21.5 GB, 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
Disk label type: dos
Disk identifier: 0x000c2a41

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb2         2099200    12584959     5242880   83  Linux
/dev/sdb3        12584960    23070719     5242880   83  Linux
/dev/sdb4        23070720    41943039     9436160    5  Extended
/dev/sdb5        23072768    41943039     9435136   83  Linux
輸入 ‘d’ 會提示要刪除哪個分割槽,可以選擇從 1-5 其中1-3是主分割槽(sdb1, sdb2, sdb3),4是擴充套件分割槽
(sdb4),5是邏輯分割槽(sdb5),如果輸入5,則直接把邏輯分割槽sdb5刪除掉,但是如果輸入4的話,會把整個
擴充套件分割槽sdb4幹掉,當然也包含擴充套件分割槽裡面的邏輯分割槽sdb5。在剛才的分割槽介面直接 Ctrl + C 退出來,
這樣剛剛的分割槽全部都取消了,咱們重新來做分割槽。

直接建立擴充套件分割槽
Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): e
Partition number (1-4, default 1): 1
First sector (2048-41943039, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): 
Using default value 41943039
Partition 1 of type Extended and of size 20 GiB is set

Command (m for help): p

Disk /dev/sda: 21.5 GB, 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
Disk label type: dos
Disk identifier: 0x000c2a41

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    41943039    20970496    5  Extended

建立分割槽
Command (m for help): n
Partition type:
   p   primary (0 primary, 1 extended, 3 free)
   l   logical (numbered from 5)
Select (default p): p
Partition number (2-4, default 2): 2
No free sectors available
基於擴充套件分割槽建立主分割槽報錯,這是因為沒有足夠空間分給主分割槽了。
所以我們建立分邏輯分割槽,大小分別都是5G
Command (m for help): n
Partition type:
   p   primary (0 primary, 1 extended, 3 free)
   l   logical (numbered from 5)
Select (default p): l
Adding logical partition 8
First sector (31467520-41943039, default 31467520): 
Using default value 31467520
Last sector, +sectors or +size{K,M,G} (31467520-41943039, default 41943039): 
Using default value 41943039
Partition 8 of type Linux and of size 5 GiB is set

Command (m for help): p

Disk /dev/sda: 21.5 GB, 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
Disk label type: dos
Disk identifier: 0x000c2a41

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    41943039    20970496    5  Extended
/dev/sdb5            4096    10489855     5242880   83  Linux
/dev/sdb6        10491904    20977663     5242880   83  Linux
/dev/sdb7        20979712    31465471     5242880   83  Linux
/dev/sdb8        31467520    41943039     5237760   83  Linux

儲存並退出
Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

儲存好分割槽記錄再使用fdisk-l/dev/sdb檢視分割槽情況
[root@localhost ~]# fdisk -l /dev/sdb              

Disk /dev/sda: 21.5 GB, 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
Disk label type: dos
Disk identifier: 0x000c2a41

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    41943039    20970496    5  Extended
/dev/sdb5            4096    10489855     5242880   83  Linux
/dev/sdb6        10491904    20977663     5242880   83  Linux
/dev/sdb7        20979712    31465471     5242880   83  Linux
/dev/sdb8        31467520    41943039     5237760   83  Linux

3、格式化磁碟分割槽

命令 : mke2fs, mkfs.ext2, mkfs.ext3, mkfs.ext4
當用man查詢這四個命令的幫助文件時,你會發現我們看到了同一個幫助文件,這說明四個命令是一樣的。
mke2fs常用的選項有:
‘-b’ 分割槽時設定每個資料區塊佔用空間大小,目前支援1024, 2048 以及4096 bytes每個塊。
‘-i’ 設定inode的大小
‘-N’ 設定inode數量,有時使用預設的inode數不夠用,所以要自定設定inode數量。
‘-c’ 在格式化前先檢測一下磁碟是否有問題,加上這個選項後會非常慢
‘-L’ 預設該分割槽的標籤label
‘-j’ 建立ext3格式的分割槽,如果使用mkfs.ext3 就不用加這個選項了
‘-t’ 用來指定什麼型別的檔案系統,可以是ext2, ext3 也可以是 ext4

通過mke2fs命令格式化sdb5分割槽
[root@localhost ~]# mke2fs -t ext4 /dev/sdb5
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1310720 blocks
65536 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done 

指定塊大小格式化分割槽
[root@localhost ~]# mke2fs -t ext4 -b 8192 /dev/sdb5
Warning: blocksize 8192 not usable on most systems.
mke2fs 1.42.9 (28-Dec-2013)
mke2fs: 8192-byte blocks too big for system (max 4096)
Proceed anyway? (y,n) y
Warning: 8192-byte blocks too big for system (max 4096), forced to continue
warning: 80 blocks unused.

Filesystem label=
OS type: Linux
Block size=8192 (log=3)
Fragment size=8192 (log=3)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 655280 blocks
32764 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=671006720
10 block groups
65528 blocks per group, 65528 fragments per group
32768 inodes per group
Superblock backups stored on blocks: 
        65528, 196584, 327640, 458696, 589752

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done 
指定塊大小為8192會提示,塊值設定太大了,我們直接輸入 ‘y’ 強制格式化

命令 : e2label
用來檢視或修改分割槽的標籤
[root@localhost ~]# e2label /dev/sdb5 Test
[root@localhost ~]# e2label /dev/sdb5 
Test

5、掛載/解除安裝磁碟

都會寫到該分割槽中。這就需要你注意一下,在掛載該分割槽前,掛載點(目錄)下必須是個空目錄。其實目錄
不為空並不影響所掛載分割槽的使用,但是一旦掛載上了,那麼該目錄下以前的東西就不能看到了。只有解除安裝
掉該分割槽後才能看到。
命令 : mount
如果不加任何選項,直接執行 “mount” 命令,會顯示如下資訊,
[root@localhost ~]# 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=485864k,nr_inodes=121466,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)
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/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
cgroup on /sys/fs/cgroup/cpu,cpuacct type cgroup (rw,nosuid,nodev,noexec,relatime,cpuacct,cpu)
cgroup on /sys/fs/cgroup/devices type cgroup (rw,nosuid,nodev,noexec,relatime,devices)
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/net_cls,net_prio type cgroup (rw,nosuid,nodev,noexec,relatime,net_prio,net_cls)
cgroup on /sys/fs/cgroup/pids type cgroup (rw,nosuid,nodev,noexec,relatime,pids)
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
configfs on /sys/kernel/config type configfs (rw,relatime)
/dev/mapper/centos-root on / type xfs (rw,relatime,attr2,inode64,noquota)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=32,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=13763)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
mqueue on /dev/mqueue type mqueue (rw,relatime)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime)
/dev/sda1 on /boot type xfs (rw,relatime,attr2,inode64,noquota)
tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,size=99576k,mode=700)
這個命令可以檢視當前系統已經掛載的所有分割槽,以及分割槽檔案系統的型別,掛載點和一些選項等資訊,
所以你如果想知道某個分割槽的檔案系統型別直接用該命令檢視即可。下面我們先建立一個空目錄,然後在
目錄裡建一個空白文件。
[root@localhost ~]# mkdir /jwt
[root@localhost ~]# touch /jwt/newfile.txt
[root@localhost ~]# ls !$
ls /jwt/newfile.txt
/jwt/newfile.txt
後把剛才格式化的 /dev/sdb5 掛載到 /jwt 上
[root@localhost ~]# mount /dev/sdb5 /jwt/
mount: wrong fs type, bad option, bad superblock on /dev/sdb5,
       missing codepage or helper program, or other error

       In some cases useful info is found in syslog - try
       dmesg | tail or so.
  由於剛剛格式化的8192不合法所以重新格式化
  [root@localhost ~]# mke2fs -t ext4 -L TEST /dev/sdb5
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=TEST
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1310720 blocks
65536 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done 

重新掛載
[root@localhost ~]# mount /dev/sdb5 /jwt/
[root@localhost ~]# ls /jwt/
lost+found
[root@localhost ~]# df -h  檢視掛載目錄
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 475M     0  475M   0% /dev
tmpfs                    487M     0  487M   0% /dev/shm
tmpfs                    487M  7.7M  479M   2% /run
tmpfs                    487M     0  487M   0% /sys/fs/cgroup
/dev/mapper/centos-root   17G  4.0G   14G  24% /
/dev/sda1               1014M  136M  879M  14% /boot
tmpfs                     98M     0   98M   0% /run/user/0
/dev/sdb5                4.8G   20M  4.6G   1% /jwt
把 /dev/sdb5 掛載到 /newdir 後,原來在 /newdir 下的 newfile.txt 被覆蓋了,通過df-h可以看到
剛剛掛載的分割槽,我們也可以使用LABEL的方式掛載分割槽。

解除安裝掛載目錄
[root@localhost ~]# umount /dev/sdb5 /jwt/ 
umount: /jwt/: not mounted
[root@localhost ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 475M     0  475M   0% /dev
tmpfs                    487M     0  487M   0% /dev/shm
tmpfs                    487M  7.7M  479M   2% /run
tmpfs                    487M     0  487M   0% /sys/fs/cgroup
/dev/mapper/centos-root   17G  4.0G   14G  24% /
/dev/sda1               1014M  136M  879M  14% /boot
tmpfs                     98M     0   98M   0% /run/user/0

使用LABEL的方式掛載分割槽
[root@localhost ~]# mount LABEL=TEST /jwt/     
[root@localhost ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 475M     0  475M   0% /dev
tmpfs                    487M     0  487M   0% /dev/shm
tmpfs                    487M  7.7M  479M   2% /run
tmpfs                    487M     0  487M   0% /sys/fs/cgroup
/dev/mapper/centos-root   17G  4.0G   14G  24% /
/dev/sda1               1014M  136M  879M  14% /boot
tmpfs                     98M     0   98M   0% /run/user/0
/dev/sdb5                4.8G   20M  4.6G   1% /jwt

檢視/etc/fstab檔案資訊
使用cat命令
[root@localhost ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Tue Jan 26 20:02:47 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
#
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=ce073cc8-aadc-492b-9000-348409a75f6f /boot                   xfs     defaults        0 0
/dev/mapper/centos-swap swap                    swap    defaults        0 0

這個檔案是系統啟動時,需要掛載的各個分割槽。第一列就是分割槽的標識,可以寫分割槽的LABEL,也可以寫分割槽
的UUID(等會筆者會著重講一下這個概念),當然也可以寫分割槽名(/dev/sda1);第二列是掛載點;第三列是分
區的格式;第四列則是mount的一些掛載引數,等下會詳細介紹一下有哪些引數,一般情況下,直接寫defaul
ts即可;第五列的數字表示是否被dump備份,是的話這裡就是1,否則就是0;第六列是開機時是否自檢磁碟。
1,2都表示檢測,0表示不檢測,在Redhat/CentOS中,這個1,2還有個說法,/ 分割槽必須設為1,而且整個
fstab中只允許出現一個1,這裡有一個優先順序的說法。1比2優先順序高,所以先檢測1,然後再檢測2,如果有
多個分割槽需要開機檢測那麼都設定成2吧,1檢測完了後會同時去檢測2。下面該說說第四列中常用到的引數了。
“async/sync” : async表示和磁碟和記憶體不同步,系統每隔一段時間把記憶體資料寫入磁碟中,而sync則會時
時同步記憶體和磁碟中資料;
“auto/noauto” : 開機自動掛載/不自動掛載;
“default” : 按照大多數永久檔案系統的預設值設定掛載定義,它包含了rw, suid, dev, exec, auto, 
nouser, async
“ro” : 按只讀許可權掛載 ;
“rw” : 按可讀可寫許可權掛載 ;
“exec/noexec” : 允許/不允許可執行檔案執行,但千萬不要把根分割槽掛載為noexec,那就無法使用系統了,
連mount命令都無法使用了,這時只有重新做系統了;
“user/nouser” : 允許/不允許root外的其他使用者掛載分割槽,為了安全考慮,請用nouser ;
“suid/nosuid” : 允許/不允許分割槽有suid屬性,一般設定nosuid ;
“usrquota” : 啟動使用者磁碟配額模式,磁碟配額相關內容在後續章節會做介紹;
“grquota” : 啟動群組磁碟配額模式;
vim /etc/fstab
新增  LABEL=TEST              /jwt                 ext4    defaults        0 0  即可
[root@localhost ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Tue Jan 26 20:02:47 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
#
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=ce073cc8-aadc-492b-9000-348409a75f6f /boot                   xfs     defaults        0 0
/dev/mapper/centos-swap swap                    swap    defaults        0 0
LABEL=TEST              /jwt                 ext4    defaults        0 0
然後解除安裝掉剛才我們已經掛載的/dev/sdb5
[root@localhost ~]# umount /dev/sdb5 /jwt/ 
umount: /jwt/: not mounted
[root@localhost ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 475M     0  475M   0% /dev
tmpfs                    487M     0  487M   0% /dev/shm
tmpfs                    487M  7.7M  479M   2% /run
tmpfs                    487M     0  487M   0% /sys/fs/cgroup
/dev/mapper/centos-root   17G  4.0G   14G  24% /
/dev/sda1               1014M  136M  879M  14% /boot
tmpfs                     98M     0   98M   0% /run/user/0
使用df-h檢視已經成功解除安裝 /dev/sdb5 下面執行命令mount-a來進行自動掛載。
[root@localhost ~]# mount -a      
[root@localhost ~]# df -h         
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 475M     0  475M   0% /dev
tmpfs                    487M     0  487M   0% /dev/shm
tmpfs                    487M  7.7M  479M   2% /run
tmpfs                    487M     0  487M   0% /sys/fs/cgroup
/dev/mapper/centos-root   17G  4.0G   14G  24% /
/dev/sda1               1014M  136M  879M  14% /boot
tmpfs                     98M     0   98M   0% /run/user/0
/dev/sdb5                4.8G   20M  4.6G   1% /jwt
時,多出來一個 /dev/sdb5 掛載到了 /newdir 下。這就是mount-a命令執行的結果,
這個 ‘-a’ 選項會把/etc/fstab中出現的所有磁碟分割槽掛載上。
‘-t’ 選項用來指定掛載的分割槽型別,預設不指定會自動識別。
[root@localhost ~]# umount /dev/sdb5 /jwt/
[root@localhost ~]# mount -t ext4 /dev/sdb5 /jwt/
[root@localhost ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 475M     0  475M   0% /dev
tmpfs                    487M     0  487M   0% /dev/shm
tmpfs                    487M  7.7M  479M   2% /run
tmpfs                    487M     0  487M   0% /sys/fs/cgroup
/dev/mapper/centos-root   17G  4.0G   14G  24% /
/dev/sda1               1014M  136M  879M  14% /boot
tmpfs                     98M     0   98M   0% /run/user/0
/dev/sdb5                4.8G   20M  4.6G   1% /jwt
‘-o’ 選項用來指定掛載的分割槽有哪些特性,即上面 “/etc/fatab” 配置檔案中第四列的那些。
[root@localhost ~]# umount /dev/sdb5 /jwt/       
umount: /jwt/: not mounted
[root@localhost ~]# mount -o ro,sync /dev/sdb5 /jwt/
[root@localhost ~]# cd /jwt/
[root@localhost jwt]# mkdir test
mkdir: cannot create directory ‘test’: Read-only file system
//mkdir: 無法建立目錄 "/newdir/dir2": 只讀檔案系統
由於指定了 ‘ro’ 引數,所以該分割槽只讀了。通過mount命令也可以看到 /dev/sdb5 有 ‘ro’ 選項。

通過mount命令檢視/dev/sdb5資訊
[root@localhost jwt]# mount |tail
cgroup on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
configfs on /sys/kernel/config type configfs (rw,relatime)
/dev/mapper/centos-root on / type xfs (rw,relatime,attr2,inode64,noquota)
systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=32,pgrp=1,timeout=0,minproto=5,maxproto=5,direct,pipe_ino=13763)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
mqueue on /dev/mqueue type mqueue (rw,relatime)
hugetlbfs on /dev/hugepages type hugetlbfs (rw,relatime)
/dev/sda1 on /boot type xfs (rw,relatime,attr2,inode64,noquota)
tmpfs on /run/user/0 type tmpfs (rw,nosuid,nodev,relatime,size=99576k,mode=700)
/dev/sdb5 on /jwt type ext4 (ro,relatime,sync,data=ordered)

恢復讀寫功能
[root@localhost jwt]# mount -o remount /dev/sdb5 /jwt/
[root@localhost jwt]# mkdir /jwt/dir2
[root@localhost jwt]# ls /jwt/
dir2  lost+found
 命令 : blkid
 可以通過blkid命令獲取各分割槽的UUID
 [root@localhost jwt]# blkid
/dev/sda1: UUID="ce073cc8-aadc-492b-9000-348409a75f6f" TYPE="xfs" 
/dev/sda2: UUID="0jUFrn-WG4o-eQWH-jTim-YL6O-QNDP-zRuEmp" TYPE="LVM2_member" 
/dev/sdb5: LABEL="TEST" UUID="7bad286f-e1f3-4f9f-a19f-7c0909b6014c" TYPE="ext4" 
/dev/sr0: UUID="2019-09-11-18-50-31-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos" 
/dev/mapper/centos-root: UUID="cf576eed-7cea-42ed-941d-b1b8a262cb26" TYPE="xfs" 
/dev/mapper/centos-swap: UUID="98537a52-77e0-43f3-ab28-6d2eacfe8563" TYPE="swap" 
樣可以獲得全部磁碟分割槽的UUID,如果格式化的時候指定了 LABEL 則該命令也會顯示LABEL值,
甚至連檔案系統型別也會顯示。
通過blkid命令指定分割槽
[root@localhost jwt]# blkid /dev/sdb5
/dev/sdb5: LABEL="TEST" UUID="7bad286f-e1f3-4f9f-a19f-7c0909b6014c" TYPE="ext4" 

通過UUID來掛載磁碟分割槽
[root@localhost jwt]# umount  /jwt/         
[root@localhost jwt]# mount UUID="7bad286f-e1f3-4f9f-a19f-7c0909b6014c" /jwt/
mount: /dev/sdb5 is already mounted or /jwt busy
       /dev/sdb5 is already mounted on /jwt
[root@localhost jwt]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 475M     0  475M   0% /dev
tmpfs                    487M     0  487M   0% /dev/shm
tmpfs                    487M  7.7M  479M   2% /run
tmpfs                    487M     0  487M   0% /sys/fs/cgroup
/dev/mapper/centos-root   17G  4.0G   14G  24% /
/dev/sda1               1014M  136M  879M  14% /boot
tmpfs                     98M     0   98M   0% /run/user/0
/dev/sdb5                4.8G   20M  4.6G   1% /jwt