package fs; # $Id$ use diagnostics; use strict; use MDK::Common::System; use MDK::Common::Various; use common; use log; use devices; use partition_table qw(:types); use run_program; use swap; use detect_devices; use modules; use fsedit; use loopback; sub read_fstab { my ($prefix, $file, @reading_options) = @_; my %comments; my $comment; my @l = grep { if (/^\s*#/) { $comment .= chomp_($_) . "\n"; 0; } else { $comments{$_} = $comment if $comment; $comment = ''; 1; } } cat_("$prefix$file"); #- attach comments at the end of fstab to the previous line $comments{$l[-1]} = $comment if $comment; map { my ($dev, $mntpoint, $type, $options, $freq, $passno) = split; my $comment = $comments{$_}; $options = 'defaults' if $options eq 'rw'; # clean-up for mtab read $type = fs2type($type); if ($type eq 'supermount') { # normalize this bloody supermount $options = join(",", 'supermount', grep { if (/fs=(.*)/) { $type = $1; 0; } elsif (/dev=(.*)/) { $dev = $1; 0; } elsif ($_ eq '--') { 0; } else { 1; } } split(',', $options)); } elsif ($type eq 'smb') { # prefering type "smbfs" over "smb" $type = 'smbfs'; } $mntpoint =~ s/\\040/ /g; $dev =~ s/\\040/ /g; my $h = { device => $dev, mntpoint => $mntpoint, type => $type, options => $options, comment => $comment, if_(member('keep_freq_passno', @reading_options), freq => $freq, passno => $passno), }; if ($dev =~ /^LABEL=/) { if (my $e = find { $_->{mntpoint} eq $mntpoint } read_fstab('', '/proc/mounts')) { $h->{device_LABEL} = $dev; $dev = $h->{device} = $e->{device}; } } if ($dev =~ m,/(tmp|dev)/,) { ($h->{major}, $h->{minor}) = unmakedev((stat "$prefix$dev")[6]); my $symlink = readlink("$prefix$dev"); $dev =~ s,/(tmp|dev)/,,; if ($symlink =~ m|^[^/]+$|) { $h->{device_alias} = $dev; $h->{device} = $symlink; } else { $h->{device} = $dev; } } if ($h->{options} =~ /credentials=/ && !member('verbatim_credentials', @reading_options)) { require network::smb; #- remove credentials=file with username=foo,password=bar,domain=zoo #- the other way is done in fstab_to_string my ($options, $unknown) = mount_options_unpack($h); my $file = delete $options->{'credentials='}; my $credentials = network::smb::read_credentials_raw($file); if ($credentials->{username}) { $options->{"$_="} = $credentials->{$_} foreach qw(username password domain); mount_options_pack($h, $options, $unknown); } } $h; } @l; } sub merge_fstabs { my ($loose, $fstab, @l) = @_; foreach my $p (@$fstab) { my ($l1, $l2) = partition { fsedit::is_same_hd($_, $p) } @l; my ($p2) = @$l1 or next; @l = @$l2; $p->{mntpoint} = $p2->{mntpoint} if delete $p->{unsafeMntpoint}; $p->{type} = $p2->{type} if $p2->{type} && !$loose; $p->{options} = $p2->{options} if $p2->{options} && !$loose; #- important to get isMounted property else DrakX may try to mount already mounted partitions :-( add2hash($p, $p2); $p->{device_alias} ||= $p2->{device_alias} || $p2->{device} if $p->{device} ne $p2->{device} && $p2->{device} !~ m|/|; $p->{type} && $p2->{type} && $p->{type} ne $p2->{type} && type2fs($p) ne type2fs($p2) && $p->{type} ne 'auto' && $p2->{type} ne 'auto' and log::l("err, fstab and partition table do not agree for $p->{device} type: " . (type2fs($p) || type2name($p->{type})) . " vs ", (type2fs($p2) || type2name($p2->{type}))); } @l; } sub add2all_hds { my ($all_hds, @l) = @_; @l = merge_fstabs('', [ fsedit::get_really_all_fstab($all_hds) ], @l); foreach (@l) { my $s = isThisFs('nfs', $_) ? 'nfss' : isThisFs('smbfs', $_) ? 'smbs' : isThisFs('davfs', $_) ? 'davs' : isTrueFS($_) || isSwap($_) || isOtherAvailableFS($_) ? '' : 'special'; push @{$all_hds->{$s}}, $_ if $s; } } sub get_major_minor { eval { my (undef, $major, $minor) = devices::entry($_->{device}); ($_->{major}, $_->{minor}) = ($major, $minor); } foreach @_; } sub merge_info_from_mtab { my ($fstab) = @_; my @l1 = map { my $l = $_; my %l = (type => fs2type('swap')); $l{$_} = $l->{$_} foreach qw(device major minor); \%l; } read_fstab('', '/proc/swaps'); my @l2 = map { read_fstab('', $_) } '/etc/mtab', '/proc/mounts'; foreach (@l1, @l2) { log::l("found mounted partition on $_->{device} with $_->{mntpoint}"); if ($::isInstall && $_->{mntpoint} eq '/tmp/hdimage') { log::l("found hdimage on $_->{device}"); $_->{real_mntpoint} = delete $_->{mntpoint}; $_->{mntpoint} = common::usingRamdisk() && "/mnt/hd"; #- remap for hd install. } $_->{isMounted} = $_->{isFormatted} = 1; delete $_->{options}; } merge_fstabs('loose', $fstab, @l1, @l2); } # - when using "$loose", it does not merge in type&options from the fstab sub merge_info_from_fstab { my ($fstab, $prefix, $uniq, $loose) = @_; my @l = grep { if ($uniq) { my $part = fsedit::mntpoint2part($_->{mntpoint}, $fstab); !$part || fsedit::is_same_hd($part, $_); #- keep it only if it is the mountpoint AND the same device } else { 1; } } read_fstab($prefix, "/etc/fstab", 'keep_freq_passno'); merge_fstabs($loose, $fstab, @l); } # - when using "$loose", it does not merge in type&options from the fstab sub get_info_from_fstab { my ($all_hds, $prefix) = @_; my @l = read_fstab($prefix, "/etc/fstab", 'keep_freq_passno'); add2all_hds($all_hds, @l) } sub prepare_write_fstab { my ($fstab, $o_prefix, $b_keep_smb_credentials) = @_; $o_prefix ||= ''; my %new; my @smb_credentials; my @l = map { my $device = isLoopback($_) ? ($_->{mntpoint} eq '/' ? "/initrd/loopfs" : $_->{loopback_device}{mntpoint}) . $_->{loopback_file} : part2device($o_prefix, $_->{device}, $_->{type}); my $real_mntpoint = $_->{mntpoint} || ${{ '/tmp/hdimage' => '/mnt/hd' }}{$_->{real_mntpoint}}; mkdir_p("$o_prefix$real_mntpoint") if $real_mntpoint =~ m|^/|; my $mntpoint = loopback::carryRootLoopback($_) ? '/initrd/loopfs' : $real_mntpoint; my ($freq, $passno) = exists $_->{freq} ? ($_->{freq}, $_->{passno}) : isTrueFS($_) && $_->{options} !~ /encryption=/ ? (1, $_->{mntpoint} eq '/' ? 1 : loopback::carryRootLoopback($_) ? 0 : 2) : (0, 0); if (($device eq 'none' || !$new{$device}) && ($mntpoint eq 'swap' || !$new{$mntpoint})) { #- keep in mind the new line for fstab. $new{$device} = 1; $new{$mntpoint} = 1; my $options = $_->{options}; if (isThisFs('smbfs', $_) && $options =~ /password=/ && !$b_keep_smb_credentials) { require network::smb; if (my ($opts, $smb_credentials) = network::smb::fstab_entry_to_credentials($_)) { $options = $opts; push @smb_credentials, $smb_credentials; } } my $type = type2fs($_); my $dev = $_->{device_LABEL} ? $_->{device_LABEL} : $_->{device_alias} ? "/dev/$_->{device_alias}" : $device; $mntpoint =~ s/ /\\040/g; $dev =~ s/ /\\040/g; # handle bloody supermount special case if ($options =~ /supermount/) { my @l = grep { $_ ne 'supermount' } split(',', $options); my @l1 = grep { member($_, 'ro', 'exec') } @l; my @l2 = difference2(\@l, \@l1); $options = join(",", "dev=$dev", "fs=$type", @l1, if_(@l2, '--', @l2)); ($dev, $type) = ('none', 'supermount'); } [ $mntpoint, $_->{comment} . join(' ', $dev, $mntpoint, $type, $options || 'defaults', $freq, $passno) . "\n" ]; } else { () } } grep { $_->{device} && ($_->{mntpoint} || $_->{real_mntpoint}) && $_->{type} } @$fstab; join('', map { $_->[1] } sort { $a->[0] cmp $b->[0] } @l), \@smb_credentials; } sub fstab_to_string { my ($all_hds, $o_prefix) = @_; my $fstab = [ fsedit::get_really_all_fstab($all_hds), @{$all_hds->{special}} ]; my ($s, undef) = prepare_write_fstab($fstab, $o_prefix, 'keep_smb_credentials'); $s; } sub write_fstab { my ($all_hds, $o_prefix) = @_; log::l("writing $o_prefix/etc/fstab"); my $fstab = [ fsedit::get_really_all_fstab($all_hds), @{$all_hds->{special}} ]; my ($s, $smb_credentials) = prepare_write_fstab($fstab, $o_prefix, ''); output("$o_prefix/etc/fstab", $s); network::smb::save_credentials($_) foreach @$smb_credentials; } sub part2device { my ($prefix, $dev, $type) = @_; $dev eq 'none' || member($type, qw(nfs smbfs davfs)) ? $dev : do { my $dir = $dev =~ m!^(/|LABEL=)! ? '' : '/dev/'; eval { devices::make("$prefix$dir$dev") }; "$dir$dev"; }; } sub auto_fs() { grep { chop; $_ && !/nodev/ } cat_("/etc/filesystems"); } sub mount_options() { my %non_defaults = ( sync => 'async', noatime => 'atime', noauto => 'auto', ro => 'rw', user => 'nouser', nodev => 'dev', noexec => 'exec', nosuid => 'suid', ); my @user_implies = qw(noexec nodev nosuid); \%non_defaults, \@user_implies; } sub mount_options_unpack { my ($part) = @_; my $packed_options = $part->{options}; my ($non_defaults, $user_implies) = mount_options(); my @auto_fs = auto_fs(); my %per_fs = ( iso9660 => [ qw(unhide) ], vfat => [ qw(umask=0) ], ntfs => [ qw(umask=0) ], nfs => [ qw(rsize=8192 wsize=8192) ], smbfs => [ qw(username= password=) ], davfs => [ qw(username= password= uid= gid=) ], reiserfs => [ 'notail' ], ); push @{$per_fs{$_}}, 'usrquota', 'grpquota' foreach 'ext2', 'ext3', 'xfs'; while (my ($fs, $l) = each %per_fs) { isThisFsAlso ensure that the compression method is xz -9 for much better compression (was previously defaulting to gzip)
-rwxr-xr-x | images/make_boot_img | 3 |
diff --git a/images/make_boot_img b/images/make_boot_img index 2be5bbde5..b0e3eec70 100755 --- a/images/make_boot_img +++ b/images/make_boot_img @@ -161,9 +161,8 @@ sub initrd { $modules="$modules mgakadeploy " if ($ENV{BUILD_KA}); mkdir_p("build/dracut.conf.d"); - touch("build/dracut.conf"); # TODO if --nofscks and --no-hostonly are switched, dracut gives an error - fix or report upstream - __ "DRAKX_STAGE1_BINARY=$stage1_binary DRAKX_INIT_BINARY=$init_binary dracut --conf ./build/dracut.conf --confdir ./build/dracut.conf.d --nofscks --no-hostonly --add ' $modules ' --omit ' dash modsign systemd plymouth btrfs crypt lvm cifs resume rootfs-block biosdevname shutdown ' --add-drivers ' $drivers ' '$img' '$kernel'" + __ "DRAKX_STAGE1_BINARY=$stage1_binary DRAKX_INIT_BINARY=$init_binary dracut --conf dracut.conf --confdir ./build/dracut.conf.d --add ' $modules ' --add-drivers ' $drivers ' '$img' '$kernel'" } |