Commit Graph

78 Commits

Author SHA1 Message Date
Steve Kowalik
58c755cf4c Create a new baremetal element
Rather than using a script to mount the image using nbd to extract the
kernel and ramdisk, make a new element called baremetal, which contains
a cleanup.d script that will copy them out to <image name>.{vmlinuz,initrd}.

Closes-Bug: 1224669
Change-Id: I8f3569aa12148d18b1c8242b6fbbd8857894b26f
2014-01-21 16:48:20 +11:00
Clint Byrum
d2cb979ddf Increase padding to allow for smaller images
With smaller base images, such as Debian, the padding value used to
size the root filesystem does not leave enough room for grub which is
installed after the filesystem is created.

Change-Id: Ic2ab9e2efc9bf1b02f802ee47a36e3fff9c3512e
2014-01-11 18:06:33 -08:00
Jenkins
37f3c4fe90 Merge "Quieten disk-image-get-kernel" 2013-12-12 16:31:54 +00:00
Derek Higgins
d5b30d126e Increase the size heuristic for images
Occasionally cloud-init fails to resize the disk on first boot, this is
occuring because the filesystem has only 10% free. Nudging the disk size
up a bit more should give us a little more headroom so this is less
likely to occur.

I havn't been able to find out what value ensures we wont hit this
problem but I can say for sure this fixes all casses of the problem I
have seen.

Change-Id: Ib23f3a654151338ad91839e49b323b65b4054245
2013-12-11 14:38:24 +00:00
Mark McLoughlin
af8b7f05a1 Quieten disk-image-get-kernel
disk-image-get-kernel is pretty noisy and you see e.g.:

  $> load-image overcloud-compute.qcow2
  XXX  -d '/tmp/image.lWGCgPoj' -o 'tmp' -i '/home/stack/overcloud-compute.qcow2' --
  Extracting kernel + ramdisk from /home/stack/overcloud-compute.qcow2 and writing them to /tmp/image.lWGCgPoj
  nbd                    17554  0
  nbd                    17554  0
  basename: missing operand
  Try 'basename --help' for more information.
  /dev/nbd0 disconnected
  tmp-vmlinuz,tmp-initrd

Clean all this up so we just get:

  $> load-image overcloud-compute.qcow2
  Extracting kernel + ramdisk from /home/stack/overcloud-compute.qcow2 to tmp-vmlinuz and tmp-initrd in /tmp/image.g6b0lG88

Change-Id: I8971ec0bbcd87157b07fc17254c56bb9f9f2a597
2013-12-09 13:39:29 +00:00
JUN JIE NAN
65a3063da3 Add examples for ramdisk-image-create
The examples to create cfn-tools image do not make sense for
ramdisk-image-create.

Change-Id: Iff50898119a1f37f41e52e6215c6bbeca003dfff
2013-12-05 18:10:28 +08:00
Dan Prince
255387a288 Drop default distribution root element support
Converts our existing default root element code to be just a check
which exits with a failure message if no root/distribution element
is found.

Change-Id: I954a6abfd7871d5807b1a171a03fa98932410cff
2013-12-02 11:01:29 -05:00
JUN JIE NAN
7c2d1b2295 Store DIB_* only env variables
Or environment variables like OS_USERNAME OS_PASSWORD will be stored
in /etc/dib_environment also. It's potentially unsafe.

Change-Id: I3a65d5bc0e4469a071db9ac23ebc82196a3f3feb
2013-12-02 09:26:35 +08:00
James Slagle
844daff526 Add option --image-size.
Adds an option for --image-size, which sets the DIB_IMAGE_SIZE
environment variable.  Having the cli option makes disk-image-create
more consistent in that parameters are able to be specified via a flag
on the command line or an environment variable.  Also, you may not be
able to remember all the environment variables that you can tweak, yet
--help will tell you about the cli parameters.  Preserves the old
behavior as well where if DIB_IMAGE_SIZE is set in your environment, it
will be honored.

Change-Id: I195c9144a80ce7b8bd5809b57f2bed71a2cbdf26
2013-11-25 15:28:18 -05:00
Jenkins
35830cc57c Merge "Usage message enhancement" 2013-11-14 09:38:10 +00:00
JUN JIE NAN
6d6634e804 Usage message enhancement
Add --help, add a simple usage and two examples

Change-Id: Iddf07ec1935f337000bd8ffb3d7c1fcc65753e8d
2013-11-14 09:18:45 +08:00
James Slagle
dee69b1810 Python code refactorings.
This commit refactors the python code in diskimage_builder slightly.  This is
in preparation for a larger review that adds more functionality to the python
code, namely the ability to apply elements to the current system as opposed to
a chroot.  Further, the refactorings can stand on their own for better clarity.
They include:
 - renaming elements.py to element_dependencies.py.  Adds clarity about the
   purpose of this module.
 - updating other code for this rename.
 - move tests into a tests submodule.

