2

During my last arch linux update using pacman -Syu I shut down my laptop, as I had forgotten that the update was running in the background and installing the packages.

Afterwards I could not start arch linux anymore and had to go through the time consuming (for me) process of creating a bootable usb with another laptop and using chroot to run re-run pacman -Syu in order to fix my arch linux install.

I've had similar problems before after accidentally shutting down my laptop while running a system update, so I was wondering if there is a way to display a warning that pacman is running if the shutdown process is about to be initiated.

I shut down my computer using the regular KDE Plasma "switch off" mechanism.

EDIT

As an idea; I think I might be able to write a script which first checks if pacman is running, as explained here, and then, if pacman is not running, calls the kde shutdown command that is shown here.

I can't try it out since I cannot access my Linux machine at the moment, but I'll try it out this evening.

1

I found a system-wide solution for this problem, preventing any kind of power-management: I created two pacman hooks, which prevent systemd from turning of the power (see https://askubuntu.com/a/858617).

The first one is masking the targets:

/etc/pacman.d/hooks/00-prevent-interruption-pre.hook

[Trigger]
Operation = Install
Operation = Upgrade
Operation = Remove
Type = Package
Target = *

[Action]
Description = Masking systemd targets to prevent interruption...
When = PreTransaction
Exec = /usr/bin/systemctl --runtime mask halt.target poweroff.target reboot.target kexec.target suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target sleep.target
Depends = systemd

And the second one is unmasking them again after all other hooks have been run:

/etc/pacman.d/hooks/99-prevent-interruption-post.hook

[Trigger]
Operation = Install
Operation = Upgrade
Operation = Remove
Type = Package
Target = *

[Action]
Description = Unmasking systemd targets to reenable power management...
When = PostTransaction
Exec = /usr/bin/systemctl --runtime unmask halt.target poweroff.target reboot.target kexec.target suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target sleep.target
Depends = systemd

This won't prevent you from logging out but will disable any shutdown functionality until pacman completed it's run sucessfully. So to keep pacman running I recommend you put it in a terminal multiplexer (like tmux) to prevent it from being interrupted when your terminal application is closed.

1
  • I use a different system now, so I cannot validate this answer. If someone else confirms that it workds I'll gladly mark it as solved Dec 21 '20 at 20:03

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.