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