Bootloader::Library.3pm

Langue: en

Version: 2007-09-26 (openSuse - 09/10/07)

Section: 3 (Bibliothèques de fonctions)

NAME

Bootloader::Library - library for accessing configuration of the bootloader

PREFACE

This package is the public API to configure bootloader settings

SYNOPSIS

"use Bootloader::Library;"

"$obj_ref = Bootloader::Library->new ();"

"$status = Bootloader::Library->SetLoaderType ($bootloader);"

"$status = Bootloader::Library->DefineMountPoints (\%mountpoints);"

"$status = Bootloader::Library->DefinePartitions (\@partitions);"

"$status = Bootloader::Library->DefineMDArrays (\%md_arrays);"

"$status = Bootloader::Library->ReadSettings ();" // FIXME ?? sysconfig ??

"$status = Bootloader::Library->WriteSettings ();"

"$status = Bootloader::Library->ReadSettingsTmp ($tmp_dir);"

"$status = Bootloader::Library->WriteSettingsTmp ($tmp_dir);"

"$files_contents_ref = Bootloader::Library->GetFilesContents ();"

"$status = Bootloader::Library->SetFilesContents (\%files_contents);"

"$status = Bootloader::Library->UpdateBootloader ($avoid_init);"

"$status = Bootloader::Library->InitializeBootloader ();"

"$file_list_ref = Bootloader::Library->ListConfigurationFiles ();"

"$settings_ref = Bootloader::Library->GetSettings ();"

"$status Bootloader::Library->SetSettings ($settings_ref);"

"$meta_ref = Bootloader::Library->GetMetaData ();"

"$global_ref = Bootloader::Library->GetGlobalSettings ();"

"$status = Bootloader::Library->SetGlobalSettings ($global_settings_ref);"

"$sections_ref = Bootloader::Library->GetSections ();"

"$status = Bootloader::Library->SetSections ($sections_ref);"

"$device_map_ref = Bootloader::Library->GetDeviceMapping ();"

"$status = Bootloader::Library->SetDeviceMapping ($device_map_ref);"

"$grub_dev = Bootloader::Library->UnixFile2GrubDev ($unix_file);"

"$unix_dev = Bootloader::Library->GrubDev2UnixDev ($grub_dev);"

DESCRIPTION

$obj_ref = Bootloader::Library->new ();
Creates an instance of the Bootloader::Library class.
$status = Bootloader::Library->SetLoaderType($bootloader);
Initializes the library for the particular bootloader. Takes the name of the bootloader as parameter. Returns undef on fail, defined nonzero value otherwise.

EXAMPLE:


  my $status = Bootloader::Library->SetLoaderType ("lilo");

  if (! defined ($status))

  {

    die "Error occurred while initalizing for LILO";

  }



$status = Bootloader::Library->DefineMountPoints (\%mountpoints);
Defines mount points in the system so that the library does not need to probe them itself when needed. Parameter (mountpoints) is a hash reference (key is mountpoint, value device). Returns undef on fail, defined nonzero value otherwise.

EXAMPLE:


  my $mp = {

    "/" => "/dev/hda3",

    "/boot" => "/dev/hda1",

  }

  Bootloader::Library->DefineMountPoints ($mp);



$status = Bootloader::Library->DefinePartitions (\@partitions);
Defines the information about partitions - what disk a partition belongs to and the number of the partition Parameter (partitions) is a list, one entry per partition, each entry is a 3-item list, containing the device of the partition, the device of the disk the partition belongs to, and the number of the partition (first is 1). Returns undef on fail, defined nonzero value otherwise.

EXAMPLE:


  my $part = [

    [ "/dev/hda1", "/dev/hda", 1],

    [ "/dev/hda3", "/dev/hda", 3]

  ];

  Bootloader::Library->DefinePartitions ($part);



$status = Bootloader::Library->DefineMDArrays (\%md_arrays);
This interface is broken by design and its use is deprecated!! We only need information about mirrored devices (RAID1) and only GRUB uses that hack.

Defines the information about MD RAID arrays (what array is built by what disks). As parameter, it takes a reference to a map of all MD devices, where key is the MD device name, and value a reference to a list of its members. Returns undef on fail, defined nonzero value otherwise.

EXAMPLE:


  my $md = {

    "/dev/md0" => ["/dev/hda1", "/dev/hdc1"],

    "/dev/md1" => ["/dev/hda2", "/dev/hdc2"],

  };

  Bootloader::Library->DefineMDArrays ($md);



$status = Bootloader::Library->ReadSettings ();
Reads the settings from the system Returns undef on fail, defined nonzero value otherwise.

EXAMPLE:


  my $status = Bootloader::Library->ReadSettings ();

  if (! defined ($status))

  {

    die "Error occurred while reading the settings";

  }



$status = Bootloader::Library->WriteSettings ();
Writes the settings to the system. Does not activate the bootloader or the written settings, InitializeBootloader or UpdateBootloader functions must be used for it. Returns undef on fail, defined nonzero value otherwise.

EXAMPLE:


  my $status = Bootloader::Library->WriteSettings ();

  if (! defined ($status))

  {

    die "Error occurred while writing the settings";

  }



$status = Bootloader::Library->ReadSettingsTmp ($tmp_dir);
Reads the settings from the Returns undef on fail, defined nonzero value otherwise.

EXAMPLE:


  my $status = Bootloader::Library->ReadSettingsTmp ("/tmp");

  if (! defined ($status))

  {

    die "Error occurred while reading the settings";

  }



$status = Bootloader::Library->WriteSettingsTmp ($tmp_dir);
Writes the settings to temporary directory. Slashes in the filename are replaced with underscores. Returns undef on fail, defined nonzero value otherwise.

EXAMPLE:


  my $status = Bootloader::Library->WriteSettingsTmp ("/tmp");

  if (! defined ($status))

  {

    die "Error occurred while writing the settings";

  }



$files_contents_ref = Bootloader::Library->GetFilesContents ();
Gets the future contents of all bootloader configuration files. Returns undef on fail, hash where key is file name and value its contents as value on success.

EXAMPLE:


  my $files_contents_ref = Bootloader::Library->GetFilesContents ();

  if (! defined ($files_contents_ref))

  {

    die "Cannot get the contents of the configuration files"

  }

  my $lilo_conf = $files_contents_ref->{"/etc/lilo.conf"};

  print "$lilo.conf contents: \n$lilo_conf\n";



$status = Bootloader::Library->SetFilesContents (\%files_contents);
Sets the contents of all configuration files (eg. from editor)

$status = Bootloader::Library->SetFilesContents (\%files_contents);

$status = Bootloader::Library->UpdateBootloader ($avoid_init);
Really updates the bootloader configuration after writing the settings. If initialization is needed to make the settings active, but not intended (because it will be done later), set $avoid_init to 1. It makes no efect eg. for GRUB, but prevents from calling /sbin/lilo in case of LILO Returns undef on fail, defined nonzero value otherwise

EXAMPLE:


  my $status = Bootloader::Library->UpdateBootloader (0);

  if (! defined ($status))

  {

    die "Connot update the bootloader configuration";

  }



$status = Bootloader::Library->InitializeBootloader ();
Initializes the firmware to boot the bootloader Returns undef on fail, defined nonzero value otherwise

EXAMPLE:


  my $status = Bootloader::Library->InitializeBootloader ();

  if (! defined ($status))

  {

    die "Connot initialize the bootloader";

  }



$files_ref = Bootloader::Library->ListConfigurationFiles ();
Returns the list of the configuration files of the bootloader Returns undef on fail

EXAMPLE:


  my $files_ref = Bootloader::Library->ListConfigurationFiles ();

  if (! defined ($files_ref))

  {

    die "Cannot list configuration files";

  }

  foreach my $fn (@{$files_ref})

  {

    system ("cp $fn $fn.backup");

  }



$sections_ref = Bootloader::Library->GetSettings ();
Returns the complete settings of the bootloader. Returns undef on fail.

EXAMPLE:


  see eg. GetSections function definition



