]> git.ipfire.org Git - thirdparty/dracut-ng.git/commitdiff
feat: memdisk dracut module
authorJo Zzsi <jozzsicsataban@gmail.com>
Fri, 16 Jan 2026 02:30:16 +0000 (21:30 -0500)
committerNeal Gompa (ニール・ゴンパ) <ngompa13@gmail.com>
Thu, 5 Feb 2026 13:43:04 +0000 (08:43 -0500)
Memdisk ISO emulation with the memdiskfind utility of the
syslinux project.

The hook of the memdisk dracut module is based on
https://salsa.debian.org/live-team/live-boot/-/blob/master/components/3050-memdisk.sh .

.github/labeler.yml
doc_site/modules/ROOT/pages/modules/core.adoc
modules.d/70memdisk/memdisk.sh [new file with mode: 0755]
modules.d/70memdisk/module-setup.sh [new file with mode: 0755]

index ae18ae121882126e944dfcdc66c640210801bd31..d8885d1fcf782e0c934b9daf2c3cda4fcd7f7c06 100644 (file)
@@ -559,6 +559,10 @@ img-lib:
     - changed-files:
           - any-glob-to-any-file: 'modules.d/[0-9][0-9]img-lib/*'
 
+memdisk:
+  - changed-files:
+      - any-glob-to-any-file: 'modules.d/[0-9][0-9]memdisk/*'
+
 memstrack:
     - changed-files:
           - any-glob-to-any-file: 'modules.d/[0-9][0-9]memstrack/*'
index d4785c7bf8291f46554f8dce7fa21c4624631dbf..bd6e729da6851228a5f1b980943e2ce499757e36 100644 (file)
@@ -145,6 +145,10 @@ code, there are no specific types or categories for dracut modules.
 | masterkey that can be used to decrypt other keys and https://repology.org/project/keyutils/[keyutils]
 |
 
+| memdisk
+| memdisk ISO emulation with the memdiskfind utility of the https://repology.org/project/syslinux/[syslinux] project
+| device
+
 | mdraid
 | kernel module for https://docs.kernel.org/driver-api/md/md-cluster.html[md raid cluster], https://repology.org/project/mdadm[mdadm]
 | device
diff --git a/modules.d/70memdisk/memdisk.sh b/modules.d/70memdisk/memdisk.sh
new file mode 100755 (executable)
index 0000000..67884bd
--- /dev/null
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+set -e
+
+if ! [ -x /usr/bin/memdiskfind ]; then
+    exit 0
+fi
+
+if ! dd if=/dev/mem of=/dev/null bs=1 count=1 > /dev/null 2>&1; then
+    # Skip memdiskfind under Secure Boot and other conditions
+    # where /dev/mem is unreadable.
+    # Avoids ugly error message from memdiskfind.
+    printf "access to /dev/mem is restricted, skipping memdisk setup"
+    exit 0
+fi
+
+if ! MEMDISK=$(/usr/bin/memdiskfind); then
+    exit 0
+fi
+
+# We found a memdisk, set up phram
+# Sometimes "modprobe phram" can not successfully create /dev/mtd0.
+# Have to try several times.
+max_try=20
+while [ ! -c /dev/mtd0 ] && [ "$max_try" -gt 0 ]; do
+    modprobe phram "phram=memdisk,${MEMDISK}"
+    sleep 0.2
+    if [ -c /dev/mtd0 ]; then
+        break
+    else
+        rmmod phram
+    fi
+    max_try=$((max_try - 1))
+done
+
+# Load mtdblock, the memdisk will be /dev/mtdblock0
+modprobe mtdblock
diff --git a/modules.d/70memdisk/module-setup.sh b/modules.d/70memdisk/module-setup.sh
new file mode 100755 (executable)
index 0000000..09b98d1
--- /dev/null
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+check() {
+    require_binaries memdiskfind || return 1
+    return 255
+}
+
+installkernel() {
+    hostonly='' instmods \
+        "=drivers/mtd/devices/phram" \
+        "=drivers/mtd/mtdblock"
+}
+
+install() {
+    inst memdiskfind
+    inst_hook cmdline 30 "$moddir/memdisk.sh"
+}