Merge lp:~dpigott/lava-master-image-scripts/move-partitioning-to-first-boot into lp:lava-master-image-scripts

Proposed by Dave Pigott
Status: Merged
Approved by: Dave Pigott
Approved revision: 61
Merged at revision: 59
Proposed branch: lp:~dpigott/lava-master-image-scripts/move-partitioning-to-first-boot
Merge into: lp:lava-master-image-scripts
Diff against target: 469 lines (+211/-145)
8 files modified
NEWS (+2/-1)
README (+5/-22)
contrib/lava-partition-disk (+0/-118)
contrib/preEnv.txt (+0/-1)
lava-create-master (+12/-2)
master-rootfs-extras/bin/lava-partition-disk (+184/-0)
master-rootfs-extras/lib/lava/common (+1/-0)
master-rootfs-extras/lib/lava/lava-master-init (+7/-1)
To merge this branch: bzr merge lp:~dpigott/lava-master-image-scripts/move-partitioning-to-first-boot
Reviewer Review Type Date Requested Status
Michael Hudson-Doyle (community) Approve
Review via email: mp+105655@code.launchpad.net

Description of the change

Get rid of the contrib, second stage code, and make it all happen on first boot. Re-write and tidy the partitioning code. Add a new option to lava-create-master-image to take in testrootfs size as a command line parameter.

Also put the image size back to 1GB. The 3GB was unnecessary, since we deploy onto testrootfs, which is usually 4G and in the LAVA farm is always 8GB.

To post a comment you must log in.
Revision history for this message
Zygmunt Krynicki (zyga) wrote :

450 -LAVA_PKGS="wget dosfstools u-boot-tools bzip2 python ntpdate"
451 +LAVA_PKGS="wget dosfstools u-boot-tools bzip2 python ntpdate parted"

Do we need parted? We use fdisk, we also need partprobe and mkfs.ext4 (they may be already contained in other packages)

Otherwise it looks fine on first read +2

Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

I tested this branch and it seems to work. Nice :)

review: Approve
Revision history for this message
Dave Pigott (dpigott) wrote :

> 450 -LAVA_PKGS="wget dosfstools u-boot-tools bzip2 python ntpdate"
> 451 +LAVA_PKGS="wget dosfstools u-boot-tools bzip2 python ntpdate parted"
>
> Do we need parted? We use fdisk, we also need partprobe and mkfs.ext4 (they
> may be already contained in other packages)
>
> Otherwise it looks fine on first read +2

It was purely because of partprobe. Wasn't aware of another package that contains it.

61. By Dave Pigott

