beefadvice64

beefadvice64

ผู้เยี่ยมชม

  UEFI Secure Boot, Timeshift Snapshots, and Driver Setup: Ubuntu Blog Focus (31) (2 อ่าน)

22 พ.ย. 2569 21:34

<h2>Executive Summary (BLUF)</h2>

<p>Establishing reliable hardware support on Ubuntu requires sequencing three interdependent operations after installation: configuring Timeshift system snapshots as a rollback safety net, installing proprietary or DKMS-built drivers via `ubuntu-drivers`, and enrolling Machine Owner Keys (MOK) so UEFI Secure Boot permits third-party kernel modules to load. Skipping snapshots before driver installation leaves no clean recovery path if a graphics or Wi-Fi module fails to initialize, while ignoring MOK enrollment results in silent module rejection (`Required key not available`) at boot.</p>

<p>The recommended workflow takes a baseline Timeshift snapshot (Btrfs or RSYNC) before touching kernel modules, stages proprietary drivers through `ubuntu-drivers install`, completes the blue-screen `mokutil` password verification during reboot, and validates `dkms status` alongside `mokutil --sb-state` once the graphical session loads.</p>

<h2>Chain of Trust, DKMS Signing, and Snapshot Isolation</h2>

<p>UEFI Secure Boot enforces cryptographic verification from firmware through the shim bootloader, GRUB, the Linux kernel, and every loadable kernel module (`.ko`). Canonical signs Ubuntu's stock kernel images and in-tree modules with its own keys, which are trusted automatically by the `shimx64.efi` binary. However, proprietary GPU drivers, out-of-tree Wi-Fi adapters, and VirtualBox or ZFS DKMS modules are compiled locally on the host machine—meaning they lack Canonical's signature.</p>

<p>When you learn more about Ubuntu hardware provisioning, a recurring failure mode is installing DKMS drivers on a Secure Boot system without completing MOK enrollment. During `ubuntu-drivers install`, `dkms` generates a local X.509 signing key pair under `/var/lib/shim-signed/mok/` and queues the public certificate for enrollment via `mokutil --import`. On the next reboot, `MokManager` (`mmx64.efi`) intercepts the boot sequence before GRUB loads Linux, prompting the user to confirm the enrollment using the one-time password set during installation.</p>

<p>Because driver updates modify `initramfs`, Xorg/Wayland configurations, and kernel module trees simultaneously, pairing driver changes with <strong>Timeshift</strong> provides deterministic rollback. Timeshift captures the root filesystem (`/` excluding `/home` by default) using either instantaneous Btrfs subvolume snapshots (`@` and `@home` layout) or hard-linked RSYNC copies. If a newly compiled Nvidia or Broadcom module causes a black screen or kernel panic, booting from a live USB or GRUB entry and restoring the pre-driver Timeshift snapshot returns `/etc`, `/usr`, and `/lib/modules` to their exact working state in minutes.</p>

<h2>Strategic Frameworks and Architectural Breakdown</h2>

<p>A resilient post-install hardware pipeline sequences snapshot creation, driver compilation, and Secure Boot key enrollment in a strict order of operations.</p>

<pre>+-------------------------------------------------------------------+
| POST-INSTALL HARDWARE &amp; ROLLBACK PIPELINE (UBUNTU) |
+-------------------------------------------------------------------+
[ 1. Baseline Timeshift ] --&gt; Snapshot "/" before driver changes
| (Btrfs @/@home or RSYNC)
v
[ 2. Driver &amp; DKMS Build ] -&gt; ubuntu-drivers install
| Signs .ko with /var/lib/shim-signed/mok
v
[ 3. MOK Enrollment Queue ]-&gt; mokutil --import MOK.der (one-time pass)
|
v
[ 4. Reboot &amp; MokManager ] -&gt; UEFI Firmware -&gt; shimx64.efi -&gt; mmx64.efi
| User enters one-time password -&gt; Key enrolled
v
[ 5. Kernel Module Load ] --&gt; Linux boots -&gt; Signed DKMS module loads
Verify: mokutil --sb-state &amp; dkms status</pre>

