From 2f8a10dcf99260a30600d4ebd7d69fd1fa9b738e Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Mon, 9 Nov 2015 01:53:28 +0200 Subject: [PATCH] initial data partition creation no longer requires two boots --- board/common/cleanups.sh | 1 - board/common/overlay/etc/fstab | 6 +-- board/common/overlay/etc/init.d/S11datapart | 46 +++++---------------- board/common/overlay/etc/init.d/S40network | 4 +- board/common/overlay/etc/init.d/S50sshd | 1 - board/common/overlay/sbin/reboot | 1 + 6 files changed, 16 insertions(+), 43 deletions(-) diff --git a/board/common/cleanups.sh b/board/common/cleanups.sh index 9e6567a082..03515aa22b 100755 --- a/board/common/cleanups.sh +++ b/board/common/cleanups.sh @@ -37,7 +37,6 @@ rm -f $TARGET/sbin/fdformat rm -f $TARGET/sbin/ctrlaltdel rm -f $TARGET/bin/findmnt rm -f $TARGET/usr/bin/colcrt -rm -f $TARGET/usr/sbin/partx rm -f $TARGET/sbin/fsfreeze rm -f $TARGET/usr/bin/colrm rm -f $TARGET/usr/sbin/addpart diff --git a/board/common/overlay/etc/fstab b/board/common/overlay/etc/fstab index de805c05cf..5da62f5656 100644 --- a/board/common/overlay/etc/fstab +++ b/board/common/overlay/etc/fstab @@ -1,11 +1,11 @@ -# /etc/fstab: static file system information. -# # /dev/mmcblk0p1 /boot vfat ro,defaults 0 0 -/dev/mmcblk0p3 /data auto defaults,noatime 0 0 +/dev/mmcblk0p3 /data ext4 defaults,noatime 0 0 proc /proc proc defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 tmpfs /dev/shm tmpfs mode=0777 0 0 tmpfs /tmp tmpfs mode=1777 0 0 sysfs /sys sysfs defaults 0 0 +/data/output /home/ftp/sdcard rbind rbind 0 0 +/data/media /home/ftp/storage rbind rbind 0 0 diff --git a/board/common/overlay/etc/init.d/S11datapart b/board/common/overlay/etc/init.d/S11datapart index 6c844ed490..4424b3837f 100755 --- a/board/common/overlay/etc/init.d/S11datapart +++ b/board/common/overlay/etc/init.d/S11datapart @@ -2,20 +2,13 @@ DISK_DEV="/dev/mmcblk0" DATA_DEV="${DISK_DEV}p3" -set +e - -# don't execute the script if kernel cmdline has "nodatapart" keyword -if /bin/cat /proc/cmdline | /bin/grep "nodatapart"; then - exit; -fi - start() { echo "Setting up data partition" - # if the partition is not present, allocate it and issue a reboot + # if the data partition is not present, create and format it if ! [ -b $DATA_DEV ]; then - echo "Allocating data partition" + echo "Creating data partition" echo -e "n p 3 @@ -24,18 +17,15 @@ start() { w " | /sbin/fdisk $DISK_DEV sync - sleep 1 - echo b > /proc/sysrq-trigger - fi + partx -a $DISK_DEV &>/dev/null - # if the filesystem is not valid (not yet formatted), format it - if /usr/sbin/debugfs -R 'lcd /' $DATA_DEV 2>&1 | grep 'Bad magic'; then echo "Formatting data partition" mkfs.ext4 $DATA_DEV + + echo "Mounting data partition" mount /data - fi - + if df /dev/mmcblk0p3 >/dev/null 2>&1; then # make sure required directories exist mkdir -p /data/etc @@ -45,6 +35,9 @@ start() { chmod 775 /data/output chmod 775 /data/media + # mount any partitions depending on data folders + mount -a + # make sure a localtime symlink exists if ! [ -e /data/etc/localtime ]; then ln -s /usr/share/zoneinfo/UTC /data/etc/localtime @@ -78,10 +71,6 @@ start() { sed -r -i 's/root:([^:]+):[[:digit:]]+:/root:\1::/' /data/etc/shadow # removes pwd expiration sed -r -i 's/admin:([^:]+):[[:digit:]]+:/admin:\1::/' /data/etc/shadow # removes pwd expiration - # mount binds - mount --rbind /data/output /home/ftp/sdcard - mount --rbind /data/media /home/ftp/storage - # copy common sys config files if [ -f /etc/watch.conf ] && ! [ -f /data/etc/watch.conf ]; then cp /etc/watch.conf /data/etc/watch.conf @@ -89,30 +78,17 @@ start() { fi } -stop() { - echo -n -} - -restart() { - stop - start -} - case "$1" in start) start ;; stop) - stop - ;; - - restart|reload) - restart + true ;; *) - echo "Usage: $0 {start|stop|restart}" + echo "Usage: $0 {start|stop}" exit 1 esac diff --git a/board/common/overlay/etc/init.d/S40network b/board/common/overlay/etc/init.d/S40network index 07b39bb19e..b12a1dc3a2 100755 --- a/board/common/overlay/etc/init.d/S40network +++ b/board/common/overlay/etc/init.d/S40network @@ -15,9 +15,7 @@ link_nego_timeout=10 eth=eth0 wlan=wlan0 -if [ -f $watch_conf ]; then - source $watch_conf -fi +test -r $watch_conf && source $watch_conf if [ -f $sys_static_conf ] && ! [ -f $static_conf ]; then mkdir -p $(dirname $static_conf) diff --git a/board/common/overlay/etc/init.d/S50sshd b/board/common/overlay/etc/init.d/S50sshd index 0e06a9908a..2efc5cd2cd 100755 --- a/board/common/overlay/etc/init.d/S50sshd +++ b/board/common/overlay/etc/init.d/S50sshd @@ -6,7 +6,6 @@ conf="/etc/sshd_config" [ -f /usr/bin/ssh-keygen ] || exit 0 # Create any missing keys -mkdir -p /data/etc/ssh /usr/bin/ssh-keygen -A umask 077 diff --git a/board/common/overlay/sbin/reboot b/board/common/overlay/sbin/reboot index e460fc8ce5..5278c19d34 100755 --- a/board/common/overlay/sbin/reboot +++ b/board/common/overlay/sbin/reboot @@ -1,6 +1,7 @@ #!/bin/bash set +e +/bin/sync (sleep 10 && /usr/bin/killall -STOP watchdog) & /bin/busybox reboot