Change-Id: I5519cc52398e442b24e33802bae42070d64b0c1d
2013-11-12 10:47:57 -05:00
Ben Nemec
237fd64b47 Ignore basename failures
Commit 0210be22ae introduced the
possibility of basename being called on an empty string.  Because
that can happen in normal operation (such as an x86_64 kernel,
in which case the PAE check will find nothing), don't allow the
basename error to kill the script.  Also ignore failures in the
second basename call so the proper error message is echoed.

Change-Id: I38a18af09ab24fda9c98cbf3ace8fd7acc6faef5
2013-10-17 22:36:53 +00:00
Lucas Alvares Gomes
0210be22ae Fix disk-image-get-kernel for redhat
disk-image-get-kernel picks the wrong version of kernel and initramfs
if there's a PAE and non-PAE version present. Only affects i386 images.

Change-Id: I06e08fdf038988759b620f549261499cb0a69b34
Closes-Bug: #1240873
2013-10-17 12:20:04 +01:00
JUN JIE NAN
39cbbd6980 Increase journal size to 64 M for ext4 file system
the problem is that the journal isn't large enough to allow online
resizing. Solution is straight forward. So the file system can be
resized successfully to disk size specified in flavor.

Fixes bug #1233008

Change-Id: Ie84fb8aea8d334706574d1a8006ec9eaee5bb5be
2013-10-05 16:53:53 +08:00
Matthew Farrellee
1d2a85d5e4 Add DIB_IMAGE_CACHE
DIB_IMAGE_CACHE will be a user override for the location where images
are cached. Default location is ~/.cache/image-create

Change-Id: I3e9b9f970864d555c9ec9436344b53f6d3d66dfa
2013-09-19 14:34:05 -04:00
Jan Provaznik
0eaddbd214 Fixes files ordering when choosing newest image
For example if there are following kernels in undercloud/overcloud
image:
/boot/vmlinuz-3.9.5-301.fc19.i686.PAE
/boot/vmlinuz-3.10.10-200.fc19.i686.PAE
then disk-image-get-kernel picks vmlinuz-3.9.5. It should use the
newest one.

Change-Id: I7bbf06705e85370d66c7dd8a5d4f8d6c93b21c0c
Fixes: bug #1224365
2013-09-12 11:26:57 +02:00
Derek Higgins
e8c73cde49 Set raw image size to be multiple of 64k
This works around a bug in qemu-img causing it to sometimes error if
compressing a raw image that isn't a multiple of 64k (the qcow2
cluster size).
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1180021
http://lists.gnu.org/archive/html/qemu-devel/2013-04/msg02520.html

Change-Id: I88f8bb5c6bf3606ef5856b085a284af6b8858dbb
2013-09-08 21:36:29 +01:00
Jenkins
771f3ec141 Merge "Add option --min-tmpfs <size> to disk-image-create" 2013-08-28 15:40:31 +00:00
Ghe Rivero
fefc28a918 Add option --min-tmpfs <size> to disk-image-create
In some scenarios, the required space in the tmpfs partition can be
larger (or smaller) than the default one, producing errors due to
the lack of enough space (or performance penalties for not using
tmpfs).

Using --min-tmpfs <size>, we can hint the working set size we'll need
and let dib choose to avoid or use tmpfs.

Change-Id: I7d5fe498302a100c8555ae542268e14b21f3a0c5
2013-08-28 11:14:06 +00:00
Ghe Rivero
dbfca7a816 Combine compress and save image into one function
When compressing an image, this is done in the same dir where the raw
image resides, doubling the amount of space needed (scarce when
using tmpfs), and then it's moved to the .cache folder in disk.

Combining these two functions, we reduce the amount of space needed
in the tmpfs partition (when in use), and the compressed image is
created directly on the .cache folder disk, so there is no need to
move the compressed image after the process into disk.

Change-Id: I451d24bdd6fa0983414244135dff5e96c0549833
2013-08-28 10:51:40 +00:00
Derek Higgins
4651913e55 Add a new break on error
A user running di-b several times while developing an element may not
want to drop to a shell in all cases but may only want to do so if one
of their in target hooks failed.

This patch gives them the ability to do so, If break=after-error is set
then a user will be provided a in target shell taking over from where the
last failed command left off.

