Skip to content

Commit

Permalink
add x-initrd.attach option to crypttab if needed (bsc#1168465)
Browse files Browse the repository at this point in the history
  • Loading branch information
wfeldt committed Apr 24, 2020
1 parent 9eb182a commit 84a3460
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/lib/y2storage/encryption.rb
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,14 @@ def in_network?

# Options that must be propagated from the fstab entries of the mount points
# to the crypttab entries of the corresponding device
OPTIONS_TO_PROPAGATE = ["_netdev", "noauto", "nofail"]
private_constant :OPTIONS_TO_PROPAGATE
OPTIONS_TO_PROPAGATE = {
"_netdev" => "_netdev",
"noauto" => "noauto",
"nofail" => "nofail",
"x-initrd.mount" => "x-initrd.attach"
}
ROOTFS_OPTIONS_TO_ADD = ["x-initrd.attach"]
private_constant :OPTIONS_TO_PROPAGATE, :ROOTFS_OPTIONS_TO_ADD

# Synchronizes {#crypt_options} with the {MountPoint#mount_options} of the
# mount points associated to this encryption device
Expand All @@ -349,8 +355,13 @@ def adjust_crypt_options
# Moreover, libstorage-ng currently enforces that behavior.
mount_points = descendants.select { |d| d.is?(:filesystem) }.map(&:mount_point).compact

OPTIONS_TO_PROPAGATE.each do |opt|
propagate_mount_option(opt, mount_points)
OPTIONS_TO_PROPAGATE.each_pair do |fstab_opt, crypttab_opt|
propagate_mount_option(fstab_opt, crypttab_opt, mount_points)
end

ROOTFS_OPTIONS_TO_ADD.each do |crypttab_opt|
is_rootfs = mount_points.any? { |m| m.path == "/" }
propagate_mount_option(nil, crypttab_opt, mount_points) if is_rootfs
end
end

Expand Down Expand Up @@ -405,14 +416,15 @@ def suitable_mount_bys
# @param option [String] option from fstab and crypttab
# @param mount_points [Array<MountPoint>] relevant mount points associated
# to the encryption device
def propagate_mount_option(option, mount_points)
in_mount_points = mount_points.all? { |mp| mp.mount_options.include?(option) }
in_encryption = crypt_options.include?(option)
def propagate_mount_option(fstab_option, crypttab_option, mount_points)
in_mount_points = fstab_option.nil? ||
mount_points.all? { |mp| mp.mount_options.include?(fstab_option) }
in_encryption = crypt_options.include?(crypttab_option)

if in_mount_points && !in_encryption
self.crypt_options = crypt_options + [option]
self.crypt_options = crypt_options + [crypttab_option]
elsif !in_mount_points && in_encryption
self.crypt_options = crypt_options - [option]
self.crypt_options = crypt_options - [crypttab_option]
end
end

Expand Down

0 comments on commit 84a3460

Please sign in to comment.