Last active
August 16, 2020 17:56
-
-
Save polymorphm/e0657228ad4f523f5a63501fc5aba8e4 to your computer and use it in GitHub Desktop.
/etc/install-vmlinuz-linux.sh: coping/generation vmlinuz and initramfs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
boot_vmlinuz_path='/boot/vmlinuz-linux' | |
boot_initramfs_path='/boot/initramfs-linux.img' | |
new_boot_vmlinuz_path="$boot_vmlinuz_path.new" | |
new_boot_initramfs_path="$boot_initramfs_path.new" | |
bak_boot_vmlinuz_path="$boot_vmlinuz_path.bak" | |
bak_boot_initramfs_path="$boot_initramfs_path.bak" | |
linux_ver="$1" | |
if [ x"$linux_ver" == "x" ] | |
then | |
auto_linux_ver="$(ls -1 -- '/lib/modules/')" | |
auto_vmlinuz_path="/lib/modules/$auto_linux_ver/vmlinuz" | |
if [ -f "$auto_vmlinuz_path" ] | |
then | |
echo "$0: auto linux_ver" | |
linux_ver="$auto_linux_ver" | |
fi | |
fi | |
if [ x"$linux_ver" == "x" ] | |
then | |
echo "$0: missing argument: linux_ver" >&2 | |
exit 1 | |
fi | |
vmlinuz_path="/lib/modules/$linux_ver/vmlinuz" | |
echo "$0: linux_ver: $linux_ver" | |
echo "$0: vmlinuz_path: $vmlinuz_path" | |
if [ ! -f "$vmlinuz_path" ] | |
then | |
echo "$0: vmlinuz not found: $vmlinuz_path" >&2 | |
exit 1 | |
fi | |
echo "$0: generation new boot files..." | |
rm -vf -- "$new_boot_vmlinuz_path" "$new_boot_initramfs_path" | |
cp -v -- "$vmlinuz_path" "$new_boot_vmlinuz_path" | |
dracut -- "$new_boot_initramfs_path" "$linux_ver" | |
echo "$0: generation new boot files: DONE!" | |
echo "$0: replacing boot files..." | |
if [ -f "$boot_vmlinuz_path" ] | |
then | |
mv -v -- "$boot_vmlinuz_path" "$bak_boot_vmlinuz_path" | |
fi | |
if [ -f "$boot_initramfs_path" ] | |
then | |
mv -v -- "$boot_initramfs_path" "$bak_boot_initramfs_path" | |
fi | |
mv -v -- "$new_boot_vmlinuz_path" "$boot_vmlinuz_path" | |
mv -v -- "$new_boot_initramfs_path" "$boot_initramfs_path" | |
rm -vf -- "$bak_boot_vmlinuz_path" "$bak_boot_initramfs_path" | |
echo "$0: replacing boot files: DONE!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment