From 8eb652f9b154ab70e576a77d6759fd2a9b219202 Mon Sep 17 00:00:00 2001 From: daniceexi Date: Thu, 12 Feb 2015 22:42:19 -0500 Subject: [PATCH] Ubuntu/genimage: support multiple local mirror in osimage.pkgdir. The first one will be used to create bootstraps. The procedure to create osimage is: 1. create bootstrap with local/remote mirror; 2. add all mirror in osimage.pkgdir to sourcelist; 3. do osimage update; 4. install kernel; 5 install otherpkgs. --- xCAT-server/lib/xcat/plugins/genimage.pm | 8 +- .../share/xcat/netboot/ubuntu/genimage | 108 ++++++++++-------- 2 files changed, 64 insertions(+), 52 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/genimage.pm b/xCAT-server/lib/xcat/plugins/genimage.pm index fc54f0619..3f068bb3f 100644 --- a/xCAT-server/lib/xcat/plugins/genimage.pm +++ b/xCAT-server/lib/xcat/plugins/genimage.pm @@ -170,12 +170,6 @@ sub process_request { $pkglist = $ref_linuximage_tab->{'pkglist'}; $srcdir = $ref_linuximage_tab->{'pkgdir'}; - my @pkgarray = split(/,/, $ref_linuximage_tab->{'pkgdir'}); - if(scalar(@pkgarray) > 1) - { - $srcdir = @pkgarray[0]; - } - $srcdir_otherpkgs = $ref_linuximage_tab->{'otherpkgdir'}; $otherpkglist = $ref_linuximage_tab->{'otherpkglist'}; @@ -299,7 +293,7 @@ sub process_request { if ($interactive) { $cmd .= " --interactive" } if ($onlyinitrd) { $cmd .= " --onlyinitrd" } - if ($srcdir) { $cmd .= " --srcdir $srcdir";} + if ($srcdir) { $cmd .= " --srcdir \"$srcdir\"";} if ($pkglist) { $cmd .= " --pkglist $pkglist";} if ($srcdir_otherpkgs) { $cmd .= " --otherpkgdir \"$srcdir_otherpkgs\""; } if ($otherpkglist) { $cmd .= " --otherpkglist $otherpkglist"; } diff --git a/xCAT-server/share/xcat/netboot/ubuntu/genimage b/xCAT-server/share/xcat/netboot/ubuntu/genimage index 4ae2c2f19..a35c2033f 100755 --- a/xCAT-server/share/xcat/netboot/ubuntu/genimage +++ b/xCAT-server/share/xcat/netboot/ubuntu/genimage @@ -228,10 +228,12 @@ unless ($onlyinitrd) { # Get the ubuntu repo path from osimage.pkgdir my @srcdirs = split(',', $srcdir); - my $pkgdir_internet; #only support one http mirror which will be used to create bootstrap + + my @pkgdir_internet; #Put all the http mirror in ths array, but only the first http mirror which will be used to create bootstrap + $srcdir = undef; foreach my $dir (@srcdirs) { if ($dir =~ /^http.*/){ - $pkgdir_internet = $dir; + push @pkgdir_internet, $dir; } else { $srcdir = $dir; #set $srcdir to be the one which is not http path find(\&isaptdir, <$dir/>); @@ -259,14 +261,14 @@ unless ($onlyinitrd) { $repnum-=1; # Add the internet mirror - if ($pkgdir_internet) { - print $aptconfig "deb $pkgdir_internet\n\n"; + if (@pkgdir_internet) { + foreach (@pkgdir_internet) { + print $aptconfig "deb $_\n\n"; + } } close($aptconfig); mkpath "$rootimg_dir/etc"; - - my $fd; open($fd,">>","$rootimg_dir/etc/fstab"); print $fd "#Dummy fstab for dpkg postscripts to see\n"; @@ -292,11 +294,18 @@ unless ($onlyinitrd) { my $aptcmd2; # Check whether a local Ubuntu mirror is specified - # if linuximage.pkgdir has second mirror is set, we consider the second mirror as a full Ubuntu mirror - if ($pkgdir_internet) { - my $mirrorurl = $pkgdir_internet; - $mirrorurl =~ s/ .*$//g; # get the url part of mirror path - $aptcmd2 = "--verbose --arch $uarch $dist $rootimg_dir $mirrorurl"; + # if linuximage.pkgdir has http mirror is set, we consider the first http mirror + # as a full Ubuntu mirror which will be used to create bootstrap + if (@pkgdir_internet) { + my $mirrorurl = $pkgdir_internet[0]; + if ($pkgdir_internet[0] =~ /(http.*?) +([^ ]+)/) { + $mirrorurl = $1; + $dist = $2; + $aptcmd2 = "--verbose --arch $uarch $dist $rootimg_dir $mirrorurl"; + } else { + print "Error: In pkgdir, the first http mirror path must includes http URL and distribute name."; + exit 1; + } } else { if ($uarch eq 'ppc64el') { $aptcmd2 = "--verbose --arch $uarch $dist $rootimg_dir http://ports.ubuntu.com/ubuntu-ports/"; @@ -305,9 +314,36 @@ unless ($onlyinitrd) { } } - mkpath("$rootimg_dir/var/lib/dpkg"); - mkpath("$rootimg_dir/var/lib/apt"); + print "Run cmd [$aptcmd1 $aptcmd2] to create rootimage bootstraps\n"; + my $rc = system("$aptcmd1 $aptcmd2"); + if ($rc) { + print "Error: cannnot create bootstraps for rootimage. Make sure you specified full http mirror path.\n"; + exit 1; + } + + # Prepare the installation mirror for the package install + print("Mount /proc, /dev, /sys, pkgdir and otherpkgdir to the rootimg.\n"); + mount_chroot($rootimg_dir, $otherpkgsdir_local, $srcdir, $kerneldir); + + # Add mirrors from pkgdir attributes to rootimage for the pkg install from pkglist + open($aptconfig,">","$rootimg_dir/etc/apt/sources.list"); + if ($srcdir) { + my $master = xCAT::TableUtils->get_site_Master(); + print $aptconfig "deb http://$master$srcdir $dist main\n"; + } + + foreach (@pkgdir_internet) { + print $aptconfig "deb $_\n"; + } + + close($aptconfig); + + # run apt-get upgrade to update any installed debs + my $aptgetcmd_update = $aptgetcmd . "&&". $aptgetcmdby . " upgrade "; + $rc = system("$aptgetcmd_update"); + + # Start to install pkgs in pkglist unless ($imagename) { $pkglist= imgutils::get_profile_def_filename($osver, $profile, $arch, $customdir, "pkglist"); unless ($pkglist) { @@ -370,40 +406,22 @@ unless ($onlyinitrd) { push @npa, $p; } } - $pkgnames .= join(',', @npa); + $pkgnames .= join(' ', @npa); } my $envlist; if(exists $pkg_hash{$pass}{ENVLIST}){ $envlist = join(',', @{$pkg_hash{$pass}{ENVLIST}}); } - print "$envlist $aptcmd1 --include=$pkgnames $aptcmd2\n"; - my $rc = system("$envlist $aptcmd1 --include=$pkgnames $aptcmd2"); + print "$envlist $aptgetcmdby install $pkgnames\n"; + my $rc = system("$envlist $aptgetcmdby install --allow-unauthenticated $pkgnames"); if ($rc) { - print "apt invocation failed\n"; + print "Failed to install packages $pkgnames\n"; exit 1; } } - print("Mount /proc, /dev, /sys, pkgdir and otherpkgdir to the rootimg.\n"); - mount_chroot($rootimg_dir, $otherpkgsdir_local, $srcdir, $kerneldir); - - # Add the local repo from MN temporarily for apt-get update/upgrade - open($aptconfig,">","$rootimg_dir/etc/apt/sources.list"); - print $aptconfig "deb file:///mnt/pkgdir/ $dist main\n"; - if (-d "$rootimage_dir/mnt/kerneldir") { - print $aptconfig "deb file:///mnt/kerneldir/ $dist main\n"; - } - close($aptconfig); - { - # run apt-get upgrade to update any installed debs - # needed when running genimage again after updating software in repositories - #my $aptgetcmd_update = $yumcmd_base . " upgrade "; - my $aptgetcmd_update = $aptgetcmd . "&&". $aptgetcmdby . " upgrade "; - $rc = system("$aptgetcmd_update"); - - ############################################################# # The section below is used to install kernel base and extra# ############################################################# @@ -411,10 +429,9 @@ unless ($onlyinitrd) { if ($kernelver) { $kernelimage = "linux-image-$kernelver linux-image-extra-$kernelver linux-firmware"; } - my $aptgetcmd_install = $aptgetcmd . "&&". $aptgetcmdby. " install --no-install-recommends ".$kernelimage; + my $aptgetcmd_install = $aptgetcmdby. " install --no-install-recommends ".$kernelimage; $rc = system("$aptgetcmd_install"); } - } #add the other package directory to for apt-get install @@ -555,11 +572,6 @@ unless ($onlyinitrd) { print("Umount /proc, /dev, /sys, pkgdir and otherpkgdir to the rootimg.\n"); umount_chroot($rootimg_dir); - # Add the local repo from MN - my $master = xCAT::TableUtils->get_site_Master(); - open($aptconfig,">","$rootimg_dir/etc/apt/sources.list"); - print $aptconfig "deb http://$master$srcdir $dist main\n"; - close($aptconfig); `rm -fr $rootimg_dir/etc/apt/sources.list.d/genimage1.apt.list`; #recover the /etc/hosts & /etc/reslov.conf @@ -1857,12 +1869,17 @@ sub mount_chroot { my $otherpkgdir = shift; my $pkgdir = shift; my $kerneldir = shift; - mkdir("$rootimage_dir/mnt/pkgdir"); - mkdir("$rootimage_dir/mnt/otherpkgdir"); #system("mount -o bind /dev $rootimage_dir/dev"); #system("mount -o bind /proc $rootimage_dir/proc"); #system("mount -o bind /sys $rootimage_dir/sys"); - system("mount -o bind $pkgdir $rootimage_dir/mnt/pkgdir"); + if ($pkgdir) { + if (-d $pkgdir) { + mkdir("$rootimage_dir/mnt/pkgdir"); + system("mount -o bind $pkgdir $rootimage_dir/mnt/pkgdir"); + } else { + print "The specified pkgdir $pkgdir does not exist!\n" + } + } if ($kerneldir){ if(-d $kerneldir){ mkdir("$rootimage_dir/mnt/kerneldir"); @@ -1873,6 +1890,7 @@ sub mount_chroot { } if ($otherpkgdir){ + mkdir("$rootimage_dir/mnt/otherpkgdir"); if(-d $otherpkgdir){ system("mount --rbind $otherpkgdir $rootimage_dir/mnt/otherpkgdir"); }else{