單純提供一個相對的解答,並不是標準答案!
單純就是個解答的參考,寫完之後再來這邊查查看答案跟你想的一樣不一樣!?
[root@station10-101 ~]# df -T Filesystem Type 1K-blocks Used Available Use% Mounted on devtmpfs devtmpfs 4096 0 4096 0% /dev tmpfs tmpfs 906728 0 906728 0% /dev/shm tmpfs tmpfs 362692 8224 354468 3% /run /dev/mapper/rocky-root xfs 10475520 4354156 6121364 42% / /dev/mapper/rocky-home xfs 3135488 71852 3063636 3% /home /dev/vda2 ext4 1992552 356272 1515040 20% /boot [root@station10-101 ~]# dumpe2fs /dev/vda2 | grep -i size dumpe2fs 1.46.5 (30-Dec-2021) 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 Total journal size: 64M所以,inode 與 block 的容量,分別是 256bytes 以及 4K 喔!有興趣的同學,可以慢慢觀察一下 dumpe2fs 的輸出喔!
[student@station10-101 ~]$ ll -i /etc/hosts 25418236 -rw-r--r--. 1 root root 158 Jun 23 2020 /etc/hosts
[student@station10-101 ~]$ cd /tmp [student@station10-101 tmp]$ mkdir inodecheck [student@station10-101 tmp]$ ll -di /tmp/inodecheck/ /tmp/inodecheck/. 25418917 drwxr-xr-x. 2 student student 6 Feb 24 11:36 /tmp/inodecheck/ 25418917 drwxr-xr-x. 2 student student 6 Feb 24 11:36 /tmp/inodecheck/.其實,這兩個『檔名』對應的 inode 號碼一模一樣,代表這兩個檔名是一模一樣的內容!因此,除了檔名不同之外, 所有的參數都會一模一樣!所以說,那個 . 代表的是目錄本身,原因就是,共用相同的 inode 號碼!
[student@station10-101 tmp]$ cd inodecheck [student@station10-101 inodecheck]$ mkdir check2 [student@station10-101 inodecheck]$ ll total 0 drwxr-xr-x. 2 student student 6 Feb 24 11:38 check2 [student@station10-101 inodecheck]$ ll -di /tmp/inodecheck/ /tmp/inodecheck/. /tmp/inodecheck/check2/.. 25418917 drwxr-xr-x. 3 student student 20 Feb 24 11:38 /tmp/inodecheck/ 25418917 drwxr-xr-x. 3 student student 20 Feb 24 11:38 /tmp/inodecheck/. 25418917 drwxr-xr-x. 3 student student 20 Feb 24 11:38 /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 3 -rw-r--r--. 1 student student 158 Feb 24 11:40 hosts
[student@station10-101 check2]$ ln hosts hosts.real [student@station10-101 check2]$ ll -i hosts* 3 -rw-r--r--. 2 student student 158 Feb 24 11:40 hosts 3 -rw-r--r--. 2 student student 158 Feb 24 11:40 hosts.real所以,實體連結,只會讓該 inode number 對應到另一個檔名,所以全部的屬性都會相同!如上所示,除了檔名之外,全部資料一模一樣喔!
[student@station10-101 check2]$ ln -s hosts hosts.symbo [student@station10-101 check2]$ ll -i hosts hosts.symbo 3 -rw-r--r--. 2 student student 158 Feb 24 11:40 hosts 4 lrwxrwxrwx. 1 student student 5 Feb 24 11:42 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 Feb 24 11:40 hosts.real lrwxrwxrwx. 1 student student 5 Feb 24 11:42 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 4096 0 4096 0% /dev tmpfs tmpfs 906728 4 906724 1% /dev/shm tmpfs tmpfs 362692 8220 354472 3% /run /dev/mapper/rocky-root xfs 10475520 4353168 6122352 42% / /dev/mapper/rocky-home xfs 3135488 71852 3063636 3% /home /dev/vda2 ext4 1992552 356272 1515040 20% /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 4096 0 4096 0% /dev
tmpfs tmpfs 906728 4 906724 1% /dev/shm
tmpfs tmpfs 362692 8220 354472 3% /run
/dev/mapper/rocky-root xfs 10475520 4353168 6122352 42% /
/dev/mapper/rocky-home xfs 3135488 71852 3063636 3% /home
/dev/vda2 ext4 1992552 356272 1515040 20% /boot
tmpfs tmpfs 181344 52 181292 1% /run/user/42
tmpfs tmpfs 181344 36 181308 1% /run/user/0
裝置名稱為 tmpfs 的,大致上都屬於系統由記憶體模擬出來的資料,而 /dev 開頭的,才會是實體裝置。至於 Type 欄位就是檔案系統類型。
屬於 xfs 的,共有兩個 XFS 檔案系統,分別在 / 以及 /home 掛載點上面。裝置名稱 /dev/mapper/rocky-root 與 /dev/mapper/rocky-home
這兩個裝置主要由 LVM 而來,我們後面章節再來談[student@station10-101 check2]$ ls -lid / /boot /home /etc /root /proc /sys 128 dr-xr-xr-x. 18 root root 235 Feb 20 14:20 / <== /dev/mapper/rocky-root 2 dr-xr-xr-x. 6 root root 4096 Feb 21 17:07 /boot <== /dev/vda2 25165953 drwxr-xr-x. 130 root root 8192 Feb 24 2023 /etc 128 drwxr-xr-x. 9 root root 117 Feb 22 10:37 /home <== /dev/mapper/rocky-home 1 dr-xr-xr-x. 222 root root 0 Feb 24 2023 /proc 16797826 dr-xr-x---. 4 root root 177 Feb 24 11:33 /root 1 dr-xr-xr-x. 13 root root 0 Feb 24 2023 /sys
[root@station10-101 ~]# lsblk -i NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS 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 |-rocky-root 253:0 0 10G 0 lvm / |-rocky-swap 253:1 0 1G 0 lvm [SWAP] `-rocky-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 MOUNTPOINTS /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/rocky-root 253:0 0 10G 0 lvm / |-/dev/mapper/rocky-swap 253:1 0 1G 0 lvm [SWAP] `-/dev/mapper/rocky-home 253:2 0 3G 0 lvm /home所以裝置檔名實際上就是 /dev/vda 了!
[root@station10-101 ~]# parted /dev/vda print Model: Virtio Block Device (virtblk) Disk /dev/vda: 32.2GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: pmbr_boot Number Start End Size File system Name Flags 1 1049kB 3146kB 2097kB bios_grub 2 3146kB 2151MB 2147MB ext4 3 2151MB 23.6GB 21.5GB lvm我們這個裝置用的是 gpt 的分割表喔!
# 先以 gdisk 進入分割畫面,然後按下 p 來觀察剩餘容量: [root@station10-101 ~]# fdisk /dev/vda Command (m for help): p Disk /dev/vda: 30 GiB, 32212254720 bytes, 62914560 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: gpt Disk identifier: 6CD584BC-1B5D-493B-9E48-1429460E793C Device Start End Sectors Size Type /dev/vda1 2048 6143 4096 2M BIOS boot /dev/vda2 6144 4200447 4194304 2G Linux filesystem /dev/vda3 4200448 46151679 41951232 20G Linux LVM # 如上表所示,三個分割槽連續使用磁碟到 46151679,但磁碟總共有 62914560,所以還有容量!目前剩餘 (free) 的磁區號碼是介於 46151680 到 62914560 之間喔!
Command (m for help): n Partition number (4-128, default 4): ↵ <==用預設值,不用變,所以按 [enter] First sector (46151680-62914526, default 46151680): ↵ <==用預設值,不用變,所以按 [enter] Last sector, +/-sectors or +/-size{K,M,G,T,P} (46151680-62914526, default 62914526): +1G Created a new partition 4 of type 'Linux filesystem' and of size 1 GiB. Command (m for help): p Disk /dev/vda: 30 GiB, 32212254720 bytes, 62914560 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: gpt Disk identifier: 6CD584BC-1B5D-493B-9E48-1429460E793C Device Start End Sectors Size Type /dev/vda1 2048 6143 4096 2M BIOS boot /dev/vda2 6144 4200447 4194304 2G Linux filesystem /dev/vda3 4200448 46151679 41951232 20G Linux LVM /dev/vda4 46151680 48248831 2097152 1G Linux filesystem <==務必觀察新建立的分割槽是否正確這樣就建置妥當了!
Command (m for help): w The partition table has been altered. Syncing disks. # 這一版本開始,核心變得很厲害!所以,如果不是更動到舊的分割槽,基本上,設計是直接生效!如果有出現警告訊息,通常是因為你更動到正在使用當中的分割槽所在的磁區,例如刪除大的分割槽,再細分數個分割時, 就有可能會出現警告訊息!我們是由原有的剩餘容量去分割,因此就不會出現任何錯誤!
[root@station10-101 ~]# lsblk -i NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS 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 | |-rocky-root 253:0 0 10G 0 lvm / | |-rocky-swap 253:1 0 1G 0 lvm [SWAP] | `-rocky-home 253:2 0 3G 0 lvm /home `-vda4 252:4 0 1G 0 part不需要重新開機或者是進行 partprobe ,立刻可以使用新的分割槽了!
# 這一題有陷阱~那就是 1.5G 這個數字!請看如下作法: [root@station10-101 ~]# fdisk /dev/vda Command (m for help): n Partition number (5-128, default 5): ↵ First sector (48248832-62914526, default 48248832): ↵ Last sector, +/-sectors or +/-size{K,M,G,T,P} (48248832-62914526, default 62914526): +1.5G Created a new partition 5 of type 'Linux filesystem' and of size 1.5 GiB. Command (m for help): n Partition number (6-128, default 6): ↵ First sector (51394560-62914526, default 51394560): ↵ Last sector, +/-sectors or +/-size{K,M,G,T,P} (51394560-62914526, default 62914526): +1G Created a new partition 6 of type 'Linux filesystem' and of size 1 GiB. Command (m for help): p Disk /dev/vda: 30 GiB, 32212254720 bytes, 62914560 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: gpt Disk identifier: 6CD584BC-1B5D-493B-9E48-1429460E793C Device Start End Sectors Size Type /dev/vda1 2048 6143 4096 2M BIOS boot /dev/vda2 6144 4200447 4194304 2G Linux filesystem /dev/vda3 4200448 46151679 41951232 20G Linux LVM /dev/vda4 46151680 48248831 2097152 1G Linux filesystem /dev/vda5 48248832 51394559 3145728 1.5G Linux filesystem /dev/vda6 51394560 53491711 2097152 1G Linux filesystem Command (m for help): l <== 輸入 L 的小寫! ..... 11 Microsoft basic data EBD0A0A2-B9E5-4433-87C0-68B6B72699C7 ..... 19 Linux swap 0657FD6D-A4AB-43C4-84E5-0933C84B4F4F 20 Linux filesystem 0FC63DAF-8483-4772-8E79-3D69D8477DE4 ..... 30 Linux LVM E6D6D379-F507-44C2-A23C-238F2A3DF928 .... # 這邊按下 q 可以結束輸出! Command (m for help): t Partition number (1-6, default 6): 5 Partition type or alias (type L to list all): 11 Changed type of partition 'Linux filesystem' to 'Microsoft basic data'. Command (m for help): t Partition number (1-6, default 6): 6 Partition type or alias (type L to list all): 19 Changed type of partition 'Linux filesystem' to 'Linux swap'. Command (m for help): p Disk /dev/vda: 30 GiB, 32212254720 bytes, 62914560 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: gpt Disk identifier: 6CD584BC-1B5D-493B-9E48-1429460E793C Device Start End Sectors Size Type /dev/vda1 2048 6143 4096 2M BIOS boot /dev/vda2 6144 4200447 4194304 2G Linux filesystem /dev/vda3 4200448 46151679 41951232 20G Linux LVM /dev/vda4 46151680 48248831 2097152 1G Linux filesystem /dev/vda5 48248832 51394559 3145728 1.5G Microsoft basic data /dev/vda6 51394560 53491711 2097152 1G Linux swap Command (m for help): w The partition table has been altered. Syncing disks. [root@station10-101 ~]# lsblk -i /dev/vda NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS 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 | |-rocky-root 253:0 0 10G 0 lvm / | |-rocky-swap 253:1 0 1G 0 lvm [SWAP] | `-rocky-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整體建置流程有點像這樣!最終還是要觀察 /dev/vda5 是否正確的顯示出兩個分割槽的容量喔!
# 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.2 (2021-01-31) # 因為 FAT 檔案系統格式比較笨,格式化速度飛快! # swap 磁碟置換資料格式 [root@station10-101 ~]# mkswap /dev/vda6 Setting up swapspace version 1, size = 1024 MiB (1073737728 bytes) no label, UUID=4ed77543-15ac-487e-a817-7303efbd7ca8 # 查看一下各個分割槽的 UUID 識別碼 [root@station10-101 ~]# blkid /dev/vda4: UUID="cb3eced9-6b90-401a-9f57-ce0ecf275906" TYPE="xfs" PARTUUID="4f1e62b4-792d-cb4e-8d03-bd3cf89cef12" /dev/vda5: UUID="348A-3015" TYPE="vfat" PARTUUID="040e1e11-a8ed-4146-854c-9d0eecd7549f" /dev/vda6: UUID="4ed77543-15ac-487e-a817-7303efbd7ca8" TYPE="swap" PARTUUID="d4c91daf-fb83-b541-90df-997e215d0708" /dev/mapper/rocky-swap: UUID="a0346684-ff07-4933-b4a2-b1fbb88256e0" TYPE="swap" /dev/mapper/rocky-home: UUID="4700cd5a-2cfa-4453-92b8-0590e6d31f1b" TYPE="xfs" /dev/mapper/rocky-root: UUID="f328617e-3668-495c-9250-94e3db7c2894" TYPE="xfs" /dev/vda2: UUID="b93d23a0-3fdb-44c5-9304-4fbbbf415542" TYPE="ext4" PARTUUID="91901786-8814-443e-8976-75ac1417d38e" /dev/vda3: UUID="psa5cO-pVqm-djqq-pqpW-AwPY-g4CB-CkGwlt" TYPE="LVM2_member" PARTUUID="ef97c95f-4d40-48d1-8691-56de8ace5617" /dev/vda1: PARTUUID="3429abcc-ed63-4c5d-8301-b9114a50e728" # 可以看到上面 /dev/vda{4,5,6} 各自有說明檔案系統 (TYPE) 內容喔!
# 先模擬使用載點的狀態,同時確認該目錄確實在掛載點內! [root@station10-101 ~]# cd /srv/linux [root@station10-101 linux]# pwd /srv/linux [root@station10-101 linux]# df /srv/linux Filesystem 1K-blocks Used Available Use% Mounted on /dev/vda4 1038336 40292 998044 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 2622 root cwd DIR 252,4 6 128 /srv/linux lsof 2772 root cwd DIR 252,4 6 128 /srv/linux grep 2773 root cwd DIR 252,4 6 128 /srv/linux lsof 2774 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 2622 2615 0 80 0 - 56023 do_wai pts/0 00:00:00 bash 4 R 0 2775 2622 0 80 0 - 56375 - pts/0 00:00:00 ps # 果然就是自己! # 模擬不再使用該載點資訊,然後卸載看看! [root@station10-101 linux]# cd [root@station10-101 ~]# umount /srv/linux [root@station10-101 ~]# df /srv/linux Filesystem 1K-blocks Used Available Use% Mounted on /dev/mapper/rocky-root 10475520 4353220 6122300 42% / # 很明顯的發現,該目錄直接掛載在根目錄上,不是額外的檔案系統囉!
[root@station10-101 ~]# df -T |grep -v 'tmpfs' Filesystem Type 1K-blocks Used Available Use% Mounted on /dev/mapper/rocky-root xfs 10475520 4353220 6122300 42% / /dev/mapper/rocky-home xfs 3135488 71852 3063636 3% /home /dev/vda2 ext4 1992552 356272 1515040 20% /boot /dev/vda5 vfat 1569768 4 1569764 1% /srv/win [root@station10-101 ~]# umount /srv/win [root@station10-101 ~]# swapon -s Filename Type Size Used Priority /dev/dm-1 partition 1048572 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 1048572 0 -2
[root@station10-101 ~]# df -T Filesystem Type 1K-blocks Used Available Use% Mounted on /dev/vda5 vfat 1569768 4 1569764 1% /srv/win /dev/vda4 xfs 1038336 40292 998044 4% /srv/linux [root@station10-101 ~]# swapon -s Filename Type Size Used Priority /dev/dm-1 partition 1048572 0 -3 /dev/vda6 partition 1048572 0 -2 [root@station10-101 ~]# umount /dev/vda4 /dev/vda5 [root@station10-101 ~]# swapoff /dev/vda6
[root@station10-101 ~]# vim /etc/fstab #UUID="cb3eced9-6b90-401a-9f57-ce0ecf275906" /srv/linux xfs defaults 0 0 #UUID="348A-3015" /srv/win vfat defaults 0 0 #UUID="4ed77543-15ac-487e-a817-7303efbd7ca8" swap swap defaults 0 0 # 我這裡暫時將它註解而已~
[root@station10-101 ~]# mount -a; swapon -a [root@station10-101 ~]# df -T /srv/win /srv/linux Filesystem Type 1K-blocks Used Available Use% Mounted on /dev/mapper/rocky-root xfs 10475520 4353724 6121796 42% / /dev/mapper/rocky-root xfs 10475520 4353724 6121796 42% / [root@station10-101 ~]# swapon -s Filename Type Size Used Priority /dev/dm-1 partition 1048572 0 -2看起來確實都沒有 /dev/vda4, /dev/vda5, /dev/vda6 這三個裝置的使用情境了!
[root@station10-101 ~]# blkid /dev/vda{4..6} /dev/vda4: UUID="cb3eced9-6b90-401a-9f57-ce0ecf275906" TYPE="xfs" ... /dev/vda5: UUID="348A-3015" TYPE="vfat" PARTUUID="040e1e11-a8ed-41 ... /dev/vda6: UUID="4ed77543-15ac-487e-a817-7303efbd7ca8" 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: PARTUUID="4f1e62b4-792d-cb4e-8d03-bd3cf89cef12" /dev/vda5: PARTUUID="040e1e11-a8ed-4146-854c-9d0eecd7549f" /dev/vda6: PARTUUID="d4c91daf-fb83-b541-90df-997e215d0708" # 很明顯的發現檔案系統類型與 UUID 不見了喔!
[root@station10-101 ~]# fdisk /dev/vda Welcome to fdisk (util-linux 2.37.4). Command (m for help): d Partition number (1-6, default 6): 6 Partition 6 has been deleted. Command (m for help): d Partition number (1-5, default 5): 5 Partition 5 has been deleted. Command (m for help): d Partition number (1-4, default 4): 4 Partition 4 has been deleted. Command (m for help): p Disk /dev/vda: 30 GiB, 32212254720 bytes, 62914560 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: gpt Disk identifier: 6CD584BC-1B5D-493B-9E48-1429460E793C Device Start End Sectors Size Type /dev/vda1 2048 6143 4096 2M BIOS boot /dev/vda2 6144 4200447 4194304 2G Linux filesystem /dev/vda3 4200448 46151679 41951232 20G Linux LVM Command (m for help): w The partition table has been altered. Syncing disks.
[root@station10-101 ~]# partprobe [root@station10-101 ~]# lsblk -i /dev/vda NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS 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 |-rocky-root 253:0 0 10G 0 lvm / |-rocky-swap 253:1 0 1G 0 lvm [SWAP] `-rocky-home 253:2 0 3G 0 lvm /home可以確認分割表當中已經不存在 /dev/vda4, /dev/vda5, /dev/vda6 了!
# a. 找出目前系統上面所有的磁碟檔名,最簡單用 lsblk 即可 [root@station10-101 ~]# lsblk -ip NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS /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/rocky-root 253:0 0 10G 0 lvm / |-/dev/mapper/rocky-swap 253:1 0 1G 0 lvm [SWAP] `-/dev/mapper/rocky-home 253:2 0 3G 0 lvm /home # b. 開始測試一下,這個 vda 是屬於那一種分割表?用 parted/fdisk 都可以! [root@station10-101 ~]# parted /dev/vda print Model: Virtio Block Device (virtblk) Disk /dev/vda: 32.2GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 1049kB 3146kB 2097kB bios_grub 2 3146kB 2151MB 2147MB ext4 3 2151MB 23.6GB 21.5GB lvm [root@station10-101 ~]# fdisk -l /dev/vda Disk /dev/vda: 30 GiB, 32212254720 bytes, 62914560 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: gpt Disk identifier: 6CD584BC-1B5D-493B-9E48-1429460E793C Device Start End Sectors Size Type /dev/vda1 2048 6143 4096 2M BIOS boot /dev/vda2 6144 4200447 4194304 2G Linux filesystem /dev/vda3 4200448 46151679 41951232 20G Linux LVM # c. 簡單直覺就用 blkid 即可: [root@station10-101 ~]# blkid /dev/mapper/rocky-root: UUID="f328617e-3668-495c-9250-94e3db7c2894" TYPE="xfs" /dev/vda3: UUID="psa5cO-pVqm-djqq-pqpW-AwPY-g4CB-CkGwlt" TYPE="LVM2_member" PARTUUID="ef97c95f-4d40-48d1-8691-56de8ace5617" /dev/mapper/rocky-swap: UUID="a0346684-ff07-4933-b4a2-b1fbb88256e0" TYPE="swap" /dev/mapper/rocky-home: UUID="4700cd5a-2cfa-4453-92b8-0590e6d31f1b" TYPE="xfs" /dev/vda2: UUID="b93d23a0-3fdb-44c5-9304-4fbbbf415542" TYPE="ext4" PARTUUID="91901786-8814-443e-8976-75ac1417d38e" /dev/vda1: PARTUUID="3429abcc-ed63-4c5d-8301-b9114a50e728" # d. 從上一題知道了 /dev/vda2 為 ext4 而 rocky-home, rocky-root 為 xfs,所以: ot@station10-101 ~]# dumpe2fs /dev/vda2 | grep -i size dumpe2fs 1.46.5 (30-Dec-2021) 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 Total journal size: 64M [root@station10-101 ~]# xfs_info /dev/mapper/rocky-root meta-data=/dev/mapper/rocky-root isize=512 agcount=4, agsize=655360 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=1, sparse=1, rmapbt=0 = reflink=1 bigtime=1 inobtcount=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/rocky-home # 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 1048572 0 -2 [root@station10-101 ~]# blkid | grep swap /dev/mapper/rocky-swap: UUID="a0346684-ff07-4933-b4a2-b1fbb88256e0" TYPE="swap" [root@station10-101 ~]# ll /dev/mapper/rocky-swap lrwxrwxrwx. 1 root root 7 Feb 25 22:31 /dev/mapper/rocky-swap -> ../dm-1 # 原來是 /dev/mapper/rocky-swap 這個檔案系統!!
# a. 用 find 找連結檔 [root@station10-101 ~]# find /etc -type l /etc/mtab /etc/fonts/conf.d/31-cantarell.conf /etc/fonts/conf.d/61-urw-bookman.conf /etc/fonts/conf.d/65-google-noto-cjk-fonts.conf .... /etc/yum/protected.d /etc/yum/vars /etc/yum.conf /etc/localtime [root@station10-101 ~]# ll /etc/yum/vars /etc/yum.conf /etc/localtime lrwxrwxrwx. 1 root root 33 Feb 16 11:50 /etc/localtime -> ../usr/share/zoneinfo/Asia/Taipei lrwxrwxrwx. 1 root root 12 Nov 15 17:28 /etc/yum.conf -> dnf/dnf.conf lrwxrwxrwx. 1 root root 11 Nov 15 17:28 /etc/yum/vars -> ../dnf/vars # 檢測一下,至少後面幾個檔案,確實全部都是連結檔! # b. 透過 ls 以及 grep 去抓取 /etc 底下 (不含子目錄) 的連結檔,透過抓 > 這個關鍵字! lrwxrwxrwx. 1 root root 56 Feb 7 00:46 favicon.png -> /usr/share/icons/hicolor/16x16/apps/fedora-logo-icon.png lrwxrwxrwx. 1 root root 22 Feb 15 03:06 grub2.cfg -> ../boot/grub2/grub.cfg lrwxrwxrwx. 1 root root 33 Feb 16 11:50 localtime -> ../usr/share/zoneinfo/Asia/Taipei lrwxrwxrwx. 1 root root 19 Feb 16 11:44 mtab -> ../proc/self/mounts lrwxrwxrwx. 1 root root 29 Feb 20 14:21 nsswitch.conf -> /etc/authselect/nsswitch.conf lrwxrwxrwx. 1 root root 21 Dec 13 14:15 os-release -> ../usr/lib/os-release lrwxrwxrwx. 1 root root 13 Jan 24 04:06 rc.local -> rc.d/rc.local lrwxrwxrwx. 1 root root 13 Dec 13 14:15 redhat-release -> rocky-release lrwxrwxrwx. 1 root root 13 Dec 13 14:15 system-release -> rocky-release lrwxrwxrwx. 1 root root 12 Nov 15 17:28 yum.conf -> dnf/dnf.conf # c. 列出 inode 號碼,加上 -i 即可! [root@station10-101 ~]# ll -i /etc | grep '>' ...... 26600650 lrwxrwxrwx. 1 root root 13 Dec 13 14:15 redhat-release -> rocky-release 25418218 lrwxrwxrwx. 1 root root 13 Dec 13 14:15 system-release -> rocky-release 27080226 lrwxrwxrwx. 1 root root 12 Nov 15 17:28 yum.conf -> dnf/dnf.conf # d. 找出 /boot 底下,容量最大的檔案檔名: [root@station10-101 ~]# cd /boot [root@station10-101 boot]# ll --sort=size -r .... -rwxr-xr-x. 1 root root 11650240 Nov 18 10:18 vmlinuz-5.14.0-162.6.1.el9_1.x86_64 -rwxr-xr-x. 1 root root 11650240 Feb 16 11:48 vmlinuz-0-rescue-d587a2c04fbb458e8015aef30df28fec -rwxr-xr-x. 1 root root 11650432 Jan 31 06:27 vmlinuz-5.14.0-162.12.1.el9_1.0.2.x86_64 -rw-------. 1 root root 34527232 Feb 25 22:33 initramfs-5.14.0-162.12.1.el9_1.0.2.x86_64kdump.img -rw-------. 1 root root 34531328 Feb 17 10:30 initramfs-5.14.0-162.6.1.el9_1.x86_64kdump.img -rw-------. 1 root root 56383925 Feb 20 14:22 initramfs-5.14.0-162.12.1.el9_1.0.2.x86_64.img -rw-------. 1 root root 58573958 Feb 16 11:51 initramfs-5.14.0-162.6.1.el9_1.x86_64.img -rw-------. 1 root root 124071986 Feb 16 11:49 initramfs-0-rescue-d587a2c04fbb458e8015aef30df28fec.img # e. 觀察 /boot 的容量相關資料 [root@station10-101 boot]# df /boot; du -s /boot; ll /boot | head -n 2 Filesystem 1K-blocks Used Available Use% Mounted on /dev/vda2 1992552 356272 1515040 20% /boot <==檔案系統資料 356268 /boot <==實際 du 結果 total 345848 <==ls 的結果 # 所有容量大多顯示大致在 350MB 左右的使用量! # f. 建立實體連結: [root@station10-101 boot]# ln initramfs-0-rescue-d587a2c04fbb458e8015aef30df28fec.img zzz.img [root@station10-101 boot]# ll initramfs-0-rescue-d587a2c04fbb458e8015aef30df28fec.img zzz.img -rw-------. 2 root root 124071986 Feb 16 11:49 initramfs-0-rescue-d587a2c04fbb458e8015aef30df28fec.img -rw-------. 2 root root 124071986 Feb 16 11:49 zzz.img # 兩個檔案一模一樣,但是第 2 個欄位的數值 +1 了! # g. 再次觀察容量變化: [root@station10-101 boot]# df /boot; du -s /boot; ll /boot | head -n 2 Filesystem 1K-blocks Used Available Use% Mounted on /dev/vda2 1992552 356272 1515040 20% /boot 356268 /boot total 467016 # 實際的磁碟容量並沒有任何變化,可由 df 與 du 看得出來! # 但是, ls 沒有這麼聰明!所以容量會將 zzz.img 重複計算喔! # h. 觀察 inode 的數量 [root@station10-101 boot]# df -i /boot Filesystem Inodes IUsed IFree IUse% Mounted on /dev/vda2 131072 374 130698 1% /boot # i. 刪除 zzz.img 看看 inode 數量有沒有變化? [root@station10-101 boot]# rm zzz.img rm: remove regular file 'zzz.img'? y [root@station10-101 boot]# df -i /boot Filesystem Inodes IUsed IFree IUse% Mounted on /dev/vda2 131072 374 130698 1% /boot # 所以, inode 數量根本沒變化!因為實體連結是加上一個檔名對應以! # j. 那麼符號連結的情況下, inode 又如何變化? [root@station10-101 boot]# ln -s initramfs-0-rescue-d587a2c04fbb458e8015aef30df28fec.img zzz.img [root@station10-101 boot]# ll initramfs-0-rescue-d587a2c04fbb458e8015aef30df28fec.img zzz.img -rw-------. 1 root root 124071986 Feb 16 11:49 initramfs-0-rescue-d587a2c04fbb458e8015aef30df28fec.img lrwxrwxrwx. 1 root root 55 Feb 25 23:12 zzz.img -> initramfs-0-rescue-d587a2c04fbb458e8015aef30df28fec.img [root@station10-101 boot]# df -i /boot Filesystem Inodes IUsed IFree IUse% Mounted on /dev/vda2 131072 375 130697 1% /boot # 果然是產生一個新檔案了!所以 inode 被多用了一個!
# a. 先來進行一個分割動作! [root@station10-101 ~]# fdisk /dev/vda Welcome to fdisk (util-linux 2.37.4). Command (m for help): n Partition number (4-128, default 4): 4 First sector (46151680-62914526, default 46151680): ↵ Last sector, +/-sectors or +/-size{K,M,G,T,P} (46151680-62914526, default 62914526): ↵ Created a new partition 4 of type 'Linux filesystem' and of size 8 GiB. Command (m for help): p Disk /dev/vda: 30 GiB, 32212254720 bytes, 62914560 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: gpt Disk identifier: 6CD584BC-1B5D-493B-9E48-1429460E793C Device Start End Sectors Size Type /dev/vda1 2048 6143 4096 2M BIOS boot /dev/vda2 6144 4200447 4194304 2G Linux filesystem /dev/vda3 4200448 46151679 41951232 20G Linux LVM /dev/vda4 46151680 62914526 16762847 8G Linux filesystem Command (m for help): w The partition table has been altered. Syncing disks. [root@station10-101 ~]# lsblk -ip /dev/vda NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS /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/rocky-root 253:0 0 10G 0 lvm / | |-/dev/mapper/rocky-swap 253:1 0 1G 0 lvm [SWAP] | `-/dev/mapper/rocky-home 253:2 0 3G 0 lvm /home `-/dev/vda4 252:4 0 8G 0 part # b. 接著進行格式化的動作: [root@station10-101 ~]# mkfs.ext4 /dev/vda4 mke2fs 1.46.5 (30-Dec-2021) Creating filesystem with 2095355 4k blocks and 524288 inodes Filesystem UUID: 1e408458-dfd4-4381-9b25-5d839f7fc302 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="1e408458-dfd4-4381-9b25-5d839f7fc302" TYPE="ext4" PARTUUID="ef94984c-350b-5f4c-9885-f1a96986d2f6" # c. 開始測試自動掛載的行為! [root@station10-101 ~]# vim /etc/fstab UUID="1e408458-dfd4-4381-9b25-5d839f7fc302" /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 -T /home/othersystem Filesystem Type 1K-blocks Used Available Use% Mounted on /dev/vda4 ext4 8147400 24 7711924 1% /home/othersystem # d. 重新開機! [root@station10-101 ~]# reboot # e. 確認可以開機後,就將該檔案系統刪除吧! [root@station10-101 ~]# umount /dev/vda4 [root@station10-101 ~]# vim /etc/fstab UUID="1e408458-dfd4-4381-9b25-5d839f7fc302" /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 ~]# fdisk /dev/vda Welcome to fdisk (util-linux 2.37.4). Command (m for help): d Partition number (1-4, default 4): 4 Partition 4 has been deleted. Command (m for help): w The partition table has been altered. Syncing disks. [root@station10-101 ~]# lsblk -ip /dev/vda NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS /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/rocky-root 253:0 0 10G 0 lvm / |-/dev/mapper/rocky-swap 253:1 0 1G 0 lvm [SWAP] `-/dev/mapper/rocky-home 253:2 0 3G 0 lvm /home # 最後看不到 /dev/vda4 了!那就是順利成功囉!