View difference between Paste ID: f657e620 and
SHOW: | | - or go back to the newest paste.
1-
1+
# Local filesystem mounting			-*- shell-script -*-
2
#
3
################################################################
4
# File:
5
# /scripts/local
6
#
7
# Root, or / in these notes is the initrd's (busybox) root, 
8
# not your system's root!
9
#
10
# You need the aufs module for this to work.  To do this install 
11
# aufs on your base install, add aufs to: /etc/initramfs-tools/modules
12
# Now using your target kernel run: 
13
# mkinitramfs -o initrd.img <kernel-name>
14
#
15
# make a directory, copy an initrd to it then cd to it and: 
16
#
17
# mv initrd.img initrd.img.gz 
18
# gunzip initrd.img.gz
19
#
20
# make sure aufs exists somewhere in /lib/modules/<uname -r>/
21
# After modifying local script, etc do the following in the initrd's 
22
# root folder where /bin and /lib etc is to create a new initrd:
23
#
24
# find ./ -print | cpio -H newc -o > ../newinitrd.img
25
# 
26
# Now tell grub to use this initrd for a RO root filesystem
27
# 
28
# Note fstab gets hosed, if you need an fstab, make sure this
29
# script reflects that.  I use an fstab for the default initrd for RW
30
# and none for RO, but you can make this script use a different one for
31
# RO if you want.
32
################################################################
33
# Parameter: device node to check
34
# Echos fstype to stdout
35
# Return value: indicates if an fs could be recognized
36
get_fstype ()
37
{
38
	local FS FSTYPE FSSIZE RET
39
	FS="${1}"
40
41
	# vol_id has a more complete list of file systems,
42
	# but fstype is more robust
43
	eval $(fstype "${FS}" 2> /dev/null)
44
	if [ "$FSTYPE" = "unknown" ] && [ -x /lib/udev/vol_id ]; then
45
		FSTYPE=$(/lib/udev/vol_id -t "${FS}" 2> /dev/null)
46
	fi
47
	RET=$?
48
49
	if [ -z "${FSTYPE}" ]; then
50
		FSTYPE="unknown"
51
	fi
52
53
	echo "${FSTYPE}"
54
	return ${RET}
55
}
56
57
# Parameter: Where to mount the filesystem
58
mountroot ()
59
{
60
	[ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-top"
61
	run_scripts /scripts/local-top
62
	[ "$quiet" != "y" ] && log_end_msg
63
64
	wait_for_udev 10
65
66
	# If the root device hasn't shown up yet, give it a little while
67
	# to deal with removable devices
68
	if [ ! -e "${ROOT}" ] || ! $(get_fstype "${ROOT}" >/dev/null); then
69
		log_begin_msg "Waiting for root file system"
70
71
		# Default delay is 180s
72
		if [ -z "${ROOTDELAY}" ]; then
73
			slumber=180
74
		else
75
			slumber=${ROOTDELAY}
76
		fi
77
		if [ -x /sbin/usplash_write ]; then
78
			/sbin/usplash_write "TIMEOUT ${slumber}" || true
79
		fi
80
81
		slumber=$(( ${slumber} * 10 ))
82
		while [ ! -e "${ROOT}" ] \
83
		|| ! $(get_fstype "${ROOT}" >/dev/null); do
84
			/bin/sleep 0.1
85
			slumber=$(( ${slumber} - 1 ))
86
			[ ${slumber} -gt 0 ] || break
87
		done
88
89
		if [ ${slumber} -gt 0 ]; then
90
			log_end_msg 0
91
		else
92
			log_end_msg 1 || true
93
		fi
94
		if [ -x /sbin/usplash_write ]; then
95
			/sbin/usplash_write "TIMEOUT 15" || true
96
		fi
97
	fi
98
99
	# We've given up, but we'll let the user fix matters if they can
100
	while [ ! -e "${ROOT}" ]; do
101
		# give hint about renamed root
102
		case "${ROOT}" in 
103
		/dev/hd*)
104
			suffix="${ROOT#/dev/hd}"
105
			major="${suffix%[[:digit:]]}"
106
			major="${major%[[:digit:]]}"
107
			if [ -d "/sys/block/sd${major}" ]; then
108
				echo "WARNING bootdevice may be renamed. Try root=/dev/sd${suffix}"
109
			fi
110
			;;
111
		/dev/sd*)
112
			suffix="${ROOT#/dev/sd}"
113
			major="${suffix%[[:digit:]]}"
114
			major="${major%[[:digit:]]}"
115
			if [ -d "/sys/block/hd${major}" ]; then
116
				echo "WARNING bootdevice may be renamed. Try root=/dev/hd${suffix}"
117
			fi
118
			;;
119
		esac
120
		echo "Gave up waiting for root device.  Common problems:"
121
		echo " - Boot args (cat /proc/cmdline)"
122
		echo "   - Check rootdelay= (did the system wait long enough?)"
123
		echo "   - Check root= (did the system wait for the right device?)"
124
		echo " - Missing modules (cat /proc/modules; ls /dev)"
125
		panic "ALERT!  ${ROOT} does not exist.  Dropping to a shell!"
126
	done
127
128
	# Get the root filesystem type if not set
129
	if [ -z "${ROOTFSTYPE}" ]; then
130
		FSTYPE=$(get_fstype "${ROOT}")
131
	else
132
		FSTYPE=${ROOTFSTYPE}
133
	fi
134
135
	[ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-premount"
136
	run_scripts /scripts/local-premount
137
	[ "$quiet" != "y" ] && log_end_msg
138
139
	if [ "${readonly}" = "y" ]; then
140
		roflag=-r
141
	else
142
		roflag=-w
143
	fi
144
145
	# FIXME This has no error checking
146
147
	modprobe ${FSTYPE}
148
##########################################################################
149
###### Mod'd by Brian Phelps aka Electronjunkie ##########################
150
151
         mkdir /root/.tmpfs
152
         mkdir /root/.rootfs
153
154
         mount -r -t ext2 /dev/sda1 /root/.rootfs
155
156
         modprobe aufs
157
         modprobe loop
158
         mount -t tmpfs -o size=20M tmpfs /root/.tmpfs
159
160
         mount -t aufs  -o br:/root/.tmpfs=rw:/root/.rootfs=ro none /root/
161
         mv /root/etc/fstab /root/etc/fstab.defunct
162
163
#########################################################################
164
165
	# FIXME This has no error checking
166
	# Mount root
167
168
	[ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-bottom"
169
	run_scripts /scripts/local-bottom
170
	[ "$quiet" != "y" ] && log_end_msg
171
}