공지사항

UEFI Secure Boot, Timeshift Snapshots, and Driver Setup: Update Ubuntu…

페이지 정보

profile_image
작성자 Laurene
댓글 0건 조회 2회 작성일 26-11-23 02:52

본문

# UEFI Secure Boot, Timeshift Snapshots, and Driver Setup: Update Ubuntu Command Line Focus (33)

600## Executive Summary (BLUF)

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.

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.

## Command-Line Control of Secure Boot, Snapshots, and Drivers

Administrators who apt update vs apt upgrade 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.

Fortunately, Ubuntu exposes the entire hardware and rollback lifecycle through deterministic CLI utilities:

1. **Timeshift CLI (`timeshift`)**: 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. **Driver CLI (`ubuntu-drivers`)**: 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. **MOK & DKMS CLI (`mokutil`, `dkms`)**: `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 | grep sig` lets you inspect the exact cryptographic signature embedded inside any `.ko` file on disk.

Combining these three CLI toolsets turns routine Ubuntu updates into a reversible, auditable terminal workflow.

## Strategic Frameworks and Architectural Breakdown

A CLI-driven update and hardware maintenance workflow inserts snapshot and Secure Boot verification gates directly around `apt` and `ubuntu-drivers` commands.

```text
+-------------------------------------------------------------------+
| COMMAND-LINE UPDATE, SNAPSHOT & DRIVER WORKFLOW |
+-------------------------------------------------------------------+
[ 1. Pre-Flight Check ] ---> mokutil --sb-state
| timeshift --list (Verify disk space)
v
[ 2. CLI Checkpoint ] ---> 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)
```

This CLI sequence enforces four operational guarantees:

1. **Zero-GUI Dependency**: Every diagnostic and remediation command runs cleanly inside `tmux`, SSH, or a `Ctrl+Alt+F3` text console.
2. **Atomic Pre-Upgrade Checkpoints**: 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. **Pending MOK Detection**: 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. **Automated Post-Build Audit**: Running `dkms status` before rebooting catches missing `linux-headers` or failed module builds while the old working kernel is still running.

## Comparative Matrix: Legacy Execution vs Modern Practice

Command-line system maintenance on Ubuntu has progressed from blind `apt-get` runs to snapshot-protected, Secure-Boot-aware terminal pipelines.

| CLI Maintenance Task | Legacy Execution (Unprotected `apt-get` & GUI Tools) | Modern Practice (CLI Timeshift + `mokutil` + `dkms`) | Operational Advantage |
|---|---|---|---|
| **Pre-Update Backup** | Skipping backups or running `tar` manually | `sudo timeshift --create --comments "Pre-Upgrade"` | Instant, repeatable OS checkpoints in one command |
| **Driver Discovery** | Opening GUI "Additional Drivers" tab | `ubuntu-drivers devices` and `ubuntu-drivers list` | Works over SSH, recovery shells, and automated scripts |
| **Secure Boot Check** | Rebooting and hoping third-party modules load | `mokutil --sb-state` and `mokutil --list-new` | Detects queued MOK enrollments before rebooting |
| **Module Build Audit** | Discovering broken drivers after rebooting | `dkms status` checked prior to `systemctl reboot` | Catches failed kernel module builds while system is still up |
| **Broken-Boot Recovery** | Reinstalling Ubuntu or chrooting manually | `sudo timeshift --restore --snapshot ` | Restores working kernel and `/etc` state cleanly from TTY |
| **Kernel Rollback** | Manually uninstalling `linux-image-*` via `dpkg` | GRUB fallback boot + `timeshift --restore` | Reverts both kernel and matching `initramfs`/driver state |

## Governance, Best Practices, and Compliance Controls

Standardizing CLI-based snapshot and driver workflows requires clear guardrails around storage, key management, and remote console access.

**Remote MOK Enrollment Planning**
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`.

**Scripted `timeshift` Retention Policies**
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.

**Verifying `linux-headers` Before Kernel Transitions**
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.

**Avoiding Partial Driver States**
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`.

## Implementation Roadmap

Adopt this four-phase CLI workflow for Secure Boot, Timeshift, and driver management on Ubuntu.

### Phase 1: CLI Tooling & Baseline Audit
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`.

### Phase 2: Pre-Change Snapshot Creation
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.

### Phase 3: Driver Installation & Pre-Reboot Verification
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.

### Phase 4: Controlled Reboot & Post-Boot Validation
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`.

## Frequently Asked Questions (FAQ)

### Can I run Timeshift completely from the command line without a desktop environment?
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.

### What is the difference between `ubuntu-drivers list` and `ubuntu-drivers devices`?
`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.

### How can I tell from the command line if I will need to enter a MOK password on the next reboot?
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.

### Why did `dkms status` show a module as `added` instead of `installed`?
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.

### Does `sudo apt full-upgrade` automatically trigger a Timeshift snapshot?
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.

### How do I delete an old Timeshift snapshot from the command line to free disk space?
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'`.

### How can I check from the command line whether a specific `.ko` kernel module is signed?
Run `modinfo | 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.

### What if `timeshift --create` complains that no snapshot device is configured on a newly installed CLI server?
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/` on your initial setup run.

## Conclusion

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.

댓글목록

등록된 댓글이 없습니다.

회원로그인

회원가입