|
|
|
@ -4,10 +4,9 @@ source /etc/make.conf
|
|
|
|
|
progname=cl-kernel
|
|
|
|
|
OVERLAY_DIRECTORY="/usr/local/portage/layman/calculate"
|
|
|
|
|
KERNEL_CONFIG_DIR="${OVERLAY_DIRECTORY}/profiles/kernel"
|
|
|
|
|
MODULESDBFILE=/var/lib/module-rebuild/moduledb
|
|
|
|
|
|
|
|
|
|
SHORTOPTS="k:c:e:ho"
|
|
|
|
|
LONGOPTS="help,kerneldir:,kernel-config:,extraversion:,no-clean,menuconfig,use-own-config"
|
|
|
|
|
SHORTOPTS="k:c:e:hmoq"
|
|
|
|
|
LONGOPTS="help,kerneldir:,kernel-config:,extraversion:,no-clean,menuconfig,use-own-config,quiet"
|
|
|
|
|
|
|
|
|
|
print_help() {
|
|
|
|
|
cat <<'EOF'
|
|
|
|
@ -20,9 +19,10 @@ Options:
|
|
|
|
|
-e, --extraversion VER Specify extraversion for kernel
|
|
|
|
|
-h, --help Print this help message
|
|
|
|
|
-k, --kerneldir DIR Location of the kernel sources
|
|
|
|
|
--menuconfig Run menuconfig after oldconfig
|
|
|
|
|
-m, --menuconfig Run menuconfig after oldconfig
|
|
|
|
|
--no-clean Do not run make clean before compilation
|
|
|
|
|
-o, --use-own-config Use config from kernel directory.
|
|
|
|
|
-q, --quiet Do not display kernel compilation process
|
|
|
|
|
|
|
|
|
|
Examples:
|
|
|
|
|
|
|
|
|
@ -35,36 +35,6 @@ The most common use is to run it like this, which build and install current kern
|
|
|
|
|
EOF
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Using: rm_link_with_file filename
|
|
|
|
|
rm_link_with_file() {
|
|
|
|
|
[[ -L $1 ]] && rm -f `readlink -f $1`
|
|
|
|
|
rm -f $1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Using: cp_link_with_file filename suffix
|
|
|
|
|
cp_link_with_file() {
|
|
|
|
|
if [[ -L $1 ]]
|
|
|
|
|
then
|
|
|
|
|
rm -f `readlink -f ${1}`$2
|
|
|
|
|
cp -aH ${1} `readlink -f ${1}`$2
|
|
|
|
|
ln -sf `readlink ${1}`${2} ${1}${2}
|
|
|
|
|
else
|
|
|
|
|
rm -f ${1}${2}
|
|
|
|
|
cp -aH ${1} ${1}${2}
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Using: make_old_file filename (result filename.old)
|
|
|
|
|
# Description: move filename to filename.old (support symlinking)
|
|
|
|
|
make_old_file() {
|
|
|
|
|
if [[ -e $1 ]]
|
|
|
|
|
then
|
|
|
|
|
rm_link_with_file $1.old
|
|
|
|
|
cp_link_with_file $1 .old
|
|
|
|
|
fi
|
|
|
|
|
rm_link_with_file $1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parse_kernel_version() {
|
|
|
|
|
if [[ ${KERNEL_VERSION} =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)([-.].+)?$ ]]
|
|
|
|
|
then
|
|
|
|
@ -91,15 +61,22 @@ die() {
|
|
|
|
|
exit 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get_value() {
|
|
|
|
|
sed -rn "s/^$1=\"?([^\"]*)\"?$/\1/p" $2
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set_param() {
|
|
|
|
|
local paramname=$1
|
|
|
|
|
local paramvalue=$2
|
|
|
|
|
local filename=$3
|
|
|
|
|
sed -ri "s/^$paramname = .*$/$paramname = $paramvalue/" $filename
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set_kernel_version() {
|
|
|
|
|
sed -ri "s/^VERSION = .*$/VERSION = $KV_MAJOR/" \
|
|
|
|
|
${KERNEL_DIR}/Makefile
|
|
|
|
|
sed -ri "s/^PATCHLEVEL = .*$/PATCHLEVEL = $KV_MINOR/" \
|
|
|
|
|
${KERNEL_DIR}/Makefile
|
|
|
|
|
sed -ri "s/^SUBLEVEL = .*$/SUBLEVEL = $KV_PATCH/" \
|
|
|
|
|
${KERNEL_DIR}/Makefile
|
|
|
|
|
sed -ri "s/^EXTRAVERSION = .*$/EXTRAVERSION = $KV_TYPE/" \
|
|
|
|
|
${KERNEL_DIR}/Makefile
|
|
|
|
|
set_param VERSION $KV_MAJOR ${KERNEL_DIR}/Makefile
|
|
|
|
|
set_param PATCHLEVEL $KV_MINOR ${KERNEL_DIR}/Makefile
|
|
|
|
|
set_param SUBLEVEL $KV_PATCH ${KERNEL_DIR}/Makefile
|
|
|
|
|
set_param EXTRAVERSION $KV_TYPE ${KERNEL_DIR}/Makefile
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
initramfs_unpack() {
|
|
|
|
@ -113,41 +90,23 @@ initramfs_unpack() {
|
|
|
|
|
&>/dev/null && arcmd="lzma"
|
|
|
|
|
${arcmd} -dc ${BOOT_DIR}/initramfs-${KERNEL_NAME}-*-${KERNEL_VERSION} |
|
|
|
|
|
cpio -di &>/dev/null || die "Cann't unpack initramfs"
|
|
|
|
|
# remove old initramfs
|
|
|
|
|
rm ${BOOT_DIR}/initramfs-${KERNEL_NAME}-*-${KERNEL_VERSION} ||
|
|
|
|
|
warning "Cann't remove old initramfs"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
initramfs_clean() {
|
|
|
|
|
# remove sound moudles
|
|
|
|
|
find -name sound -exec rm -rf {} \; &>/dev/null
|
|
|
|
|
# remove splash images if need
|
|
|
|
|
[[ ${REMOVE_SPLASH} == 'true' ]] &&
|
|
|
|
|
rm etc/splash/tty1/images/* >/dev/null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
initramfs_pack() {
|
|
|
|
|
make_old_file ${BOOT_DIR}/initrd
|
|
|
|
|
# pack new initramfs
|
|
|
|
|
find * | cpio -o --quiet -H newc |
|
|
|
|
|
gzip -9 >${BOOT_DIR}/initramfs-${KERNEL_VERSION} ||
|
|
|
|
|
gzip -9 >${BOOT_DIR}/initramfs-${KERNEL_NAME}-*-${KERNEL_VERSION} ||
|
|
|
|
|
die "Cann't pack initramfs"
|
|
|
|
|
popd &>/dev/null
|
|
|
|
|
rm -rf tmp/initramfs ||
|
|
|
|
|
warning "Cann't remove temporary directory contenting initramfs"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rename_kernel_systemmap() {
|
|
|
|
|
# rename kernel (remove arch from name)
|
|
|
|
|
mv ${BOOT_DIR}/kernel-${KERNEL_NAME}-*-${KERNEL_VERSION} \
|
|
|
|
|
${BOOT_DIR}/vmlinuz-${KERNEL_VERSION} ||
|
|
|
|
|
die "Cann't rename kernel"
|
|
|
|
|
# rename systemmap (remove arch from name)
|
|
|
|
|
mv ${BOOT_DIR}/System.map-${KERNEL_NAME}-*-${KERNEL_VERSION} \
|
|
|
|
|
${BOOT_DIR}/System.map-${KERNEL_VERSION} ||
|
|
|
|
|
die "Cann't rename System.map"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set_new_current_kernel() {
|
|
|
|
|
# set new current kernel
|
|
|
|
|
if [[ ${KERNEL_DIR} != '/usr/src/linux' ]]
|
|
|
|
@ -168,66 +127,54 @@ set_new_current_kernel() {
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
install_kernel() {
|
|
|
|
|
make_old_file ${BOOT_DIR}/System.map
|
|
|
|
|
make_old_file ${BOOT_DIR}/vmlinuz
|
|
|
|
|
rename_kernel_systemmap
|
|
|
|
|
# change kernel (make symlink)
|
|
|
|
|
ln -sf vmlinuz-${KERNEL_VERSION} ${BOOT_DIR}/vmlinuz ||
|
|
|
|
|
warning "Cann't make vmlinuz link"
|
|
|
|
|
# change System.map (make symlink)
|
|
|
|
|
ln -sf System.map-${KERNEL_VERSION} \
|
|
|
|
|
${BOOT_DIR}/System.map || warning "Cann't make System.map link"
|
|
|
|
|
# change initramfs (make symlink)
|
|
|
|
|
ln -sf initramfs-${KERNEL_VERSION} ${BOOT_DIR}/initrd ||
|
|
|
|
|
warning "Cann't make initrd link"
|
|
|
|
|
# copy config
|
|
|
|
|
make_old_file ${BOOT_DIR}/config-${KERNEL_VERSION}
|
|
|
|
|
cp ${KERNEL_CONFIG} ${BOOT_DIR}/config-${KERNEL_VERSION}
|
|
|
|
|
set_new_current_kernel
|
|
|
|
|
sed -ri 's/a:1:sys-fs\/aufs2/a:0:sys-fs\/aufs2/' $MODULESDBFILE
|
|
|
|
|
calculate --initrd
|
|
|
|
|
# mv file to file with suffix and fix symlink to this file
|
|
|
|
|
old_file() {
|
|
|
|
|
local dir=$1
|
|
|
|
|
local filename=$2
|
|
|
|
|
local suffix=$3
|
|
|
|
|
mv -f ${dir}/${filename} ${dir}/${filename}${suffix} &>/dev/null &&
|
|
|
|
|
[[ -f ${dir}/${filename}${suffix} ]] &&
|
|
|
|
|
find ${dir} -lname "$filename" -exec ln -sf ${filename}${suffix} {} \;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
make_tarball() {
|
|
|
|
|
rename_kernel_systemmap
|
|
|
|
|
# remove symlink for tarball
|
|
|
|
|
find lib -type l -delete ||
|
|
|
|
|
warning "Cann't delete symbolic links"
|
|
|
|
|
# get some files from kernel sources
|
|
|
|
|
ABSKERNEL_DIR="$(dirname `readlink -f $KERNEL_DIR/Makefile`)"
|
|
|
|
|
mkdir -p `pwd`${ABSKERNEL_DIR}/include/linux ||
|
|
|
|
|
die "Cann't create kernel sources directory"
|
|
|
|
|
pushd `pwd`${ABSKERNEL_DIR} &>/dev/null
|
|
|
|
|
cp ${ABSKERNEL_DIR}/.config . ||
|
|
|
|
|
die "Cann't copy kernel config"
|
|
|
|
|
cp ${ABSKERNEL_DIR}/System.map . ||
|
|
|
|
|
die "Cann't copy System.map"
|
|
|
|
|
cp ${ABSKERNEL_DIR}/Module.symvers . ||
|
|
|
|
|
die "Cann't copy Module.symvers"
|
|
|
|
|
cd include/linux
|
|
|
|
|
cp ${ABSKERNEL_DIR}/include/linux/version.h . ||
|
|
|
|
|
die "Cann't copy version header"
|
|
|
|
|
popd &>/dev/null
|
|
|
|
|
tar cjf ${KERNEL_TARBALL} boot lib usr ||
|
|
|
|
|
die "Cann't create kernel tarbal"
|
|
|
|
|
install_kernel() {
|
|
|
|
|
old_file ${BOOT_DIR} vmlinuz-${KERNEL_VERSION} .old
|
|
|
|
|
old_file ${BOOT_DIR} System.map-${KERNEL_VERSION} .old
|
|
|
|
|
old_file ${BOOT_DIR} initramfs-${KERNEL_VERSION} .old
|
|
|
|
|
old_file ${BOOT_DIR} initramfs-${KERNEL_VERSION}-install .old
|
|
|
|
|
old_file ${BOOT_DIR} vmlinuz .old
|
|
|
|
|
old_file ${BOOT_DIR} System.map .old
|
|
|
|
|
old_file ${BOOT_DIR} initrd .old
|
|
|
|
|
old_file ${BOOT_DIR} initrd-install .old
|
|
|
|
|
old_file ${BOOT_DIR} config-${KERNEL_VERSION} .old
|
|
|
|
|
mv ${BOOT_DIR}/kernel-${KERNEL_NAME}-*-${KERNEL_VERSION} \
|
|
|
|
|
${BOOT_DIR}/vmlinuz-${KERNEL_VERSION}
|
|
|
|
|
ln -sf vmlinuz-${KERNEL_VERSION} ${BOOT_DIR}/vmlinuz
|
|
|
|
|
mv ${BOOT_DIR}/System.map-${KERNEL_NAME}-*-${KERNEL_VERSION} \
|
|
|
|
|
${BOOT_DIR}/System.map-${KERNEL_VERSION}
|
|
|
|
|
ln -sf System.map-${KERNEL_VERSION} ${BOOT_DIR}/System.map
|
|
|
|
|
cp ${BOOT_DIR}/initramfs-${KERNEL_NAME}-*-${KERNEL_VERSION} \
|
|
|
|
|
${BOOT_DIR}/initramfs-${KERNEL_VERSION}
|
|
|
|
|
ln -sf initramfs-${KERNEL_VERSION} ${BOOT_DIR}/initrd
|
|
|
|
|
mv ${BOOT_DIR}/initramfs-${KERNEL_NAME}-*-${KERNEL_VERSION} \
|
|
|
|
|
${BOOT_DIR}/initramfs-${KERNEL_VERSION}-install
|
|
|
|
|
ln -sf initramfs-${KERNEL_VERSION}-install ${BOOT_DIR}/initrd-install
|
|
|
|
|
cp ${KERNEL_DIR}/.config ${BOOT_DIR}/config-${KERNEL_VERSION}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
KERNEL_DIR=/usr/src/linux
|
|
|
|
|
KERNEL_CONFIG=
|
|
|
|
|
USE_OWN_CONFIG=false
|
|
|
|
|
KERNEL_TARBALL=
|
|
|
|
|
SYSTEMNAME=$(sed -nr '/^system/ s/^[^=]+=(.*)$/\1/p' \
|
|
|
|
|
/etc/calculate/calculate.ini)
|
|
|
|
|
SYSTEMNAME=$(sed -nr '/^system=/ s/^[^=]+=(.*)$/\1/p' \
|
|
|
|
|
/etc/calculate/calculate.ini)
|
|
|
|
|
KERNEL_NAME=${SYSTEMNAME}
|
|
|
|
|
KERNEL_VERSION=
|
|
|
|
|
DESTINATION=
|
|
|
|
|
KERNEL_EXTRAVERSION=
|
|
|
|
|
REMOVE_SPLASH=false
|
|
|
|
|
ARCH=`arch`
|
|
|
|
|
NO_INSTALL=false
|
|
|
|
|
NOCLEAN=""
|
|
|
|
|
MENUCONFIG=""
|
|
|
|
|
LOGLEVEL="--loglevel=2"
|
|
|
|
|
|
|
|
|
|
OPTS=$(getopt -o $SHORTOPTS --long $LONGOPTS -n "$progname" -- "$@")
|
|
|
|
|
|
|
|
|
@ -243,7 +190,7 @@ while [ $# -gt 0 ]; do
|
|
|
|
|
print_help
|
|
|
|
|
exit 0
|
|
|
|
|
;;
|
|
|
|
|
--menuconfig)
|
|
|
|
|
-m|--menuconfig)
|
|
|
|
|
MENUCONFIG="--menuconfig"
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
@ -267,26 +214,14 @@ while [ $# -gt 0 ]; do
|
|
|
|
|
KERNEL_CONFIG=$2
|
|
|
|
|
shift 2
|
|
|
|
|
;;
|
|
|
|
|
-t|--make-tarball)
|
|
|
|
|
KERNEL_TARBALL=$2
|
|
|
|
|
shift 2
|
|
|
|
|
;;
|
|
|
|
|
-r|--remove-splash)
|
|
|
|
|
REMOVE_SPLASH=true
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
-n|--kernel-name)
|
|
|
|
|
KERNEL_NAME=$2
|
|
|
|
|
shift 2
|
|
|
|
|
;;
|
|
|
|
|
-v|--kernel-version)
|
|
|
|
|
KERNEL_VERSION=$2
|
|
|
|
|
shift 2
|
|
|
|
|
;;
|
|
|
|
|
-e|--extraversion)
|
|
|
|
|
KERNEL_EXTRAVERSION=$2
|
|
|
|
|
shift 2
|
|
|
|
|
;;
|
|
|
|
|
-q|--quiet)
|
|
|
|
|
LOGLEVEL="--loglevel=1"
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
--)
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
@ -302,21 +237,15 @@ done
|
|
|
|
|
|
|
|
|
|
[[ -z ${DESTINATION} ]] && DESTINATION="/"
|
|
|
|
|
|
|
|
|
|
# if kernel_version not defined get it from Makefile of sources
|
|
|
|
|
[[ -z ${KERNEL_VERSION} ]] && \
|
|
|
|
|
KERNEL_VERSION=`grep \
|
|
|
|
|
-e ^VERSION -e ^PATCHLEVEL -e ^SUBLEVEL -e ^EXTRAVERSION \
|
|
|
|
|
${KERNEL_DIR}/Makefile \
|
|
|
|
|
| sed -rn "{N;N;N;s/PATCHLEVEL = |SUBLEVEL = /./g;
|
|
|
|
|
s/EXTRAVERSION = |VERSION = |\n//g;p}"`
|
|
|
|
|
# get it from Makefile of sources
|
|
|
|
|
KERNEL_VERSION=`grep \
|
|
|
|
|
-e ^VERSION -e ^PATCHLEVEL -e ^SUBLEVEL -e ^EXTRAVERSION \
|
|
|
|
|
${KERNEL_DIR}/Makefile \
|
|
|
|
|
| sed -rn "{N;N;N;s/PATCHLEVEL = |SUBLEVEL = /./g;
|
|
|
|
|
s/EXTRAVERSION = |VERSION = |\n//g;p}"`
|
|
|
|
|
|
|
|
|
|
MODULE_INS_PATH=${DESTINATION}
|
|
|
|
|
mkdir -p ${DESTINATION}
|
|
|
|
|
# tarball should be created in empty directory
|
|
|
|
|
if [[ -n ${KERNEL_TARBALL} ]] && [[ $(ls $DESTINATION | wc -l ) -gt 2 ]];
|
|
|
|
|
then
|
|
|
|
|
die "tarball should be created in empty directory, need specify destination"
|
|
|
|
|
fi
|
|
|
|
|
BOOT_DIR=${DESTINATION%/}/boot
|
|
|
|
|
|
|
|
|
|
# if specify extraversion add - or . before extraversion if it is missed
|
|
|
|
@ -343,16 +272,9 @@ if [[ ${USE_OWN_CONFIG} != "false" ]] ||
|
|
|
|
|
$( readlink -f "${KERNEL_DIR}/.config" ) ]]
|
|
|
|
|
then
|
|
|
|
|
KERNEL_CONFIG="${KERNEL_DIR}/.config.bak"
|
|
|
|
|
if [[ ${USE_OWN_CONFIG} != "false" ]] &&
|
|
|
|
|
[[ ! -e ${KERNEL_DIR}/.config ]]
|
|
|
|
|
then
|
|
|
|
|
pushd ${KERNEL_DIR} &>/dev/null
|
|
|
|
|
make oldconfig </dev/null || die "Cannot perform oldconfig."
|
|
|
|
|
popd &>/dev/null
|
|
|
|
|
fi
|
|
|
|
|
[[ -e ${KERNEL_DIR}/.config ]] &&
|
|
|
|
|
cp ${KERNEL_DIR}/.config ${KERNEL_CONFIG} ||
|
|
|
|
|
die "Not found .config in ${KERNEL_DIR}"
|
|
|
|
|
cp ${KERNEL_DIR}/.config ${KERNEL_CONFIG} ||
|
|
|
|
|
die "Not found .config in ${KERNEL_DIR}"
|
|
|
|
|
fi
|
|
|
|
|
[[ -z ${KERNEL_CONFIG} ]] &&
|
|
|
|
|
KERNEL_CONFIG="${KERNEL_CONFIG_DIR}/config-${SYSTEMNAME}-${ARCH}-${OKV}"
|
|
|
|
@ -362,18 +284,22 @@ fi
|
|
|
|
|
|
|
|
|
|
mkdir -p ${BOOT_DIR}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# run generating kernel
|
|
|
|
|
genkernel --splash=tty1 --unionfs --all-ramdisk-modules --disklabel \
|
|
|
|
|
--slowusb --kerneldir=${KERNEL_DIR} \
|
|
|
|
|
--slowusb --kerneldir=${KERNEL_DIR} ${LOGLEVEL} \
|
|
|
|
|
--module-prefix=${MODULE_INS_PATH} --makeopts=${MAKEOPTS} \
|
|
|
|
|
${NOCLEAN} ${MENUCONFIG} --no-save-config \
|
|
|
|
|
--kernel-config=${KERNEL_CONFIG} --kernname=${KERNEL_NAME} \
|
|
|
|
|
--bootdir=${BOOT_DIR} all || die "kernel was not builded"
|
|
|
|
|
|
|
|
|
|
KERNEL_LOCALVERSION=$( get_value CONFIG_LOCALVERSION ${KERNEL_DIR}/.config )
|
|
|
|
|
KERNEL_VERSION=${KERNEL_VERSION}${KERNEL_LOCALVERSION}
|
|
|
|
|
|
|
|
|
|
pushd ${DESTINATION} &>/dev/null
|
|
|
|
|
|
|
|
|
|
initramfs_unpack
|
|
|
|
|
initramfs_clean
|
|
|
|
|
initramfs_pack
|
|
|
|
|
# if specified tarball then make archive else install kernel
|
|
|
|
|
[[ -n ${KERNEL_TARBALL} ]] && make_tarball || install_kernel
|
|
|
|
|
install_kernel
|
|
|
|
|
set_new_current_kernel
|
|
|
|
|
calculate --initrd
|
|
|
|
|