<p>Each stage eliminates a specific failure class:</p>

<p>1. <strong>Pre-Change Snapshot Boundary</strong>: Creating a tagged Timeshift snapshot (`Pre-Driver-Setup`) before running `apt` or `ubuntu-drivers` guarantees a clean rollback point that does not overwrite personal files in `/home`. 2. <strong>Managed Driver Selection</strong>: Using `ubuntu-drivers devices` and `sudo ubuntu-drivers install` pulls tested, meta-packaged driver builds from Ubuntu's `restricted` pocket rather than downloading upstream `.run` installers that bypass `dpkg` and break on every kernel update. 3. <strong>Cryptographic Key Registration</strong>: Allowing `dkms` or `mokutil` to register the local signing certificate in UEFI NVRAM keeps Secure Boot enabled—preserving firmware integrity—without forcing users to disable Secure Boot in BIOS. 4. <strong>Post-Boot Verification</strong>: Confirming `lsmod` shows the loaded driver and `mokutil --test-key` reports the MOK key as enrolled ensures future `unattended-upgrades` kernel bumps will auto-sign new DKMS modules seamlessly.</p>

<h2>Comparative Matrix: Legacy Execution vs Modern Practice</h2>

<p>Hardware enablement on Ubuntu has shifted from disabling firmware security and running manual vendor scripts to signed, snapshot-backed workflows.</p>

<table>
<tbody>
<tr>
<th>Provisioning Dimension</th>
<th>Legacy Execution (Disable Secure Boot &amp; `.run` Scripts)</th>
<th>Modern Practice (MOK-Signed DKMS &amp; Timeshift)</th>
<th>Hardware &amp; Security Outcome</th>
</tr>
<tr>
<td><strong>Secure Boot Handling</strong></td>
<td>Disabling Secure Boot in UEFI BIOS to load drivers</td>
<td>Enrolling local MOK via `mokutil` and `mmx64.efi`</td>
<td>Maintains full UEFI boot-chain integrity while loading custom drivers</td>
</tr>
<tr>
<td><strong>Driver Installation</strong></td>
<td>Downloading raw `.run` blobs from vendor websites</td>
<td>`ubuntu-drivers install` from `restricted` APT pocket</td>
<td>Integrates with `dkms` so kernel updates rebuild modules automatically</td>
</tr>
<tr>
<td><strong>Rollback Strategy</strong></td>
<td>Manual `apt purge` from a broken TTY or full OS reinstall</td>
<td>Pre-driver Timeshift snapshot (Btrfs or RSYNC)</td>
<td>Restores working kernel, `initramfs`, and display configs in minutes</td>
</tr>
<tr>
<td><strong>Signing Automation</strong></td>
<td>Re-signing `.ko` files manually after each kernel bump</td>
<td>Automatic signing via `/var/lib/shim-signed/mok/MOK.priv`</td>
<td>Eliminates `modprobe: ERROR: Required key not available` after updates</td>
</tr>
<tr>
<td><strong>User Data Safety</strong></td>
<td>Risking `/home` edits while troubleshooting broken X11</td>
<td>Timeshift isolating OS root (`/`) from `/home` user data</td>
<td>Preserves documents and dotfiles during system rollbacks</td>
</tr>
<tr>
<td><strong>Verification</strong></td>
<td>Guessing driver state from screen resolution</td>
<td>Checking `dkms status`, `mokutil --sb-state`, and `nvidia-smi`</td>
<td>Provides deterministic proof of driver and Secure Boot health</td>
</tr>
</tbody>
</table>

<h2>Governance, Best Practices, and Compliance Controls</h2>

<p>Managing Secure Boot keys, snapshots, and kernel drivers across workstations requires clear operational controls.</p>

<p><strong>Never Mix Upstream `.run` Installers with APT Driver Packages</strong> Running a vendor `.run` installer outside `dpkg` overwrites Mesa/GLVND symlinks and bypasses Ubuntu's `linux-headers` triggers. When a routine kernel security update arrives, the system boots into a fallback framebuffer or black screen. Always enforce `ubuntu-drivers` or signed Debian packages from official repositories.</p>

<p><strong>Timeshift Storage Quotas and Exclusions</strong> For RSYNC-based Timeshift setups, storing snapshots on the same partition as `/` consumes root space rapidly; administrators should direct RSYNC snapshots to a dedicated secondary partition or external drive when possible, and limit retention (for example, 3 daily and 2 boot snapshots). For Btrfs setups, keep `/home` excluded from OS rollback snapshots so rolling back a bad driver never reverts recent user work.</p>

<p><strong>MOK Password Hygiene and Key Rotation</strong> The one-time password entered during `mokutil --import` is used solely by `MokManager` at the next reboot and is not stored as a persistent login credential. However, if the private signing key in `/var/lib/shim-signed/mok/MOK.priv` is ever compromised or deleted, administrators must revoke the old key with `mokutil --delete` and re-enroll a fresh key pair.</p>

<p><strong>UEFI Firmware Update Awareness</strong> Major BIOS/UEFI firmware updates (via `fwupdmgr`) occasionally reset UEFI NVRAM variables or clear custom MOK entries on certain laptop models. Documenting a post-BIOS-update check (`mokutil --list-enrolled`) ensures drivers do not silently stop loading after a firmware flash.</p>

<h2>Implementation Roadmap</h2>

<p>Follow this four-phase sequence to configure Timeshift, Secure Boot MOK enrollment, and hardware drivers on a newly provisioned Ubuntu system.</p>

<h3>Phase 1: UEFI State and Snapshot Baseline</h3>

<p>Boot into Ubuntu and verify UEFI Secure Boot status by running `mokutil --sb-state` and `ls /sys/firmware/efi`. Install Timeshift (`sudo apt install timeshift`), select Btrfs (if using `@` and `@home` subvolumes) or RSYNC mode, exclude `/home` directories from snapshot scope, and trigger an initial baseline snapshot labeled `Baseline-Clean-Install` before modifying any drivers.</p>

<h3>Phase 2: Hardware Discovery and Managed Driver Staging</h3>

<p>Run `ubuntu-drivers devices` to inspect detected GPUs, Wi-Fi chipsets, and recommended meta-packages. Ensure `linux-headers-generic` and `dkms` are installed so kernel modules compile cleanly across HWE and security kernel transitions. Ubuntu Linux Blog `sudo ubuntu-drivers install` (or `sudo apt install` for the specific recommended driver package) and set a clear, simple one-time MOK enrollment password when prompted by `debconf`. Verify in `/var/log/apt/term.log` that `dkms` compiled the `.ko` files and signed them with `/var/lib/shim-signed/mok/MOK.priv` before proceeding to reboot.</p>

<h3>Phase 3: MOK Enrollment During Reboot</h3>

<p>Reboot the system cleanly (`sudo systemctl reboot`). When the blue `Shim UEFI key management` (`MokManager`) screen appears before GRUB, select <strong>Enroll MOK</strong>, choose <strong>Continue</strong>, confirm <strong>Yes</strong>, enter the exact one-time password configured in Phase 2, and select <strong>Reboot</strong>. Do not skip this step; pressing "Continue boot" without enrolling leaves third-party kernel modules blocked by Secure Boot.</p>

<h3>Phase 4: Post-Enrollment Verification and Snapshot Tagging</h3>

<p>Once logged back into Ubuntu, run `mokutil --sb-state` (confirming `SecureBoot enabled`), `dkms status` (confirming `installed` for the current kernel), and `lsmod` to verify the driver module is active. Take a second Timeshift snapshot labeled `Post-Driver-Verified` so future kernel or desktop updates have a known-good driver baseline to fall back to.</p>

