diff --git a/initrd/etc/Makefile b/initrd/etc/Makefile index f811d68cfc1..0b1120aad80 100644 --- a/initrd/etc/Makefile +++ b/initrd/etc/Makefile @@ -1,4 +1,4 @@ -ETC_SCRIPTS= rc rc.lvm2 rcmount_crypt rcmount_tcplay +ETC_SCRIPTS= rc rc.lvm2 rcmount_crypt rcmount_local rcmount_tcplay ETC_FILES= ${.CURDIR}/motd \ ${.CURDIR}/termcap \ ${.CURDIR}/../../etc/group \ diff --git a/initrd/etc/rc b/initrd/etc/rc index 803a2b3b6b0..cda52254f9f 100644 --- a/initrd/etc/rc +++ b/initrd/etc/rc @@ -38,27 +38,23 @@ done echo "Mounting real root partition at $NEW_ROOT ..." -IFS=':' REAL_ROOT=$(sysctl -n vfs.real_root) if [ $? -ne 0 ]; then - echo "ERROR: vfs.real_root sysctl no exist. The kernel is too old." + echo "ERROR: vfs.real_root sysctl not exist. The kernel is too old." rescue_shell fi if [ -z "${REAL_ROOT}" ]; then echo "ERROR: vfs.real_root sysctl not set." rescue_shell fi + +echo "Real root: $REAL_ROOT" +IFS=':' set -- $REAL_ROOT unset IFS TYPE=$1 -if [ "$TYPE" = "local" ]; then - FSTYPE=$2 - MOUNTFROM="/dev/${3#/dev/}" - echo "Executing: mount -t $FSTYPE $4 $MOUNTFROM $NEW_ROOT" - mount -o ro -t $FSTYPE $4 $MOUNTFROM $NEW_ROOT || - rescue_shell -elif [ -x "/etc/rcmount_${TYPE}" ]; then +if [ -x "/etc/rcmount_${TYPE}" ]; then . /etc/rcmount_${TYPE} "$@" || rescue_shell else @@ -75,5 +71,4 @@ cd / umount /var echo "Mounting devfs on real root ..." -#mount_devfs $NEW_ROOT/dev mount_null /dev $NEW_ROOT/dev diff --git a/initrd/etc/rcmount_crypt b/initrd/etc/rcmount_crypt index 4454fc3410a..340f60d35bd 100644 --- a/initrd/etc/rcmount_crypt +++ b/initrd/etc/rcmount_crypt @@ -1,10 +1,29 @@ #!/bin/sh FSTYPE=$2 -MOUNTFROM="/dev/${3#/dev/}" +DEVICE="/dev/${3#/dev/}" VOLUME=$4 OPTIONS=$5 -cryptsetup isLuks $MOUNTFROM || return 1 -cryptsetup $OPTIONS luksOpen $MOUNTFROM $VOLUME || return 2 -mount -o ro -t $FSTYPE /dev/mapper/$VOLUME $NEW_ROOT || return 3 +# Handle the PFS label of a HAMMER/HAMMER2 filesystem. +LABEL= +case $DEVICE in +*@*) + LABEL="@${DEVICE#*@}" + DEVICE=${DEVICE%@*} + ;; +esac +MOUNTFROM="/dev/mapper/${VOLUME}${LABEL}" + +cryptsetup isLuks $DEVICE || { + echo "ERROR: not a LUKS device: $DEVICE" + return 1 +} +cryptsetup $OPTIONS luksOpen $DEVICE $VOLUME || { + echo "ERROR: failed to open LUKS device: $DEVICE" + return 2 +} +mount -o ro -t $FSTYPE $MOUNTFROM $NEW_ROOT || { + echo "ERROR: failed to mount $FSTYPE from $MOUNTFROM" + return 3 +} diff --git a/initrd/etc/rcmount_local b/initrd/etc/rcmount_local new file mode 100644 index 00000000000..29d518d8154 --- /dev/null +++ b/initrd/etc/rcmount_local @@ -0,0 +1,10 @@ +#!/bin/sh + +FSTYPE=$2 +MOUNTFROM="/dev/${3#/dev/}" +OPTIONS=$4 + +mount -o ro -t $FSTYPE $OPTIONS $MOUNTFROM $NEW_ROOT || { + echo "ERROR: failed to mount $FSTYPE from $MOUNTFROM" + return 3 +} diff --git a/initrd/etc/rcmount_tcplay b/initrd/etc/rcmount_tcplay index 03bb5736efa..fd6ad54b644 100644 --- a/initrd/etc/rcmount_tcplay +++ b/initrd/etc/rcmount_tcplay @@ -1,9 +1,25 @@ #!/bin/sh FSTYPE=$2 -MOUNTFROM="/dev/${3#/dev/}" +DEVICE="/dev/${3#/dev/}" VOLUME=$4 OPTIONS=$5 -tcplay -m $VOLUME -d $MOUNTFROM $OPTIONS || return 2 -mount -o ro -t $FSTYPE /dev/mapper/$VOLUME $NEW_ROOT || return 3 +# Handle the PFS label of a HAMMER/HAMMER2 filesystem. +LABEL= +case $DEVICE in +*@*) + LABEL="@${DEVICE#*@}" + DEVICE=${DEVICE%@*} + ;; +esac +MOUNTFROM="/dev/mapper/${VOLUME}${LABEL}" + +tcplay -m $VOLUME -d $DEVICE $OPTIONS || { + echo "ERROR: failed to open tcplay device: $DEVICE" + return 2 +} +mount -o ro -t $FSTYPE $MOUNTFROM $NEW_ROOT || { + echo "ERROR: failed to mount $FSTYPE from $MOUNTFROM" + return 3 +} diff --git a/share/man/man7/initrd.7 b/share/man/man7/initrd.7 index 3dcd56a6227..c8e5d9357e7 100644 --- a/share/man/man7/initrd.7 +++ b/share/man/man7/initrd.7 @@ -1,5 +1,5 @@ .\" -.\" Copyright (c) 2018 +.\" Copyright (c) 2018,2026 .\" The DragonFly Project. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -29,7 +29,7 @@ .\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd June 2, 2018 +.Dd June 16, 2026 .Dt INITRD 7 .Os .Sh NAME @@ -98,39 +98,54 @@ Its general syntax is: vfs.root.realroot=":[arg1[:arg2[:...]]]" .Ed .Pp -Currently, the supported types of real root partition are: -.Pa local , -.Pa crypt , +The supported types of real root partition are: +.Cm local , +.Cm crypt , and -.Pa tcplay . +.Cm tcplay . The -.Pa local +.Cm local type allows to mount any local filesystem that does not require any special setup apart from the initial discovery and calling the .Xr mount 8 program. The general format is as follows: .Bd -literal -offset indent -vfs.root.realroot="local::[:]" +vfs.root.realroot="local::[@LABEL][:]" .Ed .Pp +where the +.Ar @LABEL +option may be used to specify the PFS label of a HAMMER/HAMMER2 filesystem, +and the +.Ar OPTIONS +specifies the extra options for +.Xr mount 8 . +.Pp The -.Pa crypt +.Cm crypt and -.Pa tcplay +.Cm tcplay types allow to mount volumes supported by .Xr cryptsetup 8 and .Xr tcplay 8 , respectively. The device will be set up after asking the user for the key, -and this volume will then be mounted as the root. +and then be mounted as the root. The general formats are as follows: .Bd -literal -offset indent -vfs.root.realroot="crypt:::[:]" +vfs.root.realroot="crypt::[@LABEL]:[:]" -vfs.root.realroot="tcplay:::[:]" +vfs.root.realroot="tcplay::[@LABEL]:[:]" .Ed +.Pp +where the +.Ar MAPPING-NAME +specifies the device name to be created under +.Pa /dev/mapper/ , +which may be further used in +.Pa /etc/fstab . .Sh FILES .Bl -tag -width "/boot/kernel/initrd.img.gz" .It Pa /boot/kernel/initrd.img.gz @@ -139,14 +154,19 @@ Location of the compressed image. .El .Sh EXAMPLES -.Bd -literal -offset indent +.Bd -literal vfs.root.realroot="local:ufs:/dev/vg00/lv0[:OPTIONS]" vfs.root.realroot="crypt:ufs:/dev/ad0s0a:secvolume[:OPTIONS]" vfs.root.realroot="crypt:hammer2:/dev/serno/XXXXXX.s1d:root[:OPTIONS]" + +vfs.root.realroot="crypt:hammer2:/dev/serno/XXXXXX.s3@ROOT:root[:OPTIONS]" + +vfs.root.realroot="crypt:hammer2:/dev/serno/XXXXXX.s3@ROOT.20260616:root[:OPTIONS]" .Ed .Sh SEE ALSO +.Xr kenv 1 , .Xr md 4 , .Xr loader.conf 5 , .Xr build 7 ,