Created
July 1, 2013 22:19
-
-
Save allykzam/5905135 to your computer and use it in GitHub Desktop.
Two files that can be used to rebuild a vanilla kernel on Arch linux. 01_VanillaKernel needs to be chmod 777 and located at /etc/grub.d/01_VanillaKernel, kernelbuildscript needs to be chmod +x anywhere you can point to it, and then just call it from the root directory of the kernel's source code. Code assumes your boot partition is /dev/sda1, an…
This file contains 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/sh | |
exec tail -n +3 $0 | |
menuentry 'Vanilla Kernel' { | |
VanillaVersion="3.9.8" | |
RootPartition="12345678-9abc-def0-1234-56789abcdef0" | |
load_video | |
set gfxpayload=keep | |
insmod gzio | |
insmod part_msdos | |
insmod ext2 | |
set root='hd0,msdos1' | |
if [ x$feature_platform_search_hint = xy ]; then | |
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 $RootPartition | |
else | |
search --no-floppy --fs-uuid --set=root $RootPartition | |
fi | |
echo 'Loading Linux core repo kernel ...' | |
linux /boot/vmLinuz-$VanillaVersion root=UUID=$RootPartition ro quiet | |
echo 'Loading initial ramdisk ...' | |
initrd /boot/initramfs-$VanillaVersion | |
} |
This file contains 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 | |
# Make sure to set this before running the script | |
BuildUser="" | |
# This grabs version info out of Makefile | |
echo "** Getting Version Info **" | |
VERSION=`cat Makefile | grep "^VERSION = [0-9]\+$" | tr -d 'VERSION = '` | |
PATCHLEVEL=`cat Makefile | grep "^PATCHLEVEL = [0-9]\+$" | tr -d 'PATCHLEVEL = '` | |
SUBLEVEL=`cat Makefile | grep "^SUBLEVEL = [0-9]\+$" | tr -d 'SUBLEVEL = '` | |
EXTRAVERSION=`cat Makefile | grep "^EXTRAVERSION = [0-9]\+$" | tr -d 'EXTRAVERSION = '` | |
# This wonderful block of conditions determines what the version number will be | |
if [ "$VERSION" != "" ] | |
then | |
if [ "$PATCHLEVEL" != "" ] | |
then | |
if [ "$SUBLEVEL" != "" ] | |
then | |
if [ "$EXTRAVERSION" != "" ] | |
then | |
KERNELVERSION=$VERSION.$PATCHLEVEL.$SUBLEVEL$EXTRAVERSION | |
else | |
KERNELVERSION=$VERSION.$PATCHLEVEL.$SUBLEVEL | |
fi | |
else | |
KERNELVERSION=$VERSION.$PATCHLEVEL | |
fi | |
else | |
KERNELVERSION=$VERSION | |
fi | |
else | |
# If the above code doesn't figure out the version number, fail and let the user know why | |
echo "Error:" | |
echo "Something's wrong with the Makefile, and a proper version string can't be built." | |
exit 1 | |
fi | |
echo "$KERNELVERSION" | |
# Try to find the UUID for /dev/sda1 so we can stick it in our grub files | |
echo "** Getting /dev/sda1 UUID **" | |
DevSda1=`blkid | grep "/dev/sda1" | grep -o "UUID=\".\{36\}\"" | grep -o "[0-9a-fA-F-]\{36\}"` | |
echo "$DevSda1" | |
# Run through the general build process | |
# Clean old stuff | |
echo "** Cleaning Source **" | |
sudo -u $BuildUser make mrproper | |
# Get current config stuff | |
echo "** Getting default config **" | |
sudo -u $BuildUser zcat /proc/config.gz > .config | |
# Add our local modules (this sometimes requires user intervention) | |
echo "** Adding modules **" | |
sudo -u $BuildUser make BATCH=yes localmodconfig | |
# Compile the kernel | |
echo "** Compiling Kernel **" | |
sudo -u $BuildUser make | |
# Install the modules to where they belong | |
echo "** Installing modules **" | |
make modules_install | |
# Copy new files! | |
# We need the boot image that the kernel went into | |
echo "** Copying new files **" | |
cp arch/x86/boot/bzImage /boot/vmLinuz-$KERNELVERSION | |
# And a startup ram system | |
mkinitcpio -k $KERNELVERSION-ARCH -c /etc/mkinitcpio.conf -g /boot/initramfs-$KERNELVERSION | |
# And I guess we need the System.map? | |
cp System.map /boot/System.map-$KERNELVERSION | |
# Go update our VanillaKernel file with the new kernel version and UUID of /dev/sda1 | |
echo "** Adjusting boot config **" | |
sed "s/VanillaVersion=.*/VanillaVersion=\"$KERNELVERSION\"/" /etc/grub.d/01_VanillaKernel | sed "s/RootPartition=.*/RootPartition=\"$DevSda1\"/" > /etc/grub.d/01_VanillaKernel | |
# Update grub.cfg | |
grub-mkconfig -o /boot/grub/grub.cfg | |
echo "** DONE **" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment