Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
New APIs: Add support for syslinux and extlinux (bootloaders).
This also adds tests of SYSLINUX and EXTLINUX which create bootable
guests.
  • Loading branch information
rwmjones committed Apr 4, 2013
1 parent e73cd34 commit dee1dd6
Show file tree
Hide file tree
Showing 15 changed files with 366 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -463,6 +463,8 @@ Makefile.in
/tests/regressions/rhbz790721
/tests/regressions/rhbz914931
/tests/rsync/rsyncd.pid
/tests/syslinux/extlinux-guest.img
/tests/syslinux/syslinux-guest.img
/test-tool/libguestfs-test-tool
/test-tool/libguestfs-test-tool.1
/test-tool/libguestfs-test-tool-helper
Expand Down
1 change: 1 addition & 0 deletions Makefile.am
Expand Up @@ -57,6 +57,7 @@ SUBDIRS += tests/bigdirs
SUBDIRS += tests/disk-labels
SUBDIRS += tests/hotplug
SUBDIRS += tests/nbd
SUBDIRS += tests/syslinux
SUBDIRS += tests/regressions
endif

Expand Down
3 changes: 3 additions & 0 deletions appliance/packagelist.in
Expand Up @@ -49,6 +49,7 @@
pcre
reiserfs-utils
libselinux
syslinux-extlinux
systemd /* for /sbin/reboot and udevd */
vim-minimal
xz
Expand All @@ -61,6 +62,7 @@
btrfs-tools
cryptsetup
e2fsprogs
extlinux
genisoimage
gfs-tools
gfs2-tools
Expand Down Expand Up @@ -148,6 +150,7 @@ rsync
scrub
sed
strace
syslinux
tar
udev
util-linux
Expand Down
1 change: 1 addition & 0 deletions configure.ac
Expand Up @@ -1604,6 +1604,7 @@ AC_CONFIG_FILES([Makefile
tests/regressions/Makefile
tests/rsync/Makefile
tests/selinux/Makefile
tests/syslinux/Makefile
tests/tmpdirs/Makefile
tests/xml/Makefile
tools/Makefile])
Expand Down
1 change: 1 addition & 0 deletions daemon/Makefile.am
Expand Up @@ -161,6 +161,7 @@ guestfsd_SOURCES = \
stubs.c \
swap.c \
sync.c \
syslinux.c \
tar.c \
truncate.c \
umask.c \
Expand Down
96 changes: 96 additions & 0 deletions daemon/syslinux.c
@@ -0,0 +1,96 @@
/* libguestfs - the guestfsd daemon
* Copyright (C) 2013 Red Hat Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include <config.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>

#include "daemon.h"
#include "actions.h"
#include "optgroups.h"

GUESTFSD_EXT_CMD(str_syslinux, syslinux);
GUESTFSD_EXT_CMD(str_extlinux, extlinux);

int
optgroup_syslinux_available (void)
{
return prog_exists (str_syslinux);
}

int
optgroup_extlinux_available (void)
{
return prog_exists (str_extlinux);
}

/* Takes optional arguments, consult optargs_bitmask. */
int
do_syslinux (const char *device, const char *directory)
{
const size_t MAX_ARGS = 32;
const char *argv[MAX_ARGS];
size_t i = 0;
CLEANUP_FREE char *err = NULL;
int r;

ADD_ARG (argv, i, str_syslinux);
ADD_ARG (argv, i, "--install");
ADD_ARG (argv, i, "--force");

if (optargs_bitmask & GUESTFS_SYSLINUX_DIRECTORY_BITMASK) {
ADD_ARG (argv, i, "--directory");
ADD_ARG (argv, i, directory);
}

ADD_ARG (argv, i, device);
ADD_ARG (argv, i, NULL);

r = commandv (NULL, &err, argv);
if (r == -1) {
reply_with_error ("%s", err);
return -1;
}

return 0;
}

int
do_extlinux (const char *directory)
{
CLEANUP_FREE char *buf = sysroot_path (directory);
CLEANUP_FREE char *err = NULL;
int r;

if (!buf) {
reply_with_perror ("malloc");
return -1;
}

r = command (NULL, &err, str_extlinux, "--install", buf, NULL);
if (r == -1) {
reply_with_error ("%s: %s", directory, err);
return -1;
}

return 0;
}
65 changes: 65 additions & 0 deletions generator/actions.ml
Expand Up @@ -10939,6 +10939,71 @@ call it returns a simple true/false boolean result, instead
of throwing an exception if a feature is not found. For
other documentation see C<guestfs_available>." };

