我最近在某些嵌入式 Linux 设备上遇到了一个问题,我无法再直接在 /etc/ 目录中创建文件。我第一次遇到这个问题是 dpkg 无法创建临时文件,然后“sed -i”也遇到了同样的问题。此后我尝试了 touch、cp 和重定向回显,但它们都因参数无效而失败。
我在“cp /etc/hostname /etc/hostname.bak”上运行 strace 得到以下输出,
stat64("/etc/hostname.bak", 0xbede4560) = -1 ENOENT (No such file or directory)
stat64("/etc/hostname", {st_mode=S_IFREG|0644, st_size=12, ...}) = 0
stat64("/etc/hostname.bak", 0xbede4398) = -1 ENOENT (No such file or directory)
open("/etc/hostname", O_RDONLY|O_LARGEFILE) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=12, ...}) = 0
open("/etc/hostname.bak", O_WRONLY|O_CREAT|O_EXCL|O_LARGEFILE, 0644) = -1 EINVAL (Invalid argument)
write(2, "cp: ", 4cp: ) = 4
write(2, "cannot create regular file `/etc"..., 46cannot create regular file `/etc/hostname.bak') = 46
write(2, ": Invalid argument", 18: Invalid argument) = 18
在“cp /etc/hostname /hostname.bak”上运行 strace 时产生
stat64("/hostname.bak", 0xbec75570) = -1 ENOENT (No such file or directory)
stat64("/etc/hostname", {st_mode=S_IFREG|0644, st_size=12, ...}) = 0
stat64("/hostname.bak", 0xbec753a8) = -1 ENOENT (No such file or directory)
open("/etc/hostname", O_RDONLY|O_LARGEFILE) = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=12, ...}) = 0
open("/hostname.bak", O_WRONLY|O_CREAT|O_EXCL|O_LARGEFILE, 0644) = 4
fstat64(4, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
一旦文件 /hostname.bak 存在,我就可以将其移动到 /etc/ 中而不会发生意外。
/etc/ 上的权限对我来说似乎也正确
drwxr-xr-x 75 root root 36864 Mar 29 00:08 etc
是否有任何设置或配置可能导致此行为?如果没有,我该如何进行调试