Commit Graph

28 Commits

Author SHA1 Message Date
David James
359d3e119d Simplify boilerplate common.sh code in src/scripts.
Currently, the scripts in src/scripts have multiple implementations
for handling when common.sh fails to load, some of which are buggy.
To simplify the boilerplate, these scripts now just exit if common.sh
fails to load. The shell itself will print the following message if
common.sh is not found:
  /usr/lib/crosutils/common.sh: No such file or directory

BUG=chromium-os:32442
TEST=Run these scripts with and without common.sh installed.

Change-Id: Ie54420b6c649774f9cb039c14c80f4cf6c6ebc07
Reviewed-on: https://gerrit.chromium.org/gerrit/27058
Reviewed-by: David James <davidjames@chromium.org>
Tested-by: David James <davidjames@chromium.org>
Commit-Ready: David James <davidjames@chromium.org>
2012-07-12 10:55:37 -07:00
Kees Cook
224817fda9 Relocate stateful_parition/var to stateful_partition/var_overlay
To avoid needing to migrate fresh dev images's /var contents when
using the encrypted partition, move the /var bits out of the old
stateful_partition/var location into stateful_partition/var_overlay.

The (initially empty) system /var will continue to either live
in stateful_partition/var (in the unencrypted case), or in
stateful_partition/encrypted/var (in the encrypted case).

The contents needed for gmerge will be symlinked into place at runtime
(via CL I6e68b1f334f5d5b3c4d2977008435bd929191ce7). While the installer
already makes sure that /var is not shipped on an image, this change
additionally make sure that the other contents installed by the ebuilds
will not show up in the actual /var either.

BUG=chromium-os:22172
TEST=link build, boot, install, manual testing.

