Skip to content

Commit

Permalink
added amending initramfs of liveUSB, including mount of /cow
Browse files Browse the repository at this point in the history
  • Loading branch information
mars4science committed Jan 1, 2023
1 parent d4d26cf commit 289c99e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 15 additions & 6 deletions _make_custom_liveusb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ change_squash() {

# commands that amend boot menus and options
change_boot() {

# modify boot config
# sed usage see [2]

Expand All @@ -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
Expand All @@ -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}
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 289c99e

Please sign in to comment.