tsc.id.au

  • Home
  • About
  • Blog
  • TIL
  • Blogroll
  • Tags
  • RSS

    TIL (Today I Learned):

    2025

  • Using `pacman` to Repair a Broken Arch Linux Installation
    2025-02-21 16:23:11

    Today, I learned a valuable command that can be a lifesaver when dealing with a broken Arch Linux installation. If you’ve ever found yourself in a situation where pacman fails to run due to a package upgrade issue, you might appreciate the utility of the following command:

    1sudo pacman --root=/mnt/arch --cachedir=/mnt/arch/var/cache/pacman/pkg -S <package>
    

    What Went Wrong?

    During a routine package upgrade, the icu package was accidentally left behind (my own fault) due to conflicting dependencies with some AUR packages. This left the system in a state where pacman would no longer run, effectively locking me out of my system’s package management and preventing me from rectifying the issue.

    To resolve this, I booted from a live Arch Linux image, which allowed me to access my system’s files and perform the necessary repairs to get pacman working again.

    The Fix

    Using the working pacman instance on the live image, I specified a custom root and cachedir pointing to the mounted main installation.

    1sudo pacman --root=/mnt/arch --cachedir=/mnt/arch/var/cache/pacman/pkg -Rncsd <AUR packages with conflicts>
    2sudo pacman --root=/mnt/arch --cachedir=/mnt/arch/var/cache/pacman/pkg -S icu <plus any dependent packages>
    

    This command allowed me to reinstall the icu package directly onto the mounted system, bypassing the broken pacman instance on the main installation. Once the package was successfully reinstalled, I was able to unmount the partition, reboot into my main Arch Linux system, and proceed to repair and reinstall the AUR packages that had conflicts.


  • TIL: Copy File Contents to Clipboard with `xclip`
    2025-02-10 15:42:50

    Instead of cat filename | xclip, just use:

    1xclip < filename
    

    It’s a more concise approach, saving keystrokes and avoiding the unnecessary cat command.


  • 2024

  • Recovering an Arch Linux System: Chrooting into a LUKS-Encrypted Installation
    2024-12-15 16:30:00

    If your system becomes unbootable, it may be necessary to manually fix it by logging into your installation. This process can be more complex when encrypted drives are involved. Here’s a guide to help you chroot into a LUKS-encrypted Arch Linux install.

    Step 1: Boot from a Live Arch Linux Environment

    To begin, you need a live installation of Arch Linux. Tools like Ventoy are great for creating bootable USB drives. Ensure your system’s firmware is set to boot in the same mode (UEFI or BIOS) as your installed Arch Linux.

    Step 2: Unlock the LUKS-Encrypted Partition

    If your drive is encrypted with LUKS, use the following command to unlock it:

    1sudo cryptsetup luksOpen /dev/<your_disk> luks-partition
    

    Explanation of the Command:

    • cryptsetup: Utility for managing LUKS encryption.
    • luksOpen: Opens (unlocks) a LUKS-encrypted partition.
    • /dev/<your_disk>: Replace <your_disk> with the actual device identifier (e.g., /dev/sda2). Use lsblk to list block devices and identify the correct one.
    • luks-partition: The name you assign to the unlocked partition. This creates a device mapper entry at /dev/mapper/luks-partition.

    You will be prompted to enter your encryption passphrase to unlock the drive.

    Step 3: Mount the Filesystem

    Once the partition is unlocked, you need to mount it:

    1sudo mkdir /mnt/arch
    2sudo mount /dev/mapper/luks-partition /mnt/arch
    

    Step 4: Chroot into Your Installation

    Change to the mounted directory and chroot into the system:

    1cd /mnt/arch
    2sudo arch-chroot .
    

    Step 5: Debug and Fix

    You are now inside your Arch Linux installation. From here, you can troubleshoot and resolve the issues causing your system to be unbootable. Common tasks include:

    • Reinstalling or updating bootloaders (e.g., GRUB or systemd-boot).
    • Fixing broken configurations.
    • Reinstalling missing packages.

    Once you’re done, exit the chroot environment:

    1exit
    

    By following these steps, you should be able to access your encrypted Arch Linux installation and resolve any critical issues effectively.


  • Fixing a Corrupt Pacman Database in Arch Linux
    2024-12-15 15:42:42

    In the unlikely event that you manage to corrupt your pacman database, the following commands can help you rebuild and recover it. These steps will ensure all affected or installed packages are correctly reinstalled and the database integrity is restored.

    Step 1: Rebuild the Database

    If the database structure is corrupted but the package metadata is still readable, you can use the following command to rebuild it:

    1pacman --dbonly -S $(LC_ALL=C pacman -Qkk 2>/dev/null | sed '/no mtree/!d; s/:.*//g')
    

    Explanation of the Command:

    • pacman --dbonly -S: Reinstalls packages but only modifies the database without extracting files.
    • pacman -Qkk: Checks the integrity of installed packages.
    • LC_ALL=C: Ensures consistent locale settings for predictable output.
    • sed '/no mtree/!d; s/:.*//g': Filters the output to identify packages with missing mtree entries (an indicator of database corruption).

    Step 2: Force Refresh and Overwrite Conflicts

    To force a full refresh of the package database and resolve any conflicting or outdated entries, run:

    1pacman -Syy --overwrite $(pacman -Qnq) "*"
    

    Explanation of the Command:

    • pacman -Syy: Forces a database refresh from all repositories.
    • --overwrite: Allows files that are already present in the filesystem to be replaced.
    • $(pacman -Qnq): Lists all explicitly installed packages to ensure they are included in the refresh.
    • "*": Matches all files during the reinstallation process.

    Notes on AUR Packages

    Packages installed from the AUR (e.g., via helpers like yay) are not managed by pacman directly. If these packages are affected by the database corruption, you will need to manually rebuild and reinstall them using your AUR helper. For example:

    1yay -S <package-name> --overwrite "*"
    

    Additional Tips

    1. Clear Package Cache: If corruption persists, clearing the package cache can help:

      1sudo pacman -Sc
      
    2. Reinstall Base System: For severe cases, consider reinstalling the base system:

      1sudo pacman -S base
      

    By following these steps, you should be able to recover from most cases of Pacman database corruption effectively. For further details, consult the Arch Wiki.


  • How to Automatically Sign Git Commits With a GPG Key
    2024-11-15 09:17:34

    Signing your Git commits with a GPG key can help verify the authenticity of your changes. Instead of manually specifying the -S flag with each commit, you can configure Git to automatically sign your commits.

    To set this up globally, run the following commands:

    1git config --global user.signingKey <yourSigningKey>
    2git config --global commit.gpgSign true
    
    • user.signingKey: Specifies the GPG key you want to use for signing commits. Replace <yourSigningKey> with the actual GPG key ID.
    • commit.gpgSign: Enables automatic signing of all commits.

    Once configured, Git will sign all your commits by default, making it easier to ensure your commits are properly authenticated without needing to manually specify the -S flag each time.


  • Managing Stale Buffers When Switching Git Branches in Vim
    2024-11-15 09:05:02

    When switching between branches in Git, it’s possible that files you have open in Vim may have been modified outside of the editor, without you realizing it. This can lead to a situation where the buffer in Vim becomes stale and no longer reflects the current state of the file on disk.

    To handle this more effectively, you can configure Vim to automatically detect and reload files when they change on disk. Here’s how you can set this up in your .vimrc:

    1set autoread
    2au CursorHold * checktime
    
    • set autoread: This tells Vim to automatically reload a file if it has been modified externally.
    • au CursorHold * checktime: This creates an auto-command that triggers a check whenever the cursor is idle for a brief moment (CursorHold). It checks whether the file has changed since it was last read.

    With these settings in place, Vim will automatically reload the buffer if the file changes on disk, helping you stay in sync with the latest changes.

    What if I’ve Made Changes to the File But Haven’t Saved?

    If you’ve made local changes to the file and haven’t saved them, Vim will alert you that the file has been modified externally. You’ll then have the option to either:

    • Save your changes and overwrite the external modifications.
    • Reload the file from disk, discarding your changes.

    This ensures that you can make informed decisions about how to handle the state of your file, avoiding conflicts between the file on disk and your in-memory buffer.


  • Hello World
    2024-11-14 19:16:07

    Welcome to my new microblog! This space is inspired by Julia Evans’ recent post on starting a microblog (link), and I plan to use it as a place to jot down quick notes, discoveries, and solutions to technical problems. It’ll also serve as a way to publish some long-term draft posts that may have otherwise stayed unfinished.

    My first attempt here accidentally turned into a full-length blog post: How to Delay Application Startup in Xfce.

    So, I guess I’ll need to work on keeping things short and to the point!

    BTW: There’s a separate RSS feed for the microblog here.


Copyright © 2025 tsc.id.au
  • Home
  • About
  • Blog
  • TIL
  • Blogroll
  • Tags
  • RSS