Change-Id: Ie6480a59929818fe5d36a46abf533b648fb78850
Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/26355
Reviewed-by: Chris Sosa <sosa@chromium.org>
2012-07-09 09:06:30 -07:00
Mike Frysinger
6b1abb2a6f fix up function style
The "function" keyword is superfluous, not in POSIX, is inconsistent
between bash files, and generally makes me angry.  So convert every
instance to the form:
	foo() {

BUG=None
TEST=`cbuildbot x86-generic-paladin` works

Change-Id: I97f5ca30a3edfef7222b1e08ac23917dc613b556
Reviewed-on: https://gerrit.chromium.org/gerrit/22467
Reviewed-by: David James <davidjames@chromium.org>
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
2012-05-11 14:10:38 -07:00
Brian Harring
7f175a59e1 common.sh: output a backtrace and debug information on failure.
Currently, if set -e spots a nonzero exit we basically have
no real debug information- it just stops immediately without stating
where or why.  This forces our scripts to be stupidly verbose so
we can track roughly where they were, thus when they fail we can
use that information to localize the rough exit point.

Instead we should be traping that set -e induced exit and
outputing necessary debug information to run it down.  This includes
outputing the relevant stack trace, or at least what we can get of
it.

The 'die' function is now enhanced to automatically dump the trace
that lead to it.  For most consumers this is desired- however for
commandline parsing induced dies ("--board is missing" for example),
the trace is noise.  For those cases, a 'die_notrace' function was
added that retains the original non-backtrace behaviour.

Example output via instrumenting cros_generate_breakpad_symbols
w/ the failing command '/bin/false' (nonzero exit code).

Before:
./cros_generate_breakpad_symbols  monkeys --board=x86-alex
<no output at all, just exit code 1>

With this CL:
./cros_generate_breakpad_symbols  monkeys --board=x86-alex
ERROR   : script called: ./cros_generate_breakpad_symbols 'monkeys' '--board=x86-alex'
ERROR   : Backtrace:  (most recent call is last)
ERROR   :   file cros_generate_breakpad_symbols, line 207, called: main 'monkeys' '--board=x86-alex'
ERROR   :   file cros_generate_breakpad_symbols, line 163, called: die_err_trap '/bin/false' '1'
ERROR   :
ERROR   : Command failed:
ERROR   :   Command '/bin/false' exited with nonzero code: 1

BUG=chromium-os:30598
TEST=inject a failing command into a script, verify the output.
TEST=inject a 'command not found', verify the output
TEST=cbuildbot x86-generic-full --remote
TEST=cbuildbot arm-tegra2-full --remote
TEST=cbuildbot chromiumos-sdk --remote

Change-Id: I517ffde4d1bb7e2310a74f5a6455b53ba2dea86c
Reviewed-on: https://gerrit.chromium.org/gerrit/17225
Reviewed-by: Brian Harring <ferringb@chromium.org>
Tested-by: Brian Harring <ferringb@chromium.org>
Commit-Ready: Brian Harring <ferringb@chromium.org>
2012-05-07 17:19:41 -07:00
Chris Sosa
f37f64d929 Fix bug where you can't mount a non-developer image from the most recent image.
Currently if you use -m and -i chromiumos_test_image.bin, you get an error
saying that -i and --from=<block_device> are incompatible.  -m
changes --from to the most recent folder but does this after the check so
this is broken.  This change re-orders the calls to fix this bug.

BUG=None
TEST=Ran it with args that were broken.

Change-Id: I367a74f7b77f127b6ad8eeeb92ab72ae00e5235e
Reviewed-on: https://gerrit.chromium.org/gerrit/17760
Commit-Ready: Chris Sosa <sosa@chromium.org>
Reviewed-by: Chris Sosa <sosa@chromium.org>
Tested-by: Chris Sosa <sosa@chromium.org>
2012-03-12 12:22:47 -07:00
J. Richard Barnette
8a7aa3e502 Delete unnecessary -d options from umount
The -d option to umount is unnecessary in cases where the original
mount was created with '-o loop' (it says so in the man page).
Moreover, there's a demonstrable bug when using 'umount -d' in this
case:  umount complains that it's unable to delete the loop device
in this case.  This change silences those messages.

The demonstrated bug in umount is a plausible explanation for build
failures characterized by unexpected failures of 'mount -o loop';
see the BUG, below.

BUG=chromium-os:24975
TEST=run the changed commands, see no loopback devices leaked

Change-Id: I1df9f60b40eabd279164b79ee66994ff9f644ee9
Reviewed-on: https://gerrit.chromium.org/gerrit/15998
Tested-by: Richard Barnette <jrbarnette@chromium.org>
Reviewed-by: David James <davidjames@chromium.org>
Commit-Ready: Richard Barnette <jrbarnette@chromium.org>
2012-02-15 18:23:14 -08:00
Mike Frysinger
84f66f5864 use helper info/die funcs rather than raw echo
We have helper funcs already for displaying messages, so convert
some raw `echo` calls to them.

BUG=None
TEST=build_image still works and boots

Change-Id: Ie66cc59d0362ef6aa19011fa6cb0bc64a6a4fce8
Reviewed-on: https://gerrit.chromium.org/gerrit/14478
Reviewed-by: Richard Barnette <jrbarnette@chromium.org>
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
2012-01-24 21:57:30 -08:00
J. Richard Barnette
25d540d75d Add more information to loopback mount failures.
Buildbots are periodically failing to build images; the evidence
points to failures in mount_gpt_image.sh, but it's inconclusive.
Add detailed error messages to mount failures so as to be able
to debug more the next time it happens.

BUG=chromium-os:24975
TEST=build_image, to see that successful cases still work
TEST=repeatedly mount new images with mount_gpt_image until it fails

Change-Id: I711fb0dec62dbab3817a62895b53e14376702544
Reviewed-on: https://gerrit.chromium.org/gerrit/14410
Commit-Ready: Richard Barnette <jrbarnette@chromium.org>
Tested-by: Richard Barnette <jrbarnette@chromium.org>
Reviewed-by: David James <davidjames@chromium.org>
2012-01-18 17:27:26 -08:00
Kees Cook
84a4c7a620 Use fully qualified path for helpers.
Change helper invocation to use discovered script path so image_to_vm.sh
and mount_gpt_image.sh can be run outside of ~/trunk/src/scripts.

Additionally, minimize SCRIPT_ROOT boilerplate to not potentially mix
execution locations, as suggested by David James.

BUG=None
TEST=Built images from outside of ~/trunk/src/scripts

Change-Id: I4851cc74e7da8e08b4e7be79651fb41ce8868aed
Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-on: http://gerrit.chromium.org/gerrit/10241
Reviewed-by: David James <davidjames@chromium.org>
2011-10-24 14:04:24 -07:00
Brian Harring
d5d5dbffa1 Fix/standardize exiting if common.sh can't be found
The problem here is that most were doing their exiting w/in a subshell;
exit within a subshell kills the subshell, not the parent.  Not all scripts
were using set -e (which would pick up the failing subshell); as such
just rewriting them to remove the potential via eliminateing the subshelling.

Beyond that, removed a couple of custom (working, although non-standard)
approaches, and removed a duplicate common.sh sourc'ing w/in mk_memento_images.sh

TEST=force 'find_common_sh' to fail, note the scripts fails to exit
BUG=none

Change-Id: Ia1108a091a6399ad6aedd3cade4a107f4411686c
Reviewed-on: http://gerrit.chromium.org/gerrit/3905
Reviewed-by: Brian Harring <ferringb@chromium.org>
Tested-by: Brian Harring <ferringb@chromium.org>
2011-07-22 12:06:59 -07:00
Nick Sanders
f9c49add44 Allow file in --from arg
* mount_gpt_image.sh
* image_to_usb.sh

BUG=chromium-os:12367
TEST=mount w/ --from file, check failure with file and -i, block dev and -i, check unmount, check image_to_usb, check --from dir -i file

Change-Id: I8d8604ee7ee83513edd687b0a66cda44f64db1f8

Review URL: http://codereview.chromium.org/6685101
2011-03-21 18:56:04 -07:00
Dale Curtis
d569a90bbd Fix recent change which prevented mount_gpt_image from running outside chroot.
Change-Id: Id58de45b72522077179024ee0310c70d2af1a497

BUG=chromium-os:4230
TEST=Ran mount_gpt_image.sh inside/outside chroot.

Review URL: http://codereview.chromium.org/6312112
2011-02-02 20:30:14 -08:00
Greg Spencer
798d75f3be This starts to fix the scripts so that they load from /usr/lib/crosutils
from within the chroot.

It also fixes a number of style issues.

It changes the meaning of cros_workon "list-all" to list all available
packages, and adds "list-live" to list all live packages.

It changes things that load chromeos-common.sh from the installer to
load it from /usr/lib/installer.

BUG=chromium-os:4230
TEST=synced, rebuilt chroot, made packages, made images, built chrome
from source, and wrote an image to a USB stick.

Review URL: http://codereview.chromium.org/6240018

Change-Id: I90c34420af1a64020402bafef8e9e77f56837c02
2011-02-01 22:04:49 -08:00
Nick Sanders
867fde26b7 Allow RO rootfs and writeable stateful.
BUG=9423
TEST=mount an image --safe, rootfs OK

Change-Id: I4bc48e742e2438a1d2cae17c752743e02bd124fd

Review URL: http://codereview.chromium.org/4974006
2010-11-16 20:05:06 -08:00
Chris Sosa
c60e567799 Convert rootfs and stateful mountpts to absolute paths.
Change-Id: Ib9b6b9ba7787fba337e71e4968a5c152b5a21e14

BUG=chromiumos:8885
TEST=Ran with default options and setting --rootfs_mountpt and stateful_mountpt
to dirs in my current workig directory ... saw cleanup correctly on unmount

Review URL: http://codereview.chromium.org/4853001
2010-11-12 10:54:25 -08:00
Chris Sosa
142e452d37 Fixing of the symlinks isn't being called because rootfs is being remounted ro.
This is being remounted ro in cros_make_image_bootable so I should be checking
for the stateful mount pt not the rootfs mountpt

Change-Id: I1ee64489516fae10a6246c5d79236c8b5df090ee

BUG=8116
TEST=Ran it and ran bin/cros_start vm and inspected /usr/local

Review URL: http://codereview.chromium.org/4148013
2010-10-29 11:58:15 -07:00
Chris Sosa
3b44f34de7 Fix egrep for checking for rw/ro.
Right now we're not fixing symlinks because mount_gpt_image thinks it's mounted ro.

Change-Id: Ie61536cd8d7bc276831c488e7ab892db14b05a94

BUG=8116
TEST=Mounted image from device and locally with both rw, and ro options.

Review URL: http://codereview.chromium.org/4048006
2010-10-25 13:21:42 -07:00
Chris Sosa
6addb3032c Fix latest to be consistent.
Change-Id: Ic4bc37b9c41e231b3a2448a7fabd1f7a0c163ae3

BUG=
TEST=Ran it and it was correct with -m.

Review URL: http://codereview.chromium.org/4017005
2010-10-21 16:32:26 -07:00
Will Drewry
55b42c94ca cros_make_image_bootable, mount_gpt_image, common.sh: root filesystem changes: ext2, ro by default
This change makes more of the root filesyste metadata static across builds, but
more can be done there.  It also changes the root filesystem to use ext2 as
we don't need journaling in normal mode.  Optionally we could use ext3 for
non-verified if desired (it's an easy change).

In particular, this change cleans up the following:
- clears the rootfs uuid
- labels it C-ROOT (instead of C-KEYFOB)
- removes reserved inodes and blocks

The major feature of this change, however, is that it adds two simple
helpers to common.sh: disable_rw_mount and enable_rw_mount.  They will
set high order byte (le) in the ro compat field to be 0xff.  This will
tell the kernel that the filesystem uses features R24-R31 which are safe
for use on the running kernel iff the filesystem is mounted read-only.

These functions are called in cros_make_image_bootable and
mount_gpt_image, respectively.  mount_gpt_image will always
enable_rw_mount and cros_make_image_bootable will disable_rw_mount if
--enable_rootfs_verification is true.

The approach is ugly but reasonably well contained.  If ext2 ever gets a
new revision and new features in the same range are introduced, then we
would be getting inconsistent behavior.  That said, it is unlikely that
that churmn will happen and if the impact is negative, it will ideally
show up during testing.

N.B., this will likely result in changes needing to be made to the
signing scripts in vboot_reference to ensure that rw mounting is
enabled/disabled in the same way (E.g., during stamping).

BUG=chromium-os:7468
TEST=- built x86-generic, imaged to usb stick, attempted to mount rw /dev/sdc3 on the host and was properly bounced.
     - booted to the image just fine on a dogfood device.
     - mod'd for recovery, then installed and booted.
     - mod_image_for_test runs with no errors; booted the resulting image as well
     - booted a factory_install with the pending dm changes
     - BVT passed with build_image x86-generic (vboot enabled)
     - [in progress] autotest that checks if the rootdev = /dev/dm-0 and
       then does a dumpe2fs | grep -q FEATURE_R31

Review URL: http://codereview.chromium.org/3916002

Change-Id: If4dcba7568a110f4e32627c916d9e5741e5e5414
2010-10-20 15:44:11 -05:00
Chris Sosa
e7f1a2b6bb Add read only flag to mount_gpt_image
Change-Id: I33ea8b2148a3e49a6c5de25f2957306130ff092e

BUG=
TEST=Ran and verified with and without flag.  Checked mount and tried writing
file to rootfs (to verify it was ro).  Also re-ran cros_make_image_bootable
to make sure it worked fine after changes.

Review URL: http://codereview.chromium.org/3479007
2010-09-28 18:24:13 -07:00
Chris Masone
3adf3f71e9 replace test -n ... && clauses with proper ifs
The version of this using test -n syntax didn't work in my chroot.

Review URL: http://codereview.chromium.org/2951007
2010-07-09 16:44:18 -07:00
Will Drewry
fb48fa3500 TBR: mount_gpt_image: fix missing guard for esp
Missing check during mkdir causes failure with -e empty.

The tree broke prior to this commit, but this will break the dev
build so bypassing hooks. sorry.

TEST=reran build_image
BUG=none
TBR=adlr
2010-07-02 16:35:27 -05:00
Will Drewry
61f39fb266 [PATCH 1/5] mount_gpt_image: mount the esp image
Adds support for mounting the esp image.
In the future, all legacy boot loaders will live on
the ESP partition (#12) to avoid modifying the rootfs
partition with bootloader changes in the configuration or
preamble.  This is needed.

TEST=manually reran mount_gpt_image.sh users.
BUG=chromium-os:327

Review URL: http://codereview.chromium.org/2811042
2010-07-02 16:15:22 -05:00
Bill Richardson
fc752ffdfa Use new cgpt tool when creating images and the pack/unpack scripts.
Review URL: http://codereview.chromium.org/2792011
2010-06-11 09:16:09 -07:00
Chris Sosa
d44550272c Cleanup of adding pristine image and fixing of symlinks in developer image.
TEST=Tested with building a new image, looking in the output directory, running
the image and running vi.

Review URL: http://codereview.chromium.org/2075019
2010-05-20 10:14:06 -07:00
Chris Sosa
9673f3b92e Always build pristine image as well as dev/test image.
TEST=Tested build process.  Tested dev image, test image and base image by booting all three and logging in.

Review URL: http://codereview.chromium.org/2106009
2010-05-18 13:24:40 -07:00
Chris Sosa
702618ff2b Move to using chromeos-test to emerge test dependencies in mod_image_for_test.
In addition unifies changes in mount_gpt_image and one-offs in mod_image_for_test
to consolidate gpt / var mounting.

Review URL: http://codereview.chromium.org/2064001
2010-05-14 12:52:32 -07:00
Chris Sosa
fb78b42940 New helper script to mount (and umount) gpt image into image_dir/rootfs and mount /var, /usr/local
Review URL: http://codereview.chromium.org/1648018
2010-04-19 14:56:18 -07:00