Merge lp:~jani/ubuntu/utopic/initramfs-tools-ubuntu-touch/partition into lp:ubuntu/utopic/initramfs-tools-ubuntu-touch

Proposed by Jani Monoses
Status: Merged
Merge reported by: Ricardo Salveti
Merged at revision: not available
Proposed branch: lp:~jani/ubuntu/utopic/initramfs-tools-ubuntu-touch/partition
Merge into: lp:ubuntu/utopic/initramfs-tools-ubuntu-touch
Diff against target: 258 lines (+84/-123)
1 file modified
scripts/touch (+84/-123)
To merge this branch: bzr merge lp:~jani/ubuntu/utopic/initramfs-tools-ubuntu-touch/partition
Reviewer Review Type Date Requested Status
Ricardo Salveti (community) Approve
Review via email: mp+231041@code.launchpad.net

Commit message

Allow booting Ubuntu from a partition.

Description of the change

If systempart is found in /proc/cmdline use that block device as the root filesystem partition instead of the loopmounted file.

To post a comment you must log in.
Revision history for this message
Ricardo Salveti (rsalveti) wrote :

Looks good, thanks.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'scripts/touch'
2--- scripts/touch 2014-07-26 21:52:27 +0000
3+++ scripts/touch 2014-08-15 21:58:22 +0000
4@@ -23,43 +23,6 @@
5 fi
6 }
7
8-parse_initrd_fstab() {
9- echo "initrd: mounting content from the initrd fstab" >/dev/kmsg || true
10-
11- # Please make sure rootfs is before /android/system and /android/data,
12- # otherwise they will not be mounted correctly
13- cat /fstab | while read line; do
14- set -- $line
15-
16- # Skip any unwanted entry
17- echo $1 | egrep -q "^#" && continue
18- ([ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ] || [ -z "$4" ]) && continue
19-
20- echo "initrd: checking mount label $1" >/dev/kmsg || true
21-
22- [ ! -e "$1" ] && continue
23-
24- target=${rootmnt}/$2
25- if [ "$2" = "/tmpmnt" ]; then
26- target=$2
27- fi
28-
29- mkdir -p ${target}
30- echo "initrd: mounting $1 as ${target}" >/dev/kmsg || true
31- mount $1 ${target} -t $3 -o $4
32- if [ "$2" == "/" ]; then
33- # Mount some tmpfs
34- echo "initrd: prepare needed tmpfs" >/dev/kmsg || true
35- mkdir -p ${rootmnt}/android
36- mount -o rw,size=4096 -t tmpfs none ${rootmnt}/android
37- mount -o rw,nosuid,noexec,relatime,mode=755 -t tmpfs tmpfs ${rootmnt}/run
38-
39- # Create some needed paths on tmpfs
40- mkdir -p ${rootmnt}/android/data ${rootmnt}/android/system
41- fi
42- done
43-}
44-
45 sync_dirs() {
46 base=$1
47 source=$2
48@@ -108,104 +71,87 @@
49 # Make sure the device has been created by udev before we try to mount
50 udevadm settle
51
52- # Identify the Ubuntu boot mode to be used
53- ubuntu_mode="unknown"
54- if [ -e /fstab ]; then
55- ubuntu_mode="native"
56- echo "initrd: Using native mode (fstab and partitions)" >/dev/kmsg || true
57- else
58- # find the right partition
59- for partname in $partlist; do
60- part=$(find /dev -name $partname|tail -1)
61- [ -z "$part" ] && continue
62- path=$(readlink -f $part)
63- [ -n "$path" ] && break
64- done
65-
66- # override with a possible cmdline parameter
67- if grep -q datapart= /proc/cmdline; then
68- for x in $(cat /proc/cmdline); do
69- case ${x} in
70- datapart=*)
71- path=${x#*=}
72- ;;
73- esac
74- done
75- fi
76-
77- if [ -n "$path" ]; then
78- echo "initrd: mounting $path" >/dev/kmsg || true
79-
80- # Mount the data partition to a temporary mount point
81- mount -o discard $path /tmpmnt
82-
83- if [ -e /tmpmnt/system.img ]; then
84- ubuntu_mode="flipped"
85- echo "initrd: Using loop-mounted flipped mode" >/dev/kmsg || true
86- elif [ -d /tmpmnt/ubuntu ]; then
87- ubuntu_mode="unflipped"
88- echo "initrd: Using old unflipped mode" >/dev/kmsg || true
89- fi
90- fi
91- fi
92-
93- # Panic if ubuntu mode is unknown (no fstab, no data partition, no ubuntu dir)
94- if [ "$ubuntu_mode" == "unknown" ]; then
95- echo "initrd: Couldn't identify ubuntu boot mode (lack of data/system partition)." >/dev/kmsg || true
96- panic "Couldn't identify ubuntu boot mode (lack of data/system partition). Spawning adbd ..."
97- elif [ "$ubuntu_mode" == "unflipped" ]; then
98- mount --bind /tmpmnt/ubuntu ${rootmnt}
99- mountroot_status="$?"
100- else
101- # Native or flipped modes
102- if [ "$ubuntu_mode" == "native" ]; then
103- parse_initrd_fstab
104+ # find the right partition
105+ for partname in $partlist; do
106+ part=$(find /dev -name $partname|tail -1)
107+ [ -z "$part" ] && continue
108+ path=$(readlink -f $part)
109+ [ -n "$path" ] && break
110+ done
111+
112+ # override with a possible cmdline parameter
113+ if grep -q datapart= /proc/cmdline; then
114+ for x in $(cat /proc/cmdline); do
115+ case ${x} in
116+ datapart=*)
117+ path=${x#*=}
118+ ;;
119+ esac
120+ done
121+ fi
122+
123+ if [ -z "$path" ]; then
124+ echo "initrd: Couldn't find data partition. Spawning adbd ..." >/dev/kmsg || true
125+ panic "Couldn't find data partition. Spawning adbd ..."
126+ fi
127+ echo "initrd: mounting $path" >/dev/kmsg || true
128+
129+ # Mount the data partition to a temporary mount point
130+ mount -o discard $path /tmpmnt
131+
132+ if grep -q systempart= /proc/cmdline; then
133+ for x in $(cat /proc/cmdline); do
134+ case ${x} in
135+ systempart=*)
136+ syspart=${x#*=}
137+ ;;
138+ esac
139+ done
140+ fi
141+
142+ # Loop-mounted flipped model
143+ if [ -e /tmpmnt/system.img -o -n "$syspart" ] ; then
144+ # Transition .developer_mode to .writable_image
145+ [ -e /tmpmnt/.developer_mode ] && mv /tmpmnt/.developer_mode /tmpmnt/.writable_image
146+
147+ # Prepare the root filesystem
148+ # NOTE: We mount it read-write in all cases, then remount read-only.
149+ # This is to workaround a behaviour change in busybox which now
150+ # uses read-only loops if the fs is initially mounted read-only.
151+ # An alternative implementation would be to add losetup support
152+ # to busybox and do the mount in two steps (rw loop, ro fs).
153+ if [ -n "$syspart" ]; then
154+ mount -o rw $syspart ${rootmnt}
155 else
156- # Prepare the root filesystem for flipped mode
157- # NOTE: We mount it read-write in all cases, then remount read-only.
158- # This is to workaround a behaviour change in busybox which now
159- # uses read-only loops if the fs is initially mounted read-only.
160- # An alternative implementation would be to add losetup support
161- # to busybox and do the mount in two steps (rw loop, ro fs).
162 mount -o loop,rw /tmpmnt/system.img ${rootmnt}
163- mount --move /tmpmnt ${rootmnt}/userdata
164-
165- # Mount the android system partition to a temporary location
166- mkdir -p /android-system
167- mount -o loop,ro ${rootmnt}/var/lib/lxc/android/system.img /android-system
168-
169- # Mount some tmpfs
170- echo "initrd: prepare needed tmpfs" >/dev/kmsg || true
171- mkdir -p ${rootmnt}/android
172- mount -o rw,size=4096 -t tmpfs none ${rootmnt}/android
173- mount -o rw,nosuid,noexec,relatime,mode=755 -t tmpfs tmpfs ${rootmnt}/run
174-
175- # Create some needed paths on tmpfs
176- mkdir -p ${rootmnt}/android/data ${rootmnt}/android/system
177-
178- # system is a special case
179- echo "initrd: mounting ${rootmnt}/var/lib/lxc/android/system.img as ${rootmnt}/android/system" >/dev/kmsg || true
180- mount --move /android-system ${rootmnt}/android/system
181 fi
182-
183- # Transition .developer_mode to .writable_image
184- [ -e ${rootmnt}/userdata/.developer_mode ] && mv ${rootmnt}/userdata/.developer_mode ${rootmnt}/userdata/.writable_image
185-
186- if [ -e ${rootmnt}/userdata/.writable_image ]; then
187- # Here we don't need to do anything as initially the image/partition is mounted in rw
188- echo "initrd: mounting system (image developer mode)" >/dev/kmsg || true
189+ if [ -e /tmpmnt/.writable_image ]; then
190+ echo "initrd: mounting system.img (image developer mode)" >/dev/kmsg || true
191 mountroot_status="$?"
192 else
193- echo "initrd: mounting system (user mode)" >/dev/kmsg || true
194+ echo "initrd: mounting system.img (user mode)" >/dev/kmsg || true
195 mount -o remount,ro ${rootmnt}
196 mountroot_status="$?"
197 fi
198+ mount --move /tmpmnt ${rootmnt}/userdata
199+
200+ # Mount the android system partition to a temporary location
201+ mkdir -p /android-system
202+ mount -o loop,ro ${rootmnt}/var/lib/lxc/android/system.img /android-system
203
204 # Get device information
205- device=$(grep ^ro.product.device= ${rootmnt}/android/system/build.prop |sed -e 's/.*=//')
206+ device=$(grep ^ro.product.device= /android-system/build.prop |sed -e 's/.*=//')
207 [ -z "$device" ] && device="unknown"
208 echo "initrd: device is $device" >/dev/kmsg || true
209
210+ # Mount some tmpfs
211+ mkdir -p ${rootmnt}/android
212+ mount -o rw,size=4096 -t tmpfs none ${rootmnt}/android
213+ mount -o rw,nosuid,noexec,relatime,mode=755 -t tmpfs tmpfs ${rootmnt}/run
214+
215+ # Create some needed paths on tmpfs
216+ mkdir -p ${rootmnt}/android/data ${rootmnt}/android/system
217+
218 # Prepare the fstab
219 FSTAB=${rootmnt}/etc/fstab
220 touch ${rootmnt}/run/image.fstab
221@@ -282,7 +228,7 @@
222 OLD_CWD=$(pwd)
223 mount -n -t tmpfs tmpfs ${rootmnt}/var/lib/lxc/android/rootfs
224 cd ${rootmnt}/var/lib/lxc/android/rootfs
225- cat ${rootmnt}/android/system/boot/android-ramdisk.img | gzip -d | cpio -i
226+ cat /android-system/boot/android-ramdisk.img | gzip -d | cpio -i
227 cd $OLD_CWD
228
229 # Mount all the Android partitions
230@@ -316,6 +262,10 @@
231 mount $path ${rootmnt}/android/$2 -t $3 -o $4
232 done
233
234+ # system is a special case
235+ echo "initrd: mounting ${rootmnt}/var/lib/lxc/android/system.img as ${rootmnt}/android/system" >/dev/kmsg || true
236+ mount --move /android-system ${rootmnt}/android/system
237+
238 # Ubuntu overlay available in the Android system image (hardware specific configs)
239 mount_ubuntu_overlay ${rootmnt}/android/system/ubuntu ${rootmnt}
240
241@@ -349,6 +299,17 @@
242 chown -R $dstown "$user/"
243 fi
244 done
245+
246+
247+ # Old flipped model
248+ elif [ -d /tmpmnt/ubuntu ]; then
249+ mount --bind /tmpmnt/ubuntu ${rootmnt}
250+ mountroot_status="$?"
251+
252+ # Possibly a re-partitioned device
253+ else
254+ echo "initrd: Couldn't find a system partition." >/dev/kmsg || true
255+ panic "Couldn't find a system partition. Spawning adbd ..."
256 fi
257
258 [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-bottom"

Subscribers

People subscribed via source and target branches