$status = Bootloader::Library->SetSettings ();
Returns the complete settings of the bootloader. Returns undef on fail.

EXAMPLE:


  see eg. GetSections function definition



$sections_ref = Bootloader::Library->GetSections ();
Gets the sections of the bootloader. See section description above. TODO Returns undef on fail.

EXAMPLE:


  my $sections_ref = Bootloader::Library->GetSections ();

  if (! defined ($sections_ref))

  {

    die "Getting sections failed";

  }

  my @sect_names = map {

    $_->{"name"};

  } @{$sections_ref};

  my $list = join ", " @sect_names;

  print "Sections: $list";



$meta_ref = Bootloader::Library->GetMetaData ();
Gets the meta data of the bootloader describing possible setting in the config, its data type, default value, etc. Returns undef on fail.
$global_ref = Bootloader::Library->GetGlobalSettings ();
Gets the global settings of the bootloader. See the example map above TODO Returns undef on fail.

EXAMPLE:


  my $global_ref = Bootloader::Library->GetGlobalSettings ();

  if (! defined ($global_ref))

  {

    die "Getting global data failed";

  }

  my $default = $global_ref->{"default"};

  print "Default section: $default";



$device_map_ref = Bootloader::Library->GetDeviceMapping ();
Gets the device mapping between Linux and firmware. Returns undef on fail.

EXAMPLE:


  $device_map_ref = Bootloader::Library->GetDeviceMapping ();

  if (! defined ($device_map_ref))

  {

    die "Getting device mapping failed";

  }

  my $hda = $device_map_ref->{"/dev/hda"};

  print "/dev/hda is $hda";



$status = Bootloader::Library->SetSections ();
Sets the sections of the bootloader. Sections have the same format as return value of GetSections (). Returns undef on fail, defined nonzero value on success.

EXAMPLE:


  my $sections_ref = Bootloader::Library->GetSections ();

  if (! defined ($sections_ref))

  {

    die "Getting sections failed";

  }

  my @sections = @{$sections_ref};

  pop @sections;

  my $ret = Bootloader::Library->SetSections (\@sections);

  if (! defined ($ret))

  {

    print ("Setting sections failed");

  }



$status = Bootloader::Library->SetGlobalSettings ();
Sets the global settings of the bootloader. The argument has the same format as the return value of GetGlobalSettings (). Returns undef on fail, defined nonzero value on success.

EXAMPLE:


  my $global_ref = Bootloader::Library->GetGlobalSettings ();

  if (! defined ($global_ref))

  {

    die "Getting global data failed";

  }

  $global_ref->{"default"} = "linux";

  my $ret = Bootloader::Library->SetGlobalSettings ($global_ref);

  if (! defined ($ret))

  {

    print ("Setting global options failed.");

  }



$status = Bootloader::Library->SetDeviceMapping ();
Sets the device mapping between Linux device and firmware identification. Returns undef on fail, defined nonzero value on success.

EXAMPLE:


  $device_map_ref = Bootloader::Library->GetDeviceMapping ();

  if (! defined ($device_map_ref))

  {

    die "Getting device mapping failed";

  }

  $device_map_ref->{"/dev/hda"} = "(hd0)";

  my $ret = Bootloader::Library->SetDeviceMapping ($device_map_ref);

  if (! defined ($ret))

  {

    print ("Setting global options failed.");

  }



$grub_dev = Bootloader::Library->UnixFile2GrubDev ($unix_file);
Detects the underlying partition (e.g. '/dev/sda1') a given UNIX file (e.g. '/boot') is located on and translates it to the corresponding GRUB device (e.g. '(hd0,0)'). Takes a UNIX file as argument and returns the corresponding GRUB device.
$unix_dev = Bootloader::Core::GRUB->GrubDev2UnixDev ($grub_dev);
Translates the GRUB device (eg. '(hd0,0)') to UNIX device (eg. '/dev/hda1'). As argument takes the GRUB device, returns the UNIX device (both strings). Wrapper function to be able to use this grub function in Tools.pm.