<h2>Frequently Asked Questions (FAQ)</h2>

<h3>What happens if I miss the blue MokManager screen during reboot?</h3>

<p>If you accidentally press "Continue boot" or let the timeout expire, Secure Boot remains enabled and your newly installed third-party driver will fail to load (`Required key not available`). You can re-queue the enrollment prompt at any time by running `sudo mokutil --import /var/lib/shim-signed/mok/MOK.der`, entering a new one-time password, and rebooting again.</p>

<h3>Should I just disable Secure Boot in BIOS instead of enrolling a MOK key?</h3>

<p>Disabling Secure Boot removes firmware-level protection against unsigned bootloaders and rootkits. Enrolling Ubuntu's local MOK key takes less than 60 seconds during a single reboot and lets you keep full Secure Boot protection active while running proprietary Nvidia or Wi-Fi drivers.</p>

<h3>Will Timeshift roll back my personal files in `/home` if a driver update breaks my system?</h3>

<p>By default, Timeshift excludes `/home` user directories so system rollbacks only revert OS files (`/etc`, `/usr`, `/lib`, `/var`). Always verify in Timeshift's Filter settings that `/home` is excluded before restoring a snapshot.</p>

<h3>Why did my Nvidia or Wi-Fi driver stop working after a routine kernel update?</h3>

<p>This usually occurs for one of two reasons: either `linux-headers-generic` was missing so DKMS could not compile the module for the new kernel, or the module was installed via a manual `.run` script rather than `ubuntu-drivers`. Checking `dkms status` reveals whether the module built for the new kernel version.</p>

<h3>Can I use Timeshift with ext4, or does it require Btrfs?</h3>

<p>Timeshift supports both. On ext4 partitions, Timeshift uses RSYNC with hard links to deduplicate unchanged files across snapshots. On Btrfs partitions using Ubuntu's `@` and `@home` subvolume layout, Timeshift creates near-instantaneous copy-on-write subvolume snapshots.</p>

<h3>How do I restore a Timeshift snapshot if a bad driver prevents Ubuntu from reaching the login screen?</h3>

<p>If you cannot reach the graphical desktop, press `Ctrl+Alt+F3` to switch to a text TTY, log in, and run `sudo timeshift --restore`. If the system fails to boot entirely, boot from an Ubuntu Live USB, install Timeshift in the live environment, point it to your system disk, and restore the pre-driver snapshot.</p>

<h3>How can I verify which MOK certificates are currently enrolled in my UEFI firmware?</h3>

<p>Run `mokutil --list-enrolled` from a terminal. It prints the X.509 subject (typically containing your hostname and "DKMS module signing key"), validity dates, and SHA-1 fingerprint for every key registered in UEFI NVRAM. Comparing this fingerprint against `openssl x509 -in /var/lib/shim-signed/mok/MOK.der -inform DER -noout -fingerprint` confirms your local DKMS key matches what firmware trusts.</p>

<h2>Conclusion</h2>

<p>Combining Timeshift snapshots, `ubuntu-drivers` package management, and MOK enrollment transforms Ubuntu post-install hardware setup from a brittle trial-and-error exercise into a repeatable engineering workflow. By snapshotting before Ubuntu-Blog.com , signing DKMS modules for UEFI Secure Boot, and verifying `dkms status` after reboot, users achieve reliable hardware acceleration without sacrificing boot-chain security or system recoverability.</p>

beefadvice64

beefadvice64

ผู้เยี่ยมชม

ตอบกระทู้
เว็บไซต์นี้มีการใช้งานคุกกี้ เพื่อเพิ่มประสิทธิภาพและประสบการณ์ที่ดีในการใช้งานเว็บไซต์ของท่าน ท่านสามารถอ่านรายละเอียดเพิ่มเติมได้ที่ นโยบายความเป็นส่วนตัว  และ  นโยบายคุกกี้