[Libguestfs] [PATCH] Fix mkinitrd detection of LVM root on RHEL 4
Richard W.M. Jones
rjones at redhat.com
Tue Aug 17 10:45:36 UTC 2010
On Tue, Aug 03, 2010 at 05:32:24PM +0100, Matthew Booth wrote:
> RHEL 4's mkinitrd will fail to recognise that root is on LVM when running on a
> recent kernel/udev due to changes in naming. This patch detects LVM root for
> RHEL 4, and uses a dirty hack to frig mkinitrd if required.
>
> Fixes RHBZ#580461
> ---
> lib/Sys/VirtV2V/GuestOS/RedHat.pm | 21 +++++++++++++++++++--
> 1 files changed, 19 insertions(+), 2 deletions(-)
>
> diff --git a/lib/Sys/VirtV2V/GuestOS/RedHat.pm b/lib/Sys/VirtV2V/GuestOS/RedHat.pm
> index 101a64b..74b9de1 100644
> --- a/lib/Sys/VirtV2V/GuestOS/RedHat.pm
> +++ b/lib/Sys/VirtV2V/GuestOS/RedHat.pm
> @@ -1639,13 +1639,14 @@ sub prepare_bootable
> my @modules = @_;
>
> my $g = $self->{g};
> + my $desc = $self->{desc};
>
> # Find the grub entry for the given kernel
> my $initrd;
> my $found = 0;
> eval {
> my $prefix;
> - if ($self->{desc}->{boot}->{grub_fs} eq "/boot") {
> + if ($desc->{boot}->{grub_fs} eq "/boot") {
> $prefix = '';
> } else {
> $prefix = '/boot';
> @@ -1720,7 +1721,23 @@ sub prepare_bootable
> $g->modprobe('loop');
> };
>
> - $g->command(['/sbin/mkinitrd', @module_args, $initrd, $version]);
> + my @env;
> +
> + # RHEL 4 mkinitrd determines if the root filesystem is on LVM by
> + # checking if the device name (after following symlinks) starts with
> + # /dev/mapper. However, on recent kernels/udevs, /dev/mapper/foo is
> + # just a symlink to /dev/dm-X. This means that RHEL 4 mkinitrd
> + # running in the appliance fails to detect root on LVM. We check
> + # ourselves if root is on LVM, and frig RHEL 4's mkinitrd if it is
> + # by setting root_lvm=1 in its environment. This overrides an
> + # internal variable in mkinitrd, and is therefore extremely nasty
> + # and applicable only to a particular version of mkinitrd.
> + if ($desc->{distro} eq 'rhel' && $desc->{major_version} eq '4') {
> + push(@env, 'root_lvm=1') if ($g->is_lv($desc->{root_device}));
> + }
> +
> + $g->sh(join(' ', @env).' /sbin/mkinitrd '.join(' ', @module_args).
> + " $initrd $version");
> }
>
> else {
Looks OK, ACK.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
New in Fedora 11: Fedora Windows cross-compiler. Compile Windows
programs, test, and build Windows installers. Over 70 libraries supprt'd
http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw
More information about the Libguestfs
mailing list