Skip to content

Update snap_pac.py to Solve the problem that pacman cannot run normal… #59

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

rankaiyx
Copy link

@rankaiyx rankaiyx commented Jun 7, 2025

…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

rankaiyx added 2 commits June 8, 2025 01:24
…ly after rollback due to the pacman lock file in the snapshot.
fix a bug: kernel: BTRFS warning: Attempt to set subvolume xx read-write during send
@rankaiyx
Copy link
Author

rankaiyx commented Jun 7, 2025

There are still some unexplained issues. Maybe modifying files locked by snapper isn't a good idea. I'll try handling the rolled-back system within snapper-rollback instead.

I found a method with almost no side effects, tested it repeatedly, and it works well.

@rankaiyx rankaiyx closed this Jun 7, 2025
@rankaiyx rankaiyx reopened this Jun 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant