Class: Yast::RootPartClass

Inherits:
Module
  • Object
show all
Defined in:
../../src/modules/RootPart.rb

Constant Summary

NON_MODULAR_FS =
["proc", "sysfs"]
BACKUP_DIRS =

known configuration files that are changed during update, so we need to backup them to restore if something goes wrong (bnc#882039)

{
  "sw_mgmt" => [
    "/var/lib/rpm",
    "/etc/zypp/repos.d",
    "/etc/zypp/services.d",
    "/etc/zypp/credentials.d"
  ]
}
IGNORED_OPTIONS =
[
  "ro", # in installation do not mount anything RO
  "defaults", # special defaults options in fstab
  /^locale=.*$/, #avoid locale for NTFS
]

Instance Method Summary (collapse)

Instance Method Details

- (void) AddMountedPartition(partinfo)

This method returns an undefined value.

Add information about mounted partition to internal list. see description of list “activated”

Parameters:

  • partinfo (Hash{Symbol => String})

    partinfo has to be list with exactly two strings,



364
365
366
367
368
369
370
# File '../../src/modules/RootPart.rb', line 364

def AddMountedPartition(partinfo)
  partinfo = deep_copy(partinfo)
  @activated = Builtins.prepend(@activated, partinfo)
  Builtins.y2debug("adding %1 yields %2", partinfo, @activated)

  nil
end

- (Object) AddToTargetMap



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File '../../src/modules/RootPart.rb', line 176

def AddToTargetMap
  target_map = Storage.GetOndiskTarget
  Builtins.y2milestone("On disk target map: %1", target_map)
  tmp = Builtins.filter(@activated) do |e|
    Ops.get_string(e, :type, "") == "mount"
  end
  Builtins.foreach(tmp) do |e|
    Builtins.y2milestone(
      "Setting partition data: Device: %1, MountPoint: %2",
      Ops.get_string(e, :device, ""),
      Ops.get_string(e, :mntpt, "")
    )
    target_map = Storage.SetPartitionData(
      target_map,
      Ops.get_string(e, :device, ""),
      "mount",
      Ops.get_string(e, :mntpt, "")
    )
    if Builtins.issubstring(
        Ops.get_string(e, :device, ""),
        "/dev/disk/by-id"
      )
      target_map = Storage.SetPartitionData(
        target_map,
        Ops.get_string(e, :device, ""),
        "mountby",
        :id
      )
    elsif Builtins.issubstring(Ops.get_string(e, :device, ""), "/dev/")
      target_map = Storage.SetPartitionData(
        target_map,
        Ops.get_string(e, :device, ""),
        "mountby",
        :device
      )
    else
      target_map = Storage.SetPartitionData(
        target_map,
        Ops.get_string(e, :device, ""),
        "mountby",
        :label
      )
    end
  end
  tmp = Builtins.filter(@activated) do |e|
    Ops.get_string(e, :type, "") == "swap"
  end
  Builtins.foreach(tmp) do |e|
    Builtins.y2milestone(
      "Setting swap partition data: Device: %1",
      Ops.get_string(e, :device, "")
    )
    target_map = Storage.SetPartitionData(
      target_map,
      Ops.get_string(e, :device, ""),
      "mount",
      "swap"
    )
    if Builtins.issubstring(
        Ops.get_string(e, :device, ""),
        "/dev/disk/by-id"
      )
      target_map = Storage.SetPartitionData(
        target_map,
        Ops.get_string(e, :device, ""),
        "mountby",
        :id
      )
    elsif Builtins.issubstring(Ops.get_string(e, :device, ""), "/dev/")
      target_map = Storage.SetPartitionData(
        target_map,
        Ops.get_string(e, :device, ""),
        "mountby",
        :device
      )
    else
      target_map = Storage.SetPartitionData(
        target_map,
        Ops.get_string(e, :device, ""),
        "mountby",
        :label
      )
    end
  end
  Builtins.y2milestone("Setting target map: %1", target_map)
  Storage.SetTargetMap(target_map)

  nil
end

- (Object) AnyQuestionAnyButtonsDetails(headline, question, button_yes, button_no, details)

Parameters:

  • headline (String)

    (optional; to disable, use “”)

  • question (String)
  • string

    button (true)

  • string

    button (false)

  • details (String)

    (hidden under [Details] button; optional; to disable, use “”)



402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
# File '../../src/modules/RootPart.rb', line 402

def AnyQuestionAnyButtonsDetails(headline, question, button_yes, button_no, details)
  has_details = true
  has_details = false if details == "" || details == nil

  has_heading = true
  has_heading = false if headline == "" || headline == nil

  heading = has_heading ? VBox(Left(Heading(headline))) : Empty()

  popup_def = Left(Label(question))

  details_checkbox = has_details ?
    VBox(
      VSpacing(1),
      Left(CheckBox(Id(:details), Opt(:notify), _("Show &Details"), false))
    ) :
    Empty()

  popup_buttons = VBox(
    VSpacing(1),
    HBox(
      HSpacing(8),
      PushButton(Id(:yes), button_yes),
      VSpacing(2),
      PushButton(Id(:cancel), button_no),
      HSpacing(8)
    ),
    VSpacing(0.5)
  )

  UI.OpenDialog(
    Opt(:decorated),
    VSquash(
      VBox(
        heading,
        popup_def,
        Left(Opt(:hstretch), ReplacePoint(Id(:rp_details), Empty())),
        details_checkbox,
        popup_buttons
      )
    )
  )
  UI.SetFocus(Id(:yes))

  userinput = nil
  ret = nil

  while true
    userinput = UI.UserInput

    if userinput == :yes
      ret = true
      break
    elsif userinput == :details
      curr_status = Convert.to_boolean(UI.QueryWidget(Id(:details), :Value))

      if curr_status == false
        UI.ReplaceWidget(Id(:rp_details), Empty())
      else
        UI.ReplaceWidget(
          Id(:rp_details),
          MinSize(
            60,
            10,
            RichText(Id(:details_text), Opt(:plainText, :hstretch), details)
          )
        )
      end
    else
      ret = false
      break
    end
  end

  UI.CloseDialog

  ret
end

- (Object) check_root_device(partition, fstab, found_partition)

Check that the root filesystem in fstab has the correct device.



664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
# File '../../src/modules/RootPart.rb', line 664

def check_root_device(partition, fstab, found_partition)
  fstab = deep_copy(fstab)
  tmp = Builtins.filter(fstab) do |entry|
    Ops.get_string(entry, "file", "") == "/"
  end

  if Builtins.size(tmp) != 1
    Builtins.y2error("not exactly one root partition found in fstab")
    found_partition.value = "none"
    return false
  end

  root = Ops.get(tmp, 0, {})

  if !Storage.DeviceRealDisk(Ops.get_string(root, "spec", ""))
    # There's nothing I can check.  Anyway, it's not mounted per device
    # name so it can't be wrong, in theory.
    return true
  end

  true
end

- (Object) CheckBootSize(bootpart)

bugzilla #258563



1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
# File '../../src/modules/RootPart.rb', line 1118

def CheckBootSize(bootpart)
  min_suggested_bootsize = 65536
  min_suggested_bootsize = 204800 if Arch.ia64

  bootsize = nil

  cmd = Builtins.sformat(
    "/bin/df --portability --no-sync -k '%1/boot' | grep -v '^Filesystem' | sed 's/[ ]\\+/ /g'",
    Installation.destdir
  )
  bootsizeout = Convert.to_map(
    SCR.Execute(path(".target.bash_output"), cmd)
  )

  if Ops.get_integer(bootsizeout, "exit", -1) != 0
    Builtins.y2error("Error: '%1' -> %2", cmd, bootsizeout)
  else
    scriptout = Builtins.splitstring(
      Ops.get_string(bootsizeout, "stdout", ""),
      " "
    )
    Builtins.y2milestone("Scriptout: %1", scriptout)
    bootsize = Builtins.tointeger(Ops.get(scriptout, 1, "0"))
  end

  if bootsize == nil || bootsize == 0
    Builtins.y2error(
      "Cannot find out bootpart size: %1",
      Installation.destdir
    )
    return true
  end

  Builtins.y2milestone(
    "Boot size is: %1 recommended min.: %2",
    bootsize,
    min_suggested_bootsize
  )

  # Size of the /boot partition is satisfactory
  if Ops.greater_or_equal(bootsize, min_suggested_bootsize)
    return true 

    # Less than a hero
  else
    current_bs = Ops.divide(bootsize, 1024)
    suggested_bs = Ops.divide(min_suggested_bootsize, 1024)

    cont = Popup.ContinueCancelHeadline(
      # TRANSLATORS: a popup headline
      _("Warning"),
      # TRANSLATORS: error message,
      # %1 is replaced with the current /boot partition size
      # %2 with the recommended size
      Builtins.sformat(
        _(
          "Your /boot partition is too small (%1 MB).\n" +
            "We recommend a size of no less than %2 MB or else the new Kernel may not fit.\n" +
            "It is safer to either enlarge the partition\n" +
            "or not use a /boot partition at all.\n" +
            "\n" +
            "Do you want to continue updating the current system?\n"
        ),
        current_bs,
        suggested_bs
      )
    )

    if cont
      Builtins.y2warning(
        "User decided to continue despite small a /boot partition"
      )
      return true
    else
      Builtins.y2milestone(
        "User decided not to continue with small /boot partition"
      )
      return false
    end
  end
end

- (Object) CheckPartition(partition)

Check a root partition and return map with infomations (see variable rootPartitions).



1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
# File '../../src/modules/RootPart.rb', line 1872

def CheckPartition(partition)
  partition = deep_copy(partition)
  freshman = {
    :valid  => false,
    :name   => "unknown",
    :arch   => "unknown",
    :label  => Ops.get_string(partition, "label", ""),
    :fs     => Ops.get_symbol(partition, "detected_fs", :unknown),
    :fstype => Ops.get_string(partition, "fstype", "unknown")
  }

  p_dev = Ops.get_string(partition, "device", "error")
  p_fsid = Ops.get_integer(partition, "fsid", 0)
  p_type = Ops.get_symbol(partition, "type", :primary)
  p_detect_fs = Ops.get_symbol(partition, "detected_fs", :unknown)

  # possible root FS
  if Builtins.contains(FileSystems.possible_root_fs, p_detect_fs)
    mt_map = {
      :ext2   => "ext2",
      :ext3   => "ext3",
      :ext4   => "ext4",
      :btrfs  => "btrfs",
      :reiser => "reiserfs",
      :xfs    => "xfs",
      :jfs    => "jfs"
    }
    mount_type = Ops.get(mt_map, p_detect_fs, "")

    error_message = nil
    if !(
        error_message_ref = arg_ref(error_message);
        _RunFSCKonJFS_result = RunFSCKonJFS(
          mount_type,
          p_dev,
          error_message_ref
        );
        error_message = error_message_ref.value;
        _RunFSCKonJFS_result
      )
      Ops.set(freshman, :valid, false)
      return deep_copy(freshman)
    end

    # mustn't be empty and must be modular
    if mount_type != "" && !NON_MODULAR_FS.include?(mount_type)
      SCR.Execute(path(".target.modprobe"), mount_type, "")
    end
    # mount (read-only) partition to Installation::destdir
    Storage.RemoveDmMapsTo(p_dev)
    if Convert.to_boolean(
        SCR.Execute(
          path(".target.mount"),
          [p_dev, Installation.destdir, Installation.mountlog],
          "-o ro"
        )
      )
      # Is this a root partition, does /etc/fstab exists?
      if Ops.greater_than(
          SCR.Read(
            path(".target.size"),
            Ops.add(Installation.destdir, "/etc/fstab")
          ),
          0
        )
        Builtins.y2milestone("found fstab on %1", partition)

        fstab = []
        crtab = []

        fstab_ref = arg_ref(fstab)
        crtab_ref = arg_ref(crtab)
        read_fstab_and_cryptotab(fstab_ref, crtab_ref, p_dev)
        fstab = fstab_ref.value
        crtab = crtab_ref.value
        Update.GetProductName

        fstab = Builtins.filter(fstab) do |p|
          Ops.get_string(p, "file", "") == "/"
        end

        if Builtins.size(Ops.get_string(fstab, [0, "spec"], "")) == 0
          Builtins.y2warning("Cannot find / entry in fstab %1", fstab)
        end

        Ops.set(
          freshman,
          :valid,
          Ops.greater_than(
            Builtins.size(Ops.get_string(fstab, [0, "spec"], "")),
            0
          ) &&
            Storage.DeviceMatchFstab(
              p_dev,
              Ops.get_string(
                # bugzilla #304269
                # DeviceMatchFstab expects _old_ not _translated_ device
                fstab,
                [0, "spec_old"],
                Ops.get_string(fstab, [0, "spec"], "")
              )
            )
        )

        # Why this doesn't match?
        # Possible reasons:
        # - /var not mounted so hwinfo cannot translate device names
        if Ops.get_boolean(freshman, :valid, false) != true
          Builtins.y2warning(
            "Device does not match fstab: '%1' vs. '%2'",
            p_dev,
            Ops.get_string(fstab, [0, "spec"], "")
          )
        end
        if Mode.autoinst
          # we dont care about the other checks in autoinstallation
          SCR.Execute(path(".target.umount"), Installation.destdir)
          return deep_copy(freshman)
        end

        # Get installed release name
        # TRANSLATORS: label for an unknown installed system
        freshman[:name] = Update.installed_product || _("Unknown")
        Builtins.y2debug("release: %1", freshman[:name])

        # Right architecture?
        Ops.set(
          freshman,
          :arch,
          GetArchOfELF(Ops.add(Installation.destdir, "/bin/bash"))
        )
        instsys_arch = GetArchOfELF("/bin/bash")

        # `arch_valid, see bugzilla #288201
        # installed /bin/bash and the one from inst-sys are matching
        if Ops.get_string(freshman, :arch, "unknown") == instsys_arch
          Builtins.y2milestone("Architecture (%1) is valid", instsys_arch)
          Ops.set(freshman, :arch_valid, true) 

          # both are PPC, bugzilla #249791
        elsif Builtins.contains(
            ["ppc", "ppc64"],
            Ops.get_string(freshman, :arch, "unknown")
          ) &&
            Builtins.contains(["ppc", "ppc64"], instsys_arch)
          Builtins.y2milestone(
            "Architecture for partition %1 is %2, upgrading %3",
            p_dev,
            Ops.get_string(freshman, :arch, "unknown"),
            instsys_arch
          )
          Ops.set(freshman, :arch_valid, true) 

          # Architecture is not matching
        else
          Builtins.y2milestone(
            "Architecture for partition %1 is %2, upgrading %3",
            p_dev,
            Ops.get_string(freshman, :arch, "unknown"),
            instsys_arch
          )
          Ops.set(freshman, :arch_valid, false)
        end

        # If architecture is not matching, the whole partition is considered to be wrong
        if Ops.get_boolean(freshman, :arch_valid, false) != true
          Builtins.y2milestone(
            "Architecture is not valid -> the whole partition is not valid"
          )
          Ops.set(freshman, :valid, false)
        end

        if IncompleteInstallationDetected(Installation.destdir)
          Builtins.y2milestone(
            "Incomplete installation detected, partition is not valid"
          )
          Ops.set(freshman, :valid, false)
        end

        Builtins.y2milestone(
          "Partition is valid: %1, arch is valid: %2",
          Ops.get_boolean(freshman, :valid, false),
          Ops.get_boolean(freshman, :arch_valid, false)
        )
      end

      # unmount partition
      SCR.Execute(path(".target.umount"), Installation.destdir)
    end
  end

  Builtins.y2milestone("%1 %2", partition, freshman)

  deep_copy(freshman)
end

- (Object) cleaned_mount_options(mount_options)



2234
2235
2236
2237
2238
# File '../../src/modules/RootPart.rb', line 2234

def cleaned_mount_options(mount_options)
  elements = mount_options.split(",")
  elements.delete_if { |e| IGNORED_OPTIONS.any? { |o| o === e } }
  elements.join(",")
end

- (Object) create_backup



1828
1829
1830
1831
1832
# File '../../src/modules/RootPart.rb', line 1828

def create_backup
  BACKUP_DIRS.each_pair do |name, paths|
    Update.create_backup(name, paths)
  end
end

- (Object) Detect



2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
# File '../../src/modules/RootPart.rb', line 2208

def Detect
  if !@didSearchForRootPartitions
    Wizard.SetContents(
      # TRANSLATORS: dialog caption
      _("Searching for Available Systems"),
      VBox(ReplacePoint(Id("search_progress"), Empty())),
      "",
      false,
      false
    )

    FindRootPartitions()

    @selectedRootPartition = ""
    Builtins.y2milestone("Detected root partitions: %1", @rootPartitions)
  end

  nil
end

- (String) FindPartitionInFstab(fstab, mountpoint)

Find a mount point in fstab

Parameters:

  • fstab (list <map> &)

    a list of fstab entries

  • mountpoint (String)

    string a mount point to find

Returns:

  • (String)

    the found partition



691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
# File '../../src/modules/RootPart.rb', line 691

def FindPartitionInFstab(fstab, mountpoint)
  if Builtins.substring(
      mountpoint,
      Ops.subtract(Builtins.size(mountpoint), 1),
      1
    ) == "/"
    mountpoint = Builtins.substring(
      mountpoint,
      0,
      Ops.subtract(Builtins.size(mountpoint), 1)
    )
  end

  tmp = Builtins.filter(fstab.value) do |entry|
    Ops.get_string(entry, "file", "") == mountpoint ||
      Ops.get_string(entry, "file", "") == Ops.add(mountpoint, "/")
  end

  return nil if Builtins.size(tmp) == 0

  Ops.get_string(tmp, [0, "spec"], "")
end

- (void) FindRootPartitions

This method returns an undefined value.

Find all valid root partitions and place the result in rootPartitions. The partitions are mounted and unmounted again (to Installation::destdir). Loads a bunch of kernel modules.



2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
# File '../../src/modules/RootPart.rb', line 2073

def FindRootPartitions
  return if @didSearchForRootPartitions

  modules_to_load = {
    "reiserfs" => "Reiser FS",
    "xfs" => "XFS",
    "ext3" => "Ext3",
    "ext4" => "Ext4",
    "btrfs" => "BtrFS",
    "raid0" => "Raid 0",
    "raid1" => "Raid 1",
    "raid5" => "Raid 5",
    "raid6" => "Raid 6",
    "raid10" => "Raid 10",
    "dm-multipath" => "Multipath",
    "dm-mod" => "DM",
    "dm-snapshot" => "DM Snapshot",
  }
  modules_to_load.each do |module_to_load, show_name|
    ModuleLoading.Load(module_to_load, "", "Linux", show_name, Linuxrc.manual, true)
  end

  if Mode.test
    Storage.SetTargetMap(
      Convert.convert(
        SCR.Read(path(".target.yast2"), "test_target_map.ycp"),
        :from => "any",
        :to   => "map <string, map>"
      )
    )
  end

  #	Storage::ActivateEvms();
  target_map = Storage.GetOndiskTarget
  Builtins.y2milestone("target_map: %1", target_map)

  # prepare progress-bar
  if UI.WidgetExists(Id("search_progress"))
    UI.ReplaceWidget(
      Id("search_progress"),
      ProgressBar(
        Id("search_pb"),
        _("Evaluating root partition. One moment please..."),
        100,
        0
      )
    )
  end

  @rootPartitions = {}
  @numberOfValidRootPartitions = 0

  # all partitions on all devices
  max_steps = 0
  Builtins.foreach(target_map) do |device, description|
    max_steps = Ops.add(
      max_steps,
      Builtins.size(Ops.get_list(description, "partitions", []))
    )
  end

  counter = 0
  Builtins.foreach(target_map) do |device, description|
    Builtins.foreach(Ops.get_list(description, "partitions", [])) do |partition|
      counter = Ops.add(counter, 1)
      if UI.WidgetExists(Id("search_progress"))
        UI.ChangeWidget(
          Id("search_pb"),
          :Value,
          Ops.divide(Ops.multiply(100, counter), max_steps)
        )
      end
      # some partitions don't make sense at all
      if Ops.get_symbol(partition, "detected_fs", :unknown) != :swap &&
          Ops.get_symbol(partition, "type", :primary) != :extended
        freshman = {}

        if Mode.test
          freshman = {
            :valid => true,
            :name  => "SuSE Linux 4.2",
            :arch  => "i286",
            :label => "Label"
          }
        else
          freshman = CheckPartition(partition)
        end

        @rootPartitions = Builtins.add(
          @rootPartitions,
          Ops.get_string(partition, "device", "error"),
          freshman
        )

        if Ops.get_boolean(freshman, :valid, false)
          @numberOfValidRootPartitions = Ops.add(
            @numberOfValidRootPartitions,
            1
          )
        end
      end
    end
  end

  # 100%
  if UI.WidgetExists(Id("search_progress"))
    UI.ChangeWidget(Id("search_pb"), :Value, 100)
  end

  @didSearchForRootPartitions = true

  Builtins.y2milestone("rootPartitions: %1", @rootPartitions)

  nil
end

- (String) FsckAndMount(mount_point, device, mount_type, mntopts = "")

Check filesystem on a partition and mount the partition on specified mount point

Parameters:

  • mount_point (String)

    string mount point to monut the partition at

  • device (String)

    string device to mount

  • mount_type (String)

    string filesystem type to be specified while mounting

Returns:

  • (String)

    nil on success, error description on fail



639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
# File '../../src/modules/RootPart.rb', line 639

def FsckAndMount(mount_point, device, mount_type, mntopts="")
  FSCKPartition(device)

  ret = MountPartition(mount_point, device, mount_type, mntopts)

  if ret == nil
    AddMountedPartition(
      { :type => "mount", :device => device, :mntpt => mount_point }
    )
  end

  Builtins.y2milestone(
    "mounting (%1, %2, %3) yield %4",
    Ops.add(Installation.destdir, mount_point),
    device,
    mount_type,
    ret
  )

  ret
end

- (Object) FSCKPartition(partition)

Check the filesystem of a partition.



374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
# File '../../src/modules/RootPart.rb', line 374

def FSCKPartition(partition)
  if !Mode.test
    detected_fs = Storage.DetectFs(partition)
    if detected_fs == :ext2
      # label, %1 is partition
      out = Builtins.sformat(_("Checking partition %1"), partition)
      UI.OpenDialog(Opt(:decorated), Label(out))

      Builtins.y2milestone("command: /sbin/e2fsck -y %1", partition)
      SCR.Execute(
        path(".target.bash"),
        Ops.add("/sbin/e2fsck -y ", partition)
      )

      UI.CloseDialog
    end
  end

  nil
end

- (Object) FstabHasSeparateVar(fstab)



914
915
916
917
918
919
920
921
922
923
924
# File '../../src/modules/RootPart.rb', line 914

def FstabHasSeparateVar(fstab)
  var_device_fstab = (
    fstab_ref = arg_ref(fstab.value);
    _FindPartitionInFstab_result = FindPartitionInFstab(fstab_ref, "/var");
    fstab.value = fstab_ref.value;
    _FindPartitionInFstab_result
  )
  Builtins.y2milestone("/var partition is %1", var_device_fstab)

  var_device_fstab != nil
end

- (Object) FstabUsesKernelDeviceNameForHarddisks(fstab)



927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
# File '../../src/modules/RootPart.rb', line 927

def FstabUsesKernelDeviceNameForHarddisks(fstab)
  fstab = deep_copy(fstab)
  # We just want to check the use of kernel device names for hard
  # disks. Not for e.g. BIOS RAIDs or LVM logical volumes.

  # Since we are looking at device names of hard disks that may no
  # longer exist all we have at hand is the name.

  Builtins.find(fstab) do |line|
    spec = Ops.get_string(line, "spec", "error")
    next true if Builtins.regexpmatch(spec, "^/dev/sd[a-z]+[0-9]+$")
    next true if Builtins.regexpmatch(spec, "^/dev/hd[a-z]+[0-9]+$")
    next true if Builtins.regexpmatch(spec, "^/dev/dasd[a-z]+[0-9]+$")
    false
  end != nil
end

- (Array<Hash{Symbol => String>}) GetActivated

Returns currently activated partitions.

Returns:

  • (Array<Hash{Symbol => String>})

    activated



123
124
125
# File '../../src/modules/RootPart.rb', line 123

def GetActivated
  deep_copy(@activated)
end

- (Object) GetArchOfELF(filename)

Get architecture of an elf file.



1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
# File '../../src/modules/RootPart.rb', line 1835

def GetArchOfELF(filename)
  bash_out = Convert.to_map(
    SCR.Execute(
      path(".target.bash_output"),
      Ops.add(Ops.add(Directory.ybindir, "/elf-arch "), filename)
    )
  )
  return "unknown" if Ops.get_integer(bash_out, "exit", 1) != 0
  Builtins.deletechars(Ops.get_string(bash_out, "stdout", "unknown"), "\n")
end

- (Object) GetDistroArch



2189
2190
2191
# File '../../src/modules/RootPart.rb', line 2189

def GetDistroArch
  GetArchOfELF("/bin/bash")
end

- (Object) GetInfoOfSelected(what)

Get the key what of the selected root partition.



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File '../../src/modules/RootPart.rb', line 133

def GetInfoOfSelected(what)
  i = Ops.get(@rootPartitions, @selectedRootPartition, {})

  if what == :name
    # Name is known
    if Ops.get_string(i, what, "") != ""
      return Ops.get_string(i, what, "") 

      # Linux partition, but no root FS found
    elsif Builtins.contains(
        FileSystems.possible_root_fs,
        Ops.get_symbol(i, :fs, :nil)
      )
      # label - name of sustem to update
      return _("Unknown Linux System") 

      # Non-Linux
    else
      # label - name of sustem to update
      return _("Non-Linux System")
    end
  else
    # label - name of sustem to update
    return Ops.get_locale(i, what, _("Unknown"))
  end
end

- (Boolean) IncompleteInstallationDetected(mounted_to)

Checks the partition whether it contains an incomplete installation.

Parameters:

  • string

    system mounted to directory

Returns:

  • (Boolean)

    true if incomplete

See Also:

  • #441919


1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
# File '../../src/modules/RootPart.rb', line 1851

def IncompleteInstallationDetected(mounted_to)
  # by default, installation is complete
  ret = false

  Builtins.foreach([Installation.run_yast_at_boot]) do |check_this|
    check_this = Builtins.sformat("%1/%2", mounted_to, check_this)
    if FileUtils.Exists(check_this) == true
      Builtins.y2milestone(
        "File %1 exists, installation is incomplete",
        check_this
      )
      ret = true
      raise Break
    end
  end

  ret
end

- (Boolean) IsMounted(mountpoint)

Check if specified mount point is mounted

Parameters:

  • mountpoint (String)

    the mount point to be checked

Returns:

  • (Boolean)

    true if it is mounted



1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
# File '../../src/modules/RootPart.rb', line 1093

def IsMounted(mountpoint)
  if Builtins.substring(
      mountpoint,
      Ops.subtract(Builtins.size(mountpoint), 1),
      1
    ) == "/"
    mountpoint = Builtins.substring(
      mountpoint,
      0,
      Ops.subtract(Builtins.size(mountpoint), 1)
    )
  end

  ret = true
  Builtins.foreach(@activated) do |e|
    if Ops.get_string(e, :type, "") == "mount" &&
        (Ops.get_string(e, :mntpt, "") == mountpoint ||
          Ops.get_string(e, :mntpt, "") == Ops.add(mountpoint, "/"))
      ret = true
    end
  end
  ret
end

- (Object) main



37
38
39
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File '../../src/modules/RootPart.rb', line 37

def main
  Yast.import "UI"

  textdomain "update"

  Yast.import "Directory"
  Yast.import "Mode"
  Yast.import "Linuxrc"
  Yast.import "Storage"
  Yast.import "Popup"
  Yast.import "ModuleLoading"
  Yast.import "FileSystems"
  Yast.import "Update"
  Yast.import "FileUtils"
  Yast.import "Arch"
  Yast.import "String"
  Yast.import "Installation"
  Yast.import "Report"
  Yast.import "Label"
  Yast.import "Stage"
  Yast.import "Wizard"

  Yast.include self, "partitioning/custom_part_dialogs.rb"


  # Selected root partition for the update or boot.
  @selectedRootPartition = ""

  # FATE #301844, to find out that a system for update has been changed
  @previousRootPartition = ""

  # Map of all root partitions (key) and information map (value).
  # The information map contains the keys `valid, `name and `arch.
  @rootPartitions = {}

  # Number of valid root partitions.
  @numberOfValidRootPartitions = 0

  # Show all partitions (not only root partitions) in the dialog.
  @showAllPartitions = false

  # Did we search for root partitions
  @didSearchForRootPartitions = false

  # We successfully mounted the target partitions
  @targetOk = false

  # Did we try to mount the target partitions?
  @did_try_mount_partitions = false

  @already_checked_jfs_partitions = []

  # List of mounted partitions, activated swap partitions and loop devices.
  # Amongst other things used for reversing action if mode is changed from
  # update to new installation or if root partition for update is changed.
  # The order of the list if of paramount importance.
  #
  # Each item is list [string value, string type [, string device]] where:
  #
  # Keys/values are:
  #
  #   `type     The type, one of "mount", "swap" or "crypt".
  #
  #   `device   The device.
  #
  #   `mntpt    The mount point, only for `type = "mount".  Does not
  #             include Installation::destdir.
  @activated = []


  #  Link to SDB article concerning renaming of devices.
  @sdb = Builtins.sformat(
    _(
      "See the SDB article at %1 for details\nabout how to solve this problem."
    ),
    "http://support.novell.com/techcenter/sdb/en/2003/03/fhassel_update_not_possible.html"
  )

  # translation from new to old device names
  # such as /dev/sdc4 -> /dev/hdb4
  @backward_translation = {}
end

- (Object) mount_target



2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
# File '../../src/modules/RootPart.rb', line 2193

def mount_target
  UI.OpenDialog(
    Opt(:decorated),
    # intermediate popup while mounting partitions
    Label(_("Mounting partitions. One moment please..."))
  )

  tmp = MountPartitions(@selectedRootPartition)
  # sleep (500);

  UI.CloseDialog

  tmp
end

- (Object) Mounted



127
128
129
# File '../../src/modules/RootPart.rb', line 127

def Mounted
  Ops.greater_than(Builtins.size(@activated), 0)
end

- (Object) MountFSTab(fstab, message)



1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
# File '../../src/modules/RootPart.rb', line 1201

def MountFSTab(fstab, message)
  fstab = deep_copy(fstab)
  allowed_fs = [
    "ext",
    "ext2",
    "ext3",
    "ext4",
    "btrfs",
    "minix",
    "reiserfs",
    "jfs",
    "xfs",
    "xiafs",
    "hpfs",
    "vfat",
    "auto",
  ]

  # mount sysfs first
  if MountPartition("/sys", "sysfs", "sysfs") == nil
    AddMountedPartition(
      { :type => "mount", :device => "sysfs", :mntpt => "/sys" }
    )
  end

  if MountPartition("/proc", "proc", "proc") == nil
    AddMountedPartition(
      { :type => "mount", :device => "proc", :mntpt => "/proc" }
    )
  end

  success = true

  raidMounted = false

  Builtins.foreach(fstab) do |mounts|
    vfstype = Ops.get_string(mounts, "vfstype", "")
    mntops = Ops.get_string(mounts, "mntops", "")
    spec = Ops.get_string(mounts, "spec", "")
    fspath = Ops.get_string(mounts, "file", "")
    if Builtins.contains(allowed_fs, vfstype) && fspath != "/" &&
        (fspath != "/var" || !IsMounted("/var")) &&
        !Builtins.issubstring(mntops, "noauto")
      Builtins.y2milestone("mounting %1 to %2", spec, fspath)

      if !Mode.test
        mount_type = ""
        mount_type = vfstype if vfstype == "proc"

        mount_err = ""
        while mount_err != nil
          mount_err = FsckAndMount(fspath, spec, mount_type, mntops)
          if mount_err != nil
            Builtins.y2error(
              "mounting %1 (type %2) on %3 failed",
              spec,
              mount_type,
              Ops.add(Installation.destdir, fspath)
            )
            UI.OpenDialog(
              VBox(
                Label(
                  Builtins.sformat(
                    # label in a popup, %1 is device (eg. /dev/hda1), %2 is output of the 'mount' command
                    _(
                      "The partition %1 could not be mounted.\n" +
                        "\n" +
                        "%2\n" +
                        "\n" +
                        "If you are sure that the partition is not necessary for the\n" +
                        "update (not a system partition), click Continue.\n" +
                        "To check or fix the mount options, click Specify Mount Options.\n" +
                        "To abort the update, click Cancel.\n"
                    ),
                    spec,
                    mount_err
                  )
                ),
                VSpacing(1),
                HBox(
                  PushButton(Id(:cont), Label.ContinueButton),
                  # push button
                  PushButton(Id(:cmd), _("&Specify Mount Options")),
                  PushButton(Id(:cancel), Label.CancelButton)
                )
              )
            )
            act = Convert.to_symbol(UI.UserInput)
            UI.CloseDialog
            if act == :cancel
              mount_err = nil
              success = false
            elsif act == :cont
              mount_err = nil
            elsif act == :cmd
              UI.OpenDialog(
                VBox(
                  # popup heading
                  Heading(_("Mount Options")),
                  VSpacing(0.6),
                  # text entry label
                  TextEntry(Id(:mp), _("&Mount Point"), fspath),
                  VSpacing(0.4),
                  # tex entry label
                  TextEntry(Id(:device), _("&Device"), spec),
                  VSpacing(0.4),
                  # text entry label
                  TextEntry(
                    Id(:fs),
                    _("&File System\n(empty for autodetection)"),
                    mount_type
                  ),
                  VSpacing(1),
                  HBox(
                    PushButton(Id(:ok), Label.OKButton),
                    PushButton(Id(:cancel), Label.CancelButton)
                  )
                )
              )
              act = Convert.to_symbol(UI.UserInput)
              if act == :ok
                fspath = Convert.to_string(UI.QueryWidget(Id(:mp), :Value))
                spec = Convert.to_string(
                  UI.QueryWidget(Id(:device), :Value)
                )
                mount_type = Convert.to_string(
                  UI.QueryWidget(Id(:fs), :Value)
                )
              end
              UI.CloseDialog
            end
          end
        end

        if fspath == "/boot" || fspath == "/boot/"
          checkspec = spec

          # translates new device name to the old one because
          # storage still returns them in the old way
          if Ops.get(@backward_translation, spec) != nil
            checkspec = Ops.get(@backward_translation, spec, spec)
          end

          success = false if !CheckBootSize(checkspec)
        end
      end # allowed_fs
    elsif vfstype == "swap" && fspath == "swap"
      Builtins.y2milestone("mounting %1 to %2", spec, fspath)

      if !Mode.test
        command = "/sbin/swapon "
        if spec != ""
          # swap-partition
          command = Ops.add(command, spec)

          # run /sbin/swapon
          ret_from_shell = Convert.to_integer(
            SCR.Execute(path(".target.bash"), command)
          )
          if ret_from_shell != 0
            Builtins.y2error("swapon failed: %1", command)
          else
            AddMountedPartition({ :type => "swap", :device => spec })
          end
        end
      end
    end
  end

  success
end

- (String) MountPartition(mount_point, device, mount_type, fsopts = "")

Mount partition on specified mount point

Parameters:

  • mount_point (String)

    string mount point to monut the partition at

  • device (String)

    string device to mount

  • mount_type (String)

    string filesystem type to be specified while mounting

Returns:

  • (String)

    nil on success, error description on fail



567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
# File '../../src/modules/RootPart.rb', line 567

def MountPartition(mount_point, device, mount_type, fsopts = "")
  if mount_type == ""
    # e.g. -> "reiserfs"
    mount_type = FileSystems.GetMountString(Storage.DetectFs(device), "")
  end

  # #223878, do not call modprobe with empty mount_type
  if mount_type == ""
    Builtins.y2warning("Unknown filesystem, skipping modprobe...") 
    # #211916, sysfs, proc are not modular
  elsif !NON_MODULAR_FS.include?(mount_type)
    # #167976, was broken with "-t ", modprobe before adding it
    Builtins.y2milestone("Calling 'modprobe %1'", mount_type)
    SCR.Execute(path(".target.modprobe"), mount_type, "")
  else
    Builtins.y2milestone(
      "FS type %1 is not modular, skipping modprobe...",
      mount_type
    )
  end

  error_message = nil
  if !(
      error_message_ref = arg_ref(error_message);
      _RunFSCKonJFS_result = RunFSCKonJFS(
        mount_type,
        device,
        error_message_ref
      );
      error_message = error_message_ref.value;
      _RunFSCKonJFS_result
    )
    return error_message
  end

  mnt_opts = cleaned_mount_options(fsopts)

  mnt_opts = "-o " + mnt_opts unless mnt_opts.empty?

  mnt_opts << " -t #{mount_type}" if mount_type != ""

  Builtins.y2milestone("mount options '#{mnt_opts}'")

  ret = Convert.to_boolean(
    SCR.Execute(
      path(".target.mount"),
      [
        device,
        Ops.add(Installation.destdir, mount_point),
        Installation.mountlog
      ],
      mnt_opts
    )
  )
  if ret
    return nil
  else
    return Convert.to_string(
      SCR.Read(path(".target.string"), Installation.mountlog)
    )
  end
end

- (Object) MountPartitions(root_device_current)

Mounting root-partition; reading fstab and mounting read partitions



1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
# File '../../src/modules/RootPart.rb', line 1650

def MountPartitions(root_device_current)
  Builtins.y2milestone("mount partitions: %1", root_device_current)

  return true if @did_try_mount_partitions

  @did_try_mount_partitions = true

  success = true

  # popup message, %1 will be replace with the name of the logfile
  message = Builtins.sformat(
    _(
      "Partitions could not be mounted.\n" +
        "\n" +
        "Check the log file %1."
    ),
    Ops.add(Directory.logdir, "/y2log")
  )
  Builtins.y2milestone("selected partition: %1", root_device_current)

  ret_bool = true

  fstab = []
  crtab = []

  # Mount selected root partition to Installation::destdir
  ret_bool = nil == FsckAndMount("/", root_device_current, "") if !Mode.test

  if ret_bool
    # read the keyboard settings now, so that it used when
    # typing passwords for encrypted partitions
    # Calling a script because otherwise this module would depend on yast2-country
    if Stage.initial
      WFM.call(
        "rootpart_check_keyboard",
        [{ "destdir" => Installation.destdir }]
      )
    end

    fstab_ref = arg_ref(fstab)
    crtab_ref = arg_ref(crtab)
    read_fstab_and_cryptotab(fstab_ref, crtab_ref, root_device_current)
    fstab = fstab_ref.value
    crtab = crtab_ref.value
    Storage.ChangeDmNamesFromCrypttab(
      Ops.add(Installation.destdir, "/etc/crypttab")
    )
    Update.GetProductName

    if FstabUsesKernelDeviceNameForHarddisks(fstab)
      Builtins.y2warning(
        "fstab on %1 uses kernel device name for hard disks",
        root_device_current
      )
      warning = Builtins.sformat(
        _(
          "Some partitions in the system on %1 are mounted by kernel-device name. This is\n" +
            "not reliable for the update since kernel-device names are unfortunately not\n" +
            "persistent. It is strongly recommended to start the old system and change the\n" +
            "mount-by method to any other method for all partitions."
        ),
        root_device_current
      )
      if Mode.autoupgrade
        Popup.TimedWarning(warning, 10)
      else
        Popup.Warning(warning)
      end
    end

    if Builtins.size(fstab) == 0
      Builtins.y2error("no or empty fstab found!")
      # error message
      message = _("No fstab found.")
      success = false
    else
      tmp_msg = MountVarIfRequired(fstab, root_device_current, true)
      if tmp_msg != nil
        Builtins.y2error("failed to mount /var!")
        message = tmp_msg
        success = false
      else
        tmp = ""

        if !(
            tmp_ref = arg_ref(tmp);
            check_root_device_result = check_root_device(
              root_device_current,
              fstab,
              tmp_ref
            );
            tmp = tmp_ref.value;
            check_root_device_result
          )
          Builtins.y2error("fstab has wrong root device!")
          # message part 1
          message = Ops.add(
            Ops.add(
              _(
                "The root partition in /etc/fstab has an invalid root device.\n"
              ),
              # message part 2
              Builtins.sformat(
                _("It is currently mounted as %1 but listed as %2.\n"),
                root_device_current,
                tmp
              )
            ),
            @sdb
          )
          success = false
        else
          Builtins.y2milestone("cryptotab %1", crtab)

          fstab_ref = arg_ref(fstab)
          PrepareCryptoTab(crtab, fstab_ref)
          fstab = fstab_ref.value

          Builtins.y2milestone("fstab %1", fstab)

          if !(
              message_ref = arg_ref(message);
              _MountFSTab_result = MountFSTab(fstab, message_ref);
              message = message_ref.value;
              _MountFSTab_result
            )
            success = false
          end
        end
      end
    end
  else
    Builtins.y2error(
      "Could not mount root '%1' to '%2'",
      root_device_current,
      Installation.destdir
    )
    success = false
  end

  Builtins.y2milestone(
    "MountPartition (%1) = %2",
    root_device_current,
    success
  )
  Builtins.y2milestone("activated %1", @activated)

  if !success
    Popup.Message(message)

    # some mount failed, unmount all mounted fs
    UnmountPartitions(false)
    @did_try_mount_partitions = true
  else
    # enter the mount points of the newly mounted partitions
    # in the target map of the storage module
    AddToTargetMap()
    if Yast2::FsSnapshot.configured?
      snapshot = Yast2::FsSnapshot.create_pre("before update", cleanup: :number, important: true)
      Yast2::FsSnapshotStore.save("update", snapshot.number)
    end
    Update.clean_backup
    create_backup
  end

  success
end

- (Object) MountUserDefinedVarPartition

<– BNC #448577, Cannot find /var partition automatically returns if successful



1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
# File '../../src/modules/RootPart.rb', line 1404

def MountUserDefinedVarPartition
  # function return value
  manual_mount_successful = false

  list_of_devices = []
  # $[ "/dev/sda3" : "Label: My_Partition" ]
  device_info = {}

  # Creating the list of known partitions
  Builtins.foreach(Storage.GetOndiskTarget) do |device, description|
    Builtins.foreach(Ops.get_list(description, "partitions", [])) do |partition|
      # Some partitions logically can't be used for /var
      next if Ops.get_symbol(partition, "detected_fs", :unknown) == :swap
      next if Ops.get_symbol(partition, "type", :unknown) == :extended
      next if !Builtins.haskey(partition, "device")
      list_of_devices = Builtins.add(
        list_of_devices,
        Ops.get_string(partition, "device", "")
      )
      Ops.set(
        device_info,
        Ops.get_string(partition, "device", ""),
        Builtins.sformat(
          # Informational text about selected partition, %x are replaced with values later
          _(
            "<b>File system:</b> %1, <b>Type:</b> %2,<br>\n" +
              "<b>Label:</b> %3, <b>Size:</b> %4,<br>\n" +
              "<b>udev IDs:</b> %5,<br>\n" +
              "<b>udev path:</b> %6"
          ),
          # starts with >`<
          Builtins.substring(
            Builtins.tostring(
              Ops.get_symbol(partition, "detected_fs", :unknown)
            ),
            1
          ),
          Ops.get_locale(partition, "fstype", _("Unknown")),
          Ops.get_locale(partition, "label", _("None")),
          String.FormatSize(
            Ops.multiply(Ops.get_integer(partition, "size_k", 0), 1024)
          ),
          Builtins.mergestring(Ops.get_list(partition, "udev_id", []), ", "),
          Ops.get_locale(partition, "udev_path", _("Unknown"))
        )
      )
    end
  end

  list_of_devices = Builtins.sort(list_of_devices)
  Builtins.y2milestone("Known devices: %1", list_of_devices)

  while true
    UI.OpenDialog(
      VBox(
        MarginBox(
          1,
          0,
          VBox(
            # a popup caption
            Left(
              Heading(_("Unable to find the /var partition automatically"))
            ),
            # a popup message
            Left(
              Label(
                _(
                  "Your system uses a separate /var partition which is required for the upgrade\n" +
                    "process to detect the disk-naming changes. Select the /var partition manually\n" +
                    "to continue the upgrade process."
                )
              )
            ),
            VSpacing(1),
            Left(
              ComboBox(
                Id("var_device"),
                Opt(:notify),
                # a combo-box label
                _("&Select /var Partition Device"),
                list_of_devices
              )
            ),
            VSpacing(0.5),
            # an informational rich-text widget label
            Left(Label(_("Device Info"))),
            MinHeight(3, RichText(Id("device_info"), "")),
            VSpacing(1)
          )
        ),
        MarginBox(
          1,
          0,
          ButtonBox(
            PushButton(Id(:ok), Opt(:okButton), Label.OKButton),
            PushButton(Id(:cancel), Opt(:cancelButton), Label.CancelButton)
          )
        )
      )
    )

    ret = nil

    # initial device
    var_device = Convert.to_string(UI.QueryWidget(Id("var_device"), :Value))
    UI.ChangeWidget(
      Id("device_info"),
      :Value,
      Ops.get(device_info, var_device, "")
    )

    # to handle switching the combo-box or [OK]/[Cancel]
    while true
      ret = UI.UserInput
      var_device = Convert.to_string(
        UI.QueryWidget(Id("var_device"), :Value)
      )

      if ret == "var_device"
        UI.ChangeWidget(
          Id("device_info"),
          :Value,
          Ops.get(device_info, var_device, "")
        )
      else
        break
      end
    end

    UI.CloseDialog

    # Trying user-selection
    if ret == :ok
      Builtins.y2milestone("Trying to mount %1 as /var", var_device)
      mount_error = MountVarPartition(var_device)

      if mount_error != nil
        Report.Error(mount_error)
        next
      else
        Builtins.y2milestone("Manual mount (/var) successful")
        manual_mount_successful = true
        break
      end 
      # `cancel
    else
      Builtins.y2warning(
        "User doesn't want to enter the /var partition device"
      )
      break
    end
  end

  manual_mount_successful
end

- (Object) MountVarIfRequired(fstab, root_device_current, manual_var_mount)



1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
# File '../../src/modules/RootPart.rb', line 1559

def MountVarIfRequired(fstab, root_device_current, manual_var_mount)
  fstab = deep_copy(fstab)
  var_device_fstab = (
    fstab_ref = arg_ref(fstab);
    _FindPartitionInFstab_result = FindPartitionInFstab(fstab_ref, "/var");
    fstab = fstab_ref.value;
    _FindPartitionInFstab_result
  )

  # No need to mount "/var", it's not separate == already mounted with "/"
  if var_device_fstab == nil
    Builtins.y2milestone("Not a separate /var...")
    return nil
  end

  if !Storage.DeviceRealDisk(var_device_fstab)
    Builtins.y2milestone(
      "Device %1 is not a real disk, mounting...",
      var_device_fstab
    )
    return MountVarPartition(var_device_fstab)
  end

  # BNC #494240: If a device name is not created by Kernel, we can use it for upgrade
  if !Storage.IsKernelDeviceName(var_device_fstab)
    Builtins.y2milestone(
      "Device %1 is not a Kernel device name, mounting...",
      var_device_fstab
    )
    return MountVarPartition(var_device_fstab)
  end

  tmp1 = Builtins.filter(fstab) do |entry|
    Ops.get_string(entry, "file", "") == "/"
  end
  root_device_fstab = Ops.get_string(tmp1, [0, "spec"], "")
  if !Storage.DeviceRealDisk(root_device_fstab)
    return MountVarPartition(var_device_fstab)
  end

  root_info = Storage.GetDiskPartition(root_device_fstab)
  var_info = Storage.GetDiskPartition(var_device_fstab)

  if Ops.get_string(root_info, "disk", "") ==
      Ops.get_string(var_info, "disk", "")
    tmp2 = Storage.GetDiskPartition(root_device_current)
    var_partition_current2 = Storage.GetDeviceName(
      Ops.get_string(tmp2, "disk", ""),
      Ops.get_integer(var_info, "nr", 0)
    )

    return MountVarPartition(var_partition_current2)
  end

  realdisks = []
  Builtins.foreach(Storage.GetOndiskTarget) do |s, m|
    # BNC #448577, checking device
    if Storage.IsKernelDeviceName(s) && Storage.DeviceRealDisk(s)
      realdisks = Builtins.add(realdisks, s)
    end
  end

  if Builtins.size(realdisks) != 2
    # <-- BNC #448577, Cannot find /var partition automatically
    return nil if manual_var_mount && MountUserDefinedVarPartition()

    Builtins.y2error(
      "don't know how to handle more than two disks at this point"
    )
    # error message
    return Ops.add(
      _("Unable to mount /var partition with this disk configuration.\n"),
      @sdb
    )
  end

  other_disk = Ops.get(
    realdisks,
    Ops.get(realdisks, 0, "") == Ops.get_string(root_info, "disk", "") ? 1 : 0,
    ""
  )
  var_partition_current = Storage.GetDeviceName(
    other_disk,
    Ops.get_integer(var_info, "nr", 0)
  )

  MountVarPartition(var_partition_current)
end

- (String) MountVarPartition(device)

Mount /var partition

Parameters:

  • device (String)

    string device holding the /var subtree

Returns:

  • (String)

    nil on success, error description on fail



1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
# File '../../src/modules/RootPart.rb', line 1376

def MountVarPartition(device)
  mount_err = FsckAndMount("/var", device, "")
  err_message = nil
  if mount_err != nil
    Builtins.y2error(-1, "failed to mount /var")
    err_message = Ops.add(
      Ops.add(
        Ops.add(
          Ops.add(
            Builtins.sformat(
              # error message
              _("The /var partition %1 could not be mounted.\n"),
              device
            ),
            "\n"
          ),
          mount_err
        ),
        "\n\n"
      ),
      @sdb
    )
  end
  err_message
end

- (Object) PrepareCryptoTab(crtab, fstab)



1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
# File '../../src/modules/RootPart.rb', line 1012

def PrepareCryptoTab(crtab, fstab)
  crtab = deep_copy(crtab)
  crypt_nb = 0

  Builtins.foreach(crtab) do |mounts|
    vfstype = Ops.get_string(mounts, "vfstype", "")
    mntops = Ops.get_string(mounts, "opt2", "")
    loop = Ops.get_string(mounts, "loop", "")
    fspath = Ops.get_string(mounts, "mount", "")
    device = Ops.get_string(mounts, "file", "")
    Builtins.y2milestone(
      "vfstype:%1 mntops:%2 loop:%3 fspath:%4 device:%5",
      vfstype,
      mntops,
      loop,
      fspath,
      device
    )
    if !Builtins.issubstring(mntops, "noauto")
      again = true
      while again
        crypt_ok = true
        crypt_passwd = DlgUpdateCryptFs(device, fspath)

        if crypt_passwd == nil || crypt_passwd == ""
          crypt_ok = false
          again = false
        end

        Builtins.y2milestone("crypt pwd ok:%1", crypt_ok)

        if crypt_ok
          setloop = {
            "encryption"    => "twofish",
            "passwd"        => crypt_passwd,
            "loop_dev"      => loop,
            "partitionName" => device
          }

          crypt_ok = (
            setloop_ref = arg_ref(setloop);
            _PerformLosetup_result = Storage.PerformLosetup(
              setloop_ref,
              false
            );
            setloop = setloop_ref.value;
            _PerformLosetup_result
          )
          Builtins.y2milestone("crypt ok: %1", crypt_ok)
          if crypt_ok
            loop = Ops.get_string(setloop, "loop_dev", "")
          else
            # yes-no popup
            again = Popup.YesNo(_("Incorrect password. Try again?"))
          end
        end

        if crypt_ok
          add_fs = {
            "file"    => fspath,
            "mntops"  => mntops,
            "spec"    => loop,
            "freq"    => 0,
            "passno"  => 0,
            "vfstype" => vfstype
          }
          fstab.value = Builtins.prepend(fstab.value, add_fs)
          AddMountedPartition({ :type => "crypt", :device => device })
          again = false
        end
      end
    end
  end

  true
end

- (Object) read_fstab_and_cryptotab(fstab, crtab, root_device_current)

Reads FSTab and CryptoTab and fills fstab and crtab got as parameters. Uses Installation::destdir as the base mount point.

Parameters:

  • list (map)

    ('pointer' to) fstab

  • list (map)

    ('pointer' to) crtab

  • string

    root device



951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
# File '../../src/modules/RootPart.rb', line 951

def read_fstab_and_cryptotab(fstab, crtab, root_device_current)
  default_scr = WFM.SCRGetDefault
  new_scr = nil
  @backward_translation = {}

  if Stage.initial
    fstab_ref = arg_ref(fstab.value)
    readFsTab(fstab_ref)
    fstab.value = fstab_ref.value
    crtab_ref = arg_ref(crtab.value)
    readCryptoTab(crtab_ref)
    crtab.value = crtab_ref.value
  else
    fstab.value = Convert.convert(
      SCR.Read(path(".etc.fstab")),
      :from => "any",
      :to   => "list <map>"
    )
    crtab.value = Convert.convert(
      SCR.Read(path(".etc.cryptotab")),
      :from => "any",
      :to   => "list <map>"
    )
  end

  fstab_has_separate_var = (
    fstab_ref = arg_ref(fstab.value);
    _FstabHasSeparateVar_result = FstabHasSeparateVar(fstab_ref);
    fstab.value = fstab_ref.value;
    _FstabHasSeparateVar_result
  )
  # mount /var
  if fstab_has_separate_var
    Builtins.y2warning("Separate /var partition!")
    MountVarIfRequired(fstab.value, root_device_current, false)
  else
    Builtins.y2milestone("No separate /var partition found")
  end

  Builtins.y2milestone("fstab: %1", fstab.value)
  fstab.value = TranslateFsOrCryptoTab(fstab.value, "spec", "spec_old")
  Builtins.y2milestone("fstab: (translated) %1", fstab.value)

  Builtins.y2milestone("crtab: %1", crtab.value)
  crtab.value = TranslateFsOrCryptoTab(crtab.value, "file", "file_old")
  Builtins.y2milestone("crtab: (translated) %1", crtab.value)

  # umount /var
  if fstab_has_separate_var
    SCR.Execute(
      path(".target.umount"),
      Ops.add(Installation.destdir, "/var")
    )
    @activated = Builtins.remove(@activated, 0)
  end

  true
end

- (Object) readCryptoTab(crtab)

Register a new cryptotab agent and read the configuration from Installation::destdir



860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
# File '../../src/modules/RootPart.rb', line 860

def readCryptoTab(crtab)
  crtab_file = Ops.add(Installation.destdir, "/etc/cryptotab")

  if FileUtils.Exists(crtab_file)
    SCR.RegisterAgent(
      path(".target.etc.cryptotab"),
      term(
        :ag_anyagent,
        term(
          :Description,
          term(:File, crtab_file),
          "#\n", # Comment
          false, # read-only
          term(
            :List,
            term(
              :Tuple,
              term(:loop, term(:String, "^\t ")),
              term(:Separator, "\t "),
              term(:file, term(:String, "^\t ")),
              term(:Separator, "\t "),
              term(:mount, term(:String, "^\t ")),
              term(:Separator, "\t "),
              term(:vfstype, term(:String, "^\t ")),
              term(:Separator, "\t "),
              term(:opt1, term(:String, "^\t ")),
              term(:Separator, "\t "),
              term(:opt2, term(:String, "^ \t")),
              term(:Optional, term(:Whitespace)),
              term(:Optional, term(:the_rest, term(:String, "^\n")))
            ),
            "\n"
          )
        )
      )
    )

    crtab.value = Convert.convert(
      SCR.Read(path(".target.etc.cryptotab")),
      :from => "any",
      :to   => "list <map>"
    )

    SCR.UnregisterAgent(path(".target.etc.cryptotab"))
  else
    Builtins.y2milestone(
      "No such file %1. Not using cryptotab.",
      crtab_file
    )
  end

  nil
end

- (Object) readFsTab(fstab)

Register a new fstab agent and read the configuration from Installation::destdir



807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
# File '../../src/modules/RootPart.rb', line 807

def readFsTab(fstab)
  fstab_file = Ops.add(Installation.destdir, "/etc/fstab")

  if FileUtils.Exists(fstab_file)
    SCR.RegisterAgent(
      path(".target.etc.fstab"),
      term(
        :ag_anyagent,
        term(
          :Description,
          term(:File, fstab_file),
          "#\n", # Comment
          false, # read-only
          term(
            :List,
            term(
              :Tuple,
              term(:spec, term(:String, "^\t ")),
              term(:Separator, "\t "),
              term(:file, term(:String, "^\t ")),
              term(:Separator, "\t "),
              term(:vfstype, term(:String, "^\t ")),
              term(:Separator, "\t "),
              term(:mntops, term(:String, "^ \t\n")),
              term(:Optional, term(:Whitespace)),
              term(:Optional, term(:freq, term(:Number))),
              term(:Optional, term(:Whitespace)),
              term(:Optional, term(:passno, term(:Number))),
              term(:Optional, term(:Whitespace)),
              term(:Optional, term(:the_rest, term(:String, "^\n")))
            ),
            "\n"
          )
        )
      )
    )

    fstab.value = Convert.convert(
      SCR.Read(path(".target.etc.fstab")),
      :from => "any",
      :to   => "list <map>"
    )

    SCR.UnregisterAgent(path(".target.etc.fstab"))
  else
    Builtins.y2error("No such file %1. Not using fstab.", fstab_file)
  end

  nil
end

- (Object) RemoveFromTargetMap



268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File '../../src/modules/RootPart.rb', line 268

def RemoveFromTargetMap
  target_map = Storage.GetTargetMap
  tmp = Builtins.filter(@activated) do |e|
    Ops.get_string(e, :type, "") == "mount"
  end
  Builtins.foreach(tmp) do |e|
    target_map = Storage.SetPartitionData(
      target_map,
      Ops.get_string(e, :device, ""),
      "mount",
      ""
    )
  end
  Storage.SetTargetMap(target_map)

  nil
end

- (Boolean) RunFSCKonJFS(mount_type, device, error_message)

Function checks the device and returns whether it is OK or not. The read-only FS check is performed for jfs only and only one for one device.

Parameters:

  • mount_type (String)

    “jfs”, “ext2” or “reiser”

  • device, (String)

    such as /dev/hda3 or /dev/sda8

  • error_message (string &)

    (a reference to string)

Returns:

  • (Boolean)

    if successfull or if user forces it



489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
# File '../../src/modules/RootPart.rb', line 489

def RunFSCKonJFS(mount_type, device, error_message)
  # #176292, run fsck before jfs is mounted
  if mount_type == "jfs" && device != ""
    if Builtins.contains(@already_checked_jfs_partitions, device)
      Builtins.y2milestone("Device %1 has been already checked...", device)
      return true
    end

    UI.OpenDialog(
      Label(Builtins.sformat(_("Checking file system on %1..."), device))
    )

    Builtins.y2milestone("Running fsck on %1", device)
    # -n == Check read only, make no changes to the file system.
    cmd = Convert.to_map(
      SCR.Execute(
        path(".target.bash_output"),
        Builtins.sformat("fsck.jfs -n %1", device)
      )
    )

    UI.CloseDialog

    # failed
    if Ops.get(cmd, "exit") != 0
      Builtins.y2error("Result: %1", cmd)
      error_message.value = Builtins.tostring(Ops.get(cmd, "stderr"))

      details = ""
      if Ops.get_string(cmd, "stdout", "") != ""
        details = Ops.add(details, Ops.get_string(cmd, "stdout", ""))
      end
      if Ops.get_string(cmd, "stderr", "") != ""
        details = Ops.add(
          Ops.add(details == "" ? "" : "\n", details),
          Ops.get_string(cmd, "stderr", "")
        )
      end

      return AnyQuestionAnyButtonsDetails(
        # popup headline
        _("File System Check Failed"),
        Builtins.sformat(
          # popup question (continue/cancel dialog)
          # %1 is a device name such as /dev/hda5
          _(
            "The file system check of device %1 has failed.\n" +
              "\n" +
              "Do you want to continue mounting the device?\n"
          ),
          device
        ),
        Label.ContinueButton,
        # button
        _("&Skip Mounting"),
        details
      ) 
      # succeeded
    else
      # add device into the list of already checked partitions (with exit status 0);
      @already_checked_jfs_partitions = Builtins.add(
        @already_checked_jfs_partitions,
        device
      )
      Builtins.y2milestone("Result: %1", cmd)
      return true
    end
  end

  true
end

- (Object) SetSelectedToValid

Set the selected root partition to some valid one. Only make sense if the number of valid root partition is one.



163
164
165
166
167
168
169
170
171
172
# File '../../src/modules/RootPart.rb', line 163

def SetSelectedToValid
  @selectedRootPartition = ""
  Builtins.foreach(@rootPartitions) do |p, i|
    if Ops.get_boolean(i, :valid, false) && @selectedRootPartition == ""
      @selectedRootPartition = p
    end
  end

  nil
end

- (Array<Hash>) TranslateFsOrCryptoTab(translate, key_to_translate, key_preserve_as)

Translates FS or Cryptotab (old devices to new ones). Such as /dev/hda5 to /dev/sda5.

Parameters:

  • list (map)

    of definitions to translate

  • string

    key name in map to translate

  • string

    key name in map to keep the old value

Returns:

  • (Array<Hash>)

    of translated definitions

See Also:



734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
# File '../../src/modules/RootPart.rb', line 734

def TranslateFsOrCryptoTab(translate, key_to_translate, key_preserve_as)
  translate = deep_copy(translate)
  # Check whether there is any hardware information that could be used
  check_command = Builtins.sformat(
    "/usr/bin/find '%1/var/lib/hardware/'",
    String.Quote(Installation.destdir)
  )
  cmd = Convert.to_map(
    SCR.Execute(path(".target.bash_output"), check_command)
  )

  if Ops.get(cmd, "exit") != nil
    files = Builtins.splitstring(Ops.get_string(cmd, "stdout", ""), "\n")
    files_count = Builtins.size(files)
    if files_count == nil || Ops.less_or_equal(files_count, 2)
      Builtins.y2error(
        "There are only %1 files in /var/lib/hardware/, translation needn't work!",
        files_count
      )
    else
      Builtins.y2milestone(
        "There are %1 files in /var/lib/hardware/",
        files_count
      )
    end
  end

  # first find a list of values for translation
  old_names = []
  Builtins.foreach(translate) do |m|
    old_names = Builtins.add(
      old_names,
      Ops.get_string(m, key_to_translate, "")
    )
  end

  # translate them
  new_names = Storage.GetTranslatedDevices(
    Installation.installedVersion,
    Installation.updateVersion,
    old_names
  )

  i = 0

  # replace old values with translated ones
  while Ops.less_than(i, Builtins.size(translate))
    default_val = Ops.get_string(translate, [i, key_to_translate], "")
    new_val = Ops.get(new_names, i, default_val)

    Ops.set(translate, [i, key_to_translate], new_val)
    Ops.set(translate, [i, key_preserve_as], default_val)
    Ops.set(@backward_translation, new_val, default_val)

    Ops.set(
      translate,
      [i, "mntops"],
      update_mount_options(Ops.get_string(translate, [i, "mntops"], ""))
    )

    i = Ops.add(i, 1)
  end

  Builtins.y2milestone(
    "Current backward translations: %1",
    @backward_translation
  )

  deep_copy(translate)
end

- (void) UnmountPartitions(keep_in_target)

This method returns an undefined value.

Unmount all mounted partitions, deactivate swaps, detach loopback devices. Uses list activated to make actions in reverse order.

Parameters:

  • keeep_in_target

    Do not remove mounts from targetmap



290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
# File '../../src/modules/RootPart.rb', line 290

def UnmountPartitions(keep_in_target)
  Builtins.y2milestone("UnmountPartitions: %1", keep_in_target)

  @did_try_mount_partitions = false

  Builtins.foreach(@activated) do |info|
    Builtins.y2milestone("Unmounting %1", info)
    type = Ops.get_string(info, :type, "")
    if type != ""
      if type == "mount"
        file = Ops.add(
          Installation.destdir,
          Ops.get_string(info, :mntpt, "")
        )
        if !Convert.to_boolean(SCR.Execute(path(".target.umount"), file))
          # error report, %1 is device (eg. /dev/hda1)
          Report.Error(
            Builtins.sformat(
              _(
                "Cannot unmount partition %1.\n" +
                  "\n" +
                  "It is currently in use. If the partition stays mounted,\n" +
                  "the data may be lost. Unmount the partition manually\n" +
                  "or restart your computer.\n"
              ),
              file
            )
          )
        end
      elsif type == "swap"
        device = Ops.get_string(info, :device, "")
        # FIXME? is it safe?
        if SCR.Execute(
            path(".target.bash"),
            Ops.add("/sbin/swapoff ", device)
          ) != 0
          Builtins.y2error("Cannot deactivate swap %1", device)
        end
      elsif type == "crypt"
        dmname = Ops.get_string(info, :device, "")
        dmname = Ops.add(
          "cr_",
          Builtins.substring(
            dmname,
            Ops.add(Builtins.findlastof(dmname, "/"), 1)
          )
        )
        # FIXME? is it safe?
        if WFM.Execute(
            path(".local.bash"),
            Ops.add("cryptsetup remove ", dmname)
          ) != 0
          Builtins.y2error("Cannot remove dm device %1", dmname)
        end
      end
    end
  end

  # now remove the mount points of the mounted partitions
  # in the target map of the storage module
  RemoveFromTargetMap() if !keep_in_target


  # clear activated list
  @activated = []

  nil
end

- (Object) update_mount_options(options)



714
715
716
717
718
719
720
721
722
723
# File '../../src/modules/RootPart.rb', line 714

def update_mount_options(options)
  if Builtins.regexpmatch(options, "^(.*,)?hotplug(,.*)?$")
    return Builtins.regexpsub(
      options,
      "^(.*,)?hotplug(,.*)?$",
      "\\1nofail\\2"
    )
  end
  options
end