Score:0

meaning of "dpkg-divert --local --rename --add /sbin/initctl"

za flag

This is from https://help.ubuntu.com/community/LiveCDCustomizationFromScratch.
Here I'm supposed to do inside the chroot environment,

dpkg-divert --local --rename --add /sbin/initctl

Is it telling the OS that "from now on, when you install packages, whatever the package is(--local), if that package tries to install /sbin/initctl, install it(--add) to /sbin/initctl.distrib (--rename)" ? I tried to understand the manual but couldn't understand it exactly.

Is it that if a file is diverted to another file by this dpkg-divert command(say, xfile to xfile.distrib) by a package, then when the package is used, xfile.distrib is used instead of original xfile?
I tried cat /var/lib/dpkg/diversions and it gives me this list.

/usr/share/dict/words
/usr/share/dict/words.pre-dictionaries-common
dictionaries-common
/usr/share/man/man1/sh.1.gz
/usr/share/man/man1/sh.distrib.1.gz
dash
/usr/share/man/man1/dh_gstscancodecs.1.gz
...

The file constins the list of files and not the package names and I can't understand it. For example what does the first line /usr/share/dic/words mean?
Please someone confirm me if my understanding is correct and what the list means.

Score:0
us flag

Is it telling the OS that "from now on, when you install packages, whatever the package is(--local), if that package tries to install /sbin/initctl, install it(--add) to /sbin/initctl.distrib (--rename)"

  • --rename tells it to move any existing file immediately
  • I'd put --add next to "telling the OS"

Is it that if a file is diverted to another file by this dpkg-divert command(say, xfile to xfile.distrib) by a package, then when the package is used, xfile.distrib is used instead of original xfile?

No. Whoever set up the diversion has to provide something in place of this xfile (in this case, that's you). In that page, they do:

ln -s /bin/true /sbin/initctl

The diversions file consists of three-line groups:

  1. The file to be diverted
  2. The diverted location
  3. The package that set up the diversion

So for the following three lines:

/usr/share/dict/words
/usr/share/dict/words.pre-dictionaries-common
dictionaries-common

dpkg will divert installations of /usr/share/dict/words from packages other than dictionaries-common (say, wamerican, for example) to /usr/share/dict/words.pre-dictionaries-common. If you install wamerican, you can see this in action:

# dpkg -S /usr/share/dict/words
diversion by dictionaries-common from: /usr/share/dict/words
diversion by dictionaries-common to: /usr/share/dict/words.pre-dictionaries-common
wamerican: /usr/share/dict/words

That guide is a bit outdated: initctl is Upstart, which is no longer used. You can't even install it anymore. Service management is done using systemd, and now you use systemctl instead.

za flag
Thanks! I can now almost understand it. A question, now that other packages will install into the diverted location(file), then will that other packages use the new diverted (name-changed) file instead of original file? so my question is if the diversion only for installation or for actual use other than the package who setup the diversion. (and Yes I knew the LiveCDFromScratch guide above is too old so it's almost unusable. I hope ubuntu people update those documents.)
muru avatar
us flag
Nobody other than `dpkg` and the creator of the diversion knows about the diversion. Anybody using `/path/to/some/file` that was diverted will use whatever is currently there.
za flag
Ah thanks alot!
us flag
@muru I don't even have initctl in /sbin. only init. Ubuntu 18.04.6 LTS \n \l What does those lines did , when it made sense? to keep init process in safe?
muru avatar
us flag
@CEOatApartico in the steps after that, several packages are installed. Some packages start or restart services upon installation, and this was done using the `initctl` command. Since there's no point to doing that in the chroot (and it would cause errors because init isn't running in the chroot), they replace it with `true` for the rest of the setup.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.