Commit Graph

67 Commits

Author SHA1 Message Date
Jenkins
13323c9495 Merge "Export die() function" 2016-06-07 01:00:50 +00:00
Ian Wienand
7550d25db0 Export die() function
I realised I'd been using die() in a few places assuming it was
available, but it wasn't exported.  I guess it didn't matter because
whatever was wrong, we were failing anyway :)

This exports the function to make it available to sub-processes, which
should remove the need to source it as done in several places.

Change-Id: I7b9a5a6db406e160099b6ed9fde80455ae227327
2016-05-27 09:25:22 +10:00
Ian Wienand
672705831f Add a best-effort sudo safety check
As motivation for this; we have had two breakouts of dib in recent
memory.  One was a failure to unmount through symlinks in the core
code (I335316019ef948758392b03e91f9869102a472b9) and the other was
removing host keys on the build-system
(Ib01d71ff9415a0ae04d963f6e380aab9ac2260ce).

For the most part, dib runs unprivileged.  Bits of the core code are
hopefully well tested (modulo bugs like the first one!).  We give free
reign inside the chroot (although there is still some potential there
for adverse external affects via bind mounts).  Where we could be a
bit safer (and could have prevented at least the second of these
breakouts) is with some better checking that the "sudo" calls
*outside* the chroot at least looked sane.

This adds a basic check that we're using chroot or image paths when
calling sudo in those parts of elements that run *outside* the chroot.
Various files are updated to accomodate this check; mostly by just
ignoring it for existing code (I have not audited these calls).

Nobody is pretending this type of checking makes dib magically safe,
or removes the issues with it needing to do things as root during the
build.  But this can help find egregious errors like the key removal.

Change-Id: I161a5aea1d29dcdc7236f70d372c53246ec73749
2016-05-09 15:41:38 +10:00
Jenkins
6e29b45d90 Merge "Replace sfdisk partitioning with parted" 2016-03-03 12:35:50 +00:00
Ben Kero
41f503fef3 Replace sfdisk partitioning with parted
A TODO was placed on the partitioning section of the vm element to
replace sfdisk with a saner (and less arcane) way of partitioning. It
suggested parted for replacement. This changeset should reproduce the
same disk label and partition layout as sfdisk, but with less ioctl
errors and version dependency. It will also ensure partition alignment.

Change-Id: I5d8d75131458b73bfb05f80f1bfa7e2970e004b3
2016-02-08 12:15:50 -08:00
Yolanda Robla
c54b335fcc Split vm and bootloader elements
In order to add more flexibility to the vm and bootloader
elements, split the functionality in two different ones, and
make vm depend on bootloader element.
This will allow to construct more elements that depend on
bootloader, and develop both elements independently.

Change-Id: Iad2503b7b8fe53b768a3bc79e4cb839700fbd747
2015-12-15 20:49:03 +01:00
Gregory Haynes
757b8cee3b Add --force to grub-install
Grub fails to install the bootloader due to it being on the root
partition of a block device. This is not actually a problem for us, so
we need to force it to succeed.

Change-Id: I335ef04ca8a8a8a5c242d3444b09bcce0a9f51e7
2015-10-18 02:26:31 +00:00
Ian Wienand
2c32c7ae1a Handle modern sfdisk and correctly align image partition
As described in the comments, sfdisk was rewritten for util-linux 2.26
(as shipped in F22) and now interprets arguments a sectors, rather
than cylinders.

The current partitioning line is "1 - - *" (start/size/type/bootable)
which means you start getting:

---
/usr/sbin/grub2-install: warning: this msdos-style partition label has
no post-MBR gap; embedding won't be possible.

/usr/sbin/grub2-install: warning: Embedding is not possible.  GRUB can
only be installed in this setup by using blocklists.  However,
blocklists are UNRELIABLE and their use is discoura ged..

/usr/sbin/grub2-install: error: will not proceed with blocklists.
---

when building images, because the start is interpreted by the new
sfdisk as sector 1 and it crams the partition right next to the MBR.

Specifying "-" for the size is undefined in the man page; even reading
the source it's not totally clear what "-" for the size does [2].  In
any case, the alignment is wrong in sectors or cylinders; we want to
be a multiple of 4KiB for best performance.

The intent here is to create one single, Linux, bootable, partition
taking up the whole disk starting at 1MiB, so "2048 + L *" makes this
clear.

We use the -uS argument to ensure both versions treat this start-value
as a sector offset (newer sfdisk essentially ignores the argument).
As described in the comments, bugs in the older sfdisk necessitate
usage of "--force".

