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/"
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”



33
34
35
# File 'src/lib/bootloader/boot_record_backup.rb', line 33

def initialize(device)
  @device = device
end

Instance Attribute Details

- (Object) device (readonly)

Returns the value of attribute device



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

def device
  @device
end

Instance Method Details

- (Object) restore

Restore backup

Returns:

  • true if copy is successful

Raises:



72
73
74
75
76
77
78
# File 'src/lib/bootloader/boot_record_backup.rb', line 72

def restore
  raise Missing.new 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



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'src/lib/bootloader/boot_record_backup.rb', line 40

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)

  if device == Yast::BootCommon.mbrDisk
    copy_br(device, "/boot/backup_mbr")

    # save thinkpad MBR
    if Yast::BootCommon.ThinkPadMBR(device)
      device_file_path_thinkpad = device_file_path + "thinkpadMBR"
      log.info("Backup thinkpad MBR")
      Yast::SCR.Execute(
        BASH_PATH,
        "cp #{device_file_path} #{device_file_path_thinkpad}",
      )
    end
  end
end