ACC SHELL
/**
* File:
* modules/BootLILO.ycp
*
* Module:
* Bootloader installation and configuration
*
* Summary:
* Module containing specific functions for LILO configuration
* and installation
*
* Authors:
* Jiri Srain <jsrain@suse.cz>
* Olaf Dabrunz <od@suse.de>
* Philipp Thomas <pth@suse.de>
*
* $Id: BootLILO.ycp 57310 2009-05-25 14:24:53Z jreidinger $
*
*/
{
module "BootLILO";
textdomain "bootloader";
import "Arch";
import "BootCommon";
import "BootStorage";
import "Kernel";
import "Mode";
import "Pkg";
import "String";
import "Storage";
import "Stage";
include "bootloader/routines/popups.ycp";
/**
* remove blanks from section name and replace them with _
* @param original string
* @return string fixed string
*/
string removeBlanks (string original) {
// do not allow empty labels
while (size (original) > 1 && substring (original, 0, 1) == " ") {
original = substring (original, 1);
}
while (size (original) > 1
&& substring (original, size (original) -1, 1) == " ")
{
original = substring (original, 0, size (original) - 1);
}
if (size (original) > 15)
original = substring (original, 0, 15);
return String::Replace (original, " ", "_");
}
/**
* Propose sections to bootloader menu
* modifies internal sreuctures
*/
global void CreateSections () {
list<map<string,any> > out = [
BootCommon::CreateLinuxSection ("linux")
];
list<string> others = (list<string>)Storage::GetForeignPrimary();
if (others != nil && size (others) > 0)
{
foreach (string o, others, {
list<string> parts = splitstring (o, " ");
while (parts[0]:" " == "")
parts = remove (parts, 0);
string dev = parts[0]:"";
parts = remove (parts, 0);
string label = mergestring (parts, " ");
// don't add rewritten location (#19990)
if (dev != "" && label != ""
&& dev != BootCommon::loader_device
&& (
BootCommon::AddFirmwareToBootloader (BootCommon::mbrDisk)
|| label != "Vendor diagnostics"
)
)
{
map<string,any> m = $[
"name" : BootCommon::translateSectionTitle (
removeBlanks (label)),
"original_name" : label,
"type" : "chainloader",
"chainloader" : dev,
"__auto" : true,
"__changed" : true,
"__devs" : [dev],
];
out = add (out, m);
}
});
}
out = add (out, BootCommon::CreateLinuxSection ("failsafe"));
out = add (out, BootCommon::CreateLinuxSection ("memtest86"));
out = filter (map<string,any> s, out, { return s != $[] && s != nil;});
BootCommon::sections = out;
}
/**
* Propose global options of bootloader
* modifies internal structures
*/
global void CreateGlobals () {
BootCommon::globals = $[
"default" : BootCommon::sections[0, "name"]:"",
"timeout" : "8",
"gfxmenu" : "/boot/message",
"prompt" : "1",
];
}
// general functions
/**
* Propose bootloader settings
*/
global define void Propose () ``{
y2debug ("Started propose: Glob: %1, Sec: %2",
BootCommon::globals, BootCommon::sections);
BootCommon::i386LocationProposal ();
if (BootCommon::sections == nil || size (BootCommon::sections) == 0)
{
CreateSections ();
BootCommon::kernelCmdLine = Kernel::GetCmdLine ();
}
else
{
if (Mode::autoinst ())
{
// TODO whatever will be needed
y2debug ("nothing to to in AI mode if sections exist");
}
else
BootCommon::FixSections (BootLILO::CreateSections);
}
if (BootCommon::globals == nil || size (BootCommon::globals) == 0)
{
CreateGlobals ();
}
else
{
if (Mode::autoinst ())
{
// TODO whatever will be needed
y2debug ("nothing to to in AI mode if globals are defined");
}
else
BootCommon::FixGlobals ();
}
y2milestone ("Proposed sections: %1", BootCommon::sections);
y2milestone ("Proposed globals: %1", BootCommon::globals);
}
/**
* Read settings from disk
* @param reread boolean true to force reread settings from system
* @param avoid_reading_device_map do not read new device map from file, use
* internal data
* @return boolean true on success
*/
global boolean Read (boolean reread, boolean avoid_reading_device_map) {
BootCommon::InitializeLibrary (reread, "lilo");
if (reread)
{
BootCommon::ReadFiles (avoid_reading_device_map);
}
BootCommon::DetectDisks ();
boolean ret = BootCommon::Read (false, avoid_reading_device_map);
BootCommon::loader_device = BootCommon::globals["stage1_dev"]:"";
return ret;
}
/**
* Save all bootloader configuration files to the cache of the PlugLib
* PlugLib must be initialized properly !!!
* @param clean boolean true if settings should be cleaned up (checking their
* correctness, supposing all files are on the disk
* @param init boolean true to init the library
* @param flush boolean true to flush settings to the disk
* @return boolean true if success
*/
global boolean Save (boolean clean, boolean init, boolean flush) {
BootCommon::globals["stage1_dev"] = BootCommon::loader_device;
boolean ret = BootCommon::Save (clean, init, flush);
return ret;
}
/**
* Update read settings to new version of configuration files
*/
global void Update () {
BootCommon::UpdateDeviceMap ();
// During update, for libata device name migration ("/dev/hda1" ->
// "/dev/sda1") and somesuch, we need to re-read and parse the rest of the
// configuration file contents after internally updating the device map in
// perl-Bootloader. This way, the device names are consistent with the
// partitioning information we have set up in perl-Bootloader with
// SetDiskInfo(), and device names in other config files can be translated
// to Unix device names (#328448, this hits sections that are not
// (re-)created by yast-Bootloader or later by perl-Bootloader anyway).
BootCommon::SetDeviceMap (BootStorage::device_mapping);
Read (true, true);
BootCommon::UpdateSections ();
BootCommon::UpdateGlobals ();
BootCommon::loader_device
= BootCommon::UpdateDevice (BootCommon::loader_device);
}
/**
* If device is part of RAID (md), then return first of its members
* otherwise return the same as argument
* @param device string device of the RAID
* @return string first member of the RAID
*/
string getDeviceOfRaid (string device) {
// get list of all partitions (not marked to be deleted)
map<string,map> tm = (map<string,map>)Storage::GetTargetMap ();
list<map> partitions = [];
foreach ( string dev, map disk, tm, ``{
if( Storage::IsRealDisk( disk ) ) {
list<map> l = (list<map>)filter( map p, disk["partitions"]:[],
``(p["delete"]:false==false) );
partitions = (list<map>)merge (partitions, l);
}
});
// filter partitions to relevant list according to raid name
list<map> md_list = filter (map e, partitions, ``(e["used_by_device"]:"" == device));
// get the devices
list<string> dev_list = maplist (map e, md_list, ``(e["device"]:""));
dev_list = filter (string d, dev_list, ``(d != ""));
if (size (dev_list) > 0) {
dev_list = sort (dev_list);
return dev_list[0]:"";
}
return device;
}
/**
* Write bootloader settings to disk
* @return boolean true on success
*/
global define boolean Write () {
boolean ret = BootCommon::UpdateBootloader ();
BootCommon::updateMBR ();
if (BootCommon::InstallingToFloppy ())
{
if (! saveToFLoppyPopup ())
{
y2error ("Preparing floppy disk failed.");
ret = false;
}
}
// Should we create a backup copy of bootloader bootsector?
if (Stage::initial ()) {
map mp = Storage::GetMountPoints ();
list data = mp["/boot"]:(mp["/"]:[]);
string bpd = data[0]:"";
// ???? FIXME ???? how about LVM/MD ????
if (bpd == BootStorage::BootPartitionDevice
&& getDeviceOfRaid (BootStorage::BootPartitionDevice)
!= BootStorage::BootPartitionDevice
&& contains (BootStorage::getPartitionList(`boot, "lilo"),
BootStorage::BootPartitionDevice))
{
y2milestone ("Creating backup copy to bootsector");
SCR::Execute (.target.bash, sformat ("/sbin/lilo -b %1",
BootStorage::BootPartitionDevice));
}
}
ret = ret && BootCommon::InitializeBootloader ();
if (ret == nil)
ret = false;
ret = ret && BootCommon::PostUpdateMBR ();
return ret;
}
global map<string,symbol()> Dialogs () {
return $[];
}
/**
* Set section to boot on next reboot
* @param section string section to boot
* @return boolean true on success
*/
global define boolean FlagOnetimeBoot (string section)
{
map result = (map)SCR::Execute (.target.bash_output,
sformat ("/sbin/lilo -R \"%1\"", section));
y2milestone ("lilo returned %1", result);
return (result["exit"]:-1 == 0);
}
list <string> lilo_section_types()
{
return ["image", "other"];
}
/**
* Return map of provided functions
* @return a map of functions (eg. $["write":BootLILO::Write])
*/
global map<string, any> GetFunctions () {
return $[
"dialogs" : Dialogs,
"read" : Read,
"propose" : Propose,
"save" : Save,
"summary" : BootCommon::i386Summary,
"update" : Update,
"write" : Write,
"flagonetimeboot" : FlagOnetimeBoot,
"widgets" : $[], // is not supported now
"section_types" : lilo_section_types,
];
}
/**
* Initializer of LILO bootloader
*/
global void Initializer () {
y2milestone ("Called LILO initializer");
BootCommon::current_bootloader_attribs = $[
"propose" : true,
"read" : true,
"scratch" : true,
"restore_mbr" : true,
"bootloader_on_disk" : true,
];
}
/**
* Constructor
*/
global void BootLILO () {
BootCommon::bootloader_attribs["lilo"] = $[
"required_packages" : ["lilo"],
"loader_name" : "LILO",
"initializer" : BootLILO::Initializer,
];
}
}
/*
* Local variables:
* mode: ycp
* mode: font-lock
* mode: auto-fill
* indent-level: 4
* fill-column: 78
* End:
*/
ACC SHELL 2018