Change-Id: Ia2f7ac4c21b64b971f87f4ae9cb867981b13eb5e
2013-08-01 17:08:54 +01:00
Jenkins
9233ca4056 Merge "Enable running disk-image-create on SUSE Linux" 2013-08-01 00:36:36 +00:00
Jeff Peeler
87fb533979 Modify relative paths of lib, elements for packaging
(Based on review https://review.openstack.org/#/c/36009)

Scripts test for existence of ../share/diskimage-builder and
fall-back to ../ if not found. This allows scripts to run unmodified
from a packaged installation or a local archive/repository.

Change-Id: I0cf4c1fdb8e42ec284c56860cb15818632b93b9e
2013-07-31 13:15:33 +12:00
Tim Serong
ee5ae03d58 Enable running disk-image-create on SUSE Linux
- Ensures /sbin and friends are in $PATH when invoked (without this,
  various sudo invocations fail in exciting ways).
- Use dib-run-parts in lib/common-functions instead of run-parts
  (neither SLES nor openSUSE ship run-parts).
- Ensure dib-run-parts doesn't descend into subdirectories (same
  behaviour as run-parts).
- Move dib-run-parts from root.d to bin (cleaner, consistent with
  other elements with separate bin scripts).
- Tested by building Ubuntu image on openSUSE 12.3.
- Note: this doesn't add support for creating SUSE images, it just
  lets you run disk-image-create on SUSE-based distros.

Change-Id: I906c6bc3cf51cdf2c4415adeae1ca250faac25e1
2013-07-24 20:16:31 +10:00
Robert Collins
f7f6cb45ee Fix the DIB_OFFLINE setting to actually work.
I missed the getopt parameter and forgot defaults are imported after
option processing. Untested code is broken code!

Change-Id: I133a691909d38e834c204950276a57f4884fc4ed
2013-07-18 13:19:25 +12:00
Robert Collins
b2f1d4e2af Document an interface for offline operation.
Complex image builds can download hundreds of MB of data from the
internet with many separate lookups. It would be nice to allow users
to ask for a fast build where those lookups are entirely avoided,
using locally cached resources (where possible). This new interface
allows users to signal to elements that they wish to operate without
updating cached resources, which will in turn allow us to avoid
checking for stale data at all.

As part of this I've also documented where we cache data, so that
things like the ccache cache dir and image cache files are not a
surprise to users.

Change-Id: I27f5de6ceaa4e9c6390721b7c434fe0908df84f5
2013-07-18 09:17:01 +12:00
Chris Jones
8d1ce9c0c3 Build ramdisks in an image chroot.
Ramdisks are now built inside a chroot which is built by the normal
image build process. Doing so improves our independence of the
precise state of the build host.

This fixes bug 1194055.

Change-Id: Ibc254fbb9e7b404b5f38c1b35bcde8a4136e8e28
2013-07-12 11:09:35 +01:00
Robert Collins
a969be49a2 Move functions to common-functions for reuse.
Change-Id: I12a5687d94df678d7f7e8c0b075ee4aba1082156
2013-06-25 17:36:37 +01:00
Robert Collins
0b1ff7d4b0 Factor out element processing.
This reduces code duplication for hygiene, no functional changes.

Change-Id: I10c96da4f07bcd1e5aabfcfbd115ecaef7bb65a1
2013-06-24 16:30:25 +01:00
Robert Collins
9b01f2b129 Consolidate more ramdisk and disk-image code.
RAMDISK_ELEMENT is a spurious difference, to merge the code we need
only semantic difference to exist.

Change-Id: I7d38b2457b6fc838d1a536406bb3c34c00f2b1f9
2013-06-24 20:53:19 +12:00
Robert Collins
2c47b700be Reduce duplication between ramdisk and disk image codepaths.
Change-Id: Ie9e2d60ffe94f971953d52b7b5bce9c1a86fb1b5
2013-06-19 21:26:29 +12:00
Lucas Alvares Gomes
c28cb1b5d8 Add RedHat support for disk-image-get-kernel.
RedHat and Debian based systems have different binary names.

Change-Id: I5162204759fbc4ff167d1584294c9936ab7df4c8
2013-06-05 17:12:09 +01:00
Robert Collins
1f0bc8f19b Increase the size heuristic for images.
Bug 1183597 reported that we create them too narrowly today.

Change-Id: Ia863cf2fb19c813c51f94dd0b8e210a75dccd945
2013-05-24 10:32:10 +12:00
Robert Collins
c139b0cb46 The ext4 resize fix was faulty - fix it.
Fix bug 1183251 by replacing an erroneous reference to OPTS with
MKFS_OPTS.

Change-Id: I741005d574715b8b237d9789398dbaba29df60e3
2013-05-24 10:06:33 +12:00
Lucas Alvares Gomes
85b5ef0c8d Move the ensure_nbd function call.
Move the ensure_nbd function call from the disk-image-create to the
disk-image-get-kernel. The image creation process does not use qemu-nbd
anymore.

