Update snap_pac.py to Solve the problem that pacman cannot run normal… #59
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…ly after rollback due to the pacman lock file in the snapshot.
I now regularly use snapper-rollback with Arch Linux's recommended btrfs setup to elegantly and efficiently restore my system.
However, after rolling back to pre/post snapshots created by snap-pac, pacman stops working. My old solutions don't work with snapper-rollback's elegant approach.
The core problem:
Pacman's lock mechanism doesn't work well with snapshot hooks. The current sequence is:
Pacman locks database 🔒
Pre-snapshot hook runs 📸
Post-snapshot hook runs 📸
Pacman unlocks database 🔓
This works for most hooks, but fails for system snapshots. For snapshots, the ideal sequence should be:
Pre-snapshot hook 📸
Pacman locks 🔒
Pacman unlocks 🔓
Post-snapshot hook 📸
My solution:
By deleting db.lck in snapshots, we achieve the same result as having the ideal sequence. This keeps pacman working after rollbacks while maintaining snapper-rollback's smooth operation.
before:
➜ ~ sudo snapper list
...
19 │ single │ │ Sat 07 Jun 2025 08:04:42 PM │ root │ │ test2 │
20 │ pre │ │ Sat 07 Jun 2025 08:04:51 PM │ root │ number │ pacman -S iperf3 │
21 │ post │ 20 │ Sat 07 Jun 2025 08:04:52 PM │ root │ number │ iperf3 lksctp-tools │
22 │ single │ │ Sat 07 Jun 2025 08:04:58 PM │ root │ │ test3 │
➜ ~ sudo snapper status 19..20
c..... /home/abc/.zsh_history
+..... /var/lib/pacman/db.lck
➜ ~ sudo snapper status 21..22
c..... /home/abc/.zsh_history
-..... /var/lib/pacman/db.lck
new:
➜ ~ sudo snapper list
...
26 │ single │ │ Sun 08 Jun 2025 01:17:27 AM │ root │ │ test6 │
27 │ pre │ │ Sun 08 Jun 2025 01:17:37 AM │ root │ number │ pacman -S htop │
28 │ post │ 27 │ Sun 08 Jun 2025 01:17:37 AM │ root │ number │ htop │
29 │ single │ │ Sun 08 Jun 2025 01:17:55 AM │ root │ │ test7 │
➜ ~ sudo snapper status 26..27
c..... /home/abc/.zsh_history
➜ ~ sudo snapper status 28..29
c..... /home/abc/.zsh_history
my btrfs layout:
├── @
├── @snapshots
└── @var_log
from https://wiki.archlinux.org/title/Snapper