/
RootPart.rb
2346 lines (2028 loc) · 75.4 KB
/
RootPart.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
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
480
481
482
483
484
485
486
487
488
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
560
561
562
563
564
565
566
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
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
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
804
805
806
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
857
858
859
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
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
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
# encoding: utf-8
# ------------------------------------------------------------------------------
# Copyright (c) 2006-2012 Novell, Inc. All Rights Reserved.
#
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of version 2 of the GNU General Public License as published by the
# Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, contact Novell, Inc.
#
# To contact Novell about this file by physical or electronic mail, you may find
# current contact information at www.novell.com.
# ------------------------------------------------------------------------------
# Module: RootPart.ycp
#
# Authors: Arvin Schnell <arvin@suse.de>
#
# Purpose: Responsible for searching of root partitions and
# mounting of target partitions.
require "yast"
require "yast2/fs_snapshot"
require "yast2/fs_snapshot_store"
require "y2storage"
require "fileutils"
module Yast
class RootPartClass < Module
include Logger
NON_MODULAR_FS = ["proc", "sysfs"]
def main
Yast.import "UI"
textdomain "update"
Yast.import "Directory"
Yast.import "Mode"
Yast.import "Linuxrc"
Yast.import "Popup"
Yast.import "ModuleLoading"
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"
# storage-ng
# This include allows to use DlgUpdateCryptFs, which has not equivalent in
# yast-storage-ng. So the whole method invoking DlgUpdateCryptFs should be
# checked (it's hopefully useless now).
=begin
Yast.include self, "partitioning/custom_part_dialogs.rb"
=end
# 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
# Returns currently activated partitions.
#
# @return [Array<Hash{Symbol => String>}] activated
def GetActivated
deep_copy(@activated)
end
def Mounted
Ops.greater_than(Builtins.size(@activated), 0)
end
# Get the key what of the selected root partition.
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
# Set the selected root partition to some valid one. Only
# make sense if the number of valid root partition is one.
def SetSelectedToValid
@selectedRootPartition = ""
Builtins.foreach(@rootPartitions) do |p, i|
if Ops.get_boolean(i, :valid, false) && @selectedRootPartition == ""
@selectedRootPartition = p
end
end
nil
end
#
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
# Unmount all mounted partitions, deactivate swaps, detach loopback
# devices. Uses list activated to make actions in reverse order.
# @param keeep_in_target Do not remove mounts from targetmap
# @return [void]
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 in the target system
remove_mount_points(staging) unless keep_in_target
# clear activated list
@activated = []
nil
end
# Add information about mounted partition to internal list.
# @param [Hash{Symbol => String}] partinfo partinfo has to be list with exactly two strings,
# see description of list "activated"
# @return [void]
def AddMountedPartition(partinfo)
partinfo = deep_copy(partinfo)
@activated = Builtins.prepend(@activated, partinfo)
Builtins.y2debug("adding %1 yields %2", partinfo, @activated)
nil
end
# Check the filesystem of a partition.
def FSCKPartition(partition)
detected_fs = fstype_for_device(probed, 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
nil
end
# @param [String] headline (optional; to disable, use "")
# @param [String] question
# @param string button (true)
# @param string button (false)
# @param [String] details (hidden under [Details] button; optional; to disable, use "")
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
# 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.
#
# @param [String] mount_type "jfs", "ext2" or "reiser"
# @param [String] device, such as /dev/hda3 or /dev/sda8
# @param [string &] error_message (a reference to string)
# @return [Boolean] if successfull or if user forces it
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
# Mount partition on specified mount point
# @param mount_point [String] path to mount the partition at
# @param device [String] device to mount, in the format of the first field of fstab
# @param mount_type [String] filesystem type to be specified while mounting
# @return [String] nil on success, error description on fail
def MountPartition(mount_point, device, mount_type, fsopts = "")
if mount_type == ""
# Note that "device" comes from the unmodified fstab entry so it can be
# something like 'UUID=2f61fdb9-f82a-4052-8610-1eb090b82098'.
mount_type = fstype_for_device(probed, 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
# Check filesystem on a partition and mount the partition on specified mount
# point
# @param [String] mount_point string mount point to monut the partition at
# @param [String] device string device to mount
# @param [String] mount_type string filesystem type to be specified while mounting
# @return [String] nil on success, error description on fail
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
# Check that the root filesystem in fstab has the correct device.
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
true
end
# Find a mount point in fstab
# @param [list <map> &] fstab a list of fstab entries
# @param [String] mountpoint string a mount point to find
# @return [String] the found partition
def FindPartitionInFstab(fstab, mountpoint)
# Removing the "/" and then adding it again in the comparison below looks
# weird, but let's don't change this ancient code too much.
mountpoints = mountpoint.chomp("/")
tmp = fstab.value.select do |entry|
file = entry.fetch("file", "")
mntops = entry.fetch("mntops", "")
# Discard Btrfs subvolumes, they are not really a separate device
if mntops.include?("subvol=")
log.info "FindPartitionInFstab: #{file} subvolume ignored"
next false
end
file == mountpoint || file == mountpoint + "/"
end
return nil if tmp.size.zero?
tmp.first.fetch("spec", "")
end
def update_mount_options(options)
if Builtins.regexpmatch(options, "^(.*,)?hotplug(,.*)?$")
return Builtins.regexpsub(
options,
"^(.*,)?hotplug(,.*)?$",
"\\1nofail\\2"
)
end
options
end
# Translates FS or Cryptotab (old devices to new ones).
# Such as /dev/hda5 to /dev/sda5.
#
# @param list <map> of definitions to translate
# @param string key name in map to translate
# @param string key name in map to keep the old value
# @return [Array<Hash>] of translated definitions
#
# @see #https://bugzilla.novell.com/show_bug.cgi?id=258222
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
# storage-ng
new_names = old_names
=begin
new_names = Storage.GetTranslatedDevices(
Installation.installedVersion,
Installation.updateVersion,
old_names
)
=end
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
# Register a new fstab agent and read the configuration
# from Installation::destdir
def readFsTab(fstab)
fstab_file = Ops.add(Installation.destdir, "/etc/fstab")
if FileUtils.Exists(fstab_file)
# Note: this is a copy from etc_fstab.scr file (yast2.rpm),
# keep the files in sync!
SCR.RegisterAgent(
path(".target.etc.fstab"),
term(
:ag_anyagent,
term(
:Description,
term(:File, fstab_file),
# tab and space is a workaround for white space only lines (bsc#1030425)
"#\n\t ", # 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
# Register a new cryptotab agent and read the configuration
# from Installation::destdir
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
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
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
# Reads FSTab and CryptoTab and fills fstab and crtab got as parameters.
# Uses Installation::destdir as the base mount point.
#
# @param list <map> ('pointer' to) fstab
# @param list <map> ('pointer' to) crtab
# @param string root device
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
#
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
# bugzilla #258563