From 289c99e885af1dbed0db82a7b9318e15d1be155f Mon Sep 17 00:00:00 2001 From: Alex Martian Date: Sun, 1 Jan 2023 12:44:35 +0000 Subject: [PATCH] added amending initramfs of liveUSB, including mount of /cow --- README.md | 1 + _make_custom_liveusb.sh | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 32ad145..0afa183 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ _make_custom_liveusb.sh at the start have code to set several variables: - work_path - full path with sufficient free space, end result (modified ISO file) is programmed to be left there after temporary files are deleted - change_boot_menu - set to set to "true" to edit boot menu (which adds options e.g. boot to ram, change id of live user, add rights for virt manager usage, replace splash/menu background image) - Note: above are variables to set to run example 1 of script usage (to only add some software with `apt-install` of debs), see examples at the end of README +- change_initramfs - set to true to allow changes to initramfs (early boot environment), now code does changing of user name (inc. full name) and mounting /cow in /casper to be able to see changes changes made to filesystem while running and allow ealier amending of those changes - locales - array of locales (languages/keyboard layouts) to add, first one is for interface language - user_name - to replace user name in `run_at_boot_liveusb.sh` - path_to_software_in_chroot - full path were data to be added is mounted during install (TODO - remove folder after install) diff --git a/_make_custom_liveusb.sh b/_make_custom_liveusb.sh index a524387..dc63c14 100755 --- a/_make_custom_liveusb.sh +++ b/_make_custom_liveusb.sh @@ -102,6 +102,7 @@ change_squash() { # commands that amend boot menus and options change_boot() { + # modify boot config # sed usage see [2] @@ -110,6 +111,10 @@ change_boot() { custom_init_boot_option="init=$liveiso_path_scripts_in_chroot/run_at_boot_liveusb.sh " else custom_init_boot_option=""; fi + # added after studying casper script in initramfs (initrd file): + # "showmounts" added for adding /casper with nounts to /cow that is mounted over by init/casper of initramfs (if change_initramfs set to "true") + # "nopersistence" is for not creating writable partition on USB stick to store logs + # ======= for UEFI boot ======= grub_config=$work_path/fin/boot/grub/grub.cfg @@ -120,13 +125,13 @@ change_boot() { sudo mv --force ${grub_config}_tmp ${grub_config} # change first manu entry to boot to ram, add custom init script, make verbose; 0,/ needed to edit first occurence only - sudo sed --in-place --regexp-extended -- "0,/ quiet splash --/s|| toram ${custom_init_boot_option}--|" ${grub_config} + sudo sed --in-place --regexp-extended -- "0,/ quiet splash --/s|| showmounts toram ${custom_init_boot_option}--|" ${grub_config} sudo sed --in-place --regexp-extended -- '0,/64-bit"/s//64-bit to RAM, verbose (UEFI: all menu entries)"/' ${grub_config} # change second manu entry to make text mode boot, add custom init script, make verbose; 0,/ needed to edit first occurence only - sudo sed --in-place --regexp-extended -- "0,/ quiet splash --/s|| level 3 ${custom_init_boot_option}--|" ${grub_config} + sudo sed --in-place --regexp-extended -- "0,/ quiet splash --/s|| showmounts nopersistent level 3 ${custom_init_boot_option}--|" ${grub_config} sudo sed --in-place --regexp-extended -- '0,/64-bit"/s//64-bit, text mode, verbose"/' ${grub_config} # change third manu entry to add custom init script, make verbose; 0,/ needed to edit first occurence only - sudo sed --in-place --regexp-extended -- "0,/ quiet splash --/s|| ${custom_init_boot_option}--|" ${grub_config} + sudo sed --in-place --regexp-extended -- "0,/ quiet splash --/s|| showmounts nopersistent ${custom_init_boot_option}--|" ${grub_config} sudo sed --in-place --regexp-extended -- '0,/64-bit"/s//64-bit, verbose"/' ${grub_config} # change forth menu entry to add custom init script, 0,/ needed to edit first occurence only sudo sed --in-place --regexp-extended -- "0,/ quiet splash --/s|| quiet splash ${custom_init_boot_option}--|" ${grub_config} @@ -163,15 +168,15 @@ change_boot() { # change first manu entry to boot to ram, add custom init script, make verbose; 0,/ needed to edit first occurence only sudo sed --in-place --regexp-extended -- '0,/label.*/s//label ram/' ${legacy_config} sudo sed --in-place --regexp-extended -- '0,/( *menu label.*Mint)$/s//\1 (to RAM, verbose)/' ${legacy_config} - sudo sed --in-place --regexp-extended -- "0,/ quiet splash --/s|| toram ${custom_init_boot_option}--|" ${legacy_config} + sudo sed --in-place --regexp-extended -- "0,/ quiet splash --/s|| showmounts toram ${custom_init_boot_option}--|" ${legacy_config} # change second manu entry to add custom init script, make verbose; 0,/ needed to edit first occurence only sudo sed --in-place --regexp-extended -- '0,/label.*/s//label text/' ${legacy_config} sudo sed --in-place --regexp-extended -- '0,/( *menu label.*Mint)$/s//\1 (text mode, verbose)/' ${legacy_config} - sudo sed --in-place --regexp-extended -- "0,/ quiet splash --/s|| level 3 ${custom_init_boot_option}--|" ${legacy_config} + sudo sed --in-place --regexp-extended -- "0,/ quiet splash --/s|| showmounts nopersistent level 3 ${custom_init_boot_option}--|" ${legacy_config} # change third manu entry to add custom init script, make verbose; 0,/ needed to edit first occurence only sudo sed --in-place --regexp-extended -- '0,/label.*/s//label verbose/' ${legacy_config} sudo sed --in-place --regexp-extended -- '0,/( *menu label.*Mint)$/s//\1 (verbose)/' ${legacy_config} - sudo sed --in-place --regexp-extended -- "0,/ quiet splash --/s|| ${custom_init_boot_option}--|" ${legacy_config} + sudo sed --in-place --regexp-extended -- "0,/ quiet splash --/s|| showmounts nopersistent ${custom_init_boot_option}--|" ${legacy_config} # change forth menu entry to add custom init script, 0,/ needed to edit first occurence only sudo sed --in-place --regexp-extended -- "0,/ quiet splash --/s|| quiet splash ${custom_init_boot_option}--|" ${legacy_config} sudo sed --in-place --regexp-extended -- '0,/( *menu label.*Mint)$/s//\1 (quiet)/' ${legacy_config} @@ -200,6 +205,10 @@ change_initrd(){ # amend sudo sed --in-place --regexp-extended -- "s|USERNAME=.*|USERNAME="\""$user_name"\""|" $work_path/initrd/main/etc/casper.conf sudo sed --in-place --regexp-extended -- "s|USERFULLNAME=.*|USERFULLNAME="\""User $user_name"\""|" $work_path/initrd/main/etc/casper.conf + + # add mount of /cow of initramfs to /casper of resultant fs + sudo sed --in-place --regexp-extended -- 's|(if [[] -n "[$][{]SHOWMOUNTS[}]" []]; then)|\1\n\n mkdir -p "${rootmnt}/${LIVE_MEDIA_PATH}/cow"\n mount --bind /cow "${rootmnt}/${LIVE_MEDIA_PATH}/cow"\n|' $work_path/initrd/main/scripts/casper + } # ??? where and what for this comment near initrd??? Clear out debconf database again to avoid confusing ubiquity later.