如果我们创建一个包含fallocate的swapfile,则会被告知该文件包含漏洞,因此操作将停止。
What是这些洞吗?
或
测试
fallocate -l 100MB /swap
chmod 600 /swap
mkswap /swap
swapon /swap输出
swapon: swapfile has holes
swapon: /swap: swapon failed: Invalid argument发布于 2019-05-12 16:18:03
文件中的漏洞根本没有任何与它们相关的块。使用fallocate创建的文件最终可能没有与其关联的块,只有一个大小。从未分配的块读取总是返回所有的零;写入未分配的块会导致文件系统在写入之前分配一个块(至少部分填充洞)。
带有漏洞的文件不能用于交换,因为内核希望能够在没有文件系统帮助的情况下访问文件块(一旦确定了块列表)。任何未被完全分配的文件(包含漏洞或在写上复制)都不能用于交换,因为有些写入将涉及文件系统。
您可以看到一个带有stat的文件实际使用了多少块:
$ truncate -s 16K holes
$ stat holes
File: holes
Size: 16384 Blocks: 0 IO Block: 4096 regular file
Device: fd13h/64787d Inode: 36708573 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1000/ steve) Gid: ( 1000/ steve)
Access: 2019-05-12 20:04:22.498258356 +0200
Modify: 2019-05-12 20:04:22.498258356 +0200
Change: 2019-05-12 20:04:22.498258356 +0200
Birth: -filefrag将告诉您分配了什么:
$ /usr/sbin/filefrag holes
holes: 0 extents found强制部分分配文件将减少漏洞:
$ fallocate -z -l 8K holes
$ stat holes
File: holes
Size: 16384 Blocks: 16 IO Block: 4096 regular file
Device: fd13h/64787d Inode: 36708573 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1000/ steve) Gid: ( 1000/ steve)
Access: 2019-05-12 20:04:22.498258356 +0200
Modify: 2019-05-12 20:10:12.520380272 +0200
Change: 2019-05-12 20:10:12.520380272 +0200
Birth: -
$ /usr/sbin/filefrag -e holes
Filesystem type is: ef53
File size of holes is 16384 (4 blocks of 4096 bytes)
ext: logical_offset: physical_offset: length: expected: flags:
0: 0.. 1: 116741448.. 116741449: 2: last,unwritten
holes: 1 extent foundhttps://unix.stackexchange.com/questions/518559
复制相似问题