From 36e9a14134fdcfe37997d81ea5ea5cfb5dba67d2 Mon Sep 17 00:00:00 2001 From: Stefan Seyfried Date: Wed, 13 Mar 2019 16:59:41 +0100 Subject: [PATCH] add rd.kiwi.oem.maxdisk= boot parameter this limits the disks considered for oem deployment to a given size --- doc/source/overview/workflow.rst | 10 ++++++++++ dracut/modules.d/90kiwi-dump/kiwi-dump-image.sh | 15 +++++++++++++++ dracut/modules.d/99kiwi-lib/kiwi-lib.sh | 17 +++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/doc/source/overview/workflow.rst b/doc/source/overview/workflow.rst index c5d0dddc..6d068604 100644 --- a/doc/source/overview/workflow.rst +++ b/doc/source/overview/workflow.rst @@ -875,6 +875,16 @@ the available kernel boot parameters for this modules: Note that options starting with `rd.kiwi` are not passed on to avoid side effects. +``rd.kiwi.oem.maxdisk=size[KMGT]`` + This variable configures the maximum disk size an unattended oem + installation should consider for image deployment. Unattended oem + deployments default to deploying on /dev/sda (more exactly, the first + device not filtered out by `oem-device-filter`). With RAID + controllers, it can happen that your buch of big JBOD disks is for + example `/dev/sda` to `/dev/sdi` and the 480G RAID1 configured for + OS deployment is `/dev/sdj`. With `rd.kiwi.oem.maxdisk=500G` the + deployment will land on that RAID disk. + ``rd.live.overlay.persistent`` This variable tells a live iso image to prepare a persistent write partition. diff --git a/dracut/modules.d/90kiwi-dump/kiwi-dump-image.sh b/dracut/modules.d/90kiwi-dump/kiwi-dump-image.sh index 390e8c7c..1e127ad3 100755 --- a/dracut/modules.d/90kiwi-dump/kiwi-dump-image.sh +++ b/dracut/modules.d/90kiwi-dump/kiwi-dump-image.sh @@ -45,10 +45,17 @@ function get_disk_list { local disk_device_by_id local disk_meta local list_items + local max_disk + local kiwi_oem_maxdisk local blk_opts="-p -n -r -o NAME,SIZE,TYPE" if [ -n "${kiwi_devicepersistency}" ];then disk_id=${kiwi_devicepersistency} fi + max_disk=0 + kiwi_oem_maxdisk=$(getarg rd.kiwi.oem.maxdisk=) + if [ -n "${kiwi_oem_maxdisk}" ]; then + max_disk=$(binsize_to_bytesize "${kiwi_oem_maxdisk}") || max_disk=0 + fi if getargbool 0 rd.kiwi.ramdisk; then # target should be a ramdisk on request. Thus actively # load the ramdisk block driver and support custom sizes @@ -77,6 +84,14 @@ function get_disk_list { continue fi disk_size=$(echo "${disk_meta}" | cut -f2 -d:) + if [ ${max_disk} -gt 0 ]; then + local disk_size_bytes + disk_size_bytes=$(binsize_to_bytesize "${disk_size}") || disk_size_bytes=0 + if [ "${disk_size_bytes}" -gt "${max_disk}" ]; then + info "${disk_device} filtered out by rd.kiwi.oem.maxdisk=${kiwi_oem_maxdisk} (is ${disk_size})" >&2 + continue + fi + fi disk_device_by_id=$( get_persistent_device_from_unix_node "${disk_device}" "${disk_id}" ) diff --git a/dracut/modules.d/99kiwi-lib/kiwi-lib.sh b/dracut/modules.d/99kiwi-lib/kiwi-lib.sh index 90da3056..81b1f304 100644 --- a/dracut/modules.d/99kiwi-lib/kiwi-lib.sh +++ b/dracut/modules.d/99kiwi-lib/kiwi-lib.sh @@ -113,3 +113,20 @@ function import_file { eval "export ${key}" &>/dev/null done < ${source_format} } + +function binsize_to_bytesize { + # """ + # converts binary sizes (1024k, 2.4G) to bytes + # uses awk to handle floating point numbers + # """ + local sz="$1" + local bs=${sz:0:-1} + case ${sz} in + *K|*k) mult=1024 ;; + *M) mult=$((1024*1024)) ;; + *G) mult=$((1024*1024*1024)) ;; + *T) mult=$((1024*1024*1024*1024)) ;; + *) bs=${sz}; mult=1 ;; + esac + awk "BEGIN {print int(${bs}*${mult})}" +}