- LightDM Overhaul: Rewrote `install_lightdm()` logic to verify both lightdm and lightdm-gtk-gtk-greeter-settings. Now installs the trio in a single command if missing, skipping only when fully present. Added "Enable autologin" option modifying `/etc/lightdm/lightdm.conf` with robust `sed` patterns for `SUDO_USER`. Fixed missing `debconf-set-selections` to ensure LightDM is set as default during installation. - GDM3 Implementation: Created a new sub-menu in `modules/desktop_display.sh` allowing independent installation of GDM3, User List toggle (hide/show), Autologin configuration via `/etc/gdm3/daemon.conf`, and conditional "Force Enable Wayland on NVIDIA" for Debian 12/13 using udev symlinks. - SDDM Integration: Added SDDM as option 3 in the Display Manager menu. Implemented automatic session detection (Wayland > X11) to populate `/etc/sddm.conf.d/autologin.conf` without user input, defaulting to plasmawayland, lxqt-wayland, or generic fallbacks. - greetd support: Added conditional support for Debian 12 and 13 only. Implemented sub-menu with base install, recommended `tuigreet` (with backports handling for Bookworm), and other manual setup options (`gtkgreet`, `nwg-hello`, `wlgreet`) exclusive to Trixie. - ZRAM UX Improvements: Updated descriptions in `modules/zram.sh` to explicitly mention I/O reduction and responsiveness benefits for low-RAM systems (e.g., 4GB). Cleaned up compression algorithm labels (`lz4`, `zstd`) to remove redundancy in menu values. - General Code Quality: Standardized all user-facing messages to English across modules. Ensured independent package installation checks prevent script abortion if one DM fails, while maintaining strict error handling for system configurations. - update docs and readme
6.2 KiB
Option 9: Swap
1. What does this component do?
This module is responsible for the secure management of disk-based swap space within the debianito environment. Unlike standard Linux tools that might overwrite existing configurations or conflict with memory compression features (like ZRAM), this script operates as a priority-aware, persistent swap manager.
Its primary functions include:
- Dynamic Allocation: Creating and resizing swapfiles based on detected RAM capacity without requiring physical partition changes.
- Priority Integration: Explicitly setting the swap priority (
pri=10) to ensure it sits below ZRAM (which usespriority=100). This prevents the system from using disk I/O for memory swapping until compressed RAM is exhausted, optimizing performance. - Persistence Management: Safely editing
/etc/fstabwith a unique tag (# debianito-managed-swap) to ensure swap survives reboots without corrupting manual entries. - Safety Locking: Prevents concurrent operations using file locking mechanisms to avoid race conditions during active system usage.
2. How does it work?
The script leverages several advanced Linux subsystems and safety protocols:
- File System Detection: It identifies the filesystem type of the target partition (e.g.,
ext4,btrfs). For Btrfs, it applies specific flags (chattr +Cfor copy-on-write optimization) to prevent performance degradation during swap operations. - Allocation Strategy: It prefers
fallocatefor instant space reservation on supported filesystems, falling back todd if=/dev/zerofor compatibility or zeroing requirements (like Btrfs). - Fstab Validation: Before writing changes to
/etc/fstab, it creates a temporary file and validates the syntax usingfindmnt --verify. If validation fails, the script aborts and restores the original state. - Concurrency Control: It utilizes
flockon/run/lock/debianito-swap.lock. This ensures that if another process is modifying swap settings (e.g., a system update), this script will wait or exit gracefully to prevent filesystem corruption. - Swappiness Tuning: It configures
vm.swappinessvia both runtime (sysctl -w) and persistent (/etc/sysctl.d/99-swappiness-debianito.conf) mechanisms, defaulting to values that favor RAM usage over disk swapping (e.g., 10-20).
3. The Logical Decision Tree (Step by Step)
The execution flow follows a strict logical tree designed for safety and idempotency:
-
Initialization & Locking:
- The
manage_swap()function attempts to acquire an exclusive lock (flock -n). If the lock is held by another process, it immediately exits with a "Busy" message to prevent conflicts.
- The
-
Menu Selection Loop:
- Enters a continuous loop presenting options (Status, Create, Remove, Swappiness).
- Breaks only when the user selects "Back to main menu".
-
Action Execution Paths:
- Path A: Status Check (
_swap_current_status)- Reads active swap entries via
swapon --show. - Reads current swappiness from
/proc/sys/vm/swappiness. - Parses
/etc/fstabfor managed tags.
- Reads active swap entries via
- Path B: Create/Resize (
_swap_create_file)- Recommendation: Calculates optimal size based on RAM (e.g., 2GB for >16GB RAM, 4GB for 8-16GB).
- Btrfs Check: If the filesystem is Btrfs, it warns about
nodatacowrequirements and hibernation limitations. - Existence Check: If
/swapfileexists, it prompts to confirm recreation (deleting old data first viaswapoff). - Allocation: Uses
fallocateorddto zero the file. Sets permissions (chmod 600) and initializes swap (mkswap). - Persistence: Attempts to write the new entry to
/etc/fstab. If validation fails, it cleans up (removes file) before exiting.
- Path C: Remove (
_swap_remove_file)- Checks for the unique
SWAP_FSTAB_TAGin fstab. - Confirms user intent to delete.
- Executes
swapoff, removes the fstab line, and deletes the physical file.
- Checks for the unique
- Path D: Swappiness (
_swap_set_swappiness)- Validates input (0-100 integer).
- Writes a temporary sysctl config file.
- Applies changes immediately via
sysctl -w.
- Path A: Status Check (
4. What does each menu item do and what does it mean?
Each option in the swap management submenu serves a specific technical purpose:
-
Option 1: Show current swap & swappiness
- Technical Action: Aggregates data from
/proc/swaps,/proc/sys/vm/swappiness, and/etc/fstab. - Significance: Provides an audit trail of the current memory management state. It verifies if ZRAM is active (implied by priority check) and how much disk swap is currently in use.
- Technical Action: Aggregates data from
-
Option 2: Create / resize swapfile
- Technical Action: Allocates a new block device file (
/swapfile) or expands an existing one. Sets thepri=10flag to ensure it acts as a secondary memory layer after ZRAM fills up. - Significance: Essential for systems with low RAM that need overflow protection without installing physical partitions. The "Resize" capability allows adapting to new hardware configurations dynamically.
- Technical Action: Allocates a new block device file (
-
Option 3: Remove swapfile
- Technical Action: Disables the swapfile (
swapoff), removes it from/etc/fstab, and deletes the file from disk. - Significance: Useful for troubleshooting, freeing up disk space (e.g., on SSDs where write cycles are a concern), or migrating to ZRAM-only configurations if RAM is sufficient.
- Technical Action: Disables the swapfile (
-
Option 4: Change swappiness
- Technical Action: Modifies the kernel parameter
vm.swappiness. - Significance: Controls the "aggressiveness" of swapping. A lower value (e.g., 10) tells the kernel to keep data in RAM longer, only using swap as a last resort. This is critical for desktop performance and battery life on laptops.
- Technical Action: Modifies the kernel parameter
-
Option 5: Back to main menu
- Technical Action: Releases the file lock (
exec 9>&-) and terminates the submenu loop. - Significance: Returns control to the user, ensuring no swap operations are running in the background before they navigate to other system configurations.
- Technical Action: Releases the file lock (