Added rootfs resize, automatic swap and Wi-Fi activation

This commit is contained in:
Michel-FK 2018-03-04 19:10:30 +01:00
parent bc1e2a6a8d
commit f1c81cc332
12 changed files with 268 additions and 235 deletions

View File

@ -30,6 +30,6 @@ image sdcard.img {
partition rootfs {
partition-type = 0x83
image = "rootfs.ext4"
size = 60M
size = 0
}
}

View File

@ -1,8 +1,13 @@
#!/bin/sh
BOARD_DIR="$( dirname "${0}" )"
MKIMAGE="${HOST_DIR}/bin/mkimage"
MKSWAP="${HOST_DIR}/sbin/mkswap"
BOOT_CMD="${BOARD_DIR}/boot.cmd"
BOOT_CMD_H="${BINARIES_DIR}/boot.scr"
# U-Boot script
"${MKIMAGE}" -C none -A arm -T script -d "${BOOT_CMD}" "${BOOT_CMD_H}"
# Swap
sed -i '/^\/swap/d' "${TARGET_DIR}/etc/fstab"
echo "/swap none swap defaults 0 0" >> "${TARGET_DIR}/etc/fstab"

View File

@ -1,68 +0,0 @@
#!/bin/sh
########################################################################
#
# Description : Module auto-loading script
#
# Authors : Zack Winkles
#
# Version : 00.00
#
# Notes :
#
########################################################################
. /etc/sysconfig/functions
# Assure that the kernel has module support.
[ -e /proc/ksyms -o -e /proc/modules ] || exit 0
case "${1}" in
start)
# Exit if there's no modules file or there are no
# valid entries
[ -r /etc/sysconfig/modules ] &&
egrep -qv '^($|#)' /etc/sysconfig/modules ||
exit 0
boot_mesg -n "Loading modules:" ${INFO}
# Only try to load modules if the user has actually given us
# some modules to load.
while read module args; do
# Ignore comments and blank lines.
case "$module" in
""|"#"*) continue ;;
esac
# Attempt to load the module, making
# sure to pass any arguments provided.
modprobe ${module} ${args} >/dev/null
# Print the module name if successful,
# otherwise take note.
if [ $? -eq 0 ]; then
boot_mesg -n " ${module}" ${NORMAL}
else
failedmod="${failedmod} ${module}"
fi
done < /etc/sysconfig/modules
boot_mesg "" ${NORMAL}
# Print a message about successfully loaded
# modules on the correct line.
echo_ok
# Print a failure message with a list of any
# modules that may have failed to load.
if [ -n "${failedmod}" ]; then
boot_mesg "Failed to load modules:${failedmod}" ${FAILURE}
echo_failure
fi
;;
*)
echo "Usage: ${0} {start}"
exit 1
;;
esac

View File

@ -0,0 +1,24 @@
#!/bin/sh
THIS=$(basename $0)
case "$1" in
start)
sleep 1
echo "$THIS: starting resizing the root partition" | tee /dev/kmsg &&
resize_rootfs &&
rm /etc/init.d/S02resize_rootfs
if [ $? -eq 0 ]; then
echo "$THIS: finished resizing the root partition, rebooting to enlarge the root filesystem" | tee /dev/kmsg
reboot
exit 0
else
echo "$THIS: cannot resize the root partition, aborting" | tee /dev/kmsg
exit 1
fi
;;
*)
echo "Usage: $0 start" >&2
exit 2
;;
esac

View File

