[PATCH v2] appliance: use ID_LIKE as a fallback for SUSE distro detection
by Cédric Bosdonnat
All SUSE distros have a ID_LIKE=suse, including the fake one used
for building that has a ID=Dummy value. Without reading ID_LIKE
on SUSE distros, the generated appliance packagelist is not correct.
This fix reads ID_LIKE as a fallback if ID contains nothing.
---
m4/guestfs_appliance.m4 | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/m4/guestfs_appliance.m4 b/m4/guestfs_appliance.m4
index fbba3373f..788afbd36 100644
--- a/m4/guestfs_appliance.m4
+++ b/m4/guestfs_appliance.m4
@@ -99,8 +99,16 @@ if test -f /etc/os-release; then
DISTRO="`. /etc/os-release && echo $ID | tr '@<:@:lower:@:>@' '@<:@:upper:@:>@'`"
AS_CASE([$DISTRO],
[FEDORA | RHEL | CENTOS],[DISTRO=REDHAT],
- [OPENSUSE | SLED | SLES],[DISTRO=SUSE],
+ [OPENSUSE | SLED | SLES | SUSE],[DISTRO=SUSE],
[ARCH],[DISTRO=ARCHLINUX])
+ dnl All SUSE-based distros have ID_LIKE containing 'suse', check for it if
+ dnl ID wasn't helpful.
+ if test -z "$DISTRO"; then
+ DISTRO_LIKE="`. /etc/os-release && echo $ID_LIKE`"
+ if echo $DISTRO_LIKE | tr " " "\n" | grep -i "^SUSE$"; then
+ DISTRO=SUSE
+ fi
+ fi
elif test -f /etc/debian_version; then
DISTRO=DEBIAN
if grep -q 'DISTRIB_ID=Ubuntu' /etc/lsb-release 2>&AS_MESSAGE_LOG_FD; then
--
2.13.2
7 years, 1 month
[PATCH] customize: Unconditionally set the machine-id if not set already.
by Richard W.M. Jones
systemd defined an /etc/machine-id file which is supposed to contain a
unique, unchanging ID for the host. This file is initially zero-sized
and is meant to be set by systemd on the first boot of the system.
In virt-builder Fedora templates, the file is empty.
Unfortunately the Fedora kernel %post script requires the machine-id
to have been set, else the script exits with an error:
Running scriptlet: kernel-core-4.12.13-300.fc26.x86_64 209/209
Could not determine your machine ID from /etc/machine-id.
Please run 'systemd-machine-id-setup' as root. See man:machine-id(5)
warning: %posttrans(kernel-core-4.12.13-300.fc26.x86_64) scriptlet failed, exit status 1
This also leaves the kernel package half-installed. The files are
present in the filesystem, but important initialization is not done,
in particular the vmlinuz file is not copied into /boot.
A simple reproducer for this problem is:
$ virt-builder fedora-26 --update
which will leave the system with a half-installed kernel.
This change makes virt-customize set /etc/machine-id to a random value
if it is zero sized. This is done unconditionally at the same time as
setting the random seed (a similar issue).
---
customize/customize_run.ml | 30 ++++++++++++++++++++++++++----
1 file changed, 26 insertions(+), 4 deletions(-)
diff --git a/customize/customize_run.ml b/customize/customize_run.ml
index 5564684b4..3dcf755eb 100644
--- a/customize/customize_run.ml
+++ b/customize/customize_run.ml
@@ -27,7 +27,9 @@ open Customize_cmdline
open Password
open Append_line
-let run (g : Guestfs.guestfs) root (ops : ops) =
+module G = Guestfs
+
+let run (g : G.guestfs) root (ops : ops) =
(* Is the host_cpu compatible with the guest arch? ie. Can we
* run commands in this guest?
*)
@@ -89,7 +91,7 @@ exec >>%s 2>&1
debug "running command:\n%s" cmd;
try ignore (g#sh cmd)
with
- Guestfs.Error msg ->
+ G.Error msg ->
debug_logfile ();
if warn_failed_no_network && not (g#get_network ()) then (
prerr_newline ();
@@ -194,6 +196,26 @@ exec >>%s 2>&1
if not (Random_seed.set_random_seed g root) then
warning (f_"random seed could not be set for this type of guest");
+ (* Set the systemd machine ID. This must be set before performing
+ * --install/--update since (at least in Fedora) the kernel %post
+ * script requires a machine ID and will fail if it is not set.
+ *)
+ let () =
+ let etc_machine_id = "/etc/machine-id" in
+ let statbuf =
+ try Some (g#lstatns etc_machine_id) with G.Error _ -> None in
+ (match statbuf with
+ | Some { G.st_size = 0L; G.st_mode = mode }
+ when (Int64.logand mode 0o170000_L) = 0o100000_L ->
+ message (f_"Setting the machine ID in %s") etc_machine_id;
+ let id = Urandom.urandom_bytes 16 in
+ let id = String.map_chars (fun c -> sprintf "%02x" (Char.code c)) id in
+ let id = String.concat "" id in
+ let id = id ^ "\n" in
+ g#write etc_machine_id id
+ | _ -> ()
+ ) in
+
(* Store the passwords and set them all at the end. *)
let passwords = Hashtbl.create 13 in
let set_password user pw =
@@ -399,8 +421,8 @@ exec >>%s 2>&1
let uid, gid = statbuf.st_uid, statbuf.st_gid in
let chown () =
try g#chown uid gid dest
- with Guestfs.Error m as e ->
- if g#last_errno () = Guestfs.Errno.errno_EPERM
+ with G.Error m as e ->
+ if g#last_errno () = G.Errno.errno_EPERM
then warning "%s" m
else raise e in
chown ()
--
2.13.2
7 years, 1 month
Minimum OCaml compiler version
by Richard W.M. Jones
Currently it's OCaml >= 3.11
(http://libguestfs.org/guestfs-building.1.html#full-list-of-requirements).
That was chosen because it is the version of OCaml in RHEL 6. But
actually libguestfs isn't compilable on RHEL 6 because the version of
yajl is too old (there are probably other issues too, but that's the
first one I came up against).
Can we choose a new minimum version? There are a lot of interesting
features in OCaml that we might want to use, in particular:
- Make use of Bytes unconditional. Requires OCaml >= 4.02.
- PPX extension points could be used to generate repetitive
string_of_* functions. (OCaml >= 4.02)
- ‘match’ can catch exceptions. (OCaml >= 4.02,
https://blog.janestreet.com/pattern-matching-and-exception-handling-unite/)
- Record fields and variant constructors can have the same name and
the compiler sorts out the right struct/type intelligently.
(OCaml >= 4.01,
http://www.lexifi.com/blog/type-based-selection-label-and-constructors)
- GADTs and first class modules allow more "sophisticated" used of
modules, although I tend to think that these will just make the
code more confusing so I would push back on people trying to use if
they were being too clever. (OCaml >= 3.12 and especially >= 4.00
https://forge.ocamlcore.org/docman/view.php/77/112/leroy-cug2010.pdf
https://ocaml.org/meetings/ocaml/2012/slides/oud2012-leroy-slides.pdf)
Also it would be nice to reduce the number of warnings, especially
about the new "noalloc" syntax:
File "common_utils.ml", line 26, characters 0-85:
Warning 3: deprecated: [@@noalloc] should be used instead of "noalloc"
Versions of OCaml in various major distributions:
Arch (AUR) OCaml 4.05
Debian 8 (oldstable, jessie) OCaml 4.01
Debian 9 (stable, stretch) OCaml 4.02
Debian 10 (testing, buster) OCaml 4.02
Fedora 25 OCaml 4.02
Fedora 26 OCaml 4.04
Fedora 27, 28 OCaml 4.05
OpenSUSE (all versions) OCaml 4.05
RHEL <= 7.4 OCaml 4.01
RHEL >= 7.5 OCaml 4.05
Ubuntu 14.04 OCaml 4.01
Ubuntu 16.04 OCaml 4.02
Ubuntu Zesty OCaml 4.02
Ubuntu Artful OCaml 4.04
Since most of the new, interesting features were added in OCaml 4.02,
that would be my choice of minimum version, if we were to move at all.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-p2v converts physical machines to virtual machines. Boot with a
live CD or over the network (PXE) and turn machines into KVM guests.
http://libguestfs.org/virt-v2v
7 years, 2 months
[PATCH v2 00/18] Replace many more uses of the Str module with PCRE.
by Richard W.M. Jones
v1 was here:
https://www.redhat.com/archives/libguestfs/2017-September/msg00135.html
This is a more complete evolution of the earlier patch. It replaces
most important uses of Str with PCRE throughout the code. It also
extends the bindings with some useful features like case-insensitive
regexps.
The main places I *didn't* touch are the generator (GObject uses Str
extensively); and common/mlstdutils which cannot use PCRE because it
cannot depend on C code. But pretty much everything else has been
converted now.
- - -
Same question as before:
> I wonder if there was a deep reason why we had this?
>
> let unix2dos s =
> String.concat "\r\n" (Str.split_delim (Str.regexp_string "\n") s)
>
> I replaced it with what I think should be (nearly) equivalent:
>
> let unix2dos s =
> String.concat "\r\n" (String.nsplit "\n" s)
Rich.
7 years, 2 months
[PATCH v12 00/11] Reimplement inspection in the daemon.
by Richard W.M. Jones
This fixes almost everything. Note that it adds an extra commit which
fixes the whole utf8/iconv business.
It's probably better to list what isn't fixed:
(1) I didn't leave the osinfo code around because I'm still haven't
looked too closely at virt-builder-repository. Can't we just fetch
this code from the git history when we need it?
(2) I didn't change the way that parse_os_release work fundamentally
to reduce the risk of adding new bugs in this series. However I do
agree that we need to improve them after this series.
Rich.
7 years, 2 months
[PATCH 0/4] Replace some uses of the Str module with PCRE.
by Richard W.M. Jones
Str is a pretty ugly regexp module. Let's try to replace it with
PCRE. This series of commits goes some small way towards that
eventual goal.
- - -
I wonder if there was a deep reason why we had this?
let unix2dos s =
String.concat "\r\n" (Str.split_delim (Str.regexp_string "\n") s)
I replaced it with what I think should be (nearly) equivalent:
let unix2dos s =
String.concat "\r\n" (String.nsplit "\n" s)
Rich.
7 years, 2 months