diff --git a/conf/cd-files/lib/systemd/system/mount-cd.service b/conf/cd-files/lib/systemd/system/mount-cd.service new file mode 100644 index 0000000..df2754f --- /dev/null +++ b/conf/cd-files/lib/systemd/system/mount-cd.service @@ -0,0 +1,14 @@ +[Unit] +Description=Mount installation media +DefaultDependencies=no + +Before=local-fs.target + +[Service] +Type=oneshot +RemainAfterExit=yes +TimeoutStartSec=300 +ExecStart=/sbin/mount-cd + +[Install] +WantedBy=multi-user.target diff --git a/conf/cd-files/lib/systemd/system/multi-user.target.wants/mount-cd.service b/conf/cd-files/lib/systemd/system/multi-user.target.wants/mount-cd.service new file mode 120000 index 0000000..8ae7734 --- /dev/null +++ b/conf/cd-files/lib/systemd/system/multi-user.target.wants/mount-cd.service @@ -0,0 +1 @@ +../mount-cd.service \ No newline at end of file diff --git a/conf/cd-files/root/.bash_profile b/conf/cd-files/root/.bash_profile index 468f16d..521523f 100755 --- a/conf/cd-files/root/.bash_profile +++ b/conf/cd-files/root/.bash_profile @@ -1,192 +1,6 @@ #!/bin/sh -# Inspired by https://salsa.debian.org/live-team/live-boot/-/blob/master/components/9990-misc-helpers.sh - -mountpoint=/cdrom - -is_live_path() -{ - FILE="${1}/TrueNAS-SCALE.update" - if [ -f "${FILE}" ] - then - return 0 - fi - return 1 -} - -is_nice_device () -{ - sysfs_path="${1#/sys}" - - if udevadm info --query=all --path="${sysfs_path}" | egrep -q "DEVTYPE=disk" - then - return 0 - elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$' - then - return 0 - elif echo ${sysfs_path} | grep -q "^/block/dm-" - then - return 0 - elif echo ${sysfs_path} | grep -q "^/block/mtdblock" - then - return 0 - fi - - return 1 -} - -check_dev () -{ - local force fix - sysdev="${1}" - devname="${2}" - skip_uuid_check="${3}" - - if [ -z "${devname}" ] - then - devname=$(sys2dev "${sysdev}") - fi - - mount "${devname}" $mountpoint || return 1 - - if is_live_path $mountpoint - then - echo $mountpoint - return 0 - else - umount $mountpoint - fi - - return 1 -} - -find_livefs () -{ - # scan of block devices to find the installation media - # prefer removable devices over non-removable devices, so scan them first - devices_to_scan="$(removable_dev 'sys') $(non_removable_dev 'sys')" - - for sysblock in $devices_to_scan - do - devname=$(sys2dev "${sysblock}") - [ -e "$devname" ] || continue - - if /lib/udev/cdrom_id ${devname} > /dev/null - then - if check_dev "null" "${devname}" - then - return 0 - fi - elif is_nice_device "${sysblock}" - then - for dev in $(subdevices "${sysblock}") - do - if check_dev "${dev}" - then - return 0 - fi - done - fi - done - - return 1 -} - -sys2dev () -{ - sysdev=${1#/sys} - echo "/dev/$(udevadm info -q name -p ${sysdev} 2>/dev/null|| echo ${sysdev##*/})" -} - -subdevices () -{ - sysblock=${1} - r="" - - for dev in "${sysblock}"/* "${sysblock}" - do - if [ -e "${dev}/dev" ] - then - r="${r} ${dev}" - fi - done - - echo ${r} -} - -removable_dev () -{ - output_format="${1}" - want_usb="${2}" - ret= - - for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)") - do - if [ ! -d "${sysblock}" ]; then - continue - fi - - dev_ok= - if [ "$(cat ${sysblock}/removable)" = "1" ] - then - if [ -z "${want_usb}" ] - then - dev_ok="true" - else - if readlink ${sysblock} | grep -q usb - then - dev_ok="true" - fi - fi - fi - - if [ "${dev_ok}" = "true" ] - then - case "${output_format}" in - sys) - ret="${ret} ${sysblock}" - ;; - *) - devname=$(sys2dev "${sysblock}") - ret="${ret} ${devname}" - ;; - esac - fi - done - - echo "${ret}" -} - -non_removable_dev () -{ - output_format="${1}" - ret= - - for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)") - do - if [ ! -d "${sysblock}" ]; then - continue - fi - - if [ "$(cat ${sysblock}/removable)" = "0" ] - then - case "${output_format}" in - sys) - ret="${ret} ${sysblock}" - ;; - *) - devname=$(sys2dev "${sysblock}") - ret="${ret} ${devname}" - ;; - esac - fi - done - - echo "${ret}" -} - -mkdir -p "$mountpoint" -if find_livefs +if -f /cdrom/TrueNAS-SCALE.update then until /sbin/truenas-install; do true; done else diff --git a/conf/cd-files/sbin/mount-cd b/conf/cd-files/sbin/mount-cd new file mode 100755 index 0000000..122b457 --- /dev/null +++ b/conf/cd-files/sbin/mount-cd @@ -0,0 +1,189 @@ +#!/bin/sh + +# Inspired by https://salsa.debian.org/live-team/live-boot/-/blob/master/components/9990-misc-helpers.sh + +mountpoint=/cdrom + +is_live_path() +{ + FILE="${1}/TrueNAS-SCALE.update" + if [ -f "${FILE}" ] + then + return 0 + fi + return 1 +} + +is_nice_device () +{ + sysfs_path="${1#/sys}" + + if udevadm info --query=all --path="${sysfs_path}" | egrep -q "DEVTYPE=disk" + then + return 0 + elif echo "${sysfs_path}" | grep -q '^/block/vd[a-z]$' + then + return 0 + elif echo ${sysfs_path} | grep -q "^/block/dm-" + then + return 0 + elif echo ${sysfs_path} | grep -q "^/block/mtdblock" + then + return 0 + fi + + return 1 +} + +check_dev () +{ + local force fix + sysdev="${1}" + devname="${2}" + skip_uuid_check="${3}" + + if [ -z "${devname}" ] + then + devname=$(sys2dev "${sysdev}") + fi + + mount "${devname}" $mountpoint || return 1 + + if is_live_path $mountpoint + then + echo $mountpoint + return 0 + else + umount $mountpoint + fi + + return 1 +} + +find_livefs () +{ + # scan of block devices to find the installation media + # prefer removable devices over non-removable devices, so scan them first + devices_to_scan="$(removable_dev 'sys') $(non_removable_dev 'sys')" + + for sysblock in $devices_to_scan + do + devname=$(sys2dev "${sysblock}") + [ -e "$devname" ] || continue + + if /lib/udev/cdrom_id ${devname} > /dev/null + then + if check_dev "null" "${devname}" + then + return 0 + fi + elif is_nice_device "${sysblock}" + then + for dev in $(subdevices "${sysblock}") + do + if check_dev "${dev}" + then + return 0 + fi + done + fi + done + + return 1 +} + +sys2dev () +{ + sysdev=${1#/sys} + echo "/dev/$(udevadm info -q name -p ${sysdev} 2>/dev/null|| echo ${sysdev##*/})" +} + +subdevices () +{ + sysblock=${1} + r="" + + for dev in "${sysblock}"/* "${sysblock}" + do + if [ -e "${dev}/dev" ] + then + r="${r} ${dev}" + fi + done + + echo ${r} +} + +removable_dev () +{ + output_format="${1}" + want_usb="${2}" + ret= + + for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)") + do + if [ ! -d "${sysblock}" ]; then + continue + fi + + dev_ok= + if [ "$(cat ${sysblock}/removable)" = "1" ] + then + if [ -z "${want_usb}" ] + then + dev_ok="true" + else + if readlink ${sysblock} | grep -q usb + then + dev_ok="true" + fi + fi + fi + + if [ "${dev_ok}" = "true" ] + then + case "${output_format}" in + sys) + ret="${ret} ${sysblock}" + ;; + *) + devname=$(sys2dev "${sysblock}") + ret="${ret} ${devname}" + ;; + esac + fi + done + + echo "${ret}" +} + +non_removable_dev () +{ + output_format="${1}" + ret= + + for sysblock in $(echo /sys/block/* | tr ' ' '\n' | grep -vE "/(loop|ram|dm-|fd)") + do + if [ ! -d "${sysblock}" ]; then + continue + fi + + if [ "$(cat ${sysblock}/removable)" = "0" ] + then + case "${output_format}" in + sys) + ret="${ret} ${sysblock}" + ;; + *) + devname=$(sys2dev "${sysblock}") + ret="${ret} ${devname}" + ;; + esac + fi + done + + echo "${ret}" +} + +mkdir -p "$mountpoint" +find_livefs diff --git a/scale_build/image/iso.py b/scale_build/image/iso.py index 43bdded..971fc2f 100644 --- a/scale_build/image/iso.py +++ b/scale_build/image/iso.py @@ -1,4 +1,3 @@ -import distutils.dir_util import glob import itertools import os @@ -51,8 +50,7 @@ def make_iso_file(): f.write('truenas.local') # Copy the CD files - distutils.dir_util._path_created = {} - distutils.dir_util.copy_tree(CD_FILES_DIR, CHROOT_BASEDIR, preserve_symlinks=True) + run(f'rsync -av {CD_FILES_DIR}/ {CHROOT_BASEDIR}/', shell=True) # Create the CD assembly dir if os.path.exists(CD_DIR):