[1341] | 1 | #!/usr/bin/perl -w
|
---|
| 2 | #
|
---|
| 3 | # pbmkbm, a project-builder.org utility to make boot media
|
---|
| 4 | #
|
---|
| 5 | # $Id$
|
---|
| 6 | #
|
---|
| 7 | # Copyright B. Cornec 2011
|
---|
| 8 | # Provided under the GPL v2
|
---|
| 9 |
|
---|
| 10 | # Syntax: see at end
|
---|
| 11 |
|
---|
| 12 | use strict 'vars';
|
---|
| 13 | use Getopt::Long qw(:config auto_abbrev no_ignore_case);
|
---|
| 14 | use Data::Dumper;
|
---|
| 15 | use English;
|
---|
| 16 | use File::Basename;
|
---|
| 17 | use File::Copy;
|
---|
[1402] | 18 | use POSIX qw(strftime);
|
---|
| 19 |
|
---|
[1341] | 20 | use ProjectBuilder::Version;
|
---|
| 21 | use ProjectBuilder::Base;
|
---|
| 22 | use ProjectBuilder::Env;
|
---|
| 23 | use ProjectBuilder::Conf;
|
---|
| 24 | use ProjectBuilder::Distribution;
|
---|
[1348] | 25 | use ProjectBuilder::VE;
|
---|
[1341] | 26 |
|
---|
| 27 | # Global variables
|
---|
| 28 | my %opts; # CLI Options
|
---|
| 29 |
|
---|
| 30 | =pod
|
---|
| 31 |
|
---|
| 32 | =head1 NAME
|
---|
| 33 |
|
---|
| 34 | pbmkbm - a project-builder.org utility to make boot media
|
---|
| 35 |
|
---|
| 36 | =head1 DESCRIPTION
|
---|
| 37 |
|
---|
| 38 | pbmkbm creates a bootable media (CD/DVD, USB device, Network, tape, ...)
|
---|
| 39 | with a minimal distribution in it, suited for building packages for example.
|
---|
| 40 | It aims at supporting all distributions supported by project-builder.org
|
---|
| 41 | (RHEL, RH, Fedora, OpeSUSE, SLES, Mandriva, ...)
|
---|
| 42 |
|
---|
| 43 | It is inspired by work done by Jean-Marc André around the HP SSSTK and
|
---|
| 44 | aim at replacing the mindi project (http://www.mondorescue.org), but
|
---|
| 45 | fully integrated with project-builder.org
|
---|
| 46 |
|
---|
| 47 | pbmkbm works in different phases. The first one is to check all
|
---|
| 48 |
|
---|
| 49 | pbmkbm needs to gather a certain number of components that could come
|
---|
| 50 | from various sources and could be put on a different target media.
|
---|
| 51 | We need a kernel, an initrd/initramfs for additional modules and init script,
|
---|
| 52 | a root filesystem and a boot configuration file.
|
---|
| 53 | Kernel, modules could come either from the local installed system
|
---|
| 54 | (typically for disaster recovery context) or from a kernel package of a
|
---|
[1348] | 55 | given configuration or a referenced content.
|
---|
[1341] | 56 | Utilities could come from busybox, local utilities or set of packages.
|
---|
| 57 | The root filesystem is made with them.
|
---|
| 58 | The initrd/initramfs could be made internaly or by calling dracut.
|
---|
[1348] | 59 | The boot config file is generated from analysis content or provided externally.
|
---|
[1341] | 60 |
|
---|
| 61 | =head1 SYNOPSIS
|
---|
| 62 |
|
---|
[1348] | 63 | pbmkbm [-vhq][-t boot-type [-d device]][-b boot-method][-m os-ver-arch]
|
---|
[1341] | 64 | [-s script][-a pkg1[,pkg2,...]] [target-dir]
|
---|
| 65 |
|
---|
[1348] | 66 | pbmkbm [--verbose][--help][--man][--quiet][--type boot-type [--device device]]
|
---|
| 67 | [--machine os-ver-arch][--boot boot-method]
|
---|
| 68 | [--script script][--add pkg1,[pkg2,...]] [target-dir]
|
---|
[1341] | 69 |
|
---|
| 70 | =head1 OPTIONS
|
---|
| 71 |
|
---|
| 72 | =over 4
|
---|
| 73 |
|
---|
| 74 | =item B<-v|--verbose>
|
---|
| 75 |
|
---|
| 76 | Print a brief help message and exits.
|
---|
| 77 |
|
---|
| 78 | =item B<-h|--help>
|
---|
| 79 |
|
---|
| 80 | Print a brief help message and exits.
|
---|
| 81 |
|
---|
| 82 | =item B<--man>
|
---|
| 83 |
|
---|
| 84 | Prints the manual page and exits.
|
---|
| 85 |
|
---|
| 86 | =item B<-q|--quiet>
|
---|
| 87 |
|
---|
| 88 | Do not print any output.
|
---|
| 89 |
|
---|
[1348] | 90 | =item B<-t|--type boot-type>
|
---|
| 91 |
|
---|
| 92 | Type of the boot device to generate. A boot-type can be:
|
---|
| 93 |
|
---|
| 94 | =over 4
|
---|
| 95 |
|
---|
| 96 | =item B<iso>
|
---|
| 97 |
|
---|
| 98 | Generate an ISO9660 image format (suitable to be burned later on or loopback mounted. Uses isolinux.
|
---|
| 99 |
|
---|
| 100 | =item B<usb>
|
---|
| 101 |
|
---|
| 102 | Generate a USB image format (typically a key of external hard drive). Uses syslinux.
|
---|
| 103 |
|
---|
| 104 | =item B<pxe>
|
---|
| 105 |
|
---|
| 106 | Generate a PXE environement (suitable to be integrated in a PXElinux configuration). Uses pxelinux.
|
---|
| 107 |
|
---|
| 108 | =back
|
---|
| 109 |
|
---|
| 110 | =item B<-d|--device device-file>
|
---|
| 111 |
|
---|
| 112 | Name of the device or file on which you want to create the boot media.
|
---|
| 113 |
|
---|
| 114 | =item B<-b|--boot boot-method>
|
---|
| 115 |
|
---|
| 116 | This is the boot method to use to create the boot media. A boot-method can be:
|
---|
| 117 |
|
---|
| 118 | =over 4
|
---|
| 119 |
|
---|
| 120 | =item B<native>
|
---|
| 121 |
|
---|
| 122 | Use the tools of the native distribution to create the boot media. No other dependency.
|
---|
| 123 |
|
---|
| 124 | =item B<ve>
|
---|
| 125 |
|
---|
| 126 | Use the project-builder.org virtual environment notion to create the boot media. No other dependency outside of the project.
|
---|
| 127 |
|
---|
| 128 | =item B<busybox>
|
---|
| 129 |
|
---|
| 130 | Use the busybox tool to create the boot media. Cf: L<http://www.busybox.net>
|
---|
| 131 |
|
---|
| 132 | =item B<dracut>
|
---|
| 133 |
|
---|
| 134 | Use the dracut tool to create the boot media. Cf: L<http://www.dracut.net>
|
---|
| 135 |
|
---|
| 136 | =back
|
---|
| 137 |
|
---|
[1341] | 138 | =item B<-s|--script script>
|
---|
| 139 |
|
---|
[1348] | 140 | Name of the script you want to execute on the related boot media at the end o the build.
|
---|
[1341] | 141 |
|
---|
| 142 | =item B<-a|--add pkg1[,pkg2,...]>
|
---|
| 143 |
|
---|
[1348] | 144 | Additional packages to add from the distribution you want to install on the related boot media
|
---|
| 145 | at the end of the build.
|
---|
[1341] | 146 |
|
---|
[1348] | 147 | =item B<-m|--machine os-ver-arch>
|
---|
| 148 |
|
---|
| 149 | This is the target tuple operating system-version-architecture for which you want to create the boot media.
|
---|
| 150 |
|
---|
[1341] | 151 | =back
|
---|
| 152 |
|
---|
| 153 | =head1 ARGUMENTS
|
---|
| 154 |
|
---|
[1348] | 155 | target-dir is the directory under which the boot media will be build.
|
---|
| 156 |
|
---|
[1341] | 157 | =over 4
|
---|
| 158 |
|
---|
| 159 | =back
|
---|
| 160 |
|
---|
| 161 | =head1 EXAMPLE
|
---|
| 162 |
|
---|
[1348] | 163 | To setup a USB busybox based boot media on the /dev/sdb device for a Fedora 12 distribution with an i386 architecture issue:
|
---|
[1341] | 164 |
|
---|
[1348] | 165 | pbmkbm -t usb -d /dev/sdb -m fedora-12-i386 -b busybox
|
---|
[1341] | 166 |
|
---|
[1348] | 167 | To setup an ISO image under /tmp for a RHEL 6 x86_64 distribution issue using the native environment:
|
---|
| 168 |
|
---|
| 169 | pbmkbm -t iso -d /tmp -m rhel-6-x86_64 -b ve
|
---|
| 170 |
|
---|
[1341] | 171 | =head1 WEB SITES
|
---|
| 172 |
|
---|
| 173 | The main Web site of the project is available at L<http://www.project-builder.org/>.
|
---|
| 174 | Bug reports should be filled using the trac instance of the project at L<http://trac.project-builder.org/>.
|
---|
| 175 |
|
---|
| 176 | =head1 USER MAILING LIST
|
---|
| 177 |
|
---|
| 178 | Cf: L<http://www.mondorescue.org/sympa/info/pb-announce> for announces and
|
---|
| 179 | L<http://www.mondorescue.org/sympa/info/pb-devel> for the development of the pb project.
|
---|
| 180 |
|
---|
| 181 | =head1 CONFIGURATION FILE
|
---|
| 182 |
|
---|
| 183 | Uses Project-Builder.org configuration file (/etc/pb/pb.conf or /usr/local/etc/pb/pb.conf)
|
---|
| 184 |
|
---|
| 185 | =head1 AUTHORS
|
---|
| 186 |
|
---|
| 187 | The Project-Builder.org team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
|
---|
| 188 |
|
---|
| 189 | =head1 COPYRIGHT
|
---|
| 190 |
|
---|
| 191 | Project-Builder.org is distributed under the GPL v2.0 license
|
---|
| 192 | described in the file C<COPYING> included with the distribution.
|
---|
| 193 |
|
---|
| 194 | =cut
|
---|
| 195 |
|
---|
| 196 | # ---------------------------------------------------------------------------
|
---|
| 197 |
|
---|
| 198 | my ($projectbuilderver,$projectbuilderrev) = pb_version_init();
|
---|
| 199 | my $appname = "pbmkbm";
|
---|
| 200 | $ENV{'PBPROJ'} = $appname;
|
---|
| 201 |
|
---|
| 202 | # Initialize the syntax string
|
---|
| 203 |
|
---|
| 204 | pb_syntax_init("$appname Version $projectbuilderver-$projectbuilderrev\n");
|
---|
| 205 | pb_temp_init();
|
---|
| 206 |
|
---|
| 207 | GetOptions("help|?|h" => \$opts{'h'},
|
---|
[1348] | 208 | "man" => \$opts{'man'},
|
---|
[1341] | 209 | "verbose|v+" => \$opts{'v'},
|
---|
| 210 | "quiet|q" => \$opts{'q'},
|
---|
| 211 | "log-files|l=s" => \$opts{'l'},
|
---|
| 212 | "script|s=s" => \$opts{'s'},
|
---|
| 213 | "machine|m=s" => \$opts{'m'},
|
---|
| 214 | "add|a=s" => \$opts{'a'},
|
---|
[1348] | 215 | "device|d=s" => \$opts{'d'},
|
---|
| 216 | "type|t=s" => \$opts{'t'},
|
---|
| 217 | "boot|b=s" => \$opts{'b'},
|
---|
[1341] | 218 | "version|V=s" => \$opts{'V'},
|
---|
| 219 | ) || pb_syntax(-1,0);
|
---|
| 220 |
|
---|
| 221 | if (defined $opts{'h'}) {
|
---|
| 222 | pb_syntax(0,1);
|
---|
| 223 | }
|
---|
| 224 | if (defined $opts{'man'}) {
|
---|
| 225 | pb_syntax(0,2);
|
---|
| 226 | }
|
---|
| 227 | if (defined $opts{'v'}) {
|
---|
| 228 | $pbdebug = $opts{'v'};
|
---|
| 229 | }
|
---|
| 230 | if (defined $opts{'q'}) {
|
---|
| 231 | $pbdebug=-1;
|
---|
| 232 | }
|
---|
| 233 | if (defined $opts{'l'}) {
|
---|
| 234 | open(pbLOG,"> $opts{'l'}") || die "Unable to log to $opts{'l'}: $!";
|
---|
| 235 | $pbLOG = \*pbLOG;
|
---|
| 236 | $pbdebug = 0 if ($pbdebug == -1);
|
---|
| 237 | }
|
---|
| 238 | pb_log_init($pbdebug, $pbLOG);
|
---|
[1402] | 239 | pb_log(1,"$appname Version $projectbuilderver-$projectbuilderrev\n");
|
---|
| 240 | my @date = pb_get_date();
|
---|
| 241 | my $pbdate = strftime("%Y-%m-%d %H:%M:%S", @date);
|
---|
[1341] | 242 |
|
---|
[1402] | 243 | pb_log(1,"Start: $pbdate\n");
|
---|
| 244 |
|
---|
[1341] | 245 | # Get VE name
|
---|
| 246 | $ENV{'PBV'} = $opts{'m'};
|
---|
| 247 |
|
---|
| 248 | #
|
---|
| 249 | # Initialize distribution info from pb conf file
|
---|
| 250 | #
|
---|
| 251 | my $pbos = pb_distro_get_context($ENV{'PBV'});
|
---|
[1348] | 252 | pb_log(0,"Starting boot media build for $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}\n");
|
---|
[1341] | 253 |
|
---|
[1348] | 254 | pb_env_init_pbrc(); # to get content of HOME/.pbrc
|
---|
| 255 |
|
---|
[1341] | 256 | #
|
---|
| 257 | # Check target dir
|
---|
| 258 | # Create if not existent and use default if none given
|
---|
| 259 | #
|
---|
[1348] | 260 | my $targetdir = shift @ARGV;
|
---|
[1341] | 261 |
|
---|
| 262 | #
|
---|
| 263 | # Check for command requirements
|
---|
| 264 | #
|
---|
[1402] | 265 | my ($req,$opt) = pb_conf_get_if("oscmd","oscmdopt");
|
---|
[1341] | 266 | pb_check_requirements($req,$opt,$appname);
|
---|
| 267 |
|
---|
[1348] | 268 | # After that we will need root access
|
---|
| 269 | die "$appname needs to be run as root" if ($EFFECTIVE_USER_ID != 0);
|
---|
| 270 |
|
---|
| 271 | #
|
---|
| 272 | # Where is our build target directory
|
---|
| 273 | #
|
---|
| 274 | if (not defined $targetdir) {
|
---|
| 275 | $targetdir = "/var/cache/pbmkbm";
|
---|
| 276 | my ($vestdpath) = pb_conf_get("mkbmpath");
|
---|
| 277 | $targetdir = "$vestdpath->{'default'}/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}" if (defined $vestdpath->{'default'});
|
---|
[1402] | 278 | pb_log(1,"No target-dir specified, using $targetdir\n");
|
---|
[1341] | 279 | }
|
---|
| 280 |
|
---|
[1348] | 281 | # Point to the right subdir and create it if needed
|
---|
| 282 | pb_mkdir_p($targetdir) if (! -d $targetdir);
|
---|
[1341] | 283 |
|
---|
[1402] | 284 | # Log information on our system
|
---|
| 285 | # TODO: this should be put in a subfunction
|
---|
| 286 | my ($logcmd) = pb_conf_get("logcmd");
|
---|
| 287 | my ($logopt) = pb_conf_get_if("logopt");
|
---|
| 288 | # check that the command is there first and then use it.
|
---|
| 289 | if ($logcmd->{$appname} ne "internal") {
|
---|
| 290 | $logcmd = pb_check_req($logcmd->{$appname},1);
|
---|
| 291 | if (not defined $logcmd) {
|
---|
| 292 | pb_log(1,"INFO: command $logcmd->{$appname} doesn't exist. No log report is available\n");
|
---|
| 293 | } else {
|
---|
| 294 | my $c = $logcmd->{$appname};
|
---|
| 295 | $c .= " $logopt->{$appname}" if (defined $logopt->{$appname});
|
---|
| 296 | pb_system("$c","Creating a log report of your system");
|
---|
| 297 | }
|
---|
| 298 | } else {
|
---|
| 299 | # We provide our own internal log reporter as a std one isn't found
|
---|
| 300 | my ($lcmds,$lfiles) = pb_conf_get_if("logcommands","logfiles");
|
---|
| 301 | pb_log(1,"------------------\n");
|
---|
| 302 | if (defined $lcmds->{$appname}) {
|
---|
| 303 | foreach my $c (split(/,/,$lcmds->{$appname})) {
|
---|
| 304 | my $lcmd = $c;
|
---|
| 305 | $lcmd =~ s/ .*$//;
|
---|
| 306 | $lcmd = pb_check_req($lcmd,1);
|
---|
| 307 | if (not defined $lcmd) {
|
---|
[1408] | 308 | pb_log(1,"INFO: command $c doesn't exist\n");
|
---|
[1402] | 309 | pb_log(1,"------------------\n");
|
---|
| 310 | next;
|
---|
| 311 | }
|
---|
| 312 | pb_log(1,"Execution of $c\n");
|
---|
| 313 | pb_log(1,"------------------\n");
|
---|
| 314 | pb_system($c,"",1);
|
---|
| 315 | pb_log(1,"------------------\n");
|
---|
| 316 | }
|
---|
| 317 | }
|
---|
| 318 | if (defined $lfiles->{$appname}) {
|
---|
| 319 | foreach my $f (split(/,/,$lfiles->{$appname})) {
|
---|
| 320 | if (! -e $f) {
|
---|
| 321 | pb_log(1,"INFO: $f doesn't exist\n");
|
---|
| 322 | pb_log(1,"------------------\n");
|
---|
| 323 | next;
|
---|
| 324 | }
|
---|
| 325 | if (! -r $f) {
|
---|
| 326 | pb_log(1,"INFO: $f isn't readable\n");
|
---|
| 327 | pb_log(1,"------------------\n");
|
---|
| 328 | next;
|
---|
| 329 | }
|
---|
| 330 | if ((-f $f) || (-l $f)) {
|
---|
| 331 | if (! open(FILE,$f)) {
|
---|
| 332 | pb_log(1,"INFO: Unable to open $f\n");
|
---|
| 333 | pb_log(1,"------------------\n");
|
---|
| 334 | next;
|
---|
| 335 | }
|
---|
| 336 | pb_log(1,"Content of $f\n");
|
---|
| 337 | pb_log(1,"------------------\n");
|
---|
| 338 | while (<FILE>) {
|
---|
| 339 | pb_log(1,$_);
|
---|
| 340 | }
|
---|
| 341 | close(FILE);
|
---|
| 342 | pb_log(1,"------------------\n");
|
---|
| 343 | } elsif (-d $f) {
|
---|
| 344 | my $dh;
|
---|
| 345 | if (! opendir($dh,$f)) {
|
---|
| 346 | pb_log(1,"INFO: Unable to opendir $f\n");
|
---|
| 347 | pb_log(1,"------------------\n");
|
---|
| 348 | next;
|
---|
| 349 | }
|
---|
| 350 | pb_log(1,"Content of directory $f\n");
|
---|
| 351 | pb_log(1,"----------------------------\n");
|
---|
| 352 | while (readdir $dh) {
|
---|
| 353 | my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat("$f/$_");
|
---|
| 354 | my $str = sprintf("%10s %2s %5s %5s %10s %14s %s",$mode,$ino,$uid,$gid,$size,$mtime,$_);
|
---|
| 355 | pb_log(1,"$str\n");
|
---|
| 356 | }
|
---|
| 357 | closedir($dh);
|
---|
| 358 | pb_log(1,"------------------\n");
|
---|
| 359 | } else {
|
---|
| 360 | pb_log(1,"INFO: $f is special\n");
|
---|
| 361 | pb_log(1,"------------------\n");
|
---|
| 362 | }
|
---|
| 363 | }
|
---|
| 364 | }
|
---|
| 365 | }
|
---|
[1348] | 366 |
|
---|
| 367 | # Now the preparation is over, we need to do something useful :-)
|
---|
| 368 | # But it all depends on how we're asked to do it.
|
---|
[1341] | 369 | #
|
---|
[1348] | 370 | # First we need to copy into the target dir all the relevant content
|
---|
| 371 | pb_mkbm_create_content();
|
---|
| 372 |
|
---|
| 373 | # Then we need to package this content in the destination format
|
---|
| 374 | pb_mkbm_create_media();
|
---|
| 375 |
|
---|
[1402] | 376 | @date = pb_get_date();
|
---|
| 377 | $pbdate = strftime("%Y-%m-%d %H:%M:%S", @date);
|
---|
| 378 |
|
---|
| 379 | pb_log(1,"End: $pbdate\n");
|
---|
| 380 |
|
---|
[1348] | 381 | sub pb_mkbm_create_content {
|
---|
| 382 |
|
---|
| 383 | pb_log(1,"Creating boot media content\n");
|
---|
[1350] | 384 |
|
---|
| 385 | # If not defined use VE mode by default
|
---|
| 386 | $opts{'b'} = "ve" if (not defined $opts{'b'});
|
---|
| 387 |
|
---|
[1402] | 388 | # Hash of target content
|
---|
| 389 | # atribute could be, copy, remove, link, dir
|
---|
| 390 | my %targettree;
|
---|
| 391 |
|
---|
[1348] | 392 | if ($opts{'b'} eq "ve") {
|
---|
[1402] | 393 | # Use project-builder VE mecanism to create a good VE !
|
---|
[1352] | 394 | pb_ve_launch($ENV{'PBV'},1);
|
---|
[1348] | 395 | } elsif ($opts{'b'} eq "native") {
|
---|
| 396 | # Use native tools to create a good VE !
|
---|
[1402] | 397 | } elsif ($opts{'b'} eq "drakut") {
|
---|
| 398 | # Use drakut to create a good VE !
|
---|
| 399 | } elsif ($opts{'b'} eq "busybox") {
|
---|
| 400 | # Use busybox to create a good VE !
|
---|
| 401 | pb_mkbm_create_busybox_ve(\%targettree);
|
---|
[1348] | 402 | } else {
|
---|
| 403 | die "Unknown method $opts{'b'} used to create the media content";
|
---|
| 404 | }
|
---|
[1352] | 405 |
|
---|
[1402] | 406 | # Create the directory structure needed on the target dir
|
---|
[1408] | 407 | my ($tdirs,$bdirs,$bfiles,$bcmds) = pb_distro_get_param($pbos,pb_conf_get("mkbmtargetdirs","mkbmbootdirs","mkbmbootfiles","mkbmbootcmds"));
|
---|
[1403] | 408 | # Create empty dirs for these
|
---|
| 409 | foreach my $d (split(/,/,$tdirs)) {
|
---|
[1408] | 410 | $targettree{$d} = "emptydir";
|
---|
[1403] | 411 | }
|
---|
| 412 | # And copy dirs for those
|
---|
| 413 | foreach my $d (split(/,/,$bdirs)) {
|
---|
| 414 | if (-d $d) {
|
---|
[1408] | 415 | $targettree{$d} = "dir";
|
---|
| 416 | } elsif (-l $d) {
|
---|
| 417 | $targettree{$d} = "link";
|
---|
[1403] | 418 | } else {
|
---|
[1408] | 419 | pb_log(1,"INFO: Directory $d doesn't exist\n");
|
---|
| 420 | }
|
---|
[1403] | 421 | }
|
---|
| 422 | foreach my $f (split(/,/,$bfiles)) {
|
---|
[1408] | 423 | $targettree{$f} = "file";
|
---|
[1403] | 424 | }
|
---|
[1408] | 425 | pb_log(2,"INFO: Target Tree is now: ".Dumper(%targettree)."\n");
|
---|
[1352] | 426 | # Once the environment is made, add what is needed for this boot media to it.
|
---|
[1402] | 427 | # Keyboard
|
---|
| 428 | # Terminfo
|
---|
| 429 | # List of commands
|
---|
| 430 | # List of dependencies
|
---|
[1408] | 431 | # Kernel - We use 2 objects, the running kernel and the target kernel which could be different
|
---|
| 432 | my %rkernel;
|
---|
| 433 | my %tkernel;
|
---|
| 434 | pb_mkbm_find_kernel(\%rkernel);
|
---|
[1402] | 435 | # Initrd
|
---|
| 436 | # init
|
---|
| 437 | # BootLoader and its configuration
|
---|
[1403] | 438 | # Additional data files coming from a potential caller (MondoRescue/Mindi e.g. with fstab, LVM, mountlist, ...)
|
---|
[1348] | 439 | }
|
---|
| 440 |
|
---|
[1402] | 441 | sub pb_mkbm_create_busybox_ve {
|
---|
| 442 |
|
---|
| 443 | my $tgtree = shift;
|
---|
| 444 |
|
---|
| 445 | # First, check which are the supported command in that version of busybox
|
---|
| 446 | # and create the links for it in the target VE
|
---|
| 447 |
|
---|
| 448 | my $busycmd = pb_distro_get_param($pbos,pb_conf_get("ospathcmd-busybox"));
|
---|
| 449 | open(BUSY,"$busycmd |") || die "Unable to execute $busycmd";
|
---|
| 450 | my $cmdlist = 0;
|
---|
| 451 | while (<BUSY>) {
|
---|
| 452 | pb_log(3,"busybox line : $_");
|
---|
| 453 | chomp($_);
|
---|
| 454 | # After these words, we have the list of functions, so trigger their analysis
|
---|
| 455 | if ($_ =~ /defined functions:/) {
|
---|
| 456 | $cmdlist = 1;
|
---|
| 457 | next;
|
---|
| 458 | }
|
---|
| 459 | # Analyse the list of commands provided by that busybox (, separated)
|
---|
| 460 | if ($cmdlist == 1) {
|
---|
| 461 | pb_log(3,"Analyzing that busybox line\n");
|
---|
| 462 | foreach my $c (split(/,/,$_)) {
|
---|
| 463 | $c =~ s/\s*//g;
|
---|
| 464 | # skip empty strings
|
---|
| 465 | next if ($c =~ /^$/);
|
---|
| 466 | my $c1 = pb_check_req($c,0);
|
---|
| 467 | if (defined $c1) {
|
---|
| 468 | $tgtree->{$c1} = "link:$busycmd";
|
---|
| 469 | } else {
|
---|
| 470 | # When not found on the system, create the link under /usr/bin by default
|
---|
| 471 | $tgtree->{"/usr/bin/$c"} = "link:$busycmd";
|
---|
| 472 | }
|
---|
| 473 | }
|
---|
| 474 | }
|
---|
| 475 | }
|
---|
| 476 | pb_log(2,"Target Tree is now: ".Dumper($tgtree)."\n");
|
---|
| 477 | close(BUSY);
|
---|
| 478 | }
|
---|
| 479 |
|
---|
[1408] | 480 | sub pb_mkbm_find_kernel {
|
---|
| 481 |
|
---|
| 482 | my $kernel = shift;
|
---|
| 483 |
|
---|
| 484 | $kernel->is_xen = undef;
|
---|
| 485 | # See if we're booted from a Xen kernel
|
---|
| 486 | # From http://wiki.xensource.com/xenwiki/XenCommonProblems#head-26434581604cc8357d9762aaaf040e8d87b37752
|
---|
| 487 | if ( -f "/proc/xen/capabilities") {
|
---|
| 488 | # It's a Xen kernel
|
---|
| 489 | pb_log(2,"INFO: We found a Xen Kernel running\n");
|
---|
| 490 | }
|
---|
| 491 |
|
---|
| 492 | my $kfile = pb_distro_get_param($pbos,pb_conf_get_if("mkbmkernelfile"));
|
---|
| 493 | if ((defined $kfile) && ($kfile ne "")) {
|
---|
| 494 | pb_log(1,"INFO: You specified your kernel as $kfile, so using it\n");
|
---|
| 495 | $kernel->file = $kfile;
|
---|
| 496 | } else {
|
---|
| 497 | $kernel->dir = pb_distro_get_param($pbos,pb_conf_get("mkbmkerneldir"));
|
---|
| 498 | die "ERROR: The mkbmkerneldir content ($kernel->dir) doesn't refer to a directory\n"if (! -d $kernel->dir);
|
---|
| 499 | pb_log(1,"INFO: Analyzing directory $kernel->dir to find your kernel");
|
---|
| 500 | $kernel->namere = pb_distro_get_param($pbos,pb_conf_get("mkbmkernelnamere"));
|
---|
| 501 | }
|
---|
| 502 |
|
---|
| 503 | # TODO: Look at a better way to find the name of the kernel we run
|
---|
| 504 | # look at /proc/sys/kernel/bootloader_type /proc/sys/kernel/bootloader_version
|
---|
| 505 | # to have a better guess
|
---|
| 506 | my $dh;
|
---|
| 507 | die "ERROR: Unable to open the mkbmkerneldir content ($kernel->dir)" if (! opendir($dh,$kernel->dir));
|
---|
| 508 | while (readdir $dh) {
|
---|
| 509 | # Skip non-files
|
---|
| 510 | next if ((! -f $_) && (! -l $_));
|
---|
| 511 | # Skip files not correpsonding to the RE planned
|
---|
| 512 | next if ($_ !~ /$kernel->namere/);
|
---|
| 513 | #my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat("$f/$_");
|
---|
| 514 | }
|
---|
| 515 | closedir($dh);
|
---|
| 516 | $kernel->release = pb_get_osrelase();
|
---|
| 517 | }
|
---|
| 518 |
|
---|
[1348] | 519 | sub pb_mkbm_create_media {
|
---|
| 520 |
|
---|
| 521 | }
|
---|
| 522 |
|
---|
[1341] | 523 | # Get the package list to download, store them in a cache directory
|
---|
| 524 | #
|
---|
[1352] | 525 | #my ($mkbmcachedir) = pb_conf_get_if("mkbmcachedir");
|
---|
| 526 | #my ($pkgs) = pb_distro_get_param($pbos,pb_conf_get("mkbmmindep"));
|
---|
[1341] | 527 |
|
---|
| 528 | #
|
---|
| 529 | # /proc needed
|
---|
| 530 | #
|
---|
[1352] | 531 | #pb_system("mount -o bind /proc $targetdir/proc","Mounting /proc");
|
---|
[1341] | 532 |
|
---|
| 533 | # Installed additional packages we were asked to
|
---|
[1352] | 534 | #if (defined $opts{'a'}) {
|
---|
| 535 | #$opts{'a'} =~ s/,/ /g;
|
---|
| 536 | #pb_system("chroot $targetdir /bin/bash -c \"$pbos->{'install'} $opts{'a'} \"","Adding packages to OS by running $pbos->{'install'} $opts{'a'}");
|
---|
| 537 | #}
|
---|
[1341] | 538 |
|
---|
| 539 | #
|
---|
| 540 | # Clean up
|
---|
| 541 | #
|
---|
[1352] | 542 | #pb_log(1,"Cleaning up\n");
|
---|
| 543 | #pb_system("umount $targetdir/proc","Unmounting /proc");
|
---|
[1341] | 544 |
|
---|
| 545 | # Executes post-install step if asked for
|
---|
[1352] | 546 | #if ($opts{'s'}) {
|
---|
| 547 | #pb_system("$opts{'s'} $targetdir","Executing the post-install script: $opts{'s'} $targetdir");
|
---|
| 548 | #}
|
---|