#Maintainer: JRD # vim: set syn=sh ft=sh et sw=2 sts=2 ts=2 tw=0: _kver=3.10.17 _aufscommit=ce9cff pkgname=kernelive pkgver=$(echo $_kver|tr - .) pkgrel=1cp _configname=config-huge$(uname -m|grep -q 64 || echo '-smp')-$_kver$(uname -m|grep -q 64 && echo '.x64' || echo '-smp').live source=(https://www.kernel.org/pub/linux/kernel/v3.x/linux-$_kver.tar.xz CVE-2004-0038.diff $_configname.xz $_configname.patch aufs3-standalone-$_aufscommit.tar.xz) sourcetemplate=http://people.salixos.org/jrd/salix/$pkgname/$pkgver-\$arch-$pkgrel/ docs=("readme" "copying") options=('nostrip') slackdesc=\ ( #|-----handy-ruler------------------------------------------------------| "$pkgname (Linux kernel for Salix Live)" "Linux kernel for Salix Live is compiled with support for" "squashfs, xz & aufs3 as well as for most hardware, " "including SCSI, USB booting devices, etc.. " "" "This is the same kernel config as kernel-huge but with aufs3 FS patch." ) build() { export KVER=$_kver export KVEREXTRA=$KVER$(uname -m|grep -q 64 || echo '-smp') mv $SRC/linux-$KVER $SRC/linuxsrc ARCH_BAK=$ARCH unset ARCH cd $SRC/linuxsrc echo '* Applying CVE-2004-0038.diff... *' patch -p1 -i $SRC/CVE-2004-0038.diff || exit 1 # patch the kernel to use a new FS : aufs (an unionfs like filesystem) for f in Documentation fs include/uapi/linux/aufs_type.h; do mkdir -p $(dirname $f) || exit 1 cp -r $SRC/aufs3-standalone-$_aufscommit/$f $(dirname $f)/ || exit 1 done echo '* Applying aufs3-kbuild.patch... *' patch -p1 -i $SRC/aufs3-standalone-$_aufscommit/aufs3-kbuild.patch || exit 1 echo '* Applying aufs3-base.patch... *' patch -p1 -i $SRC/aufs3-standalone-$_aufscommit/aufs3-base.patch || exit 1 echo '* Applying aufs3-mmap.patch... *' # mm/freemap.c has been changed and the patch for it cannot be applied. # So patch it with sed and remove the patch chunk from the patch file sed -ri "/mmap_region/ { i \ vma_get_file(vma); N; a \ vma_fput(vma); }" mm/fremap.c || exit 1 sed -ri '\:^diff --git a/mm/fremap.c:,+13 d' $SRC/aufs3-standalone-$_aufscommit/aufs3-mmap.patch || exit 1 patch -p1 -i $SRC/aufs3-standalone-$_aufscommit/aufs3-mmap.patch || exit 1 # use a suitable configuration for live environnement. cp $SRC/$_configname .config || exit 1 make oldconfig scripts prepare || exit 1 # compile the kernel echo '########################################' echo "Compiling modules..." echo '########################################' make -j $numjobs modules || exit 1 echo '########################################' echo "Compiling kernel image..." echo '########################################' make -j $numjobs bzImage || exit 1 export INSTALL_MOD_PATH=$PKG echo '########################################' echo "Installing modules..." echo '########################################' make -j $numjobs modules_install || exit 1 unset INSTALL_MOD_PATH ARCH=$ARCH_BAK # copy the kernel cd $PKG mkdir -p boot ( cd boot cp $SRC/linuxsrc/.config config-huge-$KVEREXTRA cp $SRC/linuxsrc/System.map System.map-huge-$KVEREXTRA cp $SRC/linuxsrc/arch/x86/boot/bzImage vmlinuz-huge-$KVEREXTRA ln -s config-huge-$KVEREXTRA config ln -s System.map-huge-$KVEREXTRA System.map ln -s vmlinuz-huge-$KVEREXTRA vmlinuz ) # create rc.modules mkdir -p etc/rc.d cat << EOF > etc/rc.d/rc.modules #!/bin/sh # rc.modules $(date) # RELEASE=\$(uname -r) echo "Updating module dependencies for Linux \$RELEASE:" /sbin/depmod -A #### ACPI support ### EOF modules_enabled="fuse ac battery button video fan dock bay processor thermal memory asus_acpi thinkpad_acpi toshiba_acpi pcspkr parport_pc lp agpgart" for m in $(find $PKG/lib/modules/$KVEREXTRA -name '*.ko' -exec basename '{}' .ko \;|sort); do if echo " $modules_enabled "|grep -q " $m "; then echo "/sbin/modprobe -q $m >/dev/null 2>&1" >> etc/rc.d/rc.modules else echo "# /bin/modprobe $m" >> etc/rc.d/rc.modules fi done cat << 'EOF' >> etc/rc.d/rc.modules ### Filesystem Quota support ### if /bin/grep -q quota /etc/fstab ; then # /sbin/modprobe quota_v1 /sbin/modprobe quota_v2 fi ### Network device support ### # Most of these drivers will probe automatically for the card if you don't # specify an I/O address and IRQ. # # First, if setup probing found a network card, there may be an 'rc.netdevice' # file that we should run to load the network module: if [ -x /etc/rc.d/rc.netdevice ]; then . /etc/rc.d/rc.netdevice fi ### CPU frequency scaling support # # Below, set CPUFREQ to enable CPU frequency scaling to save system power. # # To always try to use CPU frequency scaling, set to: on # To never use CPU frequency scaling, set to: off # To use it only when the battery module is loaded (this will cause it to # be used by default with most laptops), set to: battery # CPUFREQ=battery # If CPUFREQ=battery and the battery module is loaded, turn on CPUfreq. if [ "$CPUFREQ" = "battery" ]; then if /sbin/lsmod | grep -wq battery ; then # CPUFREQ=battery and a battery was detected, so change CPUFREQ # to 'on' so that the block of script below will try to enable it. CPUFREQ=on fi fi ### Enable CPU frequency scaling if requested: if [ "$CPUFREQ" = "on" ]; then ### CPU frequency scaling modules for the Linux kernel CPUfreq subsystem. # # Clock scaling allows you to change the clock speed of the CPUs on the fly. # This is a nice method to save battery power, because the lower the clock # speed is, the less power the CPU consumes. # # It should not hurt anything to try to load these modules. # # generic ACPI P-States based driver: /sbin/modprobe acpi-cpufreq 2>/dev/null # AMD mobile K6-2/3+ PowerNow!: /sbin/modprobe powernow-k6 2>/dev/null # AMD mobile Athlon PowerNow!: /sbin/modprobe powernow-k7 2>/dev/null # AMD Cool&Quiet PowerNow!: /sbin/modprobe powernow-k8 2>/dev/null # Intel SpeedStep using the SMI BIOS interface: /sbin/modprobe speedstep-smi 2>/dev/null # Intel SpeedStep on ICH-based chipsets: /sbin/modprobe speedstep-ich 2>/dev/null # Intel Enhanced SpeedStep : /sbin/modprobe speedstep-centrino 2>/dev/null # Intel Pentium4/Xeon clock modulation is not enabled by default. # The kernel documentation says "This adds the CPUFreq driver for Intel # Pentium 4 / XEON processors. When enabled it will lower CPU temperature # by skipping clocks. This driver should be only used in exceptional # circumstances when very low power is needed because it causes severe # slowdowns and noticeable latencies. Normally Speedstep should be used # instead." # If you still want to try the Pentium4/Xeon module, uncomment the next line: #/sbin/modprobe p4-clockmod 2>/dev/null # NatSemi Geode GX / Cyrix MediaGXm: /sbin/modprobe gx-suspmod 2>/dev/null # Transmeta Crusoe / Efficeon LongRun: /sbin/modprobe longrun 2>/dev/null # VIA Cyrix Longhaul: /sbin/modprobe longhaul 2>/dev/null # nForce2 FSB changing cpufreq driver: /sbin/modprobe cpufreq-nforce2 2>/dev/null # Enhanced PowerSaver driver for VIA C7 CPUs: /sbin/modprobe e_powersaver 2>/dev/null ### CPU frequency scaling policies: # # Use the CPUFreq governor 'powersave' as default. This sets the # frequency statically to the lowest frequency supported by the CPU. #/sbin/modprobe cpufreq_powersave # # Use the CPUFreq governor 'performance' as default. This sets the # frequency statically to the highest frequency supported by the CPU. #/sbin/modprobe cpufreq_performance # # Use the CPUFreq governor 'conservative' as default. This allows you # to get a full dynamic frequency capable system by simply loading your # cpufreq low-level hardware driver. Be aware that not all cpufreq # drivers support the 'conservative' governor -- the fallback governor # will be the 'performance' governor. #/sbin/modprobe cpufreq_conservative # # Use the CPUFreq governor 'ondemand' as default. This allows you to # get a full dynamic frequency capable system by simply loading your # cpufreq low-level hardware driver. Be aware that not all cpufreq # drivers support the 'ondemand' governor -- the fallback governor will # be the performance governor. This seems to be the most-recommended # scaling policy, so rc.modules will try to load this by default. /sbin/modprobe cpufreq_ondemand 2>/dev/null ### CPU scaling governor: # # Set the default scaling_governor to be used (such as userspace or ondemand) # if there is a CPUFreq scaling policy module loaded that supports it: SCALING_GOVERNOR=ondemand # # Try to enable the scaling_governor selected above: if [ -r /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors ]; then if grep -wq "$SCALING_GOVERNOR" /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors ; then if [ -r /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor ]; then for SYSCPUFILE in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor ; do echo "$SCALING_GOVERNOR" > $SYSCPUFILE done fi fi fi fi # End enabling CPU scaling support # We are done with these variables now: unset NEWMODS RELEASE CPUFREQ SCALING_GOVERNOR SYSCPUFILE EOF cat <<'EOF' >> etc/rc.d/rc.modules #!/bin/sh RELEASE=\$(uname -r) if [ -x /usr/bin/find -a -e /lib/modules/$RELEASE/modules.dep \ -a /lib/modules/$RELEASE/modules.dep -nt /etc/modules.conf ]; then NEWMODS="$(/usr/bin/find /lib/modules/$RELEASE -mindepth 2 -type f -newer /lib/modules/$RELEASE/modules.dep)" # Only rebuild dependencies if new module(s) are found: if [ ! "" = "$NEWMODS" ]; then echo "Updating module dependencies for Linux $RELEASE:" /sbin/depmod -a else echo "Module dependencies up to date (no new kernel modules found)." fi else # we don't have find, or there is no existing modules.dep, or it is out of date. echo "Updating module dependencies for Linux $RELEASE:" /sbin/depmod -A fi EOF modules_enabled="fuse ac battery button video fan dock bay processor thermal asus_acpi thinkpad_acpi toshiba_acpi parport_pc lp agpgart" find $PKG/lib/modules/$KVER -name '*.ko' | sed "s,$PKG/lib/modules/$KVER/,," | sed -e 's,^.*/\([^/]*\)\.ko$,# /sbin/modprobe \1,; s,# \(.*\) \('"$(echo "$modules_enabled"|sed 's/ /\\|/g')"'\)$,\1 -q \2,;' | sort >> etc/rc.d/rc.modules cat << 'EOF' >> etc/rc.d/rc.modules ### Filesystem Quota support ### if /bin/grep -q quota /etc/fstab ; then # /sbin/modprobe quota_v1 /sbin/modprobe quota_v2 fi ### Network device support ### # Most of these drivers will probe automatically for the card if you don't # specify an I/O address and IRQ. # # First, if setup probing found a network card, there may be an 'rc.netdevice' # file that we should run to load the network module: if [ -x /etc/rc.d/rc.netdevice ]; then . /etc/rc.d/rc.netdevice fi ### CPU frequency scaling support # # Below, set CPUFREQ to enable CPU frequency scaling to save system power. # # To always try to use CPU frequency scaling, set to: on # To never use CPU frequency scaling, set to: off # To use it only when the battery module is loaded (this will cause it to # be used by default with most laptops), set to: battery # CPUFREQ=on EOF /sbin/depmod -a -b $PKG -F $PKG/boot/System.map $KVEREXTRA || exit 1 find $PKG/lib/modules/$KVEREXTRA -name '*.ko' -exec basename '{}' .ko \; | sort | sed 's,.*,# /sbin/modprobe -q &,' >> etc/rc.d/rc.modules for m in ac agpgart battery button fan fuse lp parport parport_pc processor thermal video acpi-cpufreq powernow-k6 powernow-k7 powernow-k8 speedstep-smi speedstep-ich speedstep-centrino gx-suspmod longrun longhaul cpufreq-nforce2 e_powersaver cpufreq_ondemand; do sed -ri 's,# (.* '$m'$),\1 2>/dev/null,' etc/rc.d/rc.modules done cat << 'EOF' >> etc/rc.d/rc.modules SCALING_GOVERNOR=ondemand # Try to enable the scaling_governor selected above: if [ -r /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors ]; then if grep -wq "$SCALING_GOVERNOR" /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors ; then if [ -r /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor ]; then for SYSCPUFILE in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor ; do echo "$SCALING_GOVERNOR" > $SYSCPUFILE done fi fi fi EOF chmod 755 etc/rc.d/rc.modules # copy files necessary for later builds, like nvidia, ati, vbox and vmware ( cd $SRC/linuxsrc mkdir -p $PKG/usr/src/linux-$KVER/include mkdir -p $PKG/usr/src/linux-$KVER/arch for i in acpi asm-generic config drm generated linux math-emu media net pcmcia scsi sound trace video xen; do cp -rf include/$i $PKG/usr/src/linux-$KVER/include/ done cp -rf arch/x86 $PKG/usr/src/linux-$KVER/arch/ cp -rf scripts Makefile Kbuild Module.symvers .config $PKG/usr/src/linux-$KVER/ # fix permissions on scripts dir chmod 755 -R $PKG/usr/src/linux-$KVER/scripts # add video headers mkdir -p $PKG/usr/src/linux-$KVER/drivers/video for i in $(find drivers/video -name "*.h"); do mkdir -p $PKG/usr/src/linux-$KVER/$(dirname $i) cp $i $PKG/usr/src/linux-$KVER/$i done # add md headers mkdir -p $PKG/usr/src/linux-$KVER/drivers/md cp drivers/md/*.h $PKG/usr/src/linux-$KVER/drivers/md # add wireless headers mkdir -p $PKG/usr/src/linux-$KVER/net/mac80211/ cp net/mac80211/*.h $PKG/usr/src/linux-$KVER/net/mac80211/ # add CLUSTERIP file for iptables mkdir -p $PKG/usr/src/linux-$KVER/net/ipv4/netfilter/ cp net/ipv4/netfilter/ipt_CLUSTERIP.c $PKG/usr/src/linux-$KVER/net/ipv4/netfilter/ # copy Kconfig files for i in $(find . -name "Kconfig*"); do mkdir -p $PKG/usr/src/linux-$KVER/$(dirname $i) cp $i $PKG/usr/src/linux-$KVER/$i done # delete the kernel binary in the sources rm -f $PKG/usr/src/linux-$KVER/arch/x86/boot/compressed/vmlinux $PKG/usr/src/linux-$KVER/arch/x86/boot/compressed/vmlinux.bin* $PKG/usr/src/linux-$KVER/arch/x86/boot/vmlinux.bin $PKG/usr/src/linux-$KVER/arch/x86/boot/bzImage # delete all .o files for i in $(find $PKG/usr/src/linux-$KVER -name '*.o'); do rm -f $i done ) # fix build and source link in /lib/modules/XXX/ ( cd $PKG/lib/modules/$KVEREXTRA/ rm -f build && ln -s /usr/src/linux-$KVER build rm -f source && ln -s /usr/src/linux-$KVER source ) }