Although we could choose more or less, it seems most common to align
to a 1MiB boundary (i.e. starting at sector 2048).  libguestfs has
some disucssion around --alignment and where it sets it's default to
this [3].  The 2.26-era sfdisk also defaults to putting partitions
here.  1MiB should be enough for GPT schemes in the future as well.

[1] https://github.com/karelzak/util-linux/blob/master/libfdisk/src/script.c#L1050
[2] https://bugzilla.redhat.com/show_bug.cgi?id=1249893
[3] http://libguestfs.org/virt-resize.1.html

Change-Id: I2c2966f98d1d5ad4ebb433ea148b3b26c65dc1b5
2015-08-04 15:26:13 +10:00
Pino Toscano
043711e3fa vm: use $DISTRO_NAME instead of lsb_release
Use the distribution string already available as $DISTRO_NAME.

Change-Id: I4aa3b19d66cc4bed39e9778f0ed21e86743afe41
2015-05-12 17:49:03 +02:00
Monty Taylor
eadd79c2cb Port centos-minimal to yum-minimal
Now that we have a generic yum-minimal element, just use it in centos
instead of rinse. Adding base as an element-provides of yum-minimal
because this element conflicts with the base element.

Co-Authored-By: Gregory Haynes <greg@greghaynes.net>

Change-Id: I15275d821781171c118f21aa0c0bca55f65a65b3
2015-04-22 20:34:48 -04:00
Jenkins
100959de8d Merge "Add no_timer_check to vm grub cmdline" 2015-03-20 13:05:03 +00:00
Jenkins
cec46c56a4 Merge "Standarise tracing for scripts" 2015-03-04 00:38:44 +00:00
Ben Nemec
16f1de6115 Quote to handle empty DIB_RELEASE
We don't export DIB_RELEASE in the base distro scripts, so many
times it will be an unset variable in 51-bootloader from the vm
element.  Currently that script doesn't handle the situation
properly and we get errors like:

