如果圆形符号链接没有用,那为什么允许使用它们? [英] If circular symlinks are useless, then why are they allowed?

查看:29
本文介绍了如果圆形符号链接没有用,那为什么允许使用它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在这里阅读这篇文章:

I was just reading this post here:

类 Unix 系统中的循环符号链接是什么用于?

答案很有趣.他们似乎得出结论说,没有理由创建这样一个循环符号链接,因此它一定是错误创建的.如果这是真的,那为什么他们被允许呢?是因为禁止它们的机制过于复杂或计算量大吗?

And the answers were quite interesting. They seem to say conclusively that there is no reason one would ever create such a circular symlink, and therefore it must have been created in error. If this is true, then why on earth are they allowed? Is it because the mechanics of disallowing them are prohibitively complicated or computationally intensive?

我不明白为什么会这样:我们不能只是比较内存中的地址,看看它是否与目标地址相同,然后如果它们相同,则抛出错误?

I don't see why this would be the case: can't we just compare the address in memory to see if it is the same as the target address, and then if they are the same, throw an error?

也许在某些语言中会出现错误,除非您使用某种强制选项.在这些情况下,我的问题就变成了:为什么要允许强制选项?

perhaps in certain languages there will be an error unless you use some sort of forcing option. In those cases, then my question simply becomes: why would you allow a force option?

在@Wumpus Q Wembley 的帮助下进行进一步研究后,似乎在 unix 中确实不允许这样做并导致以下错误:

upon some further research with the help of @Wumpus Q Wembley, it appears that this is indeed disallowed in unix and results in the following error:

ln: ‘/usr/bin/apt-config’和‘/usr/bin/apt-config’是同一个文件

但是当与自身符号链接的文件已经是来自其他文件的符号链接时,确实会发生这种情况.我不确定为什么这种行为是可取的?

but that this can indeed happen when the files that are being symlinked to themselves are already symlinks from some other file. I'm not sure why that behavior is desirable?

-保罗

推荐答案

我知道(并使用)了一种循环符号链接很有用的情况.这是一个角落案例,但仍然如此.

I know of (and use) one case where circular symlink is useful. It's a corner case, but nonetheless.

有问题的符号链接位于 /boot 目录中,并且(循环地)指向自身,如下所示:

The symlink in question is located in the /boot directory and (circularly) points to itself as in:

boot -> ./

它是使用以下命令创建的:

It was created with the following command:

ln -s . boot

需要的理由如下:

当我设置各种 Linux 系统时,在某些情况下我使用单独的 /boot 分区,而在某些情况下 - 我不使用.

When I set up various Linux systems, in some cases I use separate /boot partition and in some - I don't.

我有一个千篇一律的 grub.cfg 文件,其内容如下:

I have a cookie-cutter grub.cfg file, which reads something like:

menuentry "Gentoo GNU/Linux" {
    echo "Loading Linux kernel"
    linux /boot/vmlinuz root=...
    echo "Loading initial ramdisk"
    initrd /boot/initramfs
}

如果我没有符号链接,则上述内容不适用于具有单独 /boot 分区的系统.对于我需要的那些系统:

If I didn't have the symlink, the above would not work for the systems with separate /boot partition. For those systems I would need to have:

menuentry "Gentoo GNU/Linux" {
    echo "Loading Linux kernel"
    linux /vmlinuz root=...
    echo "Loading initial ramdisk"
    initrd /initramfs
}

注意 /vmlinuz/initramfs 前面没有 /boot.

Note the absence of /boot in front of /vmlinuz and /initramfs.

这样做的原因是 /boot 分区是 GRUBvmlinuzroot 分区和 initramfs 位于 root / 目录中.

The reason for this is that the /boot partition is the root partition for the GRUB and vmlinuz and initramfs are located in the root / directory.

而对于没有单独 /boot 分区的系统,system/ 分区也是 GRUB 的根分区vmlinuzinitramfs 位于 /boot 目录中.

Whereas, for systems without separate /boot partition, the system root / partition is also the root partition for the GRUB, and vmlinuz and the initramfs are located in the /boot directory.

有了符号链接,我可以对两种类型的系统使用相同的 grub.cfg.

With the symlink in place, I can use the same grub.cfg for both types systems.

这篇关于如果圆形符号链接没有用,那为什么允许使用它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