[NetBSD Developer Wiki]
- view: text
- select for diffs
Wed Jun 22 07:40:39 2016 UTC
(6 years, 9 months ago) by leot
CVS tags: HEAD
Improve a bit the formatting (no functional changes intended)
- Fix a reference to the current-users@ email and point to mail-index.NetBSD.org
(instead of Gmane)
- Use [[!template id=man]] for man pages
- Use [[!template id=filecontent]] for file contents (boot.cfg)
- Use [[!template id=programlisting]] for typescript of terminal sessions
Root filesystem encryption
It is possible to run NetBSD with [complete root filesystem encryption], thanks to the `cgdroot.kmod` kernel module. It really is a memory disk (also knows as RAM disk) that is expected to be loaded in the kernel while booting.
It still requires one unencrypted partition to boot from (typically `wd0a`).
The boot process
Instead of booting normally the GENERIC kernel and using the root filesystem, a
kernel module is loaded at boot-time containing a memory disk. It contains a
minimal filesystem image, which is then considered the actual root filesystem:
The boot partition on disk only needs to contain:
* [[!template id=man name="boot" section="8"]], the second-stage bootloader
* [[!template id=man name="boot.cfg" section="5"]], the configuration file for the bootloader (optional)
* a GENERIC kernel
* the `cgdroot.kmod` kernel module
* configuration and encryption key for the encrypted volume to start from (`cgd.conf`)
Once loaded the memory disk mounts the `wd0a` partition onto `/etc/cgd`, and asks for the encryption passphrase as usual (with [[!template id=man name="cgdconfig" section="8"]]). If successful, the `cgd0a` volume configured is mounted on `/altroot`, and [[!template id=man name="init" section="8"]] is told via [[!template id=man name="sysctl" section="7"]] to chroot into this volume before actually booting. The system then starts normally.
In practice the memory disk remains the real root, and the regular system is
really ran from a chroot in `/altroot`.
Obtaining the kernel module
The `cgdroot.kmod` kernel module is part of the regular NetBSD releases since NetBSD 7.0. It can be found in the `<arch>/installation/miniroot` folder from the release. For instance, for the amd64 architecture on the German mirror for the 7.0.1 release, download it at (ftp://ftp.de.netbsd.org/pub/NetBSD/NetBSD-7.0.1/amd64/installation/miniroot/cgdroot.kmod).
Configuring the kernel module
The kernel module needs to be available in the boot partition, alongside the desired kernel. The bootloader configuration in `/boot.cfg` should be modified to load the module, as in this example:
[[!template id=filecontent name="/boot.cfg" text="""
menu=Boot normally:rndseed /etc/entropy-file;load /cgdroot.kmod;boot /netbsd.gz -z
Building the kernel module
The kernel module can be compiled in two steps from within the source tree for the NetBSD base system, once the distribution has been built. Change to the `distrib/<arch>/ramdisks/ramdisk-cgdroot` and use `nbmake-<arch>` to build:
[[!template id=programlisting text="""
Calculated size of `ramdisk-cgdroot.fs.tmp': 5120000 bytes, 85 inodes
Extent size set to 4096
ramdisk-cgdroot.fs.tmp: 4.9MB (10000 sectors) block size 4096, fragment size 512
using 1 cylinder groups of 4.88MB, 1250 blks, 96 inodes.
super-block backups (for fsck -b #) at:
Image `ramdisk-cgdroot.fs.tmp' complete
Then the kernel module can be built:
[[!template id=programlisting text="""
The biggest (known) issue with this setup occurs when firmware needs to be loaded early in the boot process (such as graphics drivers for the console). At the moment they need to be built as part of the memory disk. Some network interfaces, of which some wireless devices in particular, also require loading firmware to work properly.
This setup is not entirely safe against physical attacks. An attacker can modify the boot process to store the passphrase for later retrieval, or insert a backdoor while booting.
: https://mail-index.netbsd.org/current-users/2013/03/21/msg022311.html "Full Disk Encryption with cgd (well, almost)"
CVSweb for NetBSD wikisrc <wikimaster@NetBSD.org> software: FreeBSD-CVSweb