line 160: [: =: unary operator expected

This change quotes the references to DIB_RELEASE so that won't
happen anymore.

Change-Id: Ic8f91804334f8862c217f465be80e96d3116f5c8
2015-02-18 20:16:50 +00:00
Ian Wienand
36b59c001c Standarise tracing for scripts
There is a wide variety of tracing options through the various shell
scripts.  Some use "set -eux", others explicity set xtrace and others
do nothing.  There is a "-x" option to bin/disk-image-create but it
doesn't flow down to the many scripts it calls.

This adds a global integer variable set by disk-image-create
DIB_DEBUG_TRACE.  All scripts have a stanza added to detect this and
turn on tracing.  Any other tracing methods are rolled into this.  So
the standard header is

---
if [ "${DIB_DEBUG_TRACE:-0}" -gt 0 ]; then
    set -x
fi
set -eu
set -o pipefail
---

Multiple -x options can be specified to dib-create-image, which
increases the value of DIB_DEBUG_TRACE.  If script authors feel their
script should only trace at higher levels, they should modify the
"-gt" value.  If they feel it should trace by default, they can modify
the default value also.

Changes to pachset 16 : scripts which currently trace themselves by
default have retained this behaviour with DIB_DEBUG_TRACE defaulting
to "1".  This was done by running [1] on patch set 15.  See the thread
beginning at [2]

dib-lint is also updated to look for the variable being matched.

[1] https://gist.github.com/ianw/71bbda9e6acc74ccd0fd
[2] http://lists.openstack.org/pipermail/openstack-dev/2014-November/051575.html

Change-Id: I6c5a962260741dcf6f89da9a33b96372a719b7b0
2015-02-12 10:41:32 +11:00
Lennart Regebro
a9b07487ef Fix the bootloader on UEFI machines
The fix for UEFI machines was only applied on Fedora, not RHEL or other distros.

Change-Id: I43b7a826b7049703b0ffd84ad44b93c912dc6b53
2015-02-11 15:38:53 +01:00
Gregory Haynes
c4bbb6f3bc Create docs site containing element READMEs
We currently do not have the ability to create a docs site which
outlines all the elements.

Change-Id: I77ccf61e0c4b1509b3e7ce9b8f15ea5ccfd50d9b
2015-02-10 11:45:35 -08:00
yogananth subramanian
631cae1fee Enable vm element to create PowerPC image
Patch adds support to create PowerPC image with vm element.
It creates 2 partitions, one for PReP boot and other for root and
installs grub-ieee1275.

Change-Id: I4675ef2b82aa69b63e63a1cc7db01b0c0e6f9fff
Closes-Bug: 1418739
2015-02-06 03:39:36 +05:30
Ben Nemec
1ec93f43a8 Add no_timer_check to vm grub cmdline
no_timer_check prevents the kernel from probing for hardware timers,
which doesn't make sense in a virtual environment and can cause
hangs at boot [1] [2].

[1]: https://bugzilla.redhat.com/show_bug.cgi?id=1082030
[2]: https://bugzilla.redhat.com/show_bug.cgi?id=1102592

Change-Id: I1c42cc7fae7bba1dc6f4feb69f13760f4312e4d1
2015-02-05 11:53:48 -06:00
Abel Lopez
acccfaf181 Don't use lsb_release
Using lsb_release to figure out what distro and release an image is
is redundant, as the same information is available in DIB_ vars.
Further, it causes errors when creating new rhel7/centos7 images
like this: http://paste.openstack.org/show/144729/

Change-Id: I213ee581b8abfe119ffe3b783e6a3236e58e3e47
2014-12-04 11:07:24 -08:00
Jenkins
34c273d8df Merge "Make diskimage-builder work in Docker." 2014-10-24 20:13:45 +00:00
Ben Nemec
dde3d24213 Allow custom rootfs labels
Per [1], our current root label of cloudimg-root does not work with
XFS because XFS only allows 12 character labels.  This change
addresses that by allowing a custom rootfs label to be specified
in the call to disk-image-create.  There should be no backwards
compatibility concerns as the default label is unchanged.  Any
external elements dealing with the label would need to be updated
to support this new feature, but should continue to work as before
as long as a custom label is not specified.

[1]: https://bugzilla.redhat.com/show_bug.cgi?id=1139584

Change-Id: I596104d1a63b5dc6549e8460a1ae3da00165ef04
2014-09-26 17:44:08 -05:00
Victor Lowther
38b14df72c Make diskimage-builder work in Docker.
When running inside a Docker container, we cannot rely on devices in
/dev/mapper to be automagically created by udev, because we probably
don't have a udev at all.  To work around this, run dmsetup mknodes
after every kpartx run.

Change-Id: If7e30579224ce54c5ed26d08974d8293c144719a
2014-09-15 06:43:53 -05:00
Jenkins
bab742c854 Merge "Changed serial console setup" 2014-09-09 12:42:31 +00:00
Sandhya Ganapathy
697e771e4d Fix for host env leak into grub
While building images in a dual boot host,
/dev/sda is leaking into build's grub config.
It is visible in the logs that the commands
GRUB-INSTALL and GRUB-MKCONFIG probes Host OS environment.
This is avoided by setting grub_disable_os_prober
to true in /default/grub config file.

Change-Id: I7408de7b3bc8a62f8bf103f00a88a596f988353c
Closes-Bug: 1166491
2014-09-04 13:59:57 +05:30
Abel Lopez
dd3ad7e014 Changed serial console setup
The previous method only configured serial console for Ubuntu or
Fedora, I noticed this wasn't working when I built RedHat 7.
After reading about how grub-mkconfig works, I realized that we
shouldn't be using sed to modify grub.cfg, and set up the proper
variables in /etc/default/grub

Change-Id: I02b73dc5074cb48a716849cb8a8a9b2f054bea31
2014-09-02 21:07:08 +00:00
Juerg Haefliger
340f38d014 Extend/fix support for extlinux bootloader
Some extlinux packages install mbr.bin under /usr/lib/extlinux or
/usr/lib/EXTLINUX so tese directories need to be checked as well.
Also, there are packages that create a /boot/extlinux directory
which needs to be taken into account. Finally, commit
bccffc8bfd dropped the /boot prefix
from the kernel and initrd references in the ext/syslinux config
file which is simply a bug that needs fixing.

Change-Id: Idb071c9b18ff557b0f0f76d0d754536f2deca904
Closes-Bug: 1335042
2014-07-30 09:49:34 +02:00
Ian Wienand
5abb4a4f12 Initial centos7 support
Initial support for a centos7 image.

This is separate to rhel7 because the major differences are things
like repo and image locations, which are always going to be different.
We should merge any real changes into the redhat-common layers.

Apart from the added support files in centos7/*, the other change is
mostly modifications to redhat-common's extract-image to handle
different partition layouts of the centos7 image.

Change-Id: I943abe5ff0a803f36eda266a79af0d9220edcae7
2014-07-16 10:43:05 +10:00
Ian Wienand
13eaa40e5e Handle non-script grub2-install
grub2-install has been re-written [1] so isn't always a shell script,
so just exec it directly.  Also use $() as that follows the rest of
the file.

[1] http://git.savannah.gnu.org/cgit/grub.git/commit?id=cd46aa6cefabd7b0fcb15cd614577e1ab8c7a841

Change-Id: Ib4fd7c6854fb485c0da6a79babf4a3d45a8a0f2c
2014-07-15 10:52:52 +10:00
Kiall Mac Innes
572b8b2b13 VM element: Enable serial console on Debian
Debian based distros do not enable the serial console by default
in grub.cfg, instead sending all boot messages to the display

Change-Id: I0e80859198e77862ab0301ab27ebe11702fba09d
2014-06-25 14:13:49 +00:00
Om Kumar
bccffc8bfd Refactor code to select boot kernel
The script to find best kernel from image (used by vm
and baremetal element) is duplicated and is not in sync
with each other. Moving the code to img-functions as a
function will reduce duplicated code and make it reusable
in future.

Since img-functions is not accessible in chroot env,
kernel selection is being moved from finalise.d to
cleanup.d in the vm element.

Change-Id: I8fbccc13a2c61a5191ef9ea5d2a8302a3e43b000
2014-06-13 11:46:39 +05:30
Gonéri Le Bouder
ea3f4dd459 4 spaces indent
ensure 4 spaces indentation is used everywhere.

Change-Id: Ieb48faacb4c96b7b358771d70c17f2f22d0354f4
2014-05-10 11:17:29 +02:00
Ben Nemec
16be6d7ce0 set -u and -o pipefail everywhere
As with the previous similar changes, this is intended to catch
problems as they happen instead of ignoring them and continuing on
to potentially fail later.  Setting this on all existing scripts
will allow us to enforce use via Jenkins.

Change-Id: Iad2d490c86dceab148ea9ab08f457c49a5d5352e
2014-05-06 15:51:07 -05:00
Jenkins
95cdefebf6 Merge "Fix Grub configurations for Fedora images built on a UEFI host." 2014-04-17 07:48:06 +00:00
Ben Nemec
381ff6ab1d Fix set -eu and pipefail failures
Fixes problems found by set -eu and pipefail, including:
-Many unset variables
-Commands that can fail under normal circumstances, which breaks
with set -e.  This change swallows those expected errors to allow
our existing error code to handle them.
-The dkms element was not finding Fedora kernel versions correctly.
This may be an issue for other distros too, but since Fedora was
working fine without this functionality I only changed it to print
a warning message rather than failing the build when it happens.
-The ramdisk init script will not be set -eu because if it fails
the result is a kernel panic, which can be tricky to debug.
However, in testing with set -e a few failing commands were found
and have been fixed in this patch.

Change-Id: I44cf98dfc80cfcaec54b88cc83be80a3dbf2cec3
2014-04-15 20:53:15 -05:00
Gonéri Le Bouder
341d7aaff7 fix grub2 installation on Debian Wheezy
--target has been introduced in grub2. This patch ensure we use
the minimal version before adding the --target XXX flag.

Debian Wheezy and Precise share the same limitation regarding the
root device.

Change-Id: I5b3ad42b9fb536d13fb65d84339bc15bc23d99a3
2014-04-02 11:37:49 +02:00
Om Kumar
50d1e09df1 Fix Grub configurations for Fedora images built on a UEFI host.
The grub install scripts on Fedora have hardcoded checks for
/sys/firmware/efi and if the directory exists, it uses efi
specific instruction like initrdefi, linuxefi etc. vm element
should fix it once the configuration is generated.

Closes-bug: #1231946
Change-Id: I888304cb9167b8e074b04ca6c5b2f9143b70d37d
2014-04-02 03:09:29 +00:00
Luigi Toscano
be3efed80b Add console kernel parameters to extlinux configuration
Those parameters allow to access the console for VMs using
extlinux (CentOS 6 for example). They are already added to
Fedora images.

Change-Id: I035170bd101062e004fb3782b5f8e5a7944a4f03
Closes-Bug: 1296899
2014-03-25 14:24:43 +01:00
Jenkins
12463106c8 Merge "Enable extlinux support for (non-Ubuntu) Debian platforms" 2014-03-13 03:34:18 +00:00
Jenkins
d55d54d9cf Merge "Fix syntax error in GRUB_OPTS env var handling" 2014-03-04 18:04:29 +00:00
Jonathan Brownell
9c05300728 Fix spelling error in "vm" element README.md
Change-Id: I7b5e38277843da1ee6496292a7d6ff147c97cf31
2014-03-03 09:58:12 -08:00
Jonathan Brownell
1eabcdf35f Enable extlinux support for (non-Ubuntu) Debian platforms
Extlinux bootloader configuration in "vm" element requires vmlinuz and
initrd.img files in /boot/ with "generic" suffix. When these don't exist,
bootloader configuration should fall back to using whatever does exist.

Change-Id: I79d426e8f008e9f23db899f0b8f8cf2f23643e28
2014-02-28 06:56:41 -08:00
Jonathan Brownell
2189b627de Fix syntax error in GRUB_OPTS env var handling
Reference to ${GRUB_OPTS:""} in 'vm' element causes syntax error
if GRUB_OPTS is set. Fix by changing to ${GRUB_OPTS:-""}.

Change-Id: Iae3ee8b7c4064c92d0cfc1b5a8caa22e53d6d112
2014-02-27 13:53:07 -08:00
Derek Higgins
2c8d4b2271 Mount root filesystem readonly during boot
If creating an image of a disto without grub2 extlinux is instead used,
extlinux was being configured to mount the root filesystem as
read/write which in turn causes e2fsck to fail to test the filesystem,
on RHEL 6.5 this causes the boot process to fail.

Change-Id: I07859e0df9a2bc1ddd8c5f2ed4509ba14312e140
2014-01-23 16:03:03 +00:00
Dirk Mueller
b12c28dde8 Workaround broken udev update on openSUSE
Delete stale symlinks created by current openSUSE 13.1
for kpartx loopback partitions. Those break bootloader
installation otherwise.

Change-Id: I13a7387e341b4426b459610fd1d3c49ce5730f46
2014-01-23 08:34:22 +01:00
Ralf Haferkamp
7da1425438 Merge force-text-mode-console into the bootloader script
52-force-text-mode-console, running after 51-bootloader, calls
grub2-mkconfig (on Ubuntu that will happen via the update-grub call).
This call will overwrite all the changes that 51-bootloader did to the
grub.cfg. By merging the 52-force-text-mode-console code into
51-bootloader we avoid that. This also means that 51-bootloader will now
call grub2-mkconfig regardless of whether there is already and existing
grub2 configuration or not (52-force-text-mode-console did that in the
past anyway).

Additionally this commit enables the force to textmode code for openSUSE
(was previously only working correctly for Ubuntu and Fedora).

Closes-Bug: #1260323
Change-Id: Ida8e1a69df22d41ad70eb7154707c50613b536a8
2013-12-16 13:58:42 +01:00
Tim Serong
54c8508d45 Add support for building openSUSE images
This is currently experimental/incomplete.  See
elements/opensuse/README.md for details.

Change-Id: Ie5bcab15c9703cf15ceb642fb986a8afc34f96fb
Co-Authored-By: Ralf Haferkamp <rhafer@suse.de>
2013-12-05 15:18:46 +01:00
Victor Lowther
43b70ce224 /bin/bash all the things.
Since we are using bash syntax in some of the element fragments,
we should make sure we use bash for all of them, so that things don't
break on systems where /bin/sh != /bin/bash.

Change-Id: If2f043c57aa4e1492b7f9839213ef6123f683612
2013-11-17 16:59:31 -06:00
Chris Jones
b50dbb0571 Move textmode forcer to vm element.
Changing the grub config makes no sense in a build not heading for a vm
and may fail because grub is removed from images not including the vm
element. Forcing textmode for those images would be better done in nova.

Change-Id: I1c5b89e551e62df2463200b1889cb2342498c7dd
2013-09-18 01:57:35 +01:00
Steve Baker
9ba761ef27 Install fedora grub from cached rpm during finalise
When uninstalling grub2, leave all its dependencies
including grub2-tools installed to minimise the number of packages
which need to be installed in the finalise stage.

Since the yum cache is unmounted during finalise, installing
grub2 in finalise is slowed by re-populating the yum cache.

This change copies the grub2 rpm out of the yum cache so it can be installed
from file during finalise.

This should prevent disk becoming full during finalise on Fedora.

Closes-Bug: #1217185

Change-Id: If095adc4abb52a19a3aa0b1caebfb3e4d8f605ef
2013-09-15 09:11:58 +10:00
Lucas Alvares Gomes
5dd6c4a834 Extlinux fallback
If GRUB2 is not available in the system a fallback to install Extlinux
will happen. This patch also allows you to enforce the use of Extlinux
exporting the DIB_EXTLINUX variable.

Change-Id: I88fa792a0bd19cacca167134f2054b11c807a451
2013-08-27 11:14:44 +01:00