单纯提供一个相对的解答,并不是标准答案!
单纯就是个解答的参考,写完之后再来这边查查看答案跟你想的一样不一样!?
[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 了!那就是顺利成功啰!