63

What I mean under the question is: is there a way to dump the ordered list (like pstree does for processes) to see how systemd executed the supplied set of units, i.e. the tree after the dependencies were resolved and jobs were queued for the execution? I know that you can do it by analysing systemd state data, but is there a quick way to see such a tree? It would help a lot in failure investigation (e.g. if you see that the boot process was stuck on some unit you would be able to pinpoint the approximate location for your deeper investigation.

70

systemd-analyze is your friend. For example systemd-analyze critical-chain outputs blocking tree of daemons. Mine for example:

graphical.target @20.211s
└─multi-user.target @20.211s
  └─nginx.service @19.348s +862ms
    └─network.target @19.347s
      └─NetworkManager.service @10.315s +9.031s
        └─basic.target @10.312s
          └─timers.target @10.311s
            └─systemd-tmpfiles-clean.timer @10.311s
              └─sysinit.target @10.295s
                └─systemd-update-utmp.service @10.167s +127ms
                  └─systemd-tmpfiles-setup.service @10.124s +41ms
                    └─local-fs.target @10.097s
                      └─home-entd-Downloads.mount @10.093s +2ms
                        └─home.mount @9.326s +672ms
                          └─systemd-fsck@dev-sda6.service @8.472s +696ms
                            └─dev-sda6.device @8.471s

NetworkManager in example basically holding entire bootup.

If you want to have more detailed view you can render entire execution chain in a svg file. systemd-analyze plot > something.svg outputs entire chain (120+ modules) as progress bars to high-res svg file which show states, that are blocked and another problems.

Finally you have systemd-analyze dot tool which outputs dot file which outputs entire hierarchy: systemd-analyze dot | dot -Tpng -o stuff.png with dot tool you can output it as ps and svg files too.

All of above tools are built-in in systemd-analyze tool which comes by default with systemd in archlinux at least. I think there is some 3rd party projects dealing with it too.

  • Thanks for your answer, however it doesn't address the questions and just reiterates parts of my question (I mentioned that I'm aware of a way how to do it by analysing systemd's state data). Hence the question is how to get a pstree-like tree of the boot up sequence after all dependencies are solved (e.g. post-boot). The critical-chain is almost it (despite that it is a bottom up tree) but doesn't list all started units. What is asked in the question: a tree that lists every single unit that was executed until some point (e.g. hitting the multi-user.target). – galaxy Aug 5 '14 at 12:36
  • 4
    systemd-analyze plot > something.svg is full three of execution with targets (it is closest what you want). systemd-analyze dot is full graph of dependencies (it is most correct representation). Are these not what you want? In plot just find target and see what it needs too be run. The same dependencies are exactly listed graph, if it to much fire up some graph analysis toolkit and select graph point for which you want see dependencies (dot tool has more settings). See man page: freedesktop.org/software/systemd/man/systemd-analyze.html --order and similar – IBr Aug 6 '14 at 10:45
  • 1
    From man page: This plots all dependencies of any unit whose name starts with "avahi-daemon.": $ systemd-analyze dot 'avahi-daemon.*' | dot -Tsvg > avahi.svg $ eog avahi.svg This plots the dependencies between all known target units: systemd-analyze dot --to-pattern='*.target' --from-pattern='*.target' | dot -Tsvg > targets.svg $ eog targets.svg – IBr Aug 6 '14 at 10:48
  • 1
    IBr, but this is unusable in the text console, unfortunately. I really appreciate the time you spent on the answer (and it is correct if you want to get some data to analyse), but it does not address the original question, so I can accept it. Sorry. – galaxy Aug 7 '14 at 9:37
  • 1
    OK no problem. I love command line tools myself :) – IBr Aug 7 '14 at 9:51
13

May still not fully answering your question but try with --fuzz option

systemd-analyze critical-chain --fuzz 1h

Note you can also specify units to see their critical-chain, so you're not limited to the multi-user.target

systemd-analyze critical-chain network.target local-fs.target

Hope this helps

12

Not sure I properly understand the question, but there are tree visualizations available with the following commands :

sudo systemctl status

And also :

sudo systemctl list-dependencies 

Hope this helps :)

Also, it might be useful for other purposes to build a tree of the systemctl symlinks folders:

tree /etc/systemd/system

It was actually really useful to figure out old / buggy units that were slowing down my system startup, to disable them afterwards using the systemctl disable command.

EDIT

That said I really agree with the OP that this basic functionality should be given via command-line tools, and not a graphical tool... What if you cannot start X ? How you deal with your svg file then ?

Actually, there is a way. If you cannot use scp (ssh tool) to fetch your file on another computer, fbi might actually help you :)

sudo systemd-analyze plot > /home/user/startup.svg
fbi /home/user/startup.svg

Worked in my TTYs. Just navigate inside the picture with arrows. There are zooming options, to list do fbi -h.

Again I hope this helps. It is available in Archlinux and Ubuntu repos.

EDIT 2 :

fbi doesn't work over ssh. You can do X forwarding like this ssh -Y user@server, but you need a X server running on your remote server.

The best bet here is to use sshfs. It works GREAT in userspace, for instance with nautilus. There's a little configuration to do, see:

sudo vim /etc/fuse.conf #type a, uncomment the user_allow_other line and ESC :wq
sudo mkdir /mnt/yourmountingdir
sudo chown user:user /mnt/yourmountingdir
sshfs user@remotemachine.com:/home/user /mnt/yourmountingdir/ -o allow_other #Asks for host trusting and password
sudo fusermount -u /mnt/yourmountingdir/ #To disconnect and unmount
  • The question is about the execution tree for all activated units systemd went through after the dependency resolution. So this answer is a miss. – galaxy Mar 7 '17 at 6:28
  • Perhaps your question is well fitted for a feature request ? Sure it would help. Anyway, I posted this answer after stumbling to your question because it was somehow resembling to another question I needed some info on, and I felt that some basic exemples lacked (like the things you have tried and didn't work -that would have really helped to clarify), especially for people like me struggling after having lost System V init and their handy rc.conf file. Sorry my answer didn't fit. Not worth a downvote though. – Joel.O Mar 13 '17 at 8:57
  • Edited with a workaround to your problem. Hope it helps again. – Joel.O Mar 13 '17 at 10:36
  • I wasn't able to use fbi over ssh on my server. But sshfs works even better. See EDIT 2. – Joel.O Apr 6 '17 at 8:45

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.