單純提供一個相對的解答,並不是標準答案!
單純就是個解答的參考,寫完之後再來這邊查查看答案跟你想的一樣不一樣!?
[root@station10-101 ~]# df -T 檔案系統 類型 1K-區段 已用 可用 已用% 掛載點 devtmpfs devtmpfs 918108 0 918108 0% /dev tmpfs tmpfs 936140 0 936140 0% /dev/shm tmpfs tmpfs 936140 9372 926768 2% /run tmpfs tmpfs 936140 0 936140 0% /sys/fs/cgroup /dev/mapper/centos-root xfs 10475520 4681876 5793644 45% / /dev/mapper/centos-home xfs 3135488 70712 3064776 3% /home /dev/vda2 ext4 1998672 149448 1727984 8% /boot [root@station10-101 ~]# dumpe2fs /dev/vda2 | grep -i size Filesystem features: has_journal ext_attr resize_inode dir_index filetype .... Block size: 4096 Fragment size: 4096 Group descriptor size: 64 Flex block group size: 16 Inode size: 256 Required extra isize: 32 Desired extra isize: 32 Journal size: 64M所以,inode 與 block 的容量,分別是 256bytes 以及 4K 喔!有興趣的同學,可以慢慢觀察一下 dumpe2fs 的輸出喔!
[student@station10-101 ~]$ ll -i /etc/hosts 16808543 -rw-r--r--. 1 root root 158 9月 10 2018 /etc/hosts
[student@station10-101 ~]$ cd /tmp [student@station10-101 tmp]$ mkdir inodecheck [student@station10-101 tmp]$ ll -di /tmp/inodecheck/ /tmp/inodecheck/. 2228153 drwxrwxr-x. 2 student student 6 Apr 7 12:23 /tmp/inodecheck/ 2228153 drwxrwxr-x. 2 student student 6 Apr 7 12:23 /tmp/inodecheck/.其實,這兩個『檔名』對應的 inode 號碼一模一樣,代表這兩個檔名是一模一樣的內容!因此,除了檔名不同之外, 所有的參數都會一模一樣!所以說,那個 . 代表的是目錄本身,原因就是,共用相同的 inode 號碼!
[student@station10-101 tmp]$ cd inodecheck [student@station10-101 inodecheck]$ mkdir check2 [student@station10-101 inodecheck]$ ll total 0 drwxrwxr-x. 2 student student 6 Apr 7 12:25 check2 [student@station10-101 inodecheck]$ ll -di /tmp/inodecheck/ /tmp/inodecheck/. /tmp/inodecheck/check2/.. 2228153 drwxrwxr-x. 3 student student 20 Apr 7 12:25 /tmp/inodecheck/ 2228153 drwxrwxr-x. 3 student student 20 Apr 7 12:25 /tmp/inodecheck/. 2228153 drwxrwxr-x. 3 student student 20 Apr 7 12:25 /tmp/inodecheck/check2/..那個 .. 代表『上層目錄』,所以,每建立一個子目錄,上層目錄的連結數就會 +1,這就是因為 inode 號碼相同的緣故喔!
[student@station10-101 inodecheck]$ cd /dev/shm [student@station10-101 shm]$ mkdir check2 [student@station10-101 shm]$ cd check2
[student@station10-101 check2]$ cp /etc/hosts . [student@station10-101 check2]$ ll -i 173581 -rw-r--r--. 1 student student 158 Apr 7 13:39 hosts
[student@station10-101 check2]$ ln hosts hosts.real [student@station10-101 check2]$ ll -i hosts* 173581 -rw-r--r--. 2 student student 158 Apr 7 13:39 hosts 173581 -rw-r--r--. 2 student student 158 Apr 7 13:39 hosts.real所以,實體連結,只會讓該 inode number 對應到另一個檔名,所以全部的屬性都會相同!如上所示,除了檔名之外,全部資料一模一樣喔!
[student@station10-101 check2]$ ln -s hosts hosts.symbo [student@station10-101 check2]$ ll -i hosts hosts.symbo 173581 -rw-r--r--. 2 student student 158 Apr 7 13:39 hosts 173590 lrwxrwxrwx. 1 student student 5 Apr 7 13:40 hosts.symbo -> hosts當為符號連結時,兩個檔名對應的 inode 並不相同,代表兩個完全獨立的檔案!但是,檔名會指向正確的檔名!而且注意看這個符號連結檔的容量: 因為檔名一個英文大致佔用一個 byte 的容量 hosts 共有 5 個字元,因此佔用 5bytes 的容量之意!
[student@station10-101 check2]$ rm hosts [student@station10-101 check2]$ ll total 4 -rw-r--r--. 1 student student 158 Apr 7 13:39 hosts.real lrwxrwxrwx. 1 student student 5 Apr 7 13:40 hosts.symbo -> hosts實體連結的部份,因為檔名少一條,所以 link number 會 -1,但是檔案的部份還是正常的!資料沒有改變。 符號連結的部份,因為原始檔案不見了,所以檔名顏色會變得奇怪!
[student@station10-101 check2]$ cat hosts.real 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 [student@station10-101 check2]$ cat hosts.symbo cat: hosts.symbo: No such file or directory實體連結沒問題,因為依舊找到正確的 inode 號碼!符號連結會顯示找不到該檔案!這是因為檔名不見了!沒找到到正確的 inode 所以自然就無法取得正確的內容!因此回報找不到檔案喔!
[student@station10-101 check2]$ df -T Filesystem Type 1K-blocks Used Available Use% Mounted on devtmpfs devtmpfs 918108 0 918108 0% /dev tmpfs tmpfs 936140 4 936136 1% /dev/shm tmpfs tmpfs 936140 9372 926768 2% /run tmpfs tmpfs 936140 0 936140 0% /sys/fs/cgroup /dev/mapper/centos-root xfs 10475520 4681884 5793636 45% / /dev/mapper/centos-home xfs 3135488 70712 3064776 3% /home /dev/vda2 ext4 1998672 149448 1727984 8% /boot如上所示, /dev/shm 以及 /etc (就是 /) 分屬不同的檔案系統!現在來處理實體連結:
[student@station10-101 check2]$ ln /etc/hosts .
ln: failed to create hard link './hosts' => '/etc/hosts': Invalid cross-device link
實體連結必需要指向同一個 inode 號碼,而且,必須要再同一個裝置上面!如果跨檔案系統,因為不同的檔案系統其 inode 號碼參照並不相同,
所以不能跨檔案系統執行實體連結!所以,剛剛的指令就會失敗了!正確原因:不同的檔案系統之間,不能使用實體連結
[student@station10-101 check2]$ df -T
Filesystem Type 1K-blocks Used Available Use% Mounted on
devtmpfs devtmpfs 918108 0 918108 0% /dev
tmpfs tmpfs 936140 4 936136 1% /dev/shm
tmpfs tmpfs 936140 9372 926768 2% /run
tmpfs tmpfs 936140 0 936140 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 10475520 4681884 5793636 45% /
/dev/mapper/centos-home xfs 3135488 70712 3064776 3% /home
/dev/vda2 ext4 1998672 149448 1727984 8% /boot
tmpfs tmpfs 187228 16 187212 1% /run/user/42
tmpfs tmpfs 187228 4 187224 1% /run/user/0
裝置名稱為 tmpfs 的,大致上都屬於系統由記憶體模擬出來的資料,而 /dev 開頭的,才會是實體裝置。至於 Type 欄位就是檔案系統類型。
屬於 xfs 的,共有兩個 XFS 檔案系統,分別在 / 以及 /home 掛載點上面。裝置名稱 /dev/mapper/centos-root 與 /dev/mapper/centos-home
這兩個裝置主要由 LVM 而來,我們後面章節再來談
[student@station10-101 check2]$ ls -lid / /boot /home /etc /root /proc /sys
128 dr-xr-xr-x. 17 root root 224 Feb 26 09:02 /
2 dr-xr-xr-x. 6 root root 4096 Feb 26 09:15 /boot
16797825 drwxr-xr-x. 135 root root 8192 Apr 7 10:04 /etc
128 drwxr-xr-x. 9 root root 117 Mar 16 15:20 /home
1 dr-xr-xr-x. 230 root root 0 Apr 7 09:56 /proc
25165953 dr-xr-x---. 6 root root 286 Mar 15 23:15 /root
1 dr-xr-xr-x. 13 root root 0 Apr 7 09:56 /sys
[root@station10-101 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 1024M 0 rom vda 252:0 0 30G 0 disk ├─vda1 252:1 0 2M 0 part ├─vda2 252:2 0 2G 0 part /boot └─vda3 252:3 0 20G 0 part ├─centos-root 253:0 0 10G 0 lvm / ├─centos-swap 253:1 0 2G 0 lvm [SWAP] └─centos-home 253:2 0 3G 0 lvm /home
-i, --ascii Use ASCII characters for tree formatting. -p, --paths Print full device paths. [root@station10-101 ~]# lsblk -i -p NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT /dev/sr0 11:0 1 1024M 0 rom /dev/vda 252:0 0 30G 0 disk |-/dev/vda1 252:1 0 2M 0 part |-/dev/vda2 252:2 0 2G 0 part /boot `-/dev/vda3 252:3 0 20G 0 part |-/dev/mapper/centos-root 253:0 0 10G 0 lvm / |-/dev/mapper/centos-swap 253:1 0 2G 0 lvm [SWAP] `-/dev/mapper/centos-home 253:2 0 3G 0 lvm /home所以裝置檔名實際上就是 /dev/vda 了!
[root@station10-101 ~]# parted /dev/vda print 型號:Virtio 區塊裝置 (virtblk) 磁碟 /dev/vda:32.2GB 磁區大小 (邏輯/物理):512B/512B 分割區:gpt 磁碟旗標:pmbr_boot 編號 起始點 結束點 大小 檔案系統 名稱 旗標 1 1049kB 3146kB 2097kB bios_grub 2 3146kB 2151MB 2147MB ext4 3 2151MB 23.6GB 21.5GB lvm我們這個裝置用的是 gpt 的分割表喔!
# 先以 gdisk 進入分割畫面,然後按下 p 來觀察剩餘容量: [root@station10-101 ~]# gdisk /dev/vda GPT fdisk (gdisk) version 1.0.3 Partition table scan: MBR: protective BSD: not present APM: not present GPT: present Found valid GPT with protective MBR; using GPT. Command (? for help): p Disk /dev/vda: 62914560 sectors, 30.0 GiB <==共有 30G 以及 62914560 個磁區 Sector size (logical/physical): 512/512 bytes Disk identifier (GUID): 62CDB59E-F745-44E0-9286-FC13370D8116 Partition table holds up to 128 entries Main partition table begins at sector 2 and ends at sector 33 First usable sector is 34, last usable sector is 62914526 Partitions will be aligned on 2048-sector boundaries Total free space is 16764861 sectors (8.0 GiB) <==還有剩餘的容量! Number Start (sector) End (sector) Size Code Name 1 2048 6143 2.0 MiB EF02 2 6144 4200447 2.0 GiB 8300 3 4200448 46151679 20.0 GiB 8E00所以,還有 8G 容量可以使用喔!至於磁區 (sector) 號碼,目前用到 46151679 號,最多可到 62914560 號。
Command (? for help): n Partition number (4-128, default 4): ↵ <==用預設值,不用變,所以按 [enter] First sector (34-62914526, default = 46151680) or {+-}size{KMGTP}: ↵ <==用預設值,不用變,所以按 [enter] Last sector (46151680-62914526, default = 62914526) or {+-}size{KMGTP}: +1G <==這裡才要改! Current type is 'Linux filesystem' Hex code or GUID (L to show codes, Enter = 8300): L <==若不知道 code,可以按 L 0700 Microsoft basic data 0c01 Microsoft reserved 2700 Windows RE 3000 ONIE boot 3001 ONIE config 3900 Plan 9 4100 PowerPC PReP boot 4200 Windows LDM data 4201 Windows LDM metadata 4202 Windows Storage Spac 7501 IBM GPFS 7f00 ChromeOS kernel 7f01 ChromeOS root 7f02 ChromeOS reserved 8200 Linux swap 8300 Linux filesystem 8301 Linux reserved 8302 Linux /home 8303 Linux x86 root (/) 8304 Linux x86-64 root (/ 8305 Linux ARM64 root (/) 8306 Linux /srv 8307 Linux ARM32 root (/) 8400 Intel Rapid Start 8e00 Linux LVM a000 Android bootloader a001 Android bootloader 2 a002 Android boot a003 Android recovery a004 Android misc a005 Android metadata a006 Android system a007 Android cache ...... fb01 VMWare reserved fc00 VMWare kcore crash p fd00 Linux RAID Hex code or GUID (L to show codes, Enter = 8300): 8300 Changed type of partition to 'Linux filesystem' Command (? for help): p Disk /dev/vda: 62914560 sectors, 30.0 GiB Sector size (logical/physical): 512/512 bytes Disk identifier (GUID): 62CDB59E-F745-44E0-9286-FC13370D8116 Partition table holds up to 128 entries Main partition table begins at sector 2 and ends at sector 33 First usable sector is 34, last usable sector is 62914526 Partitions will be aligned on 2048-sector boundaries Total free space is 14667709 sectors (7.0 GiB) <==容量就減少了! Number Start (sector) End (sector) Size Code Name 1 2048 6143 2.0 MiB EF02 2 6144 4200447 2.0 GiB 8300 3 4200448 46151679 20.0 GiB 8E00 4 46151680 48248831 1024.0 MiB 8300 Linux filesystem <==務必觀察新建立的分割槽是否正確這樣就建置妥當了!
Command (? for help): w Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!! Do you want to proceed? (Y/N): y OK; writing new GUID partition table (GPT) to /dev/vda. Warning: The kernel is still using the old partition table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) The operation has completed successfully.上面的警告訊息是說,因為 Linux 作業系統擔心你做了蠢事,為了保有讓你復原的狀態,所以核心會使用舊的、可以順利運作的分割表, 而新的分割表要嘛就是重新開機 (reboot) 要嘛就是當你執行 partprobe 強制核心更新分割表,這樣才能使用新的分割喔!
[root@station10-101 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 1024M 0 rom vda 252:0 0 30G 0 disk ├─vda1 252:1 0 2M 0 part ├─vda2 252:2 0 2G 0 part /boot └─vda3 252:3 0 20G 0 part ├─centos-root 253:0 0 10G 0 lvm / ├─centos-swap 253:1 0 2G 0 lvm [SWAP] └─centos-home 253:2 0 3G 0 lvm /home # 你可以發現,並不存在 /dev/vda4 喔!這很正常!因為核心會使用舊的分割表! [root@station10-101 ~]# gdisk -l /dev/vda ...... Number Start (sector) End (sector) Size Code Name 1 2048 6143 2.0 MiB EF02 2 6144 4200447 2.0 GiB 8300 3 4200448 46151679 20.0 GiB 8E00 4 46151680 48248831 1024.0 MiB 8300 Linux filesystem # 不過,使用 gdisk -l 直接觀察 /dev/vda 的分割資訊,確實可以發現正確的分割表! [root@station10-101 ~]# partprobe [root@station10-101 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 1024M 0 rom vda 252:0 0 30G 0 disk ├─vda1 252:1 0 2M 0 part ├─vda2 252:2 0 2G 0 part /boot ├─vda3 252:3 0 20G 0 part │ ├─centos-root 253:0 0 10G 0 lvm / │ ├─centos-swap 253:1 0 2G 0 lvm [SWAP] │ └─centos-home 253:2 0 3G 0 lvm /home └─vda4 252:4 0 1G 0 part也就是說,雖然你的分割表在 gdisk 之後已經被寫入磁碟,但是核心並沒有同步更新!直到你執行 partprobe 或 reboot 之後, 核心才能夠使用最新的分割表!這是為了要保護你的系統的緣故!避免你手滑做錯的緣故!
# 這一題有陷阱~那就是 1.5G 這個數字!請看如下作法: [root@station10-101 ~]# gdisk /dev/vda GPT fdisk (gdisk) version 1.0.3 Partition table scan: MBR: protective BSD: not present APM: not present GPT: present Found valid GPT with protective MBR; using GPT. Command (? for help): n Partition number (5-128, default 5): ↵ First sector (34-62914526, default = 48248832) or {+-}size{KMGTP}: ↵ Last sector (48248832-62914526, default = 62914526) or {+-}size{KMGTP}: +1.5G Current type is 'Linux filesystem' Hex code or GUID (L to show codes, Enter = 8300): ↵ Changed type of partition to 'Linux filesystem' Command (? for help): p Disk /dev/vda: 62914560 sectors, 30.0 GiB Sector size (logical/physical): 512/512 bytes Disk identifier (GUID): 62CDB59E-F745-44E0-9286-FC13370D8116 Partition table holds up to 128 entries Main partition table begins at sector 2 and ends at sector 33 First usable sector is 34, last usable sector is 62914526 Partitions will be aligned on 2048-sector boundaries Total free space is 14667708 sectors (7.0 GiB) Number Start (sector) End (sector) Size Code Name 1 2048 6143 2.0 MiB EF02 2 6144 4200447 2.0 GiB 8300 3 4200448 46151679 20.0 GiB 8E00 4 46151680 48248831 1024.0 MiB 8300 Linux filesystem 5 48248832 48248832 512 bytes 8300 Linux filesystem # 夭壽!容量竟然只有 512bytes 耶!根本就沒有 1.5G 啊!趕緊刪除 5 號磁碟分割槽 Command (? for help): d Partition number (1-5): 5 # 開始正確的設定好 1.5G,其實是 1500M 的分割槽! Command (? for help): n Partition number (5-128, default 5): ↵ First sector (34-62914526, default = 48248832) or {+-}size{KMGTP}: ↵ Last sector (48248832-62914526, default = 62914526) or {+-}size{KMGTP}: +1500M Current type is 'Linux filesystem' Hex code or GUID (L to show codes, Enter = 8300): L 0700 Microsoft basic data 0c01 Microsoft reserved 2700 Windows RE 3000 ONIE boot 3001 ONIE config 3900 Plan 9 ...... Hex code or GUID (L to show codes, Enter = 8300): 0700 Changed type of partition to 'Microsoft basic data' Command (? for help): p ...... Number Start (sector) End (sector) Size Code Name 1 2048 6143 2.0 MiB EF02 2 6144 4200447 2.0 GiB 8300 3 4200448 46151679 20.0 GiB 8E00 4 46151680 48248831 1024.0 MiB 8300 Linux filesystem 5 48248832 51320831 1.5 GiB 0700 Microsoft basic data整體建置流程有點像這樣!最終還是要觀察 /dev/vda5 是否正確的顯示出 1.5G 的容量喔!
Command (? for help): n Partition number (6-128, default 6): ↵ First sector (34-62914526, default = 51320832) or {+-}size{KMGTP}: ↵ Last sector (51320832-62914526, default = 62914526) or {+-}size{KMGTP}: +1G Current type is 'Linux filesystem' Hex code or GUID (L to show codes, Enter = 8300): L 0700 Microsoft basic data 0c01 Microsoft reserved 2700 Windows RE 3000 ONIE boot 3001 ONIE config 3900 Plan 9 4100 PowerPC PReP boot 4200 Windows LDM data 4201 Windows LDM metadata 4202 Windows Storage Spac 7501 IBM GPFS 7f00 ChromeOS kernel 7f01 ChromeOS root 7f02 ChromeOS reserved 8200 Linux swap 8300 Linux filesystem 8301 Linux reserved 8302 Linux /home 8303 Linux x86 root (/) 8304 Linux x86-64 root (/ 8305 Linux ARM64 root (/) ...... Hex code or GUID (L to show codes, Enter = 8300): 8200 Changed type of partition to 'Linux swap' Command (? for help): p ...... Number Start (sector) End (sector) Size Code Name 1 2048 6143 2.0 MiB EF02 2 6144 4200447 2.0 GiB 8300 3 4200448 46151679 20.0 GiB 8E00 4 46151680 48248831 1024.0 MiB 8300 Linux filesystem 5 48248832 51320831 1.5 GiB 0700 Microsoft basic data 6 51320832 53417983 1024.0 MiB 8200 Linux swap兩個分割槽就此建立!但是並沒有更新核心資料!
Command (? for help): w Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!! Do you want to proceed? (Y/N): y OK; writing new GUID partition table (GPT) to /dev/vda. Warning: The kernel is still using the old partition table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) The operation has completed successfully. [root@station10-101 ~]# partprobe [root@station10-101 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 1024M 0 rom vda 252:0 0 30G 0 disk ├─vda1 252:1 0 2M 0 part ├─vda2 252:2 0 2G 0 part /boot ├─vda3 252:3 0 20G 0 part │ ├─centos-root 253:0 0 10G 0 lvm / │ ├─centos-swap 253:1 0 2G 0 lvm [SWAP] │ └─centos-home 253:2 0 3G 0 lvm /home ├─vda4 252:4 0 1G 0 part ├─vda5 252:5 0 1.5G 0 part └─vda6 252:6 0 1G 0 part
# XFS 檔案系統 [root@station10-101 ~]# mkfs.xfs /dev/vda4 meta-data=/dev/vda4 isize=512 agcount=4, agsize=65536 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=1, sparse=1, rmapbt=0 = reflink=1 data = bsize=4096 blocks=262144, 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 # isize 是 inode 容量, bsize 是 block 容量,inode 已經大到 512 咯! # VFAT 檔案系統 [root@station10-101 ~]# mkfs.vfat /dev/vda5 mkfs.fat 4.1 (2017-01-24) # swap 磁碟置換資料格式 [root@station10-101 ~]# mkswap /dev/vda6 Setting up swapspace version 1, size = 1024 MiB (1073737728 bytes) 無標籤,UUID=d4e164a3-1e73-40ce-93cb-e3558fbbe8a0 # 查看一下各個分割槽的 UUID 識別碼 [root@station10-101 ~]# blkid /dev/vda1: PARTUUID="752f812a-6c0c-4390-9a03-40e976f44bb6" /dev/vda2: UUID="73f13e7b-43c4-43c5-93b4-9e65b962752d" TYPE="ext4" PARTUUID="37f60940-db11-4b6e-83f8-52c7b73bf820" /dev/vda3: UUID="40OBvj-5n63-Dwml-s79y-3dHf-Aed0-3da0uF" TYPE="LVM2_member" PARTUUID="270edd4e-5013-44e6-aa4a-590b4d7e896e" /dev/vda4: UUID="f3f0b058-d9e3-4e78-a4f7-c7d9513513bb" TYPE="xfs" PARTLABEL="Linux filesystem" PARTUUID="3b1e32db-9125-4c9d-90fa-7a12228bbb94" /dev/vda5: UUID="2F4E-C22A" TYPE="vfat" PARTLABEL="Microsoft basic data" PARTUUID="004f925c-1677-4bae-81cf-634cbb797a9e" /dev/vda6: UUID="d4e164a3-1e73-40ce-93cb-e3558fbbe8a0" TYPE="swap" PARTLABEL="Linux swap" PARTUUID="2d08b4a9-9464-4b50-bf5d-a39adc6d020f" /dev/mapper/centos-root: UUID="6e34b71e-cb8a-4088-84b7-ec6cf0fcadd0" TYPE="xfs" /dev/mapper/centos-swap: UUID="57dd6e82-8fb4-4433-82b5-f42216c1b0a9" TYPE="swap" /dev/mapper/centos-home: UUID="9e161f20-b700-4126-a0c9-300a049cdc9f" TYPE="xfs"
# 先模擬使用載點的狀態,同時確認該目錄確實在掛載點內! [root@station10-101 ~]# cd /srv/linux [root@station10-101 linux]# pwd /srv/linux [root@station10-101 linux]# df /srv/linux 檔案系統 1K-區段 已用 可用 已用% 掛載點 /dev/vda4 1038336 40368 997968 4% /srv/linux <==這真的是個掛載點喔! # 嘗試卸載,若無法卸載,使用 lsof (list open file) 找出使用中的程序! [root@station10-101 linux]# umount /srv/linux umount: /srv/linux: target is busy. [root@station10-101 linux]# lsof | grep '/srv/linux' bash 23914 root cwd DIR 252,4 6 128 /srv/linux lsof 24585 root cwd DIR 252,4 6 128 /srv/linux grep 24586 root cwd DIR 252,4 6 128 /srv/linux lsof 24587 root cwd DIR 252,4 6 128 /srv/linux [root@station10-101 linux]# ps -l F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD 0 S 0 23914 23906 0 80 0 - 7393 - pts/0 00:00:00 bash 0 R 0 24588 23914 0 80 0 - 11191 - pts/0 00:00:00 ps # 果然就是自己! # 模擬不再使用該載點資訊,然後卸載看看! [root@station10-101 linux]# cd [root@station10-101 ~]# umount /srv/linux [root@station10-101 ~]# df /srv/linux 檔案系統 1K-區段 已用 可用 已用% 掛載點 /dev/mapper/centos-root 10475520 4682164 5793356 45% / # 很明顯的發現,該目錄直接掛載在根目錄上,不是額外的檔案系統囉!
[root@station10-101 ~]# df 檔案系統 1K-區段 已用 可用 已用% 掛載點 devtmpfs 918108 0 918108 0% /dev tmpfs 936140 4 936136 1% /dev/shm tmpfs 936140 9388 926752 2% /run tmpfs 936140 0 936140 0% /sys/fs/cgroup /dev/mapper/centos-root 10475520 4682144 5793376 45% / /dev/mapper/centos-home 3135488 70712 3064776 3% /home /dev/vda2 1998672 149448 1727984 8% /boot tmpfs 187228 16 187212 1% /run/user/42 tmpfs 187228 4 187224 1% /run/user/0 /dev/vda5 1532984 4 1532980 1% /srv/win [root@station10-101 ~]# umount /srv/win [root@station10-101 ~]# swapon -s Filename Type Size Used Priority /dev/dm-1 partition 2097148 0 -2 /dev/vda6 partition 1048572 0 -3 [root@station10-101 ~]# swapoff /dev/vda6 [root@station10-101 ~]# swapon -s Filename Type Size Used Priority /dev/dm-1 partition 2097148 0 -2
[root@station10-101 ~]# df -T 檔案系統 類型 1K-區段 已用 可用 已用% 掛載點 /dev/vda5 vfat 1532984 4 1532980 1% /srv/win /dev/vda4 xfs 1038336 40368 997968 4% /srv/linux [root@station10-101 ~]# swapon -s Filename Type Size Used Priority /dev/vda6 partition 1048572 0 -2 /dev/dm-1 partition 2097148 0 -3 [root@station10-101 ~]# umount /dev/vda4 /dev/vda5 [root@station10-101 ~]# swapoff /dev/vda6
[root@station10-101 ~]# vim /etc/fstab #UUID="f3f0b058-d9e3-4e78-a4f7-c7d9513513bb" /srv/linux xfs defaults 0 0 #UUID="2F4E-C22A" /srv/win vfat defaults 0 0 #UUID="d4e164a3-1e73-40ce-93cb-e3558fbbe8a0" swap swap defaults 0 0 # 我這裡暫時將它註解而已~
[root@station10-101 ~]# mount -a; swapon -a [root@station10-101 ~]# df -T /srv/win /srv/linux ; swapon -s 檔案系統 類型 1K-區段 已用 可用 已用% 掛載點 /dev/mapper/centos-root xfs 10475520 4682544 5792976 45% / /dev/mapper/centos-root xfs 10475520 4682544 5792976 45% / Filename Type Size Used Priority /dev/dm-1 partition 2097148 0 -2看起來確實都沒有 /dev/vda4, /dev/vda5, /dev/vda6 這三個裝置的使用情境了!
[root@station10-101 ~]# blkid /dev/vda{4..6} /dev/vda4: UUID="f3f0b058-d9e3-4e78-a4f7-c7d9513513bb" TYPE="xfs" ... /dev/vda5: UUID="2F4E-C22A" TYPE="vfat" PARTLABEL="Microsoft basic... /dev/vda6: UUID="d4e164a3-1e73-40ce-93cb-e3558fbbe8a0" TYPE="swap"... # 看起來是具有檔案系統的,所以具有 TYPE 及 UUID 資訊 [root@station10-101 ~]# dd if=/dev/zero of=/dev/vda4 bs=1M count=10 10+0 records in 10+0 records out 10485760 bytes (10 MB, 10 MiB) copied, 0.0478999 s, 219 MB/s [root@station10-101 ~]# dd if=/dev/zero of=/dev/vda5 bs=1M count=10 10+0 records in 10+0 records out 10485760 bytes (10 MB, 10 MiB) copied, 0.0344661 s, 304 MB/s [root@station10-101 ~]# dd if=/dev/zero of=/dev/vda6 bs=1M count=10 10+0 records in 10+0 records out 10485760 bytes (10 MB, 10 MiB) copied, 0.0451356 s, 232 MB/s [root@station10-101 ~]# blkid /dev/vda{4..6} /dev/vda4: PARTLABEL="Linux filesystem" PARTUUID="3b1e32db-9125-4c9d-90fa-7a12228bbb94" /dev/vda5: PARTLABEL="Microsoft basic data" PARTUUID="004f925c-1677-4bae-81cf-634cbb797a9e" /dev/vda6: PARTLABEL="Linux swap" PARTUUID="2d08b4a9-9464-4b50-bf5d-a39adc6d020f" # 很明顯的發現 UUID 不見了喔!
[root@station10-101 ~]# gdisk /dev/vda GPT fdisk (gdisk) version 1.0.3 Partition table scan: MBR: protective BSD: not present APM: not present GPT: present Found valid GPT with protective MBR; using GPT. Command (? for help): d Partition number (1-6): 6 Command (? for help): d Partition number (1-5): 5 Command (? for help): d Partition number (1-4): 4 Command (? for help): p ...... Number Start (sector) End (sector) Size Code Name 1 2048 6143 2.0 MiB EF02 2 6144 4200447 2.0 GiB 8300 3 4200448 46151679 20.0 GiB 8E00 Command (? for help): w Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!! Do you want to proceed? (Y/N): y ......
[root@station10-101 ~]# partprobe [root@station10-101 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 1024M 0 rom vda 252:0 0 30G 0 disk ├─vda1 252:1 0 2M 0 part ├─vda2 252:2 0 2G 0 part /boot └─vda3 252:3 0 20G 0 part ├─centos-root 253:0 0 10G 0 lvm / ├─centos-swap 253:1 0 2G 0 lvm [SWAP] └─centos-home 253:2 0 3G 0 lvm /home可以確認分割表當中已經不存在 /dev/vda4, /dev/vda5, /dev/vda6 了!
# a. 找出目前系統上面所有的磁碟檔名,最簡單用 lsblk 即可 [root@station10-101 ~]# lsblk -p NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT /dev/sr0 11:0 1 1024M 0 rom /dev/vda 252:0 0 30G 0 disk ├─/dev/vda1 252:1 0 2M 0 part ├─/dev/vda2 252:2 0 2G 0 part /boot └─/dev/vda3 252:3 0 20G 0 part ├─/dev/mapper/centos-root 253:0 0 10G 0 lvm / ├─/dev/mapper/centos-swap 253:1 0 2G 0 lvm [SWAP] └─/dev/mapper/centos-home 253:2 0 3G 0 lvm /home # b. 開始測試一下,這個 vda 是屬於那一種分割表? [root@station10-101 ~]# parted /dev/vda print 型號:Virtio 區塊裝置 (virtblk) 磁碟 /dev/vda:32.2GB 磁區大小 (邏輯/物理):512B/512B 分割區:gpt 磁碟旗標:pmbr_boot 編號 起始點 結束點 大小 檔案系統 名稱 旗標 1 1049kB 3146kB 2097kB bios_grub 2 3146kB 2151MB 2147MB ext4 3 2151MB 23.6GB 21.5GB lvm # c. 簡單直覺就用 blkid 即可: [root@station10-101 ~]# blkid /dev/mapper/centos-root: UUID="6e34b71e-cb8a-4088-84b7-ec6cf0fcadd0" TYPE="xfs" /dev/vda3: UUID="40OBvj-5n63-Dwml-s79y-3dHf-Aed0-3da0uF" TYPE="LVM2_member" PARTUUID="270edd4e-5013-44e6-aa4a-590b4d7e896e" /dev/vda2: UUID="73f13e7b-43c4-43c5-93b4-9e65b962752d" TYPE="ext4" PARTUUID="37f60940-db11-4b6e-83f8-52c7b73bf820" /dev/mapper/centos-swap: UUID="57dd6e82-8fb4-4433-82b5-f42216c1b0a9" TYPE="swap" /dev/mapper/centos-home: UUID="9e161f20-b700-4126-a0c9-300a049cdc9f" TYPE="xfs" /dev/vda1: PARTUUID="752f812a-6c0c-4390-9a03-40e976f44bb6" # d. 從上一題知道了 /dev/vda2 為 ext4 而 centos-home, centos-root 為 xfs,所以: ot@station10-101 ~]# dumpe2fs /dev/vda2 | grep -i size dumpe2fs 1.44.6 (5-Mar-2019) Filesystem features: has_journal ext_attr resize_inode dir_index filetype ... Block size: 4096 Fragment size: 4096 Group descriptor size: 64 Flex block group size: 16 Inode size: 256 Required extra isize: 32 Desired extra isize: 32 Journal size: 64M [root@station10-101 ~]# xfs_info /dev/mapper/centos-root meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=655360 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=1, sparse=1, rmapbt=0 = reflink=1 data = bsize=4096 blocks=2621440, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0, ftype=1 log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 [root@station10-101 ~]# xfs_info /dev/mapper/centos-home meta-data=/dev/mapper/centos-home isize=512 agcount=4, agsize=196608 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=1, sparse=1, rmapbt=0 = reflink=1 data = bsize=4096 blocks=786432, 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 # block size 大致都是 4K, inode 容量不同喔! XFS 是 512bytes, EXT4 是 256 bytes # e. 與 f. 找出 swap 的裝置名稱 [root@station10-101 ~]# swapon -s Filename Type Size Used Priority /dev/dm-1 partition 2097148 0 -2 [root@station10-101 ~]# blkid ...... /dev/mapper/centos-swap: UUID="57dd6e82-8fb4-4433-82b5-f42216c1b0a9" TYPE="swap" ...... [root@station10-101 ~]# ll /dev/mapper/centos-swap lrwxrwxrwx. 1 root root 7 4月 11 17:07 /dev/mapper/centos-swap -> ../dm-1 # 原來是 /dev/mapper/centos-swap 這個檔案系統!!
# a. 用 find 找連結檔 [root@station10-101 ~]# find /etc -type l /etc/mtab /etc/fonts/conf.d/66-sil-nuosu.conf /etc/fonts/conf.d/31-cantarell.conf /etc/fonts/conf.d/66-google-noto-sans-tai-viet.conf ...... /etc/yum/vars /etc/yum.conf /etc/grub2.cfg [root@station10-101 ~]# ll /etc/yum/vars /etc/yum.conf /etc/grub2.cfg lrwxrwxrwx. 1 root root 22 11月 26 00:08 /etc/grub2.cfg -> ../boot/grub2/grub.cfg lrwxrwxrwx. 1 root root 12 11月 12 23:35 /etc/yum.conf -> dnf/dnf.conf lrwxrwxrwx. 1 root root 11 11月 12 23:35 /etc/yum/vars -> ../dnf/vars # 檢測一下,至少後面幾個檔案,確實全部都是連結檔! # b. 透過 ls 以及 grep 去抓取 /etc 底下 (不含子目錄) 的連結檔,透過抓 > 這個關鍵字! [root@station10-101 ~]# ll /etc | grep '>' lrwxrwxrwx. 1 root root 56 7月 31 2019 favicon.png -> /usr/share/icons/hicolor/16x16/apps/fedora-logo-icon.png lrwxrwxrwx. 1 root root 22 11月 26 00:08 grub2.cfg -> ../boot/grub2/grub.cfg lrwxrwxrwx. 1 root root 11 5月 11 2019 init.d -> rc.d/init.d lrwxrwxrwx. 1 root root 33 2月 26 09:10 localtime -> ../usr/share/zoneinfo/Asia/Taipei lrwxrwxrwx. 1 root root 19 2月 26 09:03 mtab -> ../proc/self/mounts ...... lrwxrwxrwx. 1 root root 14 1月 2 23:21 redhat-release -> centos-release lrwxrwxrwx. 1 root root 14 1月 2 23:21 system-release -> centos-release lrwxrwxrwx. 1 root root 12 11月 12 23:35 yum.conf -> dnf/dnf.conf # c. 列出 inode 號碼,加上 -i 即可! [root@station10-101 ~]# ll -i /etc | grep '>' ...... 16808525 lrwxrwxrwx. 1 root root 14 1月 2 23:21 redhat-release -> centos-release 16808526 lrwxrwxrwx. 1 root root 14 1月 2 23:21 system-release -> centos-release 18101923 lrwxrwxrwx. 1 root root 12 11月 12 23:35 yum.conf -> dnf/dnf.conf # d. 找出 /boot 底下,容量最大的檔案檔名: [root@station10-101 ~]# cd /boot [root@station10-101 boot]# ll --sort=size -r 總計 137704 drwxr-xr-x. 3 root root 4096 2月 26 09:06 loader drwx------. 4 root root 4096 2月 26 09:10 grub2 drwxr-xr-x. 3 root root 4096 2月 26 09:02 efi drwx------. 2 root root 16384 2月 26 09:01 lost+found -rw-r--r--. 1 root root 184613 12月 5 05:58 config-4.18.0-147.el8.x86_64 -rw-------. 1 root root 3838259 12月 5 05:58 System.map-4.18.0-147.el8.x86_64 -rwxr-xr-x. 1 root root 8106744 12月 5 05:58 vmlinuz-4.18.0-147.el8.x86_64 -rwxr-xr-x. 1 root root 8106744 2月 26 09:08 vmlinuz-0-rescue-502dbaaf2a074134909a59ef9ab651c1 -rw-------. 1 root root 19005683 4月 11 17:08 initramfs-4.18.0-147.el8.x86_64kdump.img -rw-------. 1 root root 30020126 2月 26 09:10 initramfs-4.18.0-147.el8.x86_64.img -rw-------. 2 root root 71694380 2月 26 09:08 initramfs-0-rescue-502dbaaf2a074134909a59ef9ab651c1.img # e. 觀察 /boot 的容量相關資料 [root@station10-101 boot]# df /boot; du -s ; ll 檔案系統 1K-區段 已用 可用 已用% 掛載點 /dev/vda2 1998672 149448 1727984 8% /boot 143324 . 總計 137704 -rw-r--r--. 1 root root 184613 12月 5 05:58 config-4.18.0-147.el8.x86_64 drwxr-xr-x. 3 root root 4096 2月 26 09:02 efi ...... # 所有容量大多顯示大致在 140MB 左右的使用量! # f. 建立實體連結: [root@station10-101 boot]# ll initramfs-0-rescue-502dbaaf2a074134909a59ef9ab651c1.img -rw-------. 1 root root 71694380 2月 26 09:08 initramfs-0-rescue-502dbaaf2a074134909a59ef9ab651c1.img [root@station10-101 boot]# ln initramfs-0-rescue-502dbaaf2a074134909a59ef9ab651c1.img zzz.img [root@station10-101 boot]# ll initramfs-0-rescue-502dbaaf2a074134909a59ef9ab651c1.img zzz.img -rw-------. 2 root root 71694380 2月 26 09:08 initramfs-0-rescue-502dbaaf2a074134909a59ef9ab651c1.img -rw-------. 2 root root 71694380 2月 26 09:08 zzz.img # 兩個檔案一模一樣,但是第 2 個欄位的數值 +1 了! # g. 再次觀察容量變化: [root@station10-101 boot]# df /boot; du -s ; ll 檔案系統 1K-區段 已用 可用 已用% 掛載點 /dev/vda2 1998672 149448 1727984 8% /boot 143324 . 總計 207720 -rw-r--r--. 1 root root 184613 12月 5 05:58 config-4.18.0-147.el8.x86_64 drwxr-xr-x. 3 root root 4096 2月 26 09:02 efi ...... # 實際的磁碟容量並沒有任何變化,可由 df 與 du 看得出來! # 但是, ls 沒有這麼聰明!所以容量會將 zzz.img 重複計算喔! # h. 觀察 inode 的數量 [root@station10-101 boot]# df -i /boot 檔案系統 Inode I已用 I可用 I已用% 掛載點 /dev/vda2 131072 309 130763 1% /boot # i. 刪除 zzz.img 看看 inode 數量有沒有變化? [root@station10-101 boot]# rm zzz.img rm:是否移除普通檔案'zzz.img'? y [root@station10-101 boot]# df -i /boot 檔案系統 Inode I已用 I可用 I已用% 掛載點 /dev/vda2 131072 309 130763 1% /boot # 所以, inode 數量根本沒變化!因為實體連結是加上一個檔名對應以! # j. 那麼符號連結的情況下, inode 又如何變化? [root@station10-101 boot]# ln -s initramfs-0-rescue-502dbaaf2a074134909a59ef9ab651c1.img zzz.img [root@station10-101 boot]# ll initramfs-0-rescue-502dbaaf2a074134909a59ef9ab651c1.img zzz.img -rw-------. 1 root root 71694380 2月 26 09:08 initramfs-0-rescue-502dbaaf2a074134909a59ef9ab651c1.img lrwxrwxrwx. 1 root root 55 4月 11 23:14 zzz.img -> initramfs-0-rescue-502dbaaf2a074134909a59ef9ab651c1.img [root@station10-101 boot]# df -i /boot 檔案系統 Inode I已用 I可用 I已用% 掛載點 /dev/vda2 131072 310 130762 1% /boot # 果然是產生一個新檔案了!所以 inode 被多用了一個!
# a. 先來進行一個分割動作! [root@station10-101 ~]# gdisk /dev/vda GPT fdisk (gdisk) version 1.0.3 ...... Command (? for help): n Partition number (4-128, default 4): ↵ First sector (34-62914526, default = 46151680) or {+-}size{KMGTP}: ↵ Last sector (46151680-62914526, default = 62914526) or {+-}size{KMGTP}: ↵ Current type is 'Linux filesystem' Hex code or GUID (L to show codes, Enter = 8300): ↵ Changed type of partition to 'Linux filesystem' Command (? for help): p ...... Total free space is 2014 sectors (1007.0 KiB) Number Start (sector) End (sector) Size Code Name 1 2048 6143 2.0 MiB EF02 2 6144 4200447 2.0 GiB 8300 3 4200448 46151679 20.0 GiB 8E00 4 46151680 62914526 8.0 GiB 8300 Linux filesystem Command (? for help): w Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!! Do you want to proceed? (Y/N): y ...... [root@station10-101 ~]# partprobe [root@station10-101 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 1024M 0 rom vda 252:0 0 30G 0 disk ├─vda1 252:1 0 2M 0 part ├─vda2 252:2 0 2G 0 part /boot ├─vda3 252:3 0 20G 0 part │ ├─centos-root 253:0 0 10G 0 lvm / │ ├─centos-swap 253:1 0 2G 0 lvm [SWAP] │ └─centos-home 253:2 0 3G 0 lvm /home └─vda4 252:4 0 8G 0 part # b. 接著進行格式化的動作: [root@station10-101 ~]# mkfs.ext4 /dev/vda4 mke2fs 1.44.6 (5-Mar-2019) Creating filesystem with 2095355 4k blocks and 524288 inodes Filesystem UUID: b4306d44-d497-4031-a715-8eb74368ca8d Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632 Allocating group tables: done Writing inode tables: done Creating journal (16384 blocks): done Writing superblocks and filesystem accounting information: done [root@station10-101 ~]# blkid /dev/vda4 /dev/vda4: UUID="b4306d44-d497-4031-a715-8eb74368ca8d" TYPE="ext4" PARTLABEL="Linux filesystem" PARTUUID="77446cac-988f-40eb-98a1-c9a38c6c8ad1" # c. 開始測試自動掛載的行為! [root@station10-101 ~]# vim /etc/fstab UUID="b4306d44-d497-4031-a715-8eb74368ca8d" /home/othersystem ext4 defaults 0 0 [root@station10-101 ~]# mount -a mount: /home/othersystem: mount point does not exist. # 這個錯誤訊息很重要!我們只是沒有建立掛載點,所以再次建立,並重複執行 mount [root@station10-101 ~]# mkdir /home/othersystem [root@station10-101 ~]# mount -a [root@station10-101 ~]# df /home/othersystem 檔案系統 1K-區段 已用 可用 已用% 掛載點 /dev/vda4 8184228 36852 7711924 1% /home/othersystem # d. 重新開機! [root@station10-101 ~]# reboot # e. 確認可以開機後,就將該檔案系統刪除吧! [root@station10-101 ~]# umount /dev/vda4 [root@station10-101 ~]# vim /etc/fstab UUID="b4306d44-d497-4031-a715-8eb74368ca8d" /home/othersystem ext4 defaults 0 0 [root@station10-101 ~]# dd if=/dev/zero of=/dev/vda4 bs=1M count=10 10+0 records in 10+0 records out 10485760 bytes (10 MB, 10 MiB) copied, 0.0462547 s, 227 MB/s [root@station10-101 ~]# gdisk /dev/vda GPT fdisk (gdisk) version 1.0.3 ...... Command (? for help): d Partition number (1-4): 4 Command (? for help): w Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING PARTITIONS!! Do you want to proceed? (Y/N): y ...... [root@station10-101 ~]# partprobe [root@station10-101 ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 1024M 0 rom vda 252:0 0 30G 0 disk ├─vda1 252:1 0 2M 0 part ├─vda2 252:2 0 2G 0 part /boot └─vda3 252:3 0 20G 0 part ├─centos-root 253:0 0 10G 0 lvm / ├─centos-swap 253:1 0 2G 0 lvm [SWAP] └─centos-home 253:2 0 3G 0 lvm /home # 最後看不到 /dev/vda4 了!那就是順利成功囉!