@ -0,0 +1,54 @@
#!/bin/sh
THIS=$(basename $0)
case "$1" in
start)
if [ ! -f /swap ]; then
ROOT_PART=$(df | grep /dev/root)
set $ROOT_PART
let LEFT="$4 * 1024"
if [ $LEFT -lt 134217728 ]; then
echo "$THIS: not enough free space for swap file found, aborting" | tee /dev/kmsg
exit 1
fi
echo "$THIS: no swap file found, creating it" | tee /dev/kmsg &&
dd if=/dev/zero of=/swap bs=1M count=128 &&
mkswap /swap &&
chmod 0600 /swap
if [ $? -eq 0 ]; then
echo "$THIS: created swap file" | tee /dev/kmsg
else
echo "$THIS: cannot create swap file, aborting" | tee /dev/kmsg
rm /swap
exit 2
fi
fi
echo "$THIS: enabling swap file" | tee /dev/kmsg &&
swapon -a
if [ $? -eq 0 ]; then
echo "$THIS: swap file enabled" | tee /dev/kmsg
else
echo "$THIS: cannot enable swap file, aborting" | tee /dev/kmsg
exit 3
fi
;;
stop)
echo "$THIS: disabling swap file" | tee /dev/kmsg &&
swapoff -a
if [ $? -eq 0 ]; then
echo "$THIS: swap file disabled" | tee /dev/kmsg
else
echo "$THIS: cannot disable swap file, aborting" | tee /dev/kmsg
exit 4
fi
;;
restart|reload)
"$0" stop
"$0" start
;;
*)
echo "Usage: $0 {start|stop|restart|reload}" >&2
exit 5
;;
esac

View File

@ -0,0 +1,52 @@
#!/bin/sh
# Assure that the kernel has module support.
[ -e /proc/ksyms -o -e /proc/modules ] || exit 0
THIS=$(basename $0)
case "${1}" in
start)
# Exit if there's no modules file or there are no
# valid entries
if [ -r /etc/sysconfig/modules ]; then
egrep -qv '^($|#)' /etc/sysconfig/modules
if [ $? -ne 0 ]; then
echo "$THIS: no module found in /etc/sysconfig/modules" | tee/dev/kmsg
exit 0
fi
fi
echo "$THIS: loading modules from /etc/sysconfig/modules:" | tee/dev/kmsg
# Only try to load modules if the user has actually given us
# some modules to load.
while read MODULE ARGS; do
# Ignore comments and blank lines.
case "$MODULE" in
""|"#"*) continue ;;
esac
# Attempt to load the module, making
# sure to pass any arguments provided.
modprobe ${MODULE} ${ARGS} >/dev/null
# Print the module name if successful,
# otherwise take note.
if [ $? -eq 0 ]; then
echo "$THIS: loaded module ${MODULE}" | tee /dev/kmsg
else
echo "$THIS: failed to load module ${MODULE}" | tee /dev/kmsg
fi
done < /etc/sysconfig/modules
# Print a message about successfully loaded
# modules on the correct line.
echo "$THIS: finished loading modules" | tee /dev/kmsg
;;
*)
echo "Usage: ${0} {start}"
exit 1
;;
esac

View File

@ -1,9 +0,0 @@
auto lo
iface lo inet loopback
auto wlan0
iface wlan0 inet dhcp
wireless-essid "SSID"
wireless-key "password"
pre-up wpa_supplicant -Dnl80211 -i wlan0 -c /etc/wpa_supplicant.conf -B
post-down killall -q wpa_supplicant

View File

