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 collapse

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

#initialize(device) ⇒ BootRecordBackup

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

#deviceObject (readonly)

Returns the value of attribute device.



18
19
20
# File 'src/lib/bootloader/boot_record_backup.rb', line 18

def device
  @device
end

Instance Method Details

#restoreObject

Restore backup

Returns:

  • true if copy is successful

Raises:



58
59
60
61
62
63
64
# File 'src/lib/bootloader/boot_record_backup.rb', line 58

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, block_size: 440) == 0
end

#writeObject

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
# File 'src/lib/bootloader/boot_record_backup.rb', line 40

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

  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)
end