104 lines
2.5 KiB
Bash
Executable File
104 lines
2.5 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
################################## functions ##################################
|
|
|
|
#mkfs_jffs2() <device in /dev/by-name>
|
|
mkfs_jffs2() {
|
|
! [ -x /usr/sbin/mkfs.jffs2 ] \
|
|
&& ! [ -x /sbin/mkfs.jffs2 ] \
|
|
&& echo "Not Found /usr/sbin/mkfs.jffs2 or /sbin/mkfs.jffs2" \
|
|
&& return 1
|
|
|
|
# format to jffs2
|
|
local erase_block=$(/bin/cat /proc/mtd \
|
|
| /bin/grep "$(basename $1)" \
|
|
| /usr/bin/awk '{print $3}')
|
|
/bin/mkdir -p /tmp/jffs2.dir/tmp
|
|
mkfs.jffs2 -p -e 0x${erase_block} -d /tmp/jffs2.dir \
|
|
-o /tmp/jffs2.img >/dev/null || return 1
|
|
/bin/dd if=/tmp/jffs2.img of=$1 || return 1
|
|
/bin/rm -rf /tmp/jffs2.img /tmp/jffs2.dir
|
|
return 0
|
|
}
|
|
|
|
mount_etc() {
|
|
# if enable ota, do update
|
|
[ -f /etc/init.d/rc.ota-upgrade ] \
|
|
&& source /etc/init.d/ota-upgrade
|
|
|
|
# fix fs
|
|
local root_dev="$(readlink /dev/by-name/rootfs)"
|
|
/bin/echo ${root_dev} | /bin/grep -q "mtdblock" \
|
|
|| /usr/sbin/fsck.ext4 -p /dev/by-name/rootfs_data &>/dev/null
|
|
|
|
# if mount failed, format.
|
|
case "${root_dev}" in
|
|
/dev/mtdblock*)
|
|
/bin/mount -t jffs2 /dev/by-name/rootfs_data /etc \
|
|
&& [ -e /etc/etc_complete ] \
|
|
&& return
|
|
|
|
/bin/echo "Mount Failed: formating /dev/by-name/rootfs_data to jffs2 ..."
|
|
/bin/umount /etc
|
|
mkfs_jffs2 "/dev/by-name/rootfs_data" || return 1
|
|
mount -t jffs2 /dev/by-name/rootfs_data /mnt
|
|
;;
|
|
*)
|
|
/bin/mount -t ext4 /dev/by-name/rootfs_data /etc \
|
|
&& [ -e /etc/etc_complete ] \
|
|
&& return
|
|
|
|
/bin/echo "Mount Failed: formating /dev/by-name/rootfs_data to ext4 ..."
|
|
/bin/umount /etc
|
|
mkfs.ext4 -m 0 /dev/by-name/rootfs_data >/dev/null || return 1
|
|
/bin/mount -t ext4 /dev/by-name/rootfs_data /mnt
|
|
;;
|
|
esac
|
|
/bin/cp -af /etc/* /mnt/
|
|
touch /mnt/etc_complete
|
|
sync
|
|
/bin/mount -o move /mnt /etc
|
|
|
|
}
|
|
|
|
mount_usr(){
|
|
[ -L /dev/by-name/extend ] || return
|
|
|
|
/bin/mkdir -p /tmp/usr
|
|
/bin/mount /dev/by-name/extend /tmp/usr >/dev/null || {
|
|
rm -rf /tmp/usr
|
|
return
|
|
}
|
|
|
|
! [ -d /tmp/usr/bin ] \
|
|
&& umount /tmp/usr \
|
|
&& rm -rf /tmp/usr \
|
|
&& return
|
|
|
|
/bin/mount -o move /tmp/usr /usr \
|
|
&& rm -rf /tmp/usr
|
|
}
|
|
|
|
set_parts_by_name() {
|
|
# create by-name
|
|
local parts part
|
|
/bin/mkdir -p /dev/by-name
|
|
parts=$partitions
|
|
for part in $(/bin/echo ${parts} | /bin/sed 's/:/ /g')
|
|
do
|
|
[ ! -e /dev/${part#*@} ] && mdev -s #for initramfs
|
|
/bin/ln -fs "/dev/${part#*@}" "/dev/by-name/${part%@*}"
|
|
done
|
|
}
|
|
|
|
#----------------------------------------------------------------
|
|
/bin/mount -t proc /proc /proc
|
|
/bin/mount -t tmpfs tmpfs /tmp
|
|
/bin/mount -t sysfs sys /sys
|
|
|
|
set_parts_by_name
|
|
mount_usr
|
|
mount_etc
|
|
|
|
exec /sbin/init
|