mod_image_for_recovery: dynamically adjust kern-A size

This CL changes the copy-and-modify flow to:
  1) Build recovery kernel.
  2) Create an empty recovery image with correct KERN-A and STATE size.
  3) Copy partitions from source image to the recovery image.
  4) Copy recovery kernel to the recovery image.
  5) Update EFI partition.

This change breaks --modify_in_place because it will be implemented
by creating a temporary image and than move back to the source image
path. Not technically in-place, but should be acceptable.

TEST=1) Create an recovery ramfs with >32MB junk files, build recovery image and
        boot on DUT successfully.
     2) Verify the script fails when a super large kernel image is
     3) cros tryjob -g 2294783 puff-release-tryjob

Change-Id: If88e9f7893816ab40085d5cfeb360573682bfe57
Tested-by: Ting Shen <>
Commit-Queue: Ting Shen <>
Reviewed-by: Mike Frysinger <>
3 files changed