boot to a mapped device
Subsystems (3)
cover boot to a mapped device
This series is reviving an old patchwork.
Booting from a mapped device requires an initramfs. This series is allows for device-mapper targets to be configured at boot time for use early in the boot process (as the root device or otherwise).
Example, the following could be added in the boot parameters. dm="lroot,,,rw, 0 4096 linear 98:16 0, 4096 4096 linear 98:32 0" root=/dev/dm-0
Enric Balletbo i Serra (1):
dm ioctl: add a device mapper ioctl function.
Will Drewry (1):
init: add support to directly boot to a mapped device
.../admin-guide/kernel-parameters.rst | 1 + .../admin-guide/kernel-parameters.txt | 3 + Documentation/device-mapper/dm-boot.txt | 63 +++ drivers/md/dm-ioctl.c | 50 ++ include/linux/device-mapper.h | 6 + init/Makefile | 1 + init/do_mounts.c | 1 + init/do_mounts.h | 10 + init/do_mounts_dm.c | 475 ++++++++++++++++++ 9 files changed, 610 insertions(+) create mode 100644 Documentation/device-mapper/dm-boot.txt create mode 100644 init/do_mounts_dm.c
Signature · 1 line
2.19.0
PATCH 1/2 dm ioctl: add a device mapper ioctl function.
From: Enric Balletbo i Serra <[email protected]>
Add a dm_ioctl_cmd to issue the equivalent of a DM ioctl call in kernel.
--- drivers/md/dm-ioctl.c | 50 +++++++++++++++++++++++++++++++++++ include/linux/device-mapper.h | 6 +++++ 2 files changed, 56 insertions(+)
drivers/md/dm-ioctl.c +50 -0
@@ -2024,3 +2024,53 @@ int dm_copy_name_and_uuid(struct mapped_device *md, char *name, char *uuid)return r; } + +/** +* dm_ioctl_cmd - Device mapper ioctl's +* @command: ioctl command +* @param: Pointer to device mapped ioctl struct +*/ +int dm_ioctl_cmd (uint command,struct dm_ioctl *param) +{ +int r =0 ; +int ioctl_flags; +unsigned int cmd; +ioctl_fn fn =NULL ; +size_t input_param_size; +struct file *filp =NULL ; + +if (_IOC_TYPE (command) !=DM_IOCTL ) +return -ENOTTY ; + +/* DM_DEV_ARM_POLL is not supported */ +if (command ==DM_DEV_ARM_POLL ) +return -EINVAL ; + + cmd =_IOC_NR (command); + +/* +* Nothing more to do for the version command. +*/ +if (cmd ==DM_VERSION_CMD ) +return 0 ; + + fn =lookup_ioctl (cmd, &ioctl_flags); +if (!fn) { +DMWARN ("dm_ioctl: unknown command 0x%x" , command); +return -ENOTTY ; + } + + input_param_size = param->data_size; + r =validate_params (cmd, param); +if (r) +return r; + + param->data_size =sizeof (*param); + r =fn (filp, param, input_param_size); + +if (unlikely (param->flags &DM_BUFFER_FULL_FLAG ) && +unlikely (ioctl_flags &IOCTL_FLAGS_NO_PARAMS )) +DMERR ("ioctl %d tried to output some data but has IOCTL_FLAGS_NO_PARAMS set" , cmd); + +return r; +}
include/linux/device-mapper.h +6 -0
@@ -12,6 +12,7 @@#include <linux/blkdev.h> #include <linux/math64.h> #include <linux/ratelimit.h> +#include <linux/dm-ioctl.h> struct dm_dev ;struct dm_target ;
@@ -424,6 +425,11 @@ void dm_remap_zone_report(struct dm_target *ti, struct bio *bio, sector_t start);union map_info *dm_get_rq_mapinfo (struct request *rq); +/* +* Device mapper ioctl function. +*/ +int dm_ioctl_cmd (unsigned int command,struct dm_ioctl *param); +struct queue_limits *dm_get_queue_limits (struct mapped_device *md);/*
Signature · 1 line
2.19.0
PATCH 2/2 init: add support to directly boot to a mapped device
In reply to Helen KoikeFrom: Will Drewry <[email protected]>
Add a dm= kernel parameter modeled after the md= parameter from do_mounts_md. It allows for device-mapper targets to be configured at boot time for use early in the boot process (as the root device or otherwise).
--- .../admin-guide/kernel-parameters.rst | 1 + .../admin-guide/kernel-parameters.txt | 3 + Documentation/device-mapper/dm-boot.txt | 63 +++ init/Makefile | 1 + init/do_mounts.c | 1 + init/do_mounts.h | 10 + init/do_mounts_dm.c | 475 ++++++++++++++++++ 7 files changed, 554 insertions(+) create mode 100644 Documentation/device-mapper/dm-boot.txt create mode 100644 init/do_mounts_dm.c
Documentation/admin-guide/kernel-parameters.rst +1 -0
@@ -91,6 +91,7 @@ parameter is applicable:: AX25 Appropriate AX.25 support is enabled. CLK Common clock infrastructure is enabled. CMA Contiguous Memory Area support is enabled. + DM Device mapper support is enabled. DRM Direct Rendering Management support is enabled. DYNAMIC_DEBUG Build in debug messages and enable them at runtime EDD BIOS Enhanced Disk Drive Services (EDD) is enabled
Documentation/admin-guide/kernel-parameters.txt +3 -0
@@ -880,6 +880,9 @@ dis_ucode_ldr [X86] Disable the microcode loader. + dm= [DM] Allows early creation of a device-mapper device. + See Documentation/device-mapper/boot.txt. + dma_debug=off If the kernel is compiled with DMA_API_DEBUG support, this option disables the debugging code at boot.
Documentation/device-mapper/dm-boot.txt new file +63 -0
63 lines not on this page · raw message
init/Makefile +1 -0
@@ -19,6 +19,7 @@ mounts-y := do_mounts.o mounts-$(CONFIG_BLK_DEV_RAM) += do_mounts_rd.o mounts-$(CONFIG_BLK_DEV_INITRD) += do_mounts_initrd.o mounts-$(CONFIG_BLK_DEV_MD) += do_mounts_md.o +mounts-$(CONFIG_BLK_DEV_DM) += do_mounts_dm.o # dependencies on generated files need to be listed explicitly $(obj)/version.o: include/generated/compile.h
init/do_mounts.c +1 -0
@@ -555,6 +555,7 @@ void __init prepare_namespace(void)wait_for_device_probe ();md_run_setup (); +dm_run_setup ();if (saved_root_name[0 ]) { root_device_name = saved_root_name;
init/do_mounts.h +10 -0
@@ -61,3 +61,13 @@ void md_run_setup(void);static inline void md_run_setup (void ) {}#endif + +#ifdef CONFIG_BLK_DEV_DM + +void dm_run_setup (void ); + +#else + +static inline void dm_run_setup (void ) {} + +#endif
init/do_mounts_dm.c new file +475 -0
475 lines not on this page · raw message
Signature · 1 line
2.19.0
Quoted 14 lines · Helen Koike
This series is reviving an old patchwork.
Booting from a mapped device requires an initramfs. This series is allows for device-mapper targets to be configured at boot time for use early in the boot process (as the root device or otherwise).Example, the following could be added in the boot parameters. dm="lroot,,,rw, 0 4096 linear 98:16 0, 4096 4096 linear 98:32 0" root=/dev/dm-0
Enric Balletbo i Serra (1):
dm ioctl: add a device mapper ioctl function.Will Drewry (1):
init: add support to directly boot to a mapped device
Quoted 13 lines
.../admin-guide/kernel-parameters.rst | 1 + .../admin-guide/kernel-parameters.txt | 3 + Documentation/device-mapper/dm-boot.txt | 63 +++ drivers/md/dm-ioctl.c | 50 ++ include/linux/device-mapper.h | 6 + init/Makefile | 1 + init/do_mounts.c | 1 + init/do_mounts.h | 10 + init/do_mounts_dm.c | 475 ++++++++++++++++++ 9 files changed, 610 insertions(+) create mode 100644 Documentation/device-mapper/dm-boot.txt create mode 100644 init/do_mounts_dm.c
Sorry about sending this email multiple times, my git send-email wans't properly configured.
Helen
Helen,
Quoted 5 lines · Helen Koike
This series is reviving an old patchwork.
Booting from a mapped device requires an initramfs. This series is allows for device-mapper targets to be configured at boot time for use early in the boot process (as the root device or otherwise).
What is the reason for this patch series?
Setting up non-trivial root filesystems/storage always requires an initramfs, there is nothing
wrong about this.
Quoted 2 lines
Example, the following could be added in the boot parameters. dm="lroot,,,rw, 0 4096 linear 98:16 0, 4096 4096 linear 98:32 0" root=/dev/dm-0
Hmmm, the new dm= parameter is anything but easy to get right.
Signature · 2 lines
Thanks, //richard
Randy Dunlap
reviewerRe: [PATCH 2/2] init: add support to directly boot to a mapped device
In reply to Helen KoikeQuoted 7 lines · Helen Koike
From: Will Drewry <[email protected]>
Add a dm= kernel parameter modeled after the md= parameter from
do_mounts_md. It allows for device-mapper targets to be configured at boot time for use early in the boot process (as the root device or otherwise).
Quoted 6 lines
Signed-off-by Will Drewry <[email protected]>Signed-off-by Kees Cook <[email protected]>[rework to use dm_ioctl calls]Signed-off-by Enric Balletbo i Serra <[email protected]>[rework to use concise format | rework for upstream]Signed-off-by Helen Koike <[email protected]>
Hi,
A few small comments inline...
Quoted 18 lines
--- .../admin-guide/kernel-parameters.rst | 1 + .../admin-guide/kernel-parameters.txt | 3 + Documentation/device-mapper/dm-boot.txt | 63 +++ init/Makefile | 1 + init/do_mounts.c | 1 + init/do_mounts.h | 10 + init/do_mounts_dm.c | 475 ++++++++++++++++++ 7 files changed, 554 insertions(+) create mode 100644 Documentation/device-mapper/dm-boot.txt create mode 100644 init/do_mounts_dm.cDocumentation/device-mapper/dm-boot.txt new file +0
-0
Documentation/device-mapper/dm-boot.txt line 10
Quoted 10 lines
Documentation/device-mapper/dm-boot.txt new file +10
-0@@ -0,0 +1,63 @@ +Boot time creation of mapped devices +==================================== + +It is possible to configure a device mapper device to act as the root +device for your system in two ways. + +The first is to build an initial ramdisk which boots to a minimal +userspace which configures the device, then pivot_root(8) in to it. + +The second is to possible when the device-mapper and any targets are
parse error: ^^^^^^^^^^^^^^
Documentation/device-mapper/dm-boot.txt line 15
Quoted 5 lines
Documentation/device-mapper/dm-boot.txt new file +5
-0+compiled into the kernel (not a module), one or more device-mappers may +be created and used as the root device at boot time with the parameters +given with the boot line dm=... + +The format is specified as a simple string of data separated by commas and
for some definition of "simple".
Quoted 100 lines
Documentation/device-mapper/dm-boot.txt new file +48
-0+optionally semi-colons, where: + - a comma is used to separate fields like name, uuid, flags and table (specifies + one device) + - a semi-colon is used to separate devices. + +So the format will look like this: + + dm=<name>,<uuid>,<minor>,<flags>,<table>[,<table>+][;<dev_name>,<uuid>,<minor>,<flags>,<table>[,<table>+]] + +Where, + <dev_name> ::= The device name. + <uuid> ::= xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx | "" + <minor> ::= The device minor number. + <flags> ::= "ro" | "rw" + <table> ::= <start> <length> <type> <options> + <type> ::= "verity" | "bootcache" | ... + +The dm line may be as normal when using the dmsetup tool when using the +--concise argument. + +Examples +======== +An example of booting to a linear array made up of user-mode linux block +devices: + + dm="lroot,,,rw, 0 4096 linear 98:16 0, 4096 4096 linear 98:32 0" \ + root=/dev/dm-0 + +This will boot to a rw dm-linear target of 8192 sectors split across two +block devices identified by their major:minor numbers. After boot, udev +will rename this target to /dev/mapper/lroot (depending on the rules). +No uuid was assigned. + +An example of multiple device-mappers, with the dm="..." contents shown +here split on multiple lines for readability: + + vboot,,ro, + 0 1768000 bootcache + aa55b119-2a47-8c45-946a-5ac57765011f+1 + 76e9be054b15884a9fa85973e9cb274c93afadb6 + 1768000 100000 23 20000; + vroot,,ro, + 0 1740800 verity 254:0 254:0 1740800 sha1 + 76e9be054b15884a9fa85973e9cb274c93afadb6 + 5b3549d54d6c7a3837b9b81ed72e49463a64c03680c47835bef94d768e5646fe; + vram,,rw, + 0 32768 linear 1:0 0, + 32768 32768 linear 1:1 0init/do_mounts_dm.c new file +45
-0@@ -0,0 +1,475 @@ +// SPDX-License-Identifier: <SPDX License Expression> + +/* +* do_mounts_dm.c +* Copyright (C) 2017 The Chromium OS Authors <[email protected]> +* Based on do_mounts_md.c +* +* This file is released under the GPLv2. +*/ +#include <linux/async.h> +#include <linux/ctype.h> +#include <linux/device-mapper.h> +#include <linux/fs.h> +#include <linux/string.h> +#include <linux/delay.h> + +#include "do_mounts.h" + +#define DM_MAX_DEVICES 256 +#define DM_MAX_NAME 32 +#define DM_MAX_UUID 129 + +#define DM_MSG_PREFIX "init" + +#define is_even (a) (((a) & 1) == 0) + +/* See Documentation/device-mapper/dm-boot.txt for dm="..." format details. */ + +struct target { +sector_t start; +sector_t length; +char *type; +char *params; +/* simple singly linked list */ +struct target *next; +}; + +struct dm_device { +int minor; +int ro; +char name[DM_MAX_NAME ]; +char uuid[DM_MAX_UUID ]; +struct target *table; +int table_count; +/* simple singly linked list */
init/do_mounts_dm.c line 55
Quoted 10 lines
init/do_mounts_dm.c new file +10
-0+struct dm_device *next; +}; + +static struct { +unsigned long num_devices; +char *str; +} dm_setup_args__initdata ; + +static int dm_early_setup__initdata ; +
// @a: must be a power of 2
init/do_mounts_dm.c line 61
Quoted 6 lines
init/do_mounts_dm.c new file +6
-0+static void __init *_align (void *ptr,unsigned int a) +{ + registerunsigned long agn = --a; + +return (void *) (((unsigned long ) ptr + agn) & ~agn); +}
thanks.
Signature · 1 line
~Randy
Quoted 9 lines · Richard Weinberger
Helen,
Quoted 5 lines · Helen Koike
This series is reviving an old patchwork.
Booting from a mapped device requires an initramfs. This series is allows for device-mapper targets to be configured at boot time for use early in the boot process (as the root device or otherwise).
Quoted 4 lines
What is the reason for this patch series?
Setting up non-trivial root filesystems/storage always requires an initramfs, there is nothing
wrong about this.
Exactly. If phones or whatever would benefit from this patchset then say as much.
I will not accept this patchset at this time.
Quoted 4 lines
Quoted 2 lines
Example, the following could be added in the boot parameters. dm="lroot,,,rw, 0 4096 linear 98:16 0, 4096 4096 linear 98:32 0" root=/dev/dm-0
Hmmm, the new dm= parameter is anything but easy to get right.
No, it isn't.. exposes way too much potential for users hanging themselves.
Quoted 12 lines · Mike Snitzer
Quoted 9 lines · Richard Weinberger
Helen,
Quoted 5 lines · Helen Koike
This series is reviving an old patchwork.
Booting from a mapped device requires an initramfs. This series is allows for device-mapper targets to be configured at boot time for use early in the boot process (as the root device or otherwise).
Quoted 7 lines
Quoted 4 lines
What is the reason for this patch series?
Setting up non-trivial root filesystems/storage always requires an initramfs, there is nothing
wrong about this.Exactly. If phones or whatever would benefit from this patchset then say as much.
I think some of the context for the series was lost in commit logs, but yes, both Android and Chrome OS do not use initramfs. The only thing that was needed to do this was being able to configure dm devices on the kernel command line, so the overhead of a full initramfs was seen as a boot time liability, a boot image size liability (e.g. Chrome OS has a limited amount of storage available for the boot image that is covered by the static root of trust signature), and a complexity risk: everything that is needed for boot could be specified on the kernel command line, so better to avoid the whole initramfs dance.
So, instead, this plumbs the dm commands directly instead of bringing up a full userspace and performing ioctls.
Quoted 9 lines
I will not accept this patchset at this time.
Quoted 4 lines
Quoted 2 lines
Example, the following could be added in the boot parameters. dm="lroot,,,rw, 0 4096 linear 98:16 0, 4096 4096 linear 98:32 0" root=/dev/dm-0
Hmmm, the new dm= parameter is anything but easy to get right.
No, it isn't.. exposes way too much potential for users hanging themselves.
IIRC, the changes in syntax were suggested back when I was trying to drive this series:
https://www.redhat.com/archives/dm-devel/2016-February/msg00199.html
And it matches the "concise" format in dmsetup:
https://sourceware.org/git/?p=lvm2.git;a=commit;h=827be01758ec5adb7b9d5ea75b658092adc65534
What do you feel are next steps?
Thanks!
-Kees
Signature · 2 lines
Kees Cook Pixel Security
Quoted 45 lines · Kees Cook
Quoted 12 lines · Mike Snitzer
Quoted 9 lines · Richard Weinberger
Helen,
Quoted 5 lines · Helen Koike
This series is reviving an old patchwork.
Booting from a mapped device requires an initramfs. This series is allows for device-mapper targets to be configured at boot time for use early in the boot process (as the root device or otherwise).Quoted 7 lines
Quoted 4 lines
What is the reason for this patch series?
Setting up non-trivial root filesystems/storage always requires an initramfs, there is nothing
wrong about this.Exactly. If phones or whatever would benefit from this patchset then say as much.
I think some of the context for the series was lost in commit logs, but yes, both Android and Chrome OS do not use initramfs. The only thing that was needed to do this was being able to configure dm devices on the kernel command line, so the overhead of a full initramfs was seen as a boot time liability, a boot image size liability (e.g. Chrome OS has a limited amount of storage available for the boot image that is covered by the static root of trust signature), and a complexity risk: everything that is needed for boot could be specified on the kernel command line, so better to avoid the whole initramfs dance.
So, instead, this plumbs the dm commands directly instead of bringing up a full userspace and performing ioctls.
Quoted 9 lines
I will not accept this patchset at this time.
Quoted 4 lines
Quoted 2 lines
Example, the following could be added in the boot parameters. dm="lroot,,,rw, 0 4096 linear 98:16 0, 4096 4096 linear 98:32 0" root=/dev/dm-0
Hmmm, the new dm= parameter is anything but easy to get right.
No, it isn't.. exposes way too much potential for users hanging themselves.
Quoted 8 lines
IIRC, the changes in syntax were suggested back when I was trying to drive this series:
https://www.redhat.com/archives/dm-devel/2016-February/msg00199.htmlAnd it matches the "concise" format in dmsetup:
https://sourceware.org/git/?p=lvm2.git;a=commit;h=827be01758ec5adb7b9d5ea75b658092adc65534What do you feel are next steps?
There is quite a lot of init/ code, to handle parsing the concise DM format, that is being proposed for inclusion. I question why that DM-specific code would be located in init/
There also needs to be a careful comparison done between the proposed init/ code to support consise DM format and the userspace lvm2 equivalent (e.g. lvm2.git commit 827be0175)
That aside, the DM targets that are allowed to be supported by this dm= commandline boot interface must be constrained (there are serious risks in allowing activation of certain DM targets without first using userspace tools to check the validity of associated metadata, as is done by the DM thin and cache targets). Also, all targets supported must be upstream. "linear", "verity" and "bootcache" DM targets are referenced in Documentation, "bootcache" must be a Google target. I'm not aware of it.
Mike
Hi all,
Sorry the delay of my reply.
Quoted 35 lines · Mike Snitzer
Quoted 32 lines · Kees Cook
Quoted 12 lines · Mike Snitzer
Quoted 9 lines · Richard Weinberger
Helen,
Quoted 5 lines · Helen Koike
This series is reviving an old patchwork.
Booting from a mapped device requires an initramfs. This series is allows for device-mapper targets to be configured at boot time for use early in the boot process (as the root device or otherwise).Quoted 7 lines
Quoted 4 lines
What is the reason for this patch series?
Setting up non-trivial root filesystems/storage always requires an initramfs, there is nothing
wrong about this.Exactly. If phones or whatever would benefit from this patchset then say as much.
I think some of the context for the series was lost in commit logs, but yes, both Android and Chrome OS do not use initramfs. The only thing that was needed to do this was being able to configure dm devices on the kernel command line, so the overhead of a full initramfs was seen as a boot time liability, a boot image size liability (e.g. Chrome OS has a limited amount of storage available for the boot image that is covered by the static root of trust signature), and a complexity risk: everything that is needed for boot could be specified on the kernel command line, so better to avoid the whole initramfs dance.
Quoted 2 lines
Quoted 2 lines
So, instead, this plumbs the dm commands directly instead of bringing up a full userspace and performing ioctls.
Sorry about the missing context, I should've added the change log and worked a bit more in the cover letter with a more verbose explanation on the reasons for this patch.
Just for reference (I'll describe better the changes in the next version):
v5: https://www.redhat.com/archives/dm-devel/2016-February/msg00112.html
v6: https://www.redhat.com/archives/dm-devel/2017-April/msg00316.html
v7: http://lkml.iu.edu/hypermail/linux/kernel/1705.2/02657.html
v8: https://www.redhat.com/archives/linux-lvm/2017-May/msg00055.html
Quoted 11 lines
Quoted 11 lines
Quoted 10 lines
I will not accept this patchset at this time.
Quoted 4 lines
Quoted 2 lines
Example, the following could be added in the boot parameters. dm="lroot,,,rw, 0 4096 linear 98:16 0, 4096 4096 linear 98:32 0" root=/dev/dm-0
Hmmm, the new dm= parameter is anything but easy to get right.
No, it isn't.. exposes way too much potential for users hanging themselves.
Quoted 6 lines
Quoted 6 lines
IIRC, the changes in syntax were suggested back when I was trying to drive this series:
https://www.redhat.com/archives/dm-devel/2016-February/msg00199.htmlAnd it matches the "concise" format in dmsetup:
https://sourceware.org/git/?p=lvm2.git;a=commit;h=827be01758ec5adb7b9d5ea75b658092adc65534
Exactly, this is the "concise" format from dmsetup, it also makes it easier for users to copy and paste from "dmsetup --concise", which doesn't mean this format is ideal, but imho keeping it consistent with dmsetup is a good thing, please let me know if you have any other ideas.
Quoted 6 lines
Quoted 2 lines
What do you feel are next steps?
There is quite a lot of
init/code, to handle parsing the concise DM format, that is being proposed for inclusion. I question why that DM-specific code would be located ininit/
The main reason was that, taking "md=" and "raid=" as a reference, its command line arguments are parsed in init/do_mounts_md.c, I could move the parsing logic to drivers/md/* but I was wondering if it wouldn't be better to be consistent with init/do_mounts_md.c, what do you think?
Quoted 4 lines
There also needs to be a careful comparison done between the proposed
init/code to support consise DM format and the userspace lvm2 equivalent (e.g. lvm2.git commit827be0175)
Yes, I am taking a deeper look into the lvm2 parsing code, and actually we can use almost the same logic for parsing, which seems better because lvm2 is already using it, we already have some validation/review and it also seems cleaner.
I'll update this in the next version.
Quoted 10 lines
That aside, the DM targets that are allowed to be supported by this dm= commandline boot interface must be constrained (there are serious risks in allowing activation of certain DM targets without first using userspace tools to check the validity of associated metadata, as is done by the DM thin and cache targets). Also, all targets supported must be upstream. "linear", "verity" and "bootcache" DM targets are referenced in Documentation, "bootcache" must be a Google target. I'm not aware of it.
Quoted 2 lines
Mike
I see, I can add this constraint and I'll clean up the documentation for the next version.
Thank you all for your comments and reviews, I am working on the next version of this patch series taking yours comments into consideration and cleaning up several parts of the code and documentation.
Please let me know if you have any other concerns.
Thanks
Helen