diff --git a/.rubocop.yml b/.rubocop.yml index e943d5bba..ca13d32ea 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -36,7 +36,7 @@ Metrics/ClassLength: # Configuration parameters: CountComments. Metrics/ClassLength: - Max: 176 # TODO this should be lower for new code + Max: 200 # TODO this should be lower for new code Include: - 'src/lib/**/*.rb' # be more strict for new code in lib diff --git a/package/yast2-bootloader.changes b/package/yast2-bootloader.changes index b4a09df19..2bce94a0b 100644 --- a/package/yast2-bootloader.changes +++ b/package/yast2-bootloader.changes @@ -1,3 +1,11 @@ +------------------------------------------------------------------- +Mon Jun 29 12:46:58 UTC 2015 - jreidinger@suse.com + +- set only proper boot flags ("boot" for DOS partition table and + legacy_boot for GPT partition table), otherwise it can confuse + some firmware and cause booting problems (bnc#930903) +- 3.1.136 + ------------------------------------------------------------------- Mon Jun 22 11:01:16 UTC 2015 - jreidinger@suse.com diff --git a/package/yast2-bootloader.spec b/package/yast2-bootloader.spec index a7faa1330..f24be1c7f 100644 --- a/package/yast2-bootloader.spec +++ b/package/yast2-bootloader.spec @@ -17,7 +17,7 @@ Name: yast2-bootloader -Version: 3.1.135 +Version: 3.1.136 Release: 0 BuildRoot: %{_tmppath}/%{name}-%{version}-build diff --git a/src/lib/bootloader/mbr_update.rb b/src/lib/bootloader/mbr_update.rb index 11e35dd77..3d505c1bd 100644 --- a/src/lib/bootloader/mbr_update.rb +++ b/src/lib/bootloader/mbr_update.rb @@ -136,11 +136,13 @@ def activate_partitions next unless can_activate_partition?(num) log.info "Activating partition #{num} on #{mbr_dev}" - # this is needed only on gpt disks but we run it always - # anyway; parted just fails, then - set_parted_flag(mbr_dev, num, "legacy_boot") + # set corresponding flag only bnc#930903 + if mbr_is_gpt? + out = set_parted_flag(mbr_dev, num, "legacy_boot") + else + out = set_parted_flag(mbr_dev, num, "boot") + end - out = set_parted_flag(mbr_dev, num, "boot") ret &&= out["exit"].zero? end ret diff --git a/test/mbr_update_test.rb b/test/mbr_update_test.rb index e41470903..b6ed75fd9 100644 --- a/test/mbr_update_test.rb +++ b/test/mbr_update_test.rb @@ -176,112 +176,132 @@ allow(Yast::WFM).to receive(:Execute).and_return("exit" => 0, "stdout" => "") end - it "sets boot flag on all partitions in Bootloader devices" do - allow(Yast::BootCommon).to receive(:GetBootloaderDevices) - .and_return(["/dev/sda1", "/dev/sdb1"]) - - expect(Yast::WFM).to receive(:Execute) - .with(anything, /parted -s \/dev\/sda set 1 boot on/) - .and_return("exit" => 0) - subject.run - end - - it "resets all old boot flags on disk before set boot flag" do - allow(Yast::BootCommon).to receive(:GetBootloaderDevices) - .and_return(["/dev/sda1", "/dev/sdb1"]) - - parted_output = "BYT;\n" \ - "/dev/sda:500GB:scsi:512:4096:gpt:ATA WDC WD5000BPKT-7:;\n" \ - "1:1049kB:165MB:164MB:fat16:primary:boot, legacy_boot;\n" \ - "2:165MB:8760MB:8595MB:linux-swap(v1):primary:;\n" \ - "3:8760MB:30.2GB:21.5GB:ext4:primary:boot;\n" \ - "4:30.2GB:500GB:470GB:ext4:primary:legacy_boot;" - - allow(Yast::WFM).to receive(:Execute) - .with(anything, /parted -m \/dev\/sda print/) - .and_return( - "exit" => 0, - "stdout" => parted_output - ) - expect(Yast::WFM).to receive(:Execute) - .with(anything, /parted -s \/dev\/sda set 1 boot off/) - .and_return( - "exit" => 0, - "stdout" => parted_output + context "disk label is DOS mbr" do + before do + allow(Yast::Storage).to receive(:GetTargetMap).and_return( + double(:fetch => { "label" => "msdos" }, + :[] => { "label" => "msdos" } + ) ) - expect(Yast::WFM).to receive(:Execute) - .with(anything, /parted -s \/dev\/sda set 3 boot off/) - .and_return( - "exit" => 0, - "stdout" => parted_output - ) - - subject.run - end - - it "returns false if any setting of boot flag failed" do - allow(Yast::BootCommon).to receive(:GetBootloaderDevices) - .and_return(["/dev/sda1", "/dev/sdb1"]) - - allow(Yast::WFM).to receive(:Execute) - .with(anything, /parted -s \/dev\/sda set 1 boot on/) - .and_return("exit" => 1) - - expect(subject.run).to be false + end + + it "sets boot flag on all partitions in Bootloader devices" do + allow(Yast::BootCommon).to receive(:GetBootloaderDevices) + .and_return(["/dev/sda1", "/dev/sdb1"]) + + expect(Yast::WFM).to receive(:Execute) + .with(anything, /parted -s \/dev\/sda set 1 boot on/) + .and_return("exit" => 0) + subject.run + end + + it "resets all old boot flags on disk before set boot flag" do + allow(Yast::BootCommon).to receive(:GetBootloaderDevices) + .and_return(["/dev/sda1", "/dev/sdb1"]) + + parted_output = "BYT;\n" \ + "/dev/sda:500GB:scsi:512:4096:gpt:ATA WDC WD5000BPKT-7:;\n" \ + "1:1049kB:165MB:164MB:fat16:primary:boot, legacy_boot;\n" \ + "2:165MB:8760MB:8595MB:linux-swap(v1):primary:;\n" \ + "3:8760MB:30.2GB:21.5GB:ext4:primary:boot;\n" \ + "4:30.2GB:500GB:470GB:ext4:primary:legacy_boot;" + + allow(Yast::WFM).to receive(:Execute) + .with(anything, /parted -m \/dev\/sda print/) + .and_return( + "exit" => 0, + "stdout" => parted_output + ) + expect(Yast::WFM).to receive(:Execute) + .with(anything, /parted -s \/dev\/sda set 1 boot off/) + .and_return( + "exit" => 0, + "stdout" => parted_output + ) + expect(Yast::WFM).to receive(:Execute) + .with(anything, /parted -s \/dev\/sda set 3 boot off/) + .and_return( + "exit" => 0, + "stdout" => parted_output + ) + + subject.run + end + + it "returns false if any setting of boot flag failed" do + allow(Yast::BootCommon).to receive(:GetBootloaderDevices) + .and_return(["/dev/sda1", "/dev/sdb1"]) + + allow(Yast::WFM).to receive(:Execute) + .with(anything, /parted -s \/dev\/sda set 1 boot on/) + .and_return("exit" => 1) + + expect(subject.run).to be false + end end - it "sets legacy_boot flag on all partitions in Bootloader devices" do - allow(Yast::BootCommon).to receive(:GetBootloaderDevices) - .and_return(["/dev/sda1", "/dev/sdb1"]) - - expect(Yast::WFM).to receive(:Execute) - .with(anything, /parted -s \/dev\/sda set 1 legacy_boot on/) - .and_return("exit" => 0) - subject.run - end - - it "resets all old boot flags on disk before set boot flag" do - allow(Yast::BootCommon).to receive(:GetBootloaderDevices) - .and_return(["/dev/sda1", "/dev/sdb1"]) - - parted_output = "BYT;\n" \ - "/dev/sda:500GB:scsi:512:4096:gpt:ATA WDC WD5000BPKT-7:;\n" \ - "1:1049kB:165MB:164MB:fat16:primary:boot, legacy_boot;\n" \ - "2:165MB:8760MB:8595MB:linux-swap(v1):primary:;\n" \ - "3:8760MB:30.2GB:21.5GB:ext4:primary:boot;\n" \ - "4:30.2GB:500GB:470GB:ext4:primary:legacy_boot;" - - allow(Yast::WFM).to receive(:Execute) - .with(anything, /parted -m \/dev\/sda print/) - .and_return( - "exit" => 0, - "stdout" => parted_output - ) - expect(Yast::WFM).to receive(:Execute) - .with(anything, /parted -s \/dev\/sda set 1 legacy_boot off/) - .and_return( - "exit" => 0, - "stdout" => parted_output + context "disk label is GPT" do + before do + allow(Yast::Storage).to receive(:GetTargetMap).and_return( + double(:fetch => { "label" => "gpt" }, + :[] => { "label" => "gpt" } + ) ) - expect(Yast::WFM).to receive(:Execute) - .with(anything, /parted -s \/dev\/sda set 4 legacy_boot off/) - .and_return( - "exit" => 0, - "stdout" => parted_output - ) - - subject.run - end - - it "do not return false if setting legacy_boot failed" do - allow(Yast::BootCommon).to receive(:GetBootloaderDevices) - .and_return(["/dev/sda1", "/dev/sdb1"]) - - allow(Yast::WFM).to receive(:Execute) - .with(anything, /parted -s \/dev\/sda set 1 legacy_boot on/) - .and_return("exit" => 1) - - expect(subject.run).to be true + end + + it "sets legacy_boot flag on all partitions in Bootloader devices" do + allow(Yast::BootCommon).to receive(:GetBootloaderDevices) + .and_return(["/dev/sda1", "/dev/sdb1"]) + + expect(Yast::WFM).to receive(:Execute) + .with(anything, /parted -s \/dev\/sda set 1 legacy_boot on/) + .and_return("exit" => 0) + subject.run + end + + it "resets all old boot flags on disk before set boot flag" do + allow(Yast::BootCommon).to receive(:GetBootloaderDevices) + .and_return(["/dev/sda1", "/dev/sdb1"]) + + parted_output = "BYT;\n" \ + "/dev/sda:500GB:scsi:512:4096:gpt:ATA WDC WD5000BPKT-7:;\n" \ + "1:1049kB:165MB:164MB:fat16:primary:boot, legacy_boot;\n" \ + "2:165MB:8760MB:8595MB:linux-swap(v1):primary:;\n" \ + "3:8760MB:30.2GB:21.5GB:ext4:primary:boot;\n" \ + "4:30.2GB:500GB:470GB:ext4:primary:legacy_boot;" + + allow(Yast::WFM).to receive(:Execute) + .with(anything, /parted -m \/dev\/sda print/) + .and_return( + "exit" => 0, + "stdout" => parted_output + ) + expect(Yast::WFM).to receive(:Execute) + .with(anything, /parted -s \/dev\/sda set 1 legacy_boot off/) + .and_return( + "exit" => 0, + "stdout" => parted_output + ) + expect(Yast::WFM).to receive(:Execute) + .with(anything, /parted -s \/dev\/sda set 4 legacy_boot off/) + .and_return( + "exit" => 0, + "stdout" => parted_output + ) + + subject.run + end + + it "returns false if setting legacy_boot failed" do + allow(Yast::BootCommon).to receive(:GetBootloaderDevices) + .and_return(["/dev/sda1", "/dev/sdb1"]) + + allow(Yast::WFM).to receive(:Execute) + .with(anything, /parted -s \/dev\/sda set 1 legacy_boot on/) + .and_return("exit" => 1) + + expect(subject.run).to be false + end end it "do not set any flag on old DOS MBR for logical partitions" do