{ defaults with
name = "syslinux";
style = RErr, [Device "device"], [OString "directory"];
proc_nr = Some 399;
optional = Some "syslinux";
shortdesc = "install the SYSLINUX bootloader";
longdesc = "\
Install the SYSLINUX bootloader on C<device>.
The device parameter must be either a whole disk formatted
as a FAT filesystem, or a partition formatted as a FAT filesystem.
In the latter case, the partition should be marked as \"active\"
(C<guestfs_part_set_bootable>) and a Master Boot Record must be
installed (eg. using C<guestfs_pwrite_device>) on the first
sector of the whole disk.
The SYSLINUX package comes with some suitable Master Boot Records.
See the L<syslinux(1)> man page for further information.
The optional arguments are:
=over 4
=item C<directory>
Install SYSLINUX in the named subdirectory, instead of in the
root directory of the FAT filesystem.
=back
Additional configuration can be supplied to SYSLINUX by
placing a file called C<syslinux.cfg> on the FAT filesystem,
either in the root directory, or under C<directory> if that
optional argument is being used. For further information
about the contents of this file, see L<syslinux(1)>.
See also C<guestfs_extlinux>." };

{ defaults with
name = "extlinux";
style = RErr, [Pathname "directory"], [];
proc_nr = Some 400;
optional = Some "extlinux";
shortdesc = "install the SYSLINUX bootloader on an ext2/3/4 or btrfs filesystem";
longdesc = "\
Install the SYSLINUX bootloader on the device mounted at C<directory>.
Unlike C<guestfs_syslinux> which requires a FAT filesystem, this can
be used on an ext2/3/4 or btrfs filesystem.
The C<directory> parameter can be either a mountpoint, or a
directory within the mountpoint.
You also have to marked the partition as \"active\"
(C<guestfs_part_set_bootable>) and a Master Boot Record must
be installed (eg. using C<guestfs_pwrite_device>) on the first
sector of the whole disk.
The SYSLINUX package comes with some suitable Master Boot Records.
See the L<extlinux(1)> man page for further information.
Additional configuration can be supplied to SYSLINUX by
placing a file called C<extlinux.conf> on the filesystem
under C<directory>. For further information
about the contents of this file, see L<extlinux(1)>.
See also C<guestfs_syslinux>." };

]

(* Non-API meta-commands available only in guestfish.
Expand Down
6 changes: 4 additions & 2 deletions gobject/Makefile.inc
Expand Up @@ -83,7 +83,8 @@ guestfs_gobject_headers= \
include/guestfs-gobject/optargs-hivex_open.h \
include/guestfs-gobject/optargs-xfs_repair.h \
include/guestfs-gobject/optargs-mke2fs.h \
include/guestfs-gobject/optargs-mktemp.h
include/guestfs-gobject/optargs-mktemp.h \
include/guestfs-gobject/optargs-syslinux.h

guestfs_gobject_sources= \
src/session.c \
Expand Down Expand Up @@ -148,4 +149,5 @@ guestfs_gobject_sources= \
src/optargs-hivex_open.c \
src/optargs-xfs_repair.c \
src/optargs-mke2fs.c \
src/optargs-mktemp.c
src/optargs-mktemp.c \
src/optargs-syslinux.c
2 changes: 2 additions & 0 deletions po/POTFILES
Expand Up @@ -85,6 +85,7 @@ daemon/strings.c
daemon/stubs.c
daemon/swap.c
daemon/sync.c
daemon/syslinux.c
daemon/tar.c
daemon/truncate.c
daemon/umask.c
Expand Down Expand Up @@ -179,6 +180,7 @@ gobject/src/optargs-rsync.c
gobject/src/optargs-rsync_in.c
gobject/src/optargs-rsync_out.c
gobject/src/optargs-set_e2attrs.c
gobject/src/optargs-syslinux.c
gobject/src/optargs-tar_in.c
gobject/src/optargs-tar_out.c
gobject/src/optargs-tune2fs.c
Expand Down
2 changes: 1 addition & 1 deletion src/MAX_PROC_NR
@@ -1 +1 @@
398
400
30 changes: 30 additions & 0 deletions tests/syslinux/Makefile.am
@@ -0,0 +1,30 @@
# libguestfs
# Copyright (C) 2013 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

include $(top_srcdir)/subdir-rules.mk

TESTS = \
test-syslinux.sh \
test-extlinux.sh

TESTS_ENVIRONMENT = $(top_builddir)/run --test

EXTRA_DIST = \
$(TESTS) \
test-syslinux.pl

CLEANFILES = syslinux-guest.img extlinux-guest.img
13 changes: 13 additions & 0 deletions tests/syslinux/README
@@ -0,0 +1,13 @@
The tests in this directory simply run SYSLINUX/EXTLINUX (if
available) to make sure they work.

However if you want, you can also try booting the resultant guests,
although this is not part of the test.

qemu-kvm -hda syslinux-guest.img
qemu-kvm -hda extlinux-guest.img

Note that there is just a kernel, no operating system, inside these
guests so the Linux kernel is expected to panic once it tries to find
an init process to run. (You could modify these tests to add an init
process if you wanted to).
19 changes: 19 additions & 0 deletions tests/syslinux/test-extlinux.sh
@@ -0,0 +1,19 @@
#!/bin/sh
# libguestfs
# Copyright (C) 2013 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

BOOTLOADER=extlinux ./test-syslinux.pl

0 comments on commit dee1dd6

Please sign in to comment.