Skip to content

Commit

Permalink
testing: Reduce the difference in creating initramfs between differen…
Browse files Browse the repository at this point in the history
…t vendors

Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
  • Loading branch information
legionus committed Jan 1, 2025
1 parent 39c45ce commit 1fc4acc
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 38 deletions.
51 changes: 29 additions & 22 deletions testing/testing-altlinux-ks-initrd.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,20 @@
blkid
findmnt

echo "ENABLE=no" > /etc/sysconfig/framebuffer

tee /etc/initrd.mk <<-EOF
IMAGEFILE = /boot/initrd-\$(KERNEL)\$(IMAGE_SUFFIX).img
AUTODETECT = all
`[ ! -f /etc/initrd.mk.addon ] || cat /etc/initrd.mk.addon`
EOF

kver="$(readlink -ev /boot/vmlinuz)"
kver="${kver##*/vmlinuz-}"
grub_install="$( for f in grub-install grub2-install; do type -P "$f" && break; done )"
grub_mkconfig="$( for f in grub-mkconfig grub2-mkconfig; do type -P "$f" && break; done )"
grub_bootdir="$( find /boot -type d \( -name 'grub' -o -name 'grub2' \) )"
grub_params="/etc/sysconfig/grub2"

kver="$(find /lib/modules -mindepth 1 -maxdepth 1 -printf '%f\n' -quit)"

export PATH="/srv/.build/dest/usr/sbin:/srv/.build/dest/usr/bin:$PATH"

env -i PATH="$PATH" \
/srv/.build/dest/usr/sbin/make-initrd -k "$kver"
Expand All @@ -34,14 +39,10 @@
echo; echo;
echo 'IT WORKS!'
echo; echo;
exec reboot
exec systemctl reboot
EOF
chmod +x /sbin/init.once

tee -a /etc/inittab <<-EOF
z0:3:once:/sbin/init.once
EOF

tee -a /usr/lib/systemd/system/init-once.service <<-EOF
[Unit]
Description=Make-initrd target
Expand All @@ -59,33 +60,39 @@
WantedBy=sysinit.target
EOF

systemctl enable init-once ||:
systemctl enable init-once

tee -a /etc/sysconfig/grub2 <<-EOF
GRUB_CMDLINE_LINUX_DEFAULT='console=ttyS0,115200n8 fastboot @CMDLINE@'
tee -a "$grub_params" <<-EOF
GRUB_CMDLINE_LINUX_DEFAULT='console=ttyS0,115200n8 @CMDLINE@'
GRUB_TIMEOUT=3
GRUB_TERMINAL_INPUT='serial console'
GRUB_TERMINAL_OUTPUT='serial console'
GRUB_SERIAL_COMMAND='serial --unit=0 --speed=115200'
EOF

