xref: /OK3568_Linux_fs/debian/overlay/usr/bin/mount-helper (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1#!/bin/sh
2### BEGIN INIT INFO
3# Provides:       mount-all
4# Default-Start:  S
5# Default-Stop:
6# Description:    Mount all internal partitions in /etc/fstab
7### END INIT INFO
8
9# Don't exit on error status
10set +e
11
12# Uncomment below to see more logs
13# set -x
14
15. $(dirname $0)/disk-helper
16
17LOGFILE=/tmp/mount-all.log
18
19do_part()
20{
21	# Not enough args
22	[ $# -lt 6 ] && return
23
24	# Ignore comments
25	echo $1 | grep -q "^#" && return
26
27	DEV=$(device_from_attr ${1##*=})
28	MOUNT_POINT=$2
29	FSTYPE=$3
30	OPTS=$4
31	PASS=$6 # Skip fsck when pass is 0
32
33	echo "Handling $DEV $MOUNT_POINT $FSTYPE $OPTS $PASS"
34
35	# Setup check/mount tools and do some prepare
36	prepare_part || return
37
38	# Parse ro/rw opt
39	MOUNT_RO_RW=rw
40	if echo $OPTS | grep -o "[^,]*ro\>" | grep "^ro$"; then
41		MOUNT_RO_RW=ro
42	fi
43
44	if mountpoint -q $MOUNT_POINT && ! is_rootfs; then
45		# Make sure other partitions are unmounted.
46		umount $MOUNT_POINT &>/dev/null || return
47	fi
48
49	# Check and repair
50	check_part
51
52	# Mount partition
53	is_rootfs || mount_part || return
54
55	# Resize partition if needed
56	resize_part
57
58	# Restore ro/rw
59	remount_part $MOUNT_RO_RW
60}
61
62mount_all()
63{
64	echo "Will now mount all partitions in /etc/fstab"
65
66	AUTO_MKFS="/.auto_mkfs"
67	if [ -f $AUTO_MKFS ];then
68		echo "Note: Will auto format partitons, remove $AUTO_MKFS to disable"
69	else
70		unset AUTO_MKFS
71	fi
72
73	SKIP_FSCK="/.skip_fsck"
74	if [ -f $SKIP_FSCK ];then
75		echo "Note: Will skip fsck, remove $SKIP_FSCK to enable"
76	else
77		echo "Note: Create $SKIP_FSCK to skip fsck"
78		echo " - The check might take a while if didn't shutdown properly!"
79		unset SKIP_FSCK
80	fi
81
82	while read LINE;do
83		do_part $LINE
84	done < /etc/fstab
85}
86
87case "$1" in
88	start|"")
89		# Mount basic file systems firstly
90		mount -a -t "proc,devpts,tmpfs,sysfs,debugfs,pstore"
91
92		mount_all 2>&1 | tee $LOGFILE
93		echo "Log saved to $LOGFILE"
94		;;
95	*)
96		echo "Usage: mount-helper start" >&2
97		exit 3
98		;;
99esac
100
101:
102