是否update-alternatives --config
简单地使用ln
创建硬链接?例如,
$ sudo update-alternatives --config javaws
There are 3 choices for the alternative javaws (providing /usr/bin/javaws).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-6-openjdk-i386/jre/bin/javaws 1061 auto mode
1 /usr/lib/jvm/java-6-openjdk-i386/jre/bin/javaws 1061 manual mode
2 /usr/lib/jvm/java-7-openjdk-i386/jre/bin/javaws 1060 manual mode
3 /usr/lib/jvm/jdk1.7.0_67/bin/javaws 1 manual mode
Press enter to keep the current choice[*], or type selection number: 3
update-alternatives: using /usr/lib/jvm/jdk1.7.0_67/bin/javaws to provide /usr/bin/javaws (javaws) in manual mode.
答案1
不是硬链接,而是软/符号链接:
$ stat /etc/alternatives/default.plymouth
File: ‘/etc/alternatives/default.plymouth’ -> ‘/lib/plymouth/themes/ubuntu-logo/ubuntu-logo-scale-2.plymouth’
Size: 61 Blocks: 8 IO Block: 4096 symbolic link
Device: 801h/2049d Inode: 174731 Links: 1
Access: (0777/lrwxrwxrwx) Uid: ( 0/ root) Gid: ( 0/ root)
(这控制启动时显示的主题。)
update-alternatives
使用unlink
和symlink
系统调用:
$ sudo strace update-alternatives --config default.plymouth
execve("/usr/bin/update-alternatives", ["update-alternatives", "--config", "default.plymouth"], [/* 18 vars */]) = 0
brk(0) = 0x18c3000
...
write(1, "Press enter to keep the current "..., 69Press enter to keep the current choice[*], or type selection number: ) = 69
fstat(0, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 17), ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f8d4c8a2000
read(0, 1
"1\n", 1024)
...
unlink("/etc/alternatives/default.plymouth.dpkg-tmp") = -1 ENOENT (No such file or directory)
symlink("/lib/plymouth/themes/ubuntu-logo/ubuntu-logo-scale-2.plymouth", "/etc/alternatives/default.plymouth.dpkg-tmp") = 0
lstat("/lib/plymouth/themes/default.plymouth", {st_mode=S_IFLNK|0777, st_size=34, ...}) = 0
lstat("/lib/plymouth/themes/default.plymouth", {st_mode=S_IFLNK|0777, st_size=34, ...}) = 0
readlink("/lib/plymouth/themes/default.plymouth", "/etc/alternatives/default.plymou"..., 34) = 34
stat("/lib/plymouth/themes/ubuntu-logo/ubuntu-logo.grub", {st_mode=S_IFREG|0644, st_size=47, ...}) = 0
unlink("/etc/alternatives/default.plymouth.grub.dpkg-tmp") = -1 ENOENT (No such file or directory)
symlink("/lib/plymouth/themes/ubuntu-logo/ubuntu-logo.grub",
...
exit_group(0) = ?
+++ exited with 0 +++
备选方案实际上都是符号链接,如果我没记错的话。您可以根据需要手动链接它们。具体做法update-alternatives
是管理这些链接可以指向的内容,分配优先级并提供选项。
事实上,手册页的第一段:
update-alternatives creates, removes, maintains and displays
information about the symbolic links comprising the Debian alternatives
system.