0

Does update-alternatives --config simply use ln to create hard links? For example,

$ 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

Not hard links, but soft/symbolic links:

$ 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)

(This controls the theme shown while booting.)

update-alternatives uses the unlink and symlink system calls:

$ 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 +++

The alternatives are all really symbolic links, IIRC. You could manually link them if you wish. What update-alternatives does is manage what those links can point to, assigning priorities and offering options.

In fact, the first paragraph of the manpage:

update-alternatives   creates,   removes,   maintains   and    displays
   information about the symbolic links comprising the Debian alternatives
   system.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.