pigleaf04
mitchellsander58wyibac@docmailz.com
UEFI Secure Boot, Timeshift Snapshots, and Driver Setup: Update Ubuntu Command Line Focus (33) (4 อ่าน)
22 พ.ย. 2569 20:08
<h2>Executive Summary (BLUF)</h2>
<p>Managing UEFI Secure Boot, Timeshift snapshots, and hardware drivers entirely from the Ubuntu command line eliminates dependence on graphical tools and makes post-install setup scriptable across headless servers, SSH sessions, and recovery TTYs. Every step—creating pre-upgrade snapshots with `timeshift --create`, querying and installing drivers via `ubuntu-drivers`, and queueing MOK certificates with `mokutil`—has a first-class CLI interface.</p>
<p>A command-line-first workflow wraps every major `apt` or `ubuntu-drivers` transaction in a `timeshift --create` checkpoint, uses `mokutil --import` and `dkms status` to audit Secure Boot module signing, and relies on `timeshift --restore` from a TTY or live environment if a kernel or driver update fails to boot.</p>
<h2>Command-Line Control of Secure Boot, Snapshots, and Drivers</h2>
<p>Administrators who visit website guides for updating Ubuntu via the command line often master `apt update && apt full-upgrade` quickly, only to get caught off guard when a kernel or driver upgrade triggers Secure Boot module rejection or breaks a display manager. Relying on GUI apps like "Software & Updates" or the Timeshift desktop window is impractical on remote systems or when troubleshooting a broken graphical session.</p>
<p>Fortunately, Ubuntu exposes the entire hardware and rollback lifecycle through deterministic CLI utilities:</p>
<p>1. <strong>Timeshift CLI (`timeshift`)</strong>: While often associated with its GTK interface, `timeshift` operates natively as a CLI tool. Running `sudo timeshift --create --comments "Pre-Update" --tags D` creates a snapshot before any `apt full-upgrade` or driver change, and `sudo timeshift --list` displays available restore points in plain text. You can also inspect `/etc/timeshift/timeshift.json` directly from the terminal to verify the snapshot UUID, schedule flags, and exclude patterns without ever launching a window manager. 2. <strong>Driver CLI (`ubuntu-drivers`)</strong>: Running `ubuntu-drivers list` or `ubuntu-drivers devices` enumerates PCI/USB hardware modaliases and matching Ubuntu packages without touching X11. `sudo ubuntu-drivers install` installs the recommended driver and its DKMS dependencies non-interactively (except for MOK password setup when Secure Boot is active). Adding `--gpgpu` targets compute-only server drivers on headless nodes. 3. <strong>MOK & DKMS CLI (`mokutil`, `dkms`)</strong>: `mokutil --sb-state` confirms whether Secure Boot is enforced, `mokutil --list-enrolled` dumps the subject and SHA-1/SHA-256 fingerprints of trusted keys in UEFI NVRAM, and `dkms status` verifies whether every third-party module compiled cleanly for the target kernel version. Pairing these with `modinfo <module>
| grep sig` lets you inspect the exact cryptographic signature embedded inside any `.ko` file on disk.
</module></p>
<p>Combining these three CLI toolsets turns routine Ubuntu updates into a reversible, auditable terminal workflow.</p>
<h2>Strategic Frameworks and Architectural Breakdown</h2>
<p>A CLI-driven update and hardware maintenance workflow inserts snapshot and Secure Boot verification gates directly around `apt` and `ubuntu-drivers` commands.</p>
<pre>+-------------------------------------------------------------------+
| COMMAND-LINE UPDATE, SNAPSHOT & DRIVER WORKFLOW |
+-------------------------------------------------------------------+
[ 1. Pre-Flight Check ] ---> mokutil --sb-state
| timeshift --list (Verify disk space)
v
[ 2. apt update vs apt upgrade ] ---> sudo timeshift --create --comments ...
|
v
[ 3. Package / Driver ] ---> sudo apt update && sudo apt full-upgrade
| (or) sudo ubuntu-drivers install
v
[ 4. Build & Sign Gate ] ---> dkms status (Confirm "installed")
| mokutil --list-new (Check pending MOK)
v
[ 5. Reboot / Verify ] ---> sudo systemctl reboot
(Enroll MOK in mmx64.efi if queued)</pre>
<p>This CLI sequence enforces four operational guarantees:</p>
<p>1. <strong>Zero-GUI Dependency</strong>: Every diagnostic and remediation command runs cleanly inside `tmux`, SSH, or a `Ctrl+Alt+F3` text console. 2. <strong>Atomic Pre-Upgrade Checkpoints</strong>: Creating a Timeshift snapshot immediately before `apt full-upgrade` or `ubuntu-drivers install` ensures a known-good fallback exists even when `dpkg` upgrades dozens of core packages at once. 3. <strong>Pending MOK Detection</strong>: Checking `mokutil --list-new` before rebooting tells the administrator in advance whether `MokManager` will appear at the next boot, preventing surprises on remote or unattended consoles. 4. <strong>Automated Post-Build Audit</strong>: Running `dkms status` before rebooting catches missing `linux-headers` or failed module builds while the old working kernel is still running.</p>
<h2>Comparative Matrix: Legacy Execution vs Modern Practice</h2>
<p>Command-line system maintenance on Ubuntu has progressed from blind `apt-get` runs to snapshot-protected, Secure-Boot-aware terminal pipelines.</p>
<table>
<tbody>
<tr>
<th>CLI Maintenance Task</th>
<th>Legacy Execution (Unprotected `apt-get` & GUI Tools)</th>
<th>Modern Practice (CLI Timeshift + `mokutil` + `dkms`)</th>
<th>Operational Advantage</th>
</tr>
<tr>
<td><strong>Pre-Update Backup</strong></td>
<td>Skipping backups or running `tar` manually</td>
<td>`sudo timeshift --create --comments "Pre-Upgrade"`</td>
<td>Instant, repeatable OS checkpoints in one command</td>
</tr>
<tr>
<td><strong>Driver Discovery</strong></td>
<td>Opening GUI "Additional Drivers" tab</td>
<td>`ubuntu-drivers devices` and `ubuntu-drivers list`</td>
<td>Works over SSH, recovery shells, and automated scripts</td>
</tr>
<tr>
<td><strong>Secure Boot Check</strong></td>
<td>Rebooting and hoping third-party modules load</td>
<td>`mokutil --sb-state` and `mokutil --list-new`</td>
<td>Detects queued MOK enrollments before rebooting</td>
</tr>
<tr>
<td><strong>Module Build Audit</strong></td>
<td>Discovering broken drivers after rebooting</td>
<td>`dkms status` checked prior to `systemctl reboot`</td>
<td>Catches failed kernel module builds while system is still up</td>
</tr>
<tr>
<td><strong>Broken-Boot Recovery</strong></td>
<td>Reinstalling Ubuntu or chrooting manually</td>
<td>`sudo timeshift --restore --snapshot <name>
`
</name></td>
<td>Restores working kernel and `/etc` state cleanly from TTY</td>
</tr>
<tr>
<td><strong>Kernel Rollback</strong></td>
<td>Manually uninstalling `linux-image-*` via `dpkg`</td>
<td>GRUB fallback boot + `timeshift --restore`</td>
<td>Reverts both kernel and matching `initramfs`/driver state</td>
</tr>
</tbody>
</table>
<h2>Governance, Best Practices, and Compliance Controls</h2>
<p>Standardizing CLI-based snapshot and driver workflows requires clear guardrails around storage, key management, and remote console access.</p>
<p><strong>Remote MOK Enrollment Planning</strong> Because `MokManager` executes in UEFI pre-boot firmware before networking or `sshd` initializes, an administrator cannot type a MOK one-time password over SSH. Always check `mokutil --list-new` before rebooting a remote machine; if a new MOK key is queued, coordinate physical console or out-of-band KVM access before issuing `systemctl reboot`.</p>
<p><strong>Scripted `timeshift` Retention Policies</strong> On servers or workstations updated frequently via the command line, unpruned manual snapshots can consume significant storage. Configure `/etc/timeshift/timeshift.json` with explicit retention counts (such as keeping 3 daily and 2 weekly snapshots) and periodically verify `timeshift --list` so disk usage stays predictable.</p>
<p><strong>Verifying `linux-headers` Before Kernel Transitions</strong> When updating Ubuntu from the command line, always use `sudo apt full-upgrade` (or `dist-upgrade`) rather than `apt upgrade` alone when kernel meta-packages are held back. Pairing `linux-image-generic` with `linux-headers-generic` ensures `dkms` always has the matching header tree required to compile and sign third-party drivers.</p>
<p><strong>Avoiding Partial Driver States</strong> Never interrupt `ubuntu-drivers install` or `dkms autoinstall` with `Ctrl+C` while `initramfs` is regenerating. If an interruption occurs—such as a dropped SSH connection when not using `tmux`—run `sudo dpkg --configure -a` and `sudo update-initramfs -u -k all` before rebooting so the system never attempts to boot with a truncated `initrd.img`.</p>
<h2>Implementation Roadmap</h2>
<p>Adopt this four-phase CLI workflow for Secure Boot, Timeshift, and driver management on Ubuntu.</p>
<h3>Phase 1: CLI Tooling & Baseline Audit</h3>
<p>Install required utilities from the command line: `sudo apt update && sudo apt install -y timeshift ubuntu-drivers-common mokutil dkms`. Check current firmware and driver state by running `mokutil --sb-state`, `ubuntu-drivers devices`, and `dkms status`. Confirm whether `/etc/timeshift/timeshift.json` is configured for Btrfs or RSYNC and verify free disk space with `df -h`.</p>
<h3>Phase 2: Pre-Change Snapshot Creation</h3>
<p>Before modifying drivers or applying a major system update, create a tagged CLI snapshot: `sudo timeshift --create --comments "Pre-Driver-Update" --tags O`. Verify the snapshot appears in `sudo timeshift --list` before proceeding.</p>
<h3>Phase 3: Driver Installation & Pre-Reboot Verification</h3>
<p>Run `sudo ubuntu-drivers install` (or `sudo apt full-upgrade` for routine kernel and package updates). If prompted for a MOK enrollment password, record the one-time password securely. Before rebooting, run `dkms status` to confirm all modules built for the new kernel (`installed` rather than `added` or `broken`), inspect `modinfo` on the newly built `.ko` module to confirm a valid signature, and run `mokutil --list-new` to see if `MokManager` will prompt on reboot.</p>
<h3>Phase 4: Controlled Reboot & Post-Boot Validation</h3>
<p>Issue `sudo systemctl reboot`. If a MOK key was queued, complete the `Enroll MOK` prompt in `MokManager` using your console or out-of-band KVM. After boot, verify `uname -r`, `mokutil --sb-state`, `dkms status`, and `lsmod` from the terminal to confirm every driver loaded cleanly. If any regression occurs, boot into a TTY or Live USB and run `sudo timeshift --restore` to revert cleanly without touching `/home`.</p>
<h2>Frequently Asked Questions (FAQ)</h2>
<h3>Can I run Timeshift completely from the command line without a desktop environment?</h3>
<p>Yes. `timeshift` has a full CLI mode supporting `--create`, `--list`, `--restore`, `--delete`, and `--check`. It works over SSH, in server environments, and inside `Ctrl+Alt+F3` recovery terminals without X11 or Wayland.</p>
<h3>What is the difference between `ubuntu-drivers list` and `ubuntu-drivers devices`?</h3>
<p>`ubuntu-drivers list` prints a concise list of applicable driver package names for your hardware, which is ideal for shell scripting. `ubuntu-drivers devices` prints detailed hardware modalias info, vendor names, and marks which specific package Ubuntu recommends.</p>
<h3>How can I tell from the command line if I will need to enter a MOK password on the next reboot?</h3>
<p>Run `mokutil --list-new`. If it outputs a certificate subject and fingerprint (such as a local DKMS signing key), `MokManager` will prompt you to enroll that key on the next reboot. If it reports that no new keys are queued, the system will boot normally.</p>
<h3>Why did `dkms status` show a module as `added` instead of `installed`?</h3>
<p>A status of `added` means the driver source is registered with DKMS, but it has not been compiled for the target kernel—often because `linux-headers` for that kernel version are missing. Installing `linux-headers-generic` and running `sudo dkms autoinstall` builds and installs the module.</p>
<h3>Does `sudo apt full-upgrade` automatically trigger a Timeshift snapshot?</h3>
<p>Not by default on standard Ubuntu installations. You must either run `sudo timeshift --create` manually before `apt full-upgrade`, or install an APT hook package such as `timeshift-autosnap-apt` to automate pre-upgrade snapshots.</p>
<h3>How do I delete an old Timeshift snapshot from the command line to free disk space?</h3>
<p>Run `sudo timeshift --list` to get the exact snapshot timestamp name (for example, `2026-11-15_08-30-00`), then run `sudo timeshift --delete --snapshot '2026-11-15_08-30-00'`.</p>
<h3>How can I check from the command line whether a specific `.ko` kernel module is signed?</h3>
<p>Run `modinfo <module_name>
| grep -E 'signer|sig_id|sig_key'`. If the module was signed by Canonical or your local DKMS MOK key, `signer` displays the certificate common name; if blank, UEFI Secure Boot will reject the module.
</module_name></p>
<h3>What if `timeshift --create` complains that no snapshot device is configured on a newly installed CLI server?</h3>
<p>Before running `--create` from the command line, either configure `backup_device_uuid` in `/etc/timeshift/timeshift.json` (using the root or backup partition UUID from `blkid`) or pass `--snapshot-device /dev/<partition>
` on your initial setup run.
</partition></p>
<h2>Conclusion</h2>
<p>Managing UEFI Secure Boot, Timeshift snapshots, and Ubuntu drivers from the command line gives administrators fast, scriptable control over system reliability across both local workstations and remote servers. By taking `timeshift --create` checkpoints before updates, auditing `dkms status`, `modinfo`, and `mokutil --list-new` prior to rebooting, and keeping `timeshift --restore` ready for TTY or Live USB recovery, CLI operators maintain rock-solid hardware support without ever needing a GUI.</p>
172.245.58.46
pigleaf04
ผู้เยี่ยมชม
mitchellsander58wyibac@docmailz.com