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