@ -1,145 +0,0 @@
#!/bin/sh
#######################################################################
#
# Description : Run Level Control Functions
#
# Authors : Gerard Beekmans - gerard@linuxfromscratch.org
#
# Version : 00.00
#
# Notes : With code based on Matthias Benkmann's simpleinit-msb
# http://winterdrache.de/linux/newboot/index.html
#
########################################################################
## Environmental setup
# Setup default values for environment
umask 022
export PATH="/bin:/usr/bin:/sbin:/usr/sbin"
# Signal sent to running processes to refresh their configuration
RELOADSIG="HUP"
# Number of seconds between STOPSIG and FALLBACK when stopping processes
KILLDELAY="3"
## Screen Dimensions
# Find current screen size
if [ -z "${COLUMNS}" ]; then
COLUMNS=$(stty size)
COLUMNS=${COLUMNS##* }
fi
# When using remote connections, such as a serial port, stty size returns 0
if [ "${COLUMNS}" = "0" ]; then
COLUMNS=80
fi
## Measurements for positioning result messages
COL=$((${COLUMNS} - 8))
WCOL=$((${COL} - 2))
## Provide an echo that supports -e and -n
# If formatting is needed, $ECHO should be used
case "`echo -e -n test`" in
-[en]*)
ECHO=/bin/echo
;;
*)
ECHO=echo
;;
esac
## Set Cursor Position Commands, used via $ECHO
SET_COL="\\033[${COL}G" # at the $COL char
SET_WCOL="\\033[${WCOL}G" # at the $WCOL char
CURS_UP="\\033[1A\\033[0G" # Up one line, at the 0'th char
## Set color commands, used via $ECHO
# Please consult `man console_codes for more information
# under the "ECMA-48 Set Graphics Rendition" section
#
# Warning: when switching from a 8bit to a 9bit font,
# the linux console will reinterpret the bold (1;) to
# the top 256 glyphs of the 9bit font. This does
# not affect framebuffer consoles
NORMAL="\\033[0;39m" # Standard console grey
SUCCESS="\\033[1;32m" # Success is green
WARNING="\\033[1;33m" # Warnings are yellow
FAILURE="\\033[1;31m" # Failures are red
INFO="\\033[1;36m" # Information is light cyan
BRACKET="\\033[1;34m" # Brackets are blue
STRING_LENGTH="0" # the length of the current message
#*******************************************************************************
# Function - boot_mesg()
#
# Purpose: Sending information from bootup scripts to the console
#
# Inputs: $1 is the message
# $2 is the colorcode for the console
#
# Outputs: Standard Output
#
# Dependencies: - sed for parsing strings.
# - grep for counting string length.
#
# Todo:
#*******************************************************************************
boot_mesg()
{
local ECHOPARM=""
while true
do
case "${1}" in
-n)
ECHOPARM=" -n "
shift 1
;;
-*)
echo "Unknown Option: ${1}"
return 1
;;
*)
break
;;
esac
done
## Figure out the length of what is to be printed to be used
## for warning messages.
STRING_LENGTH=$((${#1} + 1))
# Print the message to the screen
${ECHO} ${ECHOPARM} -e "${2}${1}"
}
boot_mesg_flush()
{
# Reset STRING_LENGTH for next message
STRING_LENGTH="0"
}
echo_ok()
{
${ECHO} -n -e "${CURS_UP}${SET_COL}${BRACKET}[${SUCCESS} OK ${BRACKET}]"
${ECHO} -e "${NORMAL}"
boot_mesg_flush
}
echo_failure()
{
${ECHO} -n -e "${CURS_UP}${SET_COL}${BRACKET}[${FAILURE} FAIL ${BRACKET}]"
${ECHO} -e "${NORMAL}"
boot_mesg_flush
}
echo_warning()
{
${ECHO} -n -e "${CURS_UP}${SET_COL}${BRACKET}[${WARNING} WARN ${BRACKET}]"
${ECHO} -e "${NORMAL}"
boot_mesg_flush
}

View File

@ -1,12 +0,0 @@
ctrl_interface=/var/run/wpa_supplicant
ctrl_interface_group=0
ap_scan=1
network={
ssid="SSID"
psk="password"
scan_ssid=1
key_mgmt=WPA-EAP WPA-PSK IEEE8021X NONE
pairwise=TKIP CCMP
group=CCMP TKIP WEP104 WEP40
priority=5
}

View File

@ -0,0 +1,45 @@
#!/bin/sh
#set -x
THIS=$(basename $0)
if [ $(id -u) -ne 0 ]; then
echo "This script must be run as root. Try 'sudo activate_wifi <SSID> <password>'" >&2
exit 1
fi
if [ $# -ne 2 ]; then
echo "Usage: ${0} <SSID> <password>" >&2
exit 2
fi
SSID=${1}
PASSWORD=${2}
cat <<EOF > /etc/wpa_supplicant.conf
ctrl_interface=/var/run/wpa_supplicant
ctrl_interface_group=0
ap_scan=1
network={
ssid="$SSID"
psk="$PASSWORD"
scan_ssid=1
key_mgmt=WPA-EAP WPA-PSK IEEE8021X NONE
pairwise=TKIP CCMP
group=CCMP TKIP WEP104 WEP40
priority=5
}
EOF
egrep '^iface wlan0' /etc/network/interfaces
if [ $? -ne 0 ]; then
cat <<EOF >>/etc/network/interfaces
auto wlan0
iface wlan0 inet dhcp
pre-up wpa_supplicant -Dnl80211 -i wlan0 -c /etc/wpa_supplicant.conf -B
post-down killall -q wpa_supplicant
EOF
fi
ifup wlan0

View File

@ -0,0 +1,80 @@
#!/bin/sh
#set -x
THIS=$(basename $0)
echo "$THIS: resizing rootfs" | tee /dev/kmsg
if [ $(id -u) -ne 0 ]; then
echo "$THIS: this script must be run as root. Try 'sudo resize_rootfs'\n" | tee /dev/kmsg
exit 1
fi
ROOT_PART=$(cat /proc/cmdline | sed -n 's|^.*root=/dev/\([^ ]*\).*|\1|p')
PART_NUM=${ROOT_PART#mmcblk0p}
if [ "$PART_NUM" = "$ROOT_PART" ]; then
echo "$THIS: $ROOT_PART is not an SD card. Don't know how to expand" | tee /dev/kmsg
exit 2
fi
if [ "$PART_NUM" -ne 2 ]; then
echo "$THIS: your partition layout is not currently supported by this tool" | tee /dev/kmsg
exit 3
fi
LAST_PART_LINE=$(fdisk /dev/mmcblk0 -l | grep '^/' | tail -n 1)
set $LAST_PART_LINE
LAST_PART=${1#/dev/}
PART_START=${2}
if [ "$LAST_PART" != "$ROOT_PART" ]; then
echo "$THIS: $ROOT_PART is not the last partition. Don't know how to expand" | tee /dev/kmsg
exit 4
fi
# Return value will likely be error for fdisk as it fails to reload the
# partition table because the root fs is mounted
# NOTE: This script only works the genuine fdisk, NOT with the busybox one!!!
fdisk /dev/mmcblk0 <<EOF
p
d
$PART_NUM
n
p
$PART_NUM
$PART_START
n
p
w
EOF
sync
# Now set up an init.d script
cat <<EOF > /etc/init.d/S02resize2fs &&
#!/bin/sh
THIS=\$(basename \$0)
case "\$1" in
start)
sleep 1
echo "\$THIS: starting resizing the root filesystem" | tee /dev/kmsg &&
resize2fs /dev/$ROOT_PART &&
rm /etc/init.d/S02resize2fs
if [ \$? -eq 0 ]; then
echo "\$THIS: finished resizing the root filesystem" | tee /dev/kmsg
else
echo "\$THIS: cannot resize the root filesystem, aborting" | tee /dev/kmsg
fi
;;
*)
echo "Usage: \$0 start" >&2
exit 3
;;
esac
EOF
chmod +x /etc/init.d/S02resize2fs
echo "$THIS: the root partition has been resized" | tee /dev/kmsg
echo "$THIS: the system must reboot to enlarge the root filesystem" | tee /dev/kmsg

View File

@ -47,6 +47,10 @@ BR2_LINUX_KERNEL_INTREE_DTS_NAME="sun8i-v3s-licheepi-zero sun8i-v3s-licheepi-zer
# Custom BusyBox configuration
BR2_PACKAGE_BUSYBOX_CONFIG="$(BR2_EXTERNAL_FUNKEY_PATH)/board/funkey/busybox.config"
# E2fsprog package for e2fsck and resize2fs
BR2_PACKAGE_E2FSPROGS=y
BR2_PACKAGE_E2FSPROGS_RESIZE2FS=y
# SDL package for Retro games
BR2_PACKAGE_SDL=y
BR2_PACKAGE_SDL_GFX=y
@ -67,6 +71,9 @@ BR2_PACKAGE_WPA_SUPPLICANT=y
BR2_PACKAGE_WPA_SUPPLICANT_AUTOSCAN=y
BR2_PACKAGE_WPA_SUPPLICANT_PASSPHRASE=y
# Util-linux package for fdisk
BR2_PACKAGE_UTIL_LINUX_BINARIES=y
# Nano text editor package
BR2_PACKAGE_NANO=y