if ! blkid -L "EFI" >/dev/null; then
bootdev=$(findmnt -k -no SOURCE -T /boot)
syspath="$(readlink -ev "/sys/class/block/${bootdev#/dev/}")"
syspath="${syspath%/*}/uevent"
bootdev="$(sed -n -e 's,^DEVNAME=,/dev/,p' "$syspath")"
bootdev=$(findmnt -k -no SOURCE -T /boot)
syspath="$(readlink -ev "/sys/class/block/${bootdev#/dev/}")"
syspath="${syspath%/*}/uevent"
bootdev="$(sed -n -e 's,^DEVNAME=,/dev/,p' "$syspath")"

grub-install "$bootdev"
else
if blkid -L "EFI" >/dev/null; then
strace -e %file efibootmgr ||:
grub-install \
"$grub_install" \
--root-directory "/" \
--boot-directory "/boot" \
--efi-directory "/boot/efi" \
--efi-directory "/boot/efi" \
#
else
"$grub_install" "$bootdev"
fi

grub-mkconfig -o /boot/grub/grub.cfg
"$grub_mkconfig" -o "$grub_bootdir/grub.cfg"

cat "$grub_params"
{
find /boot \! -type d -printf '%M %p\n'
find /boot -type l -printf '%M %p -> %l\n'
} | sort -t\ -k1,1

umount /proc /sys /dev
%end
21 changes: 16 additions & 5 deletions testing/testing-fedora-ks-initrd.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
mkdir -p /dev
mount -t devtmpfs devfs /dev

! blkid -L "EFI" >/dev/null ||
mount -t efivarfs none /sys/firmware/efi/efivars

blkid
findmnt

Expand All @@ -19,6 +22,11 @@
`[ ! -f /etc/initrd.mk.addon ] || cat /etc/initrd.mk.addon`
EOF

grub_install="$( for f in grub-install grub2-install; do type -P "$f" && break; done )"
grub_mkconfig="$( for f in grub-mkconfig grub2-mkconfig; do type -P "$f" && break; done )"
grub_bootdir="$( find /boot -type d \( -name 'grub' -o -name 'grub2' \) )"
grub_params="/etc/default/grub"

kver="$(find /lib/modules -mindepth 1 -maxdepth 1 -printf '%f\n' -quit)"

export PATH="/srv/.build/dest/usr/sbin:/srv/.build/dest/usr/bin:$PATH"
Expand Down Expand Up @@ -54,7 +62,7 @@

systemctl enable init-once

tee -a /etc/default/grub <<-EOF
tee -a "$grub_params" <<-EOF
GRUB_CMDLINE_LINUX_DEFAULT='console=ttyS0,115200n8 @CMDLINE@'
GRUB_TIMEOUT=3
GRUB_TERMINAL_INPUT='serial console'
Expand All @@ -71,11 +79,14 @@
syspath="${syspath%/*}/uevent"
bootdev="$(sed -n -e 's,^DEVNAME=,/dev/,p' "$syspath")"

grub2-install "$bootdev"
grub2-mkconfig -o /boot/grub2/grub.cfg
"$grub_install" "$bootdev"
"$grub_mkconfig" -o "$grub_bootdir/grub.cfg"

ls -la /boot
cat /etc/default/grub
cat "$grub_params"
{
find /boot \! -type d -printf '%M %p\n'
find /boot -type l -printf '%M %p -> %l\n'
} | sort -t\ -k1,1

umount /proc /sys /dev
%end
36 changes: 25 additions & 11 deletions testing/testing-ubuntu-ks-initrd.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,32 @@
mkdir -p /dev
mount -t devtmpfs devfs /dev

! blkid -L "EFI" >/dev/null ||
mount -t efivarfs none /sys/firmware/efi/efivars

blkid
findmnt

cat /etc/fstab

# Hack. Drop symlink if any.
cat /etc/os-release > /etc/os-release.$$
rm -f /etc/os-release
mv /etc/os-release.$$ /etc/os-release
# Hack. Drop symlink. This change is necessary to avoid an error:
# /etc/grub.d/10_linux_zfs: 403: .: cannot open /tmp/zfsmnt.QMGi2Y/etc/os-release: No such file
if [ -L /etc/os-release ]; then
cat /etc/os-release > /etc/os-release.$$
rm -f /etc/os-release
mv /etc/os-release.$$ /etc/os-release
fi

tee /etc/initrd.mk <<-EOF
IMAGEFILE = /boot/initrd.img-\$(KERNEL)\$(IMAGE_SUFFIX)
AUTODETECT = all
`[ ! -f /etc/initrd.mk.addon ] || cat /etc/initrd.mk.addon`
EOF

kver="$(readlink -ev /boot/vmlinuz)"
kver="${kver##*/vmlinuz-}"
grub_install="$( for f in grub-install grub2-install; do type -P "$f" && break; done )"
grub_mkconfig="$( for f in grub-mkconfig grub2-mkconfig; do type -P "$f" && break; done )"
grub_bootdir="$( find /boot -type d \( -name 'grub' -o -name 'grub2' \) )"
grub_params="/etc/default/grub"

kver="$(find /lib/modules -mindepth 1 -maxdepth 1 -printf '%f\n' -quit)"

export PATH="/srv/.build/dest/usr/sbin:/srv/.build/dest/usr/bin:$PATH"

Expand Down Expand Up @@ -62,7 +70,7 @@

systemctl enable init-once

tee -a /etc/default/grub <<-EOF
tee -a "$grub_params" <<-EOF
GRUB_CMDLINE_LINUX_DEFAULT='console=ttyS0,115200n8 @CMDLINE@'
GRUB_TIMEOUT=3
GRUB_TERMINAL_INPUT='serial console'
Expand All @@ -77,8 +85,14 @@
syspath="${syspath%/*}/uevent"
bootdev="$(sed -n -e 's,^DEVNAME=,/dev/,p' "$syspath")"

grub-install "$bootdev"
grub-mkconfig -o /boot/grub/grub.cfg
"$grub_install" "$bootdev"
"$grub_mkconfig" -o "$grub_bootdir/grub.cfg"

cat "$grub_params"
{
find /boot \! -type d -printf '%M %p\n'
find /boot -type l -printf '%M %p -> %l\n'
} | sort -t\ -k1,1

umount /proc /sys /dev
%end

0 comments on commit 1fc4acc

Please sign in to comment.