Add a little more commentary

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2012-05-04 11:46:04 +0000
3+++ NEWS 2012-05-15 08:44:18 +0000
4@@ -1,11 +1,12 @@
5 2012.05:
6
7 * Unreleased
8- * Increase the size of the default image to 3G
9+ * Increase the size of the default image to 3G - now back at 1G
10 * Add support for partitioning SD cards via both native mmc interface and
11 USB adapters
12 * Rename run-beagle-master-in-qemu.sh to boot-snaphot-in-qemu.sh and allow
13 the user to point it at any image pathname
14+ * Add partitioning on boot up rather than as a seperate phase
15
16 2u12.04:
17
18
19=== modified file 'README'
20--- README 2012-05-03 09:53:27 +0000
21+++ README 2012-05-15 08:44:18 +0000
22@@ -32,25 +32,8 @@
23 from the Linaro website. Once prepared the caches "vanilla" image can be reused
24 over and over. The tool creates a single file <board>-master.img.
25
26-This image is not complete: it lacks the special partitioning layout required by
27-LAVA dispatcher. To finish the process copy the image to an SD card as instructed
28-by the tool and run:
29-
30- $ ./contrib/lava-partition-disk <board type> <device path> <boot mount>
31-
32-Replace <board type> with one of: beagle, imx53, origen, panda, snowball
33-or vexpress.
34-
35-Replace <device path> with the name of the system device that represents your
36-SD card, typically this is /dev/sdX or /dev/mmcblkX (with X being a number or
37-letter representing subsequent devices in your system).
38-
39-Replace <boot mount> with the mount point for the boot partition, typically on
40-Ubuntu this will be /media/boot.
41-
42-This step will be integrated into the tool in the future. At this time the card
43-is now ready and can be cloned (like a template). The first boot of a device
44-with this card is special. It will initialize the master image and will likely
45-take a few extra minutes to finish. The interactive serial console will be
46-activated after this process has finished. Once this process is done it is *not
47-recommended* to clone the SD card anymore.
48+The first boot of a device with this card is special. It will initialize the
49+master image, including partitioning and labeling, and will likely take a few
50+extra minutes to finish. The interactive serial console will be activated after
51+this process has finished. Once this process is done it is *not recommended* to
52+clone the SD card anymore.
53
54=== removed directory 'contrib'
55=== removed file 'contrib/lava-partition-disk'
56--- contrib/lava-partition-disk 2012-05-14 08:38:47 +0000
57+++ contrib/lava-partition-disk 1970-01-01 00:00:00 +0000
58@@ -1,118 +0,0 @@
59-#!/bin/bash
60-
61-show_usage() {
62- echo "Usage: $0 <board type> <device path> <boot mount> {testrootfs partition size}"
63- echo "Where <board typei> is one of: beagle, imx53, origen, panda,"
64- echo " snowball or vexpress"
65- echo
66- echo "<device path> is the path to your sd card (e.g. /dev/sdb)"
67- echo "<boot mount> is where the boot partition of the sd card is (e.g. /media/boot"
68- echo
69- echo "The testrootfs partition size is optional and defauts to 4G."
70- echo "Make sure you specify the \"G\" in uppercase"
71-}
72-
73-if [ "$3" = "" ]
74-then
75- show_usage
76- exit 1
77-fi
78-
79-PRE_ENV=
80-
81-case $1 in
82- beagle)
83- PRE_ENV=Y
84- SCHEME=2part;;
85-
86- imx53)
87- SCHEME=3part;;
88-
89- origen)
90- SCHEME=3part;;
91-
92- panda)
93- PRE_ENV=Y
94- SCHEME=2part;;
95-
96- snowball)
97- SCHEME=2part;;
98-
99- vexpress)
100- SCHEME=2part;;
101-
102- *)
103- echo "Board type \"$1\" not recognised"
104- exit 1;;
105-esac
106-
107-DEVICE=$2
108-
109-BOOT_MOUNT=$3
110-
111-if [ "$4" = "" ]
112-then
113- # SIZE is the size of the testrootfs partition. On an 8G sd you can fit
114- # 4G - put it up to 8G on a 16GB. The rest is allocated to sdcard for
115- # android
116- SIZE="4G"
117-else
118- SIZE=$4
119-fi
120-
121-if [ "$PRE_ENV" = "Y" ]
122-then
123- cp ./contrib/preEnv.txt $BOOT_MOUNT
124- if [ "$?" != "0" ]
125- then
126- echo "Failed to copy preEnv.txt. Is the disk read only?"
127- exit 1
128- fi
129-fi
130-
131-# origen and imx53 have a different original layout with 3 partitions
132-# all others are the same (so far)
133-
134-if [ $SCHEME = "2part" ]
135-then
136- TESTBOOT_PART=3
137- TESTROOTFS_PART=5
138- SDCARD_PART=6
139- LAST_BLOCK=2
140-else
141- TESTBOOT_PART=5
142- TESTROOTFS_PART=6
143- SDCARD_PART=7
144- LAST_BLOCK=3
145-fi
146-
147-if [[ $DEVICE =~ 'mmc' ]];
148-then
149- PARTITION_PREFIX="p"
150-else
151- PARTITION_PREFIX=""
152-fi
153-
154-FIRST_BLOCK_START=`sudo fdisk -S 63 -H 255 -lc $DEVICE | grep "${DEVICE}${PARTITION_PREFIX}${LAST_BLOCK}" | awk '{print $3 + 1}'`
155-
156-if [ "$FIRST_BLOCK_START" = "" ]
157-then
158- echo "Device specification error: $DEVICE"
159- exit 1
160-fi
161-
162-if [ $SCHEME = "2part" ]
163-then
164- EXTENDED_BLOCK_START=`echo $FIRST_BLOCK_START | awk '{print $1 + 131072}'`
165- FDISK_SCRIPT="n\np\n3\n$FIRST_BLOCK_START\n+64M\nt\n3\nc\nn\ne\n$EXTENDED_BLOCK_START\n\nn\n\n+$SIZE\nn\n\n\nt\n6\nc\np\nw\n"
166-else
167- FDISK_SCRIPT="n\ne\n$FIRST_BLOCK_START\n\nn\n\n+64M\nt\n5\nc\nn\n\n+$SIZE\nn\n\n\nt\n7\nc\np\nw\n"
168-fi
169-
170-echo -e $FDISK_SCRIPT | sudo fdisk -S 63 -H 255 -c $DEVICE
171-
172-sudo partprobe $DEVICE
173-sudo mkfs.vfat -n testboot "${DEVICE}${PARTITION_PREFIX}${TESTBOOT_PART}"
174-sudo mkfs.vfat -n sdcard "${DEVICE}${PARTITION_PREFIX}${SDCARD_PART}"
175-sudo mkfs.ext3 -L testrootfs "${DEVICE}${PARTITION_PREFIX}${TESTROOTFS_PART}"
176-sync
177
178=== removed file 'contrib/preEnv.txt'
179--- contrib/preEnv.txt 2012-05-03 09:52:40 +0000
180+++ contrib/preEnv.txt 1970-01-01 00:00:00 +0000
181@@ -1,1 +0,0 @@
182-bootdelay=10
183
184=== modified file 'lava-create-master'
185--- lava-create-master 2012-05-14 08:38:47 +0000
186+++ lava-create-master 2012-05-15 08:44:18 +0000
187@@ -16,6 +16,10 @@
188 # When non-empty the tool will stop just before jumping into the rootfs
189 export DEBUG=
190
191+# Used during partitioning on first boot - size of the testrootsfs partition
192+# defaults to 4G (4 GigaBytes)
193+export ROOTFS_SIZE="4G"
194+
195 # TODO: change to BOARD
196 dev=
197
198@@ -58,7 +62,7 @@
199
200 show_usage() {
201 # Display the usage line
202- echo "Usage: lava-create-master [--rebuild-vanilla] [--verbose] (--help | --version | DEVICE) [ --output|-o IMAGE]"
203+ echo "Usage: lava-create-master [--rebuild-vanilla] [--verbose] (--help | --version | DEVICE) [ --output|-o IMAGE] [--rootfs-size|-r SIZE]"
204 }
205
206
207@@ -73,6 +77,7 @@
208 printf -- " %-9s - %s\n" "--verbose" "Display additional messages"
209 printf -- " %-9s - %s\n" "--output" "Save the output as IMAGE"
210 printf -- " %-9s - %s\n" "--rebuild-vanilla" "Always rebuild vanilla image"
211+ printf -- " %-9s - %s\n" "--rootfs-size" "Size of the testrootfs partition (default 4G)"
212 echo
213 echo "supported devices:"
214 echo
215@@ -119,6 +124,10 @@
216 OUTPUT_IMAGE="$2"
217 shift 2
218 ;;
219+ --rootfs-size|-r)
220+ ROOTFS_SIZE="$2"
221+ shift 2
222+ ;;
223 *)
224 if [ -n "$dev" ]; then
225 show_usage
226@@ -335,7 +344,7 @@
227 --dev $LMC_DEV \
228 --rootfs ext4 \
229 --image-file $CACHE_DIR/pristine-images/$dev-vanilla.img \
230- --image-size 3G \
231+ --image-size 1G \
232 --align-boot-part \
233 --binary $CACHE_DIR/image-pieces/$ROOTFS \
234 --hwpack $CACHE_DIR/image-pieces/$HWPACK \
235@@ -408,6 +417,7 @@
236 sed \
237 -e "s!@LAVA_VERSION@!$LAVA_VERSION!" \
238 -e "s!@LAVA_URL@!$LAVA_URL!" \
239+ -e "s!@LAVA_ROOTFS_SIZE@!$ROOTFS_SIZE!" \
240 -i \
241 $MASTER_MNT/lib/lava/common
242
243
244=== added file 'master-rootfs-extras/bin/lava-partition-disk'
245--- master-rootfs-extras/bin/lava-partition-disk 1970-01-01 00:00:00 +0000
246+++ master-rootfs-extras/bin/lava-partition-disk 2012-05-15 08:44:18 +0000
247@@ -0,0 +1,184 @@
248+#!/bin/bash
249+
250+# By default we build a 4GByte partition. Specifiy on the command line for
251+# anything different
252+ROOTFS_SIZE="4G"
253+
254+show_usage() {
255+ echo "Usage: $0 [--rootfs-size|-r SIZE]"
256+}
257+
258+show_help() {
259+ show_usage
260+ echo
261+ echo "available options:"
262+ echo
263+ printf -- " %-9s - %s\n" "--help" "Show this message"
264+ printf -- " %-9s - %s\n" "--rootfs-size" "Size of the testrootfs partition (default 4G)"
265+ echo
266+ echo "See: $LAVA_URL for more information"
267+}
268+
269+parse_argv() {
270+ while test -n "$1"; do
271+ case "$1" in
272+ --help)
273+ show_help
274+ exit 0
275+ ;;
276+ --rootfs-size|-r)
277+ ROOTFS_SIZE=$2;
278+ shift 2
279+ ;;
280+ *)
281+ show_usage
282+ echo "Too many arguments, see --help for details"
283+ exit 1
284+ ;;
285+ esac
286+ done
287+}
288+
289+# Basically, there are just enough differences between boards that you need
290+# to specify which schemes and actions need to take place.
291+#
292+# PRE_ENV: means that we can put a preEnv.txt in the boot partition and it
293+# will be read on boot and used, so we get a default bootdelay of 10s
294+#
295+# SCHEME: Basically describes the topology of the disk at the start. Some
296+# boards have 2 partitions, others 3: TODO Make it sense which one, and even
297+# detect that the card doesn't conform (e.g. already partitioned)
298+#
299+# DEVICE: Fairly self explanatory - the device that will be partitioned
300+set_device() {
301+ DEVICE_TYPE=`lava-device-info --device-type`
302+
303+ case $DEVICE_TYPE in
304+ lava:beagle)
305+ PRE_ENV=Y
306+ SCHEME=2part
307+ DEVICE="/dev/mmcblk0"
308+ ;;
309+ lava:imx53)
310+ PRE_ENV=N
311+ SCHEME=3part
312+ DEVICE="/dev/mmcblk0"
313+ ;;
314+ lava:origen)
315+ PRE_ENV=N
316+ SCHEME=3part
317+ DEVICE="/dev/mmcblk0"
318+ ;;
319+ lava:panda)
320+ PRE_ENV=Y
321+ SCHEME=2part
322+ DEVICE="/dev/mmcblk0"
323+ ;;
324+ lava:snowball)
325+ PRE_ENV=N
326+ SCHEME=2part
327+ DEVICE="/dev/mmcblk1"
328+ ;;
329+ lava:vexpress)
330+ PRE_ENV=N
331+ SCHEME=2part
332+ DEVICE="/dev/mmcblk0"
333+ ;;
334+ *)
335+ echo "Board type \"$1\" not supported"
336+ exit 1
337+ ;;
338+ esac
339+
340+ # origen and imx53 have a different original layout with 3 partitions
341+ # all others are the same (so far). All we're doing is defining the
342+ # partition numbers for the partitions we're going to add
343+
344+ if [ $SCHEME = "2part" ]
345+ then
346+ TESTBOOT_PART=3
347+ TESTROOTFS_PART=5
348+ SDCARD_PART=6
349+ LAST_BLOCK=2
350+ else
351+ TESTBOOT_PART=5
352+ TESTROOTFS_PART=6
353+ SDCARD_PART=7
354+ LAST_BLOCK=3
355+ fi
356+
357+ if [[ $DEVICE =~ 'mmc' ]];
358+ then
359+ PARTITION_PREFIX="p"
360+ else
361+ PARTITION_PREFIX=""
362+ fi
363+
364+}
365+
366+
367+write_preenv() {
368+ mkdir -p /mnt/boot
369+ mount /dev/disk/by-label/boot /mnt/boot
370+ echo "bootdelay=10" >> /mnt/boot/preEnv.txt
371+ if [ "$?" != "0" ]; then
372+ echo "Failed to copy preEnv.txt. Is the disk read only?"
373+ exit 1
374+ fi
375+ umount /mnt/boot
376+}
377+
378+# Basically, we need the following scheme:
379+# /dev/disk/by-label/boot - the master boot image
380+# /dev/disk/by-label/rootfs - the master root filing system
381+# /dev/disk/by-label/testboot - the deployed test boot image will go here
382+# /dev/disk/by-label/testrootfs - the deployed test rootfs will go here
383+# /dev/disk/by-label/sdcard - the Android sdcard partition goes here
384+#
385+# so first we partition the disk, if it's 2part, then 3 will be the testboot
386+# and 4 will be an extended partition containing 5 as the testrootfs and 6
387+# as sdcard.
388+# For 3part then 4 will be an extended partition containing 5/testboot,
389+# 6/testrootfs and 7/sdcard
390+partition_disk() {
391+ FIRST_BLOCK_START=`fdisk -S 63 -H 255 -lc $DEVICE | grep "${DEVICE}${PARTITION_PREFIX}${LAST_BLOCK}" | awk '{print $3 + 1}'`
392+
393+ if [ "$FIRST_BLOCK_START" = "" ]
394+ then
395+ echo "Device specification error: $DEVICE"
396+ exit 1
397+ fi
398+
399+ if [ $SCHEME = "2part" ]
400+ then
401+ # 131072 = 65536 * 2 - fdisk works in 512K blocks, and we want a 64M
402+ # partition for testboot.
403+ EXTENDED_BLOCK_START=`echo $FIRST_BLOCK_START | awk '{print $1 + 131072}'`
404+ FDISK_SCRIPT="n\np\n3\n$FIRST_BLOCK_START\n+64M\nt\n3\nc\nn\ne\n$EXTENDED_BLOCK_START\n\nn\n\n+$ROOTFS_SIZE\nn\n\n\nt\n6\nc\np\nw\n"
405+ else
406+ FDISK_SCRIPT="n\ne\n$FIRST_BLOCK_START\n\nn\n\n+64M\nt\n5\nc\nn\n\n+$ROOTFS_SIZE\nn\n\n\nt\n7\nc\np\nw\n"
407+ fi
408+
409+ echo -e $FDISK_SCRIPT | fdisk -S 63 -H 255 -c $DEVICE
410+}
411+
412+# Do the partition labelling
413+make_fs() {
414+ partprobe $DEVICE
415+ mkfs.vfat -n testboot "${DEVICE}${PARTITION_PREFIX}${TESTBOOT_PART}"
416+ mkfs.vfat -n sdcard "${DEVICE}${PARTITION_PREFIX}${SDCARD_PART}"
417+ mkfs.ext3 -L testrootfs "${DEVICE}${PARTITION_PREFIX}${TESTROOTFS_PART}"
418+ sync
419+}
420+
421+main() {
422+ parse_argv "$@"
423+ set_device
424+ if [ "$PRE_ENV" = "Y" ]; then
425+ write_preenv
426+ fi
427+ partition_disk
428+ make_fs
429+}
430+
431+main "$@"
432
433=== modified file 'master-rootfs-extras/lib/lava/common'
434--- master-rootfs-extras/lib/lava/common 2012-03-22 17:46:56 +0000
435+++ master-rootfs-extras/lib/lava/common 2012-05-15 08:44:18 +0000
436@@ -1,6 +1,7 @@
437 # Replaced by lava-create-master
438 LAVA_VERSION=@LAVA_VERSION@
439 LAVA_URL=@LAVA_URL@
440+LAVA_ROOTFS_SIZE=@LAVA_ROOTFS_SIZE@
441
442 # Persistent device configuration file
443 LAVA_DEVICE_CONF=/var/lib/lava/device.conf
444
445=== modified file 'master-rootfs-extras/lib/lava/lava-master-init'
446--- master-rootfs-extras/lib/lava/lava-master-init 2012-05-14 07:05:18 +0000
447+++ master-rootfs-extras/lib/lava/lava-master-init 2012-05-15 08:44:18 +0000
448@@ -14,7 +14,7 @@
449 LAVA_FIRST_BOOT_LOG=/var/log/lava/first-boot.log
450
451 # Set of packages to install on first boot
452-LAVA_PKGS="wget dosfstools u-boot-tools bzip2 python ntpdate"
453+LAVA_PKGS="wget dosfstools u-boot-tools bzip2 python ntpdate parted"
454
455 DEVICE_TYPE=`lava-device-info --device-type`
456
457@@ -54,6 +54,12 @@
458 echo "Unable to synchronize time" >&2
459 return 1
460 fi
461+ # Do disk partitioning
462+ echo "Partitioning disk to LAVA format" >> "$LAVA_FIRST_BOOT_LOG"
463+ if ! lava-partition-disk -r $LAVA_ROOTFS_SIZE >> "$LAVA_FIRST_BOOT_LOG" 2>&1; then
464+ echo "Unable to partition disk" >&2
465+ return 1
466+ fi
467 if [ "$DEVICE_TYPE" = "lava:panda" ]; then
468 echo "Applying sysctl fix for streaming errors on Panda" >> "$LAVA_FIRST_BOOT_LOG"
469 echo vm.min_free_kbytes = 32768 >> /etc/sysctl.conf

Subscribers

People subscribed via source and target branches