Skip to content

Commit c023517

Browse files
committed
Automatically select initramfs generator when not forced
If no command-line or configuration option to force one of dracut or mkinitcpio is specified, prefer dracut if the command is available and mkinitcpio otherwise.
1 parent 80ccbdc commit c023517

File tree

4 files changed

+30
-18
lines changed

4 files changed

+30
-18
lines changed

bin/generate-zbm

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ my ( %runConf, %config );
5555

5656
$runConf{config} = "/etc/zfsbootmenu/config.yaml";
5757
$runConf{bootdir} = "/boot";
58-
$runConf{usecpio} = false;
5958

6059
GetOptions(
6160
"version|v=s" => \$runConf{version},
@@ -68,7 +67,7 @@ GetOptions(
6867
"config|c=s" => \$runConf{config},
6968
"enable" => \$runConf{enable},
7069
"disable" => \$runConf{disable},
71-
"initcpio|i" => \$runConf{usecpio},
70+
"initcpio|i!" => \$runConf{usecpio},
7271
"hookd|H=s@" => \$runConf{cpio_hookd},
7372
"debug|d" => \$runConf{debug},
7473
"help|h" => sub {
@@ -120,13 +119,21 @@ unless ( $config{Global}{ManageImages} ) {
120119
exit;
121120
}
122121

123-
unless ( $runConf{usecpio} ) {
122+
unless ( defined $runConf{usecpio} ) {
124123

125-
# If usecpio wasn't set by cmdline, load from the config
124+
# If usecpio wasn't set by cmdline, try loading from the config
126125
if ( defined $config{Global}{InitCPIO} ) {
127126
$runConf{usecpio} = $config{Global}{InitCPIO};
128127
} else {
129-
$runConf{usecpio} = false;
128+
my @output = execute(qw(sh -c "command -v dracut"));
129+
my $status = pop(@output);
130+
if ( $status eq 0 ) {
131+
print "No initramfs generator specified; using dracut\n";
132+
$runConf{usecpio} = false;
133+
} else {
134+
print "No initramfs generator specified; using mkinitcpio\n";
135+
$runConf{usecpio} = true;
136+
}
130137
}
131138
}
132139

@@ -1052,7 +1059,11 @@ Manually specify the output image prefix; supersedes I<Kernel.Prefix>
10521059
10531060
=item B<--initcpio|-i>
10541061
1055-
Use mkinitcpio instead of dracut.
1062+
Force the use of mkinitcpio instead of dracut.
1063+
1064+
=item B<--no-initcpio|-i>
1065+
1066+
Force the use of dracut instead of mkinitcpio.
10561067
10571068
=item B<--confd|-C> I<config-path>
10581069

etc/zfsbootmenu/config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ Global:
44
DracutConfDir: /etc/zfsbootmenu/dracut.conf.d
55
PreHooksDir: /etc/zfsbootmenu/generate-zbm.pre.d
66
PostHooksDir: /etc/zfsbootmenu/generate-zbm.post.d
7-
InitCPIO: false
87
InitCPIOConfig: /etc/zfsbootmenu/mkinitcpio.conf
98
Components:
109
ImageDir: /boot/efi/EFI/zbm

testing/helpers/chroot-arch.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ trap 'gpgconf --homedir /etc/pacman.d/gnupg --kill all; exit' EXIT INT TERM
2828
pacman-key --init
2929
pacman-key --populate
3030

31-
# Do this in two stages to avoid dracut providing the initramfs virtual
31+
# Install everything needed to build a mkinitcpio image
3232
pacman --noconfirm -Sy linux linux-headers mkinitcpio vi openssh \
33-
fakeroot automake autoconf pkg-config gcc make libtool binutils curl
34-
pacman --noconfirm -Sy dkms git dracut fzf kexec-tools cpanminus
33+
fzf fakeroot automake autoconf pkg-config gcc libtool binutils \
34+
make curl dkms git kexec-tools cpanminus
3535

3636
# Install ZFS command-line utilities
3737
runuser -u nobody -- /bin/sh -c "cd /tmp && \
@@ -68,7 +68,7 @@ mkinitcpio -p linux
6868

6969
if [ -x /root/zbm-populate.sh ]; then
7070
# Arch installs cpanm in the vendor_perl subdirectory
71-
PATH="${PATH}:/usr/bin/site_perl:/usr/bin/vendor_perl" INITCPIO=yes /root/zbm-populate.sh
71+
PATH="${PATH}:/usr/bin/site_perl:/usr/bin/vendor_perl" /root/zbm-populate.sh
7272
rm /root/zbm-populate.sh
7373
fi
7474

testing/helpers/zbm-populate.sh

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@ fi
1111

1212
# Adjust the configuration for convenient builds
1313
if [ -f /etc/zfsbootmenu/config.yaml ]; then
14-
if [ -z "${INITCPIO}" ]; then
15-
use_initcpio="false"
16-
else
17-
use_initcpio="true";
18-
fi
19-
2014
sed -e 's/Versions:.*/Versions: false/' \
2115
-e 's/ManageImages:.*/ManageImages: true/' \
22-
-e "s/InitCPIO:.*/InitCPIO: ${use_initcpio}/" \
2316
-e 's@ImageDir:.*@ImageDir: /zfsbootmenu/build@' \
2417
-e '/BootMountPoint:/d' -i /etc/zfsbootmenu/config.yaml
18+
19+
case "${INITCPIO}" in
20+
[Yy][Ee][Ss]|[Yy]|[Oo][Nn]|1)
21+
sed -e "s/InitCPIO:.*/InitCPIO: true/" -i /etc/zfsbootmenu/config.yaml
22+
;;
23+
[Nn][Oo]|[Nn]|[Oo][Ff][Ff]|0)
24+
sed -e "s/InitCPIO:.*/InitCPIO: false/" -i /etc/zfsbootmenu/config.yaml
25+
;;
26+
esac
2527
fi

0 commit comments

Comments
 (0)