Class: Bootloader::BootRecordBackup

Inherits:
Object
  • Object
show all
Includes:
Yast::Logger
Defined in:
src/lib/bootloader/boot_record_backup.rb

Overview

Responsibility of class is to manage backup of MBR, respective PBR of disk, respective partition.

Defined Under Namespace

Classes: Error, Missing

Constant Summary

BASH_PATH =
Yast::Path.new(".target.bash")
BASH_OUTPUT_PATH =
Yast::Path.new(".target.bash_output")
TARGET_SIZE =
Yast::Path.new(".target.size")
MAIN_BACKUP_DIR =
"/var/lib/YaST2/backup_boot_sectors/".freeze
KEPT_BACKUPS =
10

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (BootRecordBackup) initialize(device)

Create backup handling class for given device

Parameters:

  • device (String)

    expect kernel name of device like “/dev/sda”



30
31
32
# File 'src/lib/bootloader/boot_record_backup.rb', line 30

def initialize(device)
  @device = device
end

Instance Attribute Details

- (Object) device (readonly)

Returns the value of attribute device



15
16
17
# File 'src/lib/bootloader/boot_record_backup.rb', line 15

def device
  @device
end

Instance Method Details

- (Object) restore

Restore backup

Returns:

  • true if copy is successful

Raises:



61
62
63
64
65
66
67
# File 'src/lib/bootloader/boot_record_backup.rb', line 61

def restore
  raise Missing unless exists?

  # Copy only 440 bytes for Vista booting problem bnc #396444
  # and also to not destroy partition table
  copy_br(device_file_path, device, bs: 440) == 0
end

- (Object) write

Write fresh backup of MBR or PBR of given device. Backup is stored in /var/lib/YaST2/backup_boot_sectors, in logs directory and if it is MBR of primary disk, then also in /boot/backup_mbr



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'src/lib/bootloader/boot_record_backup.rb', line 37

def write
  Yast::SCR.Execute(BASH_PATH, "mkdir -p #{MAIN_BACKUP_DIR}")

  if exists?
    rotate
    reduce_backup_count
  end

  copy_br(device, device_file_path)

  # save MBR to yast2 log directory
  logs_path = "/var/log/YaST2/" + device_file
  copy_br(device, logs_path)

  # special backup only if device is mbr disk
  Yast.import "BootStorage"
  return if device != Yast::BootStorage.mbr_disk

  copy_br(device, "/boot/backup_mbr")
end