Changeset 1348 in ProjectBuilder for devel/pbmkbm/bin/pbmkbm


Ignore:
Timestamp:
Oct 26, 2011, 11:28:44 AM (13 years ago)
Author:
Bruno Cornec
Message:

r4374@localhost: bruno | 2011-10-25 12:10:59 +0200

  • Add mkbmpath parameter and document it
  • Create a new VE.pm module to host pb_ve_launch (from pb code now reusable for pbmkbm)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • devel/pbmkbm/bin/pbmkbm

    r1341 r1348  
    2121use ProjectBuilder::Conf;
    2222use ProjectBuilder::Distribution;
     23use ProjectBuilder::VE;
    2324
    2425# Global variables
     
    5051Kernel, modules could come either from the local installed system
    5152(typically for disaster recovery context) or from a kernel package of a
    52 given configuration.
     53given configuration or a referenced content.
    5354Utilities could come from busybox, local utilities or set of packages.
    5455The root filesystem is made with them.
    5556The initrd/initramfs could be made internaly or by calling dracut.
    56 THe boot config file is generated from analysis content or provided externally.
     57The boot config file is generated from analysis content or provided externally.
    5758
    5859=head1 SYNOPSIS
    5960
    60 pbmkbm [-vhq][-t boot-media-type [-d device]][-m os-ver-arch]
     61pbmkbm [-vhq][-t boot-type [-d device]][-b boot-method][-m os-ver-arch]
    6162[-s script][-a pkg1[,pkg2,...]] [target-dir]
    6263
    63 pbmkbm [--verbose][--help][--man][--quiet][--type  boot-media-type [-device device]]
    64 [--script script][--iso iso][--add pkg1,[pkg2,...]][target-dir]
     64pbmkbm [--verbose][--help][--man][--quiet][--type boot-type [--device device]]
     65[--machine os-ver-arch][--boot boot-method]
     66[--script script][--add pkg1,[pkg2,...]] [target-dir]
    6567
    6668=head1 OPTIONS
     
    8486Do not print any output.
    8587
     88=item B<-t|--type boot-type>
     89
     90Type of the boot device to generate. A boot-type can be:
     91
     92=over 4
     93
     94=item B<iso>
     95
     96Generate an ISO9660 image format (suitable to be burned later on or loopback mounted. Uses isolinux.
     97
     98=item B<usb>
     99
     100Generate a USB image format (typically a key of external hard drive). Uses syslinux.
     101
     102=item B<pxe>
     103
     104Generate a PXE environement (suitable to be integrated in a PXElinux configuration). Uses pxelinux.
     105
     106=back
     107
     108=item B<-d|--device device-file>
     109
     110Name of the device or file on which you want to create the boot media.
     111
     112=item B<-b|--boot boot-method>
     113
     114This is the boot method to use to create the boot media. A boot-method can be:
     115
     116=over 4
     117
     118=item B<native>
     119
     120Use the tools of the native distribution to create the boot media. No other dependency.
     121
     122=item B<ve>
     123
     124Use the project-builder.org virtual environment notion to create the boot media. No other dependency outside of the project.
     125
     126=item B<busybox>
     127
     128Use the busybox tool to create the boot media. Cf: L<http://www.busybox.net>
     129
     130=item B<dracut>
     131
     132Use the dracut tool to create the boot media. Cf: L<http://www.dracut.net>
     133
     134=back
     135
    86136=item B<-s|--script script>
    87137
    88 Name of the script you want to execute on the related VEs after the installation.
    89 It is executed in host environment.
    90 You can use the chroot command to execute actions in the VE.
     138Name of the script you want to execute on the related boot media at the end o the build.
    91139
    92140=item B<-a|--add pkg1[,pkg2,...]>
    93141
    94 Additional packages to add from the distribution you want to install on the related VE
    95 at the end of the chroot build.
     142Additional packages to add from the distribution you want to install on the related boot media
     143at the end of the build.
     144
     145=item B<-m|--machine os-ver-arch>
     146
     147This is the target tuple operating system-version-architecture for which you want to create the boot media.
    96148
    97149=back
     
    99151=head1 ARGUMENTS
    100152
     153target-dir is the directory under which the boot media will be build.
     154
    101155=over 4
    102156
    103 =item B<target-dir>
    104 
    105 This is the target directory under which the VE will be created.
    106 Created on the fly if needed.
    107 If none is given use the default directory hosting VE for project-builder.org
    108 (Cf: vepath parameter in $HOME/.pbrc)
    109 
    110157=back
    111158
    112159=head1 EXAMPLE
    113160
    114 To setup a USB boot media on the /dev/sdb device for a Fedora 12 distribution with an i386 architecture issue:
    115 
    116 pbmkbm -t usb -d /dev/sdb -m fedora-12-i386
     161To setup a USB busybox based boot media on the /dev/sdb device for a Fedora 12 distribution with an i386 architecture issue:
     162
     163pbmkbm -t usb -d /dev/sdb -m fedora-12-i386 -b busybox
     164
     165To setup an ISO image under /tmp for a RHEL 6 x86_64 distribution issue using the native environment:
     166
     167pbmkbm -t iso -d /tmp -m rhel-6-x86_64 -b ve
    117168
    118169=head1 WEB SITES
     
    153204
    154205GetOptions("help|?|h" => \$opts{'h'},
    155     "man|m" => \$opts{'man'},
     206    "man" => \$opts{'man'},
    156207    "verbose|v+" => \$opts{'v'},
    157208    "quiet|q" => \$opts{'q'},
     
    160211    "machine|m=s" => \$opts{'m'},
    161212    "add|a=s" => \$opts{'a'},
     213    "device|d=s" => \$opts{'d'},
     214    "type|t=s" => \$opts{'t'},
     215    "boot|b=s" => \$opts{'b'},
    162216    "version|V=s" => \$opts{'V'},
    163217) || pb_syntax(-1,0);
     
    184238# Get VE name
    185239$ENV{'PBV'} = $opts{'m'};
    186 die pb_syntax(-1,1) if (not defined $ENV{'PBV'});
    187 
    188 die "Needs to be run as root" if ($EFFECTIVE_USER_ID != 0);
    189240
    190241#
    191242# Initialize distribution info from pb conf file
    192243#
    193 pb_log(0,"Starting VE build for $ENV{'PBV'}\n");
    194244my $pbos = pb_distro_get_context($ENV{'PBV'});
     245pb_log(0,"Starting boot media build for $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}\n");
     246
     247pb_env_init_pbrc(); # to get content of HOME/.pbrc
    195248
    196249#
     
    198251# Create if not existent and use default if none given
    199252#
    200 pb_env_init_pbrc(); # to get content of HOME/.pbrc
    201 my $vepath = shift @ARGV;
     253my $targetdir = shift @ARGV;
    202254
    203255#
     
    207259pb_check_requirements($req,$opt,$appname);
    208260
    209 if (not defined $vepath) {
    210     my ($vestdpath) = pb_conf_get("vepath");
    211     $vepath = "$vestdpath->{'default'}/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}" if (defined $vestdpath->{'default'});
    212 }
    213 
    214 die pb_log(0,"No target-dir specified and no default vepath found in $ENV{'PBETC'}\n") if (not defined $vepath);
    215 
    216 pb_mkdir_p($vepath) if (! -d $vepath);
    217 
    218 #
     261# After that we will need root access
     262die "$appname needs to be run as root" if ($EFFECTIVE_USER_ID != 0);
     263
     264#
     265# Where is our build target directory
     266#
     267
     268if (not defined $targetdir) {
     269    $targetdir = "/var/cache/pbmkbm";
     270    my ($vestdpath) = pb_conf_get("mkbmpath");
     271    $targetdir = "$vestdpath->{'default'}/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}" if (defined $vestdpath->{'default'});
     272}
     273
     274die pb_log(0,"No target-dir specified and no default mkbmpath found in $ENV{'PBETC'}\n") if (not defined $targetdir);
     275
     276# Point to the right subdir and create it if needed
     277pb_mkdir_p($targetdir) if (! -d $targetdir);
     278
     279
     280# Now the preparation is over, we need to do something useful :-)
     281# But it all depends on how we're asked to do it.
     282#
     283# First we need to copy into the target dir all the relevant content
     284pb_mkbm_create_content();
     285
     286# Then we need to package this content in the destination format
     287pb_mkbm_create_media();
     288
     289sub pb_mkbm_create_content {
     290
     291pb_log(1,"Creating boot media content\n");
     292if ($opts{'b'} eq "ve") {
     293    # Use existing tools to create a good VE !
     294    pb_ve_launch($ENV{'PBV'});
     295} elsif ($opts{'b'} eq "native") {
     296    # Use native tools to create a good VE !
     297} else {
     298    die "Unknown method $opts{'b'} used to create the media content";
     299}
     300}
     301
     302sub pb_mkbm_create_media {
     303
     304}
     305
    219306# Get the package list to download, store them in a cache directory
    220307#
    221308my ($mkbmcachedir) = pb_conf_get_if("mkbmcachedir");
    222 my ($pkgs,$mirror) = pb_distro_get_param($pbos,pb_conf_get("mkbmmindep","mkbmmirrorsrv"));
    223 
    224 my $cachedir = "/var/cache/pbmkbm";
    225 $cachedir = $mkbmcachedir->{'default'} if (defined $mkbmcachedir->{'default'});
    226 
    227 # Point to the right subdir and create it if needed
    228 $cachedir .= "/$pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}";
    229 pb_mkdir_p($cachedir) if (! -d $cachedir);
     309my ($pkgs) = pb_distro_get_param($pbos,pb_conf_get("mkbmmindep"));
    230310
    231311#
    232312# /proc needed
    233313#
    234 pb_system("mount -o bind /proc $vepath/proc","Mounting /proc");
     314pb_system("mount -o bind /proc $targetdir/proc","Mounting /proc");
    235315
    236316# Installed additional packages we were asked to
    237317if (defined $opts{'a'}) {
    238318    $opts{'a'} =~ s/,/ /g;
    239     pb_system("chroot $vepath /bin/bash -c \"$pbos->{'install'} $opts{'a'} \"","Adding packages to OS by running $pbos->{'install'} $opts{'a'}");
     319    pb_system("chroot $targetdir /bin/bash -c \"$pbos->{'install'} $opts{'a'} \"","Adding packages to OS by running $pbos->{'install'} $opts{'a'}");
    240320}
    241321
     
    244324#
    245325pb_log(1,"Cleaning up\n");
    246 pb_system("umount $vepath/proc","Unmounting /proc");
     326pb_system("umount $targetdir/proc","Unmounting /proc");
    247327
    248328# Executes post-install step if asked for
    249329if ($opts{'s'}) {
    250     pb_system("$opts{'s'} $vepath","Executing the post-install script: $opts{'s'} $vepath");
    251 }
     330    pb_system("$opts{'s'} $targetdir","Executing the post-install script: $opts{'s'} $targetdir");
     331}
Note: See TracChangeset for help on using the changeset viewer.