Change-Id: I8ff2ad54f322a9e33d52408fa4e253a7b45900c7
2013-05-20 11:59:21 +01:00
Robert Collins
fb246a02eb Ensure that the ext4 fs can be rebuilt up to 1PB in size.
Change-Id: I16c5fe4eb0a9951d44745d6a46450f70d33b3481
2013-05-18 13:08:06 +12:00
Jenkins
ffdf0ba7ff Merge "Honor $DIB_IMAGE_SIZE." 2013-05-13 17:56:17 +00:00
Tim Miller
9983245249 Honor $DIB_IMAGE_SIZE.
The recent change to use loopdev instead of nbd stopped
honoring the DIB_IMAGE_SIZE setting.

This change adds it back, by resizing the image to
DIB_IMAGE_SIZE GB, if specified. If unspecified, it resizes
the image to (actual usage + 20%), as it did before this change.

Change-Id: I69afd9584e644ddacc948619100f153d3d8713a4
2013-05-13 10:20:53 -07:00
Clint Byrum
20661e8d80 Retry losetup -d for up to 10 seconds.
When partition tables are added to loopback devices, this can set off a
chain of udev hooks that may still be holding the loopback open. Failing
to detach loopback devices was the reason we were seeing leaked tmpfs
volumes.

Fixes bug #1178091

Change-Id: I836d6e2bbce824951dd4786e3ef28273ea18ee73
2013-05-09 09:34:53 -07:00
Chris Krelle
76d8d98a60 Remove img-functions from ramdisk-image-create.
Ramdisk-image-create sources both img-functions and ramdisk-functions
causing duplicate functions. To correct this situation this patch
removes the import of img-functions from ramdisk-image-create.
It moves cleanup_dirs and run_d functions from img-functions to
common-functions to allow this.

fixes bug 1175427
Authored-by: Chris Krelle <nobodycam@gmail.com>

Change-Id: I971d019b0d92b06d9de661663b49c433e823ea42
2013-05-08 07:39:30 -07:00
Clint Byrum
d9a2211d14 Only use tmpfs if build machine has 4GB+ RAM.
For machines with low RAM (or no access to /proc/meminfo) the builder
will still run, but will just build inside the filesystem that is
hosting /tmp. This will result in a slower build (especially if there
are a lot of .deb packages installed).

Fixes bug #1175453

Change-Id: I79f2672058c11e377548820df0ab4fad8f47ffdc
2013-05-03 06:55:53 -07:00
Robert Collins
d119c28f49 Revert "Improve Fedora build host support."
This reverts commit 591059ffd3.

Change-Id: I8ad5bde2eabe12c6575d51e7443d9b46521c0928
2013-05-03 08:16:43 +12:00
Jenkins
55993863fc Merge "Improve Fedora build host support." 2013-05-02 19:30:43 +00:00
Lucas Alvares Gomes
591059ffd3 Improve Fedora build host support.
Sudo command (even using -E) resets $PATH for security reasons, Fedora
and other distos might have to explicitly add /usr/local/bin to $PATH
in order to run the commands in the chroot environment.

Change-Id: I95068ecf1e7437152e11c6d6789f59bcfd6ae9cc
2013-05-01 09:40:15 +01:00
Robert Collins
e27ac025fc Use a different approach to solving the ramdisk-image-create failure.
Change-Id: I2861927d1989bde1137c253c8b3a48b245c65f19
2013-05-01 15:03:44 +12:00
Robert Collins
cb62bae9b8 Build images using loopdev instead of qemu-nbd.
Qemu-nbd does not perform well with older versions of qemu due to
the lack of writeback caching mode. It also only builds qcow2 images
and there is a desire for raw image support. Finally, qemu-nbd makes
it very difficult to build images concurrently due to the somewhat
opaque nature of how it selects a /dev/nbd# device. losetup, on
the other hand, makes this process very straight forward.

Change-Id: I309fad8af4fd1e8d1720c17b65e1897a76d5e897
Co-Author: Clint Byrum <clint@fewbar.com>
2013-04-30 08:56:12 -07:00
Lucas Alvares Gomes
45173ccdb5 Adds support for post-install scripts.
Post install scripts are useful because they can perform tasks you want
to handle after the OS/application install but before the first boot
of the image. e.g: Clean the cache left by the package manager reducing
the size of the image.

Change-Id: I03e77f602192bbdce29c02999d1b57fac8051ddc
Fixes: Bug #1145786
2013-04-17 09:47:51 +01:00
Lucas Alvares Gomes
b20e133714 Grab the next available /dev/nbdX.
Change-Id: I6a2c8e58cdab889d747e870d0009f51bba0ff148
2013-04-12 17:49:23 +01:00
Chris Jones
bd1bae7c58 Introduce the DIB_ namespace for build-time config.
Document the use of DIB_ as a prefix on environmental variables that can
be overridden at build time.

Introduce the first such variable by migrating IMAGE_SIZE to
DIB_IMAGE_SIZE.

Change-Id: Ie36b734991b913a23f37f2add47d470d7c1576e4
2013-04-12 09:50:34 +01:00