You are not logged in.

#1 2020-01-26 10:00:27

spiri
Member
Registered: 2016-12-31
Posts: 65

[solved] mkinitcpio fails generating initramfs

Hello,

I cannot generate the initramfs images using the linux preset anymore. I didn't touch those files at all.

I get the following error:

$ sudo mkinitcpio -p linux
[sudo] password for spiri: 
==> Building image from preset: /etc/mkinitcpio.d/linux.preset: 'default'
  -> -k /boot/vmlinuz-linux -c /etc/mkinitcpio.conf -g /boot/initramfs-linux.img
Error: [-n]: Cannot open for reading
==> ERROR: invalid kernel specified: `/boot/vmlinuz-linux'
==> Building image from preset: /etc/mkinitcpio.d/linux.preset: 'fallback'
  -> -k /boot/vmlinuz-linux -c /etc/mkinitcpio.conf -g /boot/initramfs-linux-fallback.img -S autodetect
Error: [-n]: Cannot open for reading
==> ERROR: invalid kernel specified: `/boot/vmlinuz-linux'

I solved the problem by mounting the system on a Live CD, doing arch-chroot and run mkinitcpio.

But when I boot to my system and doing mkinitcpio I get the same error. Like I had specified an invalid kernel but it isn't.

$ file /boot/vmlinuz-linux 
/boot/vmlinuz-linux: Linux kernel x86 boot executable bzImage, version 5.4.14-arch1-1 (linux@archlinux) #1 SMP PREEMPT Thu, 23 Jan 2020 10:07:05 +0000, RO-rootFS, swap_dev 0x6, Normal VGA
$ ls /lib/modules
5.4.14-arch1-1
$ uname -r
5.4.14-arch1-1

linux.preset file:

# mkinitcpio preset file for the 'linux' package

ALL_config="/etc/mkinitcpio.conf"
ALL_kver="/boot/vmlinuz-linux"

PRESETS=('default' 'fallback')

#default_config="/etc/mkinitcpio.conf"
default_image="/boot/initramfs-linux.img"
#default_options=""

#fallback_config="/etc/mkinitcpio.conf"
fallback_image="/boot/initramfs-linux-fallback.img"
fallback_options="-S autodetect"

How can I solve this problem?
I want to run mkinitcpio without errors live on my system.

/boot partition is ext2 using rw,relatime mount options in fstab.
Also, boot is properly mounted.

Last edited by spiri (2020-02-05 12:18:09)

Offline

#2 2020-01-26 10:32:42

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,636
Website

Re: [solved] mkinitcpio fails generating initramfs

spiri wrote:
==> ERROR: invalid kernel specified: `/boot/vmlinuz-linux'

Never seen that before... try reinstalling the kernel package which will recreate that file and then run that command.  Any change?

As an aside, why are you using ext2 for anything?

Last edited by graysky (2020-01-26 10:33:16)


CPU-optimized Linux-ck packages @ Repo-ck  • AUR packagesZsh and other configs

Offline

#3 2020-01-26 11:29:35

spiri
Member
Registered: 2016-12-31
Posts: 65

Re: [solved] mkinitcpio fails generating initramfs

graysky wrote:

Never seen that before... try reinstalling the kernel package which will recreate that file and then run that command.  Any change?

No.

graysky wrote:

As an aside, why are you using ext2 for anything?

I now use vfat for the boot partition.

TARGET SOURCE    FSTYPE OPTIONS
/boot  /dev/sda2 vfat   rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro

Offline

#4 2020-01-26 11:50:17

xerxes_
Member
Registered: 2018-04-29
Posts: 757

Re: [solved] mkinitcpio fails generating initramfs

Remove option 'errors=remount-ro'. It was it some thread that it cause problems with boot partition.

Offline

#5 2020-01-26 15:36:06

seth
Member
Registered: 2012-09-03
Posts: 57,020

Re: [solved] mkinitcpio fails generating initramfs

This looks weird:

Error: [-n]: Cannot open for reading
bash #run a new bash instance (has to be bash, not zsh, fish, etc.)
source /usr/lib/initcpio/functions # source the mkinitcpio functions
type kver # should now be a script
set +x # make bash talk a lot
kver /boot/vmlinuz-linux # run the function that figures the kernel version

Online

#6 2020-01-26 15:49:04

Head_on_a_Stick
Member
From: Belsize Park
Registered: 2014-02-20
Posts: 8,193
Website

Re: [solved] mkinitcpio fails generating initramfs

xerxes_ wrote:

Remove option 'errors=remount-ro'. It was it some thread that it cause problems with boot partition.

That problem was (probably) caused by corruption on the FAT-formatted partition, the remount-ro option just exposed it in a non-obvious way. As it is applied automatically if no options are explicitly specified then it's probably a good idea to leave it in, it should prevent further damage to the filesystem if there are any errors.

@OP: you only need to have a FAT-formatted /boot partition if you're using it as an EFI system partition.


godisnowhere

Offline

#7 2020-01-27 17:03:07

spiri
Member
Registered: 2016-12-31
Posts: 65

Re: [solved] mkinitcpio fails generating initramfs

seth wrote:

This looks weird:

Error: [-n]: Cannot open for reading
bash #run a new bash instance (has to be bash, not zsh, fish, etc.)
source /usr/lib/initcpio/functions # source the mkinitcpio functions
type kver # should now be a script
set +x # make bash talk a lot
kver /boot/vmlinuz-linux # run the function that figures the kernel version

Hello. I get the following output:

/usr/lib/initcpio/functions: line 811: syntax error near unexpected token `('
/usr/lib/initcpio/functions: line 811: `    rm "$moduledest"/modules.!(*.bin|devname|softdep)'
kver is a function
kver () 
{ 
    local kver re='^[[:digit:]]+(\.[[:digit:]]+)+';
    local offset=$(hexdump -s 526 -n 2 -e '"%0d"' "$1");
    [[ $offset = +([0-9]) ]] || return 1;
    read kver _ < <(dd if="$1" bs=1 count=127 skip=$(( offset + 0x200 )) 2>/dev/null);
    [[ $kver =~ $re ]] || return 1;
    printf '%s' "$kver"
}
Error: [-n]: Cannot open for reading

I also tried to fix the script error. Same result.

Offline

#8 2020-01-27 17:36:11

Head_on_a_Stick
Member
From: Belsize Park
Registered: 2014-02-20
Posts: 8,193
Website

Re: [solved] mkinitcpio fails generating initramfs

Are there any filesystem problems?

# umount /boot
# fsck.fat /dev/sda2
# mount /boot

And where are the fifth & sixth fields in your fstab line? Did you crop them or are they missing?


godisnowhere

Offline

#9 2020-01-27 17:50:11

spiri
Member
Registered: 2016-12-31
Posts: 65

Re: [solved] mkinitcpio fails generating initramfs

Head_on_a_Stick wrote:

Are there any filesystem problems?

# umount /boot
# fsck.fat /dev/sda2
# mount /boot

I think its clean

# fsck.fat /dev/sda2
fsck.fat 4.1 (2017-01-24)
/dev/sda2: 328 files, 19564/261628 clusters

And where are the fifth & sixth fields in your fstab line? Did you crop them or are they missing?

My fstab is okay. Everything is mounted properly.

Offline

#10 2020-01-27 18:10:13

seth
Member
Registered: 2012-09-03
Posts: 57,020

Re: [solved] mkinitcpio fails generating initramfs

Why would it throw a syntax error at this point?

Please run "bash --norc" and try again.

Online

#11 2020-01-27 18:25:21

spiri
Member
Registered: 2016-12-31
Posts: 65

Re: [solved] mkinitcpio fails generating initramfs

seth wrote:

Why would it throw a syntax error at this point?

Because of the parentheses in the line

 rm "$moduledest"/modules.!(*.bin|devname|softdep)
seth wrote:

Please run "bash --norc" and try again.

# bash --norc
bash-5.0# ./fix-initcpio.run 
/usr/lib/initcpio/functions: line 811: syntax error near unexpected token `('
/usr/lib/initcpio/functions: line 811: `    rm "$moduledest"/modules.!(*.bin|devname|softdep)'
kver is a function
kver () 
{ 
    local kver re='^[[:digit:]]+(\.[[:digit:]]+)+';
    local offset=$(hexdump -s 526 -n 2 -e '"%0d"' "$1");
    [[ $offset = +([0-9]) ]] || return 1;
    read kver _ < <(dd if="$1" bs=1 count=127 skip=$(( offset + 0x200 )) 2>/dev/null);
    [[ $kver =~ $re ]] || return 1;
    printf '%s' "$kver"
}
Error: [-n]: Cannot open for reading

Offline

#12 2020-01-27 18:33:29

spiri
Member
Registered: 2016-12-31
Posts: 65

Re: [solved] mkinitcpio fails generating initramfs

seth wrote:

Why would it throw a syntax error at this point?

Because of the parentheses in the line

 rm "$moduledest"/modules.!(*.bin|devname|softdep)

Apparently, they are doing some regex operations although this is not legal in bash.

seth wrote:

Please run "bash --norc" and try again.

# bash --norc
bash-5.0# ./fix-initcpio.run 
/usr/lib/initcpio/functions: line 811: syntax error near unexpected token `('
/usr/lib/initcpio/functions: line 811: `    rm "$moduledest"/modules.!(*.bin|devname|softdep)'
kver is a function
kver () 
{ 
    local kver re='^[[:digit:]]+(\.[[:digit:]]+)+';
    local offset=$(hexdump -s 526 -n 2 -e '"%0d"' "$1");
    [[ $offset = +([0-9]) ]] || return 1;
    read kver _ < <(dd if="$1" bs=1 count=127 skip=$(( offset + 0x200 )) 2>/dev/null);
    [[ $kver =~ $re ]] || return 1;
    printf '%s' "$kver"
}
Error: [-n]: Cannot open for reading

Sorry for double posting

Last edited by spiri (2020-01-27 18:34:50)

Offline

#13 2020-01-27 18:38:43

seth
Member
Registered: 2012-09-03
Posts: 57,020

Re: [solved] mkinitcpio fails generating initramfs

What is ./fix-initcpio.run ?
This will run a subshell and source the rcs.

Actually run "bash --norc" and then "source /usr/lib/initcpio/functions" - there's nothing wrong w/ the line as is in the file - the single quotes in your output looks weird, though.

localectl
locale
locale -a

Online

#14 2020-01-27 18:46:20

spiri
Member
Registered: 2016-12-31
Posts: 65

Re: [solved] mkinitcpio fails generating initramfs

@seth,

# bash --norc
bash-5.0# source /usr/lib/initcpio/functions # source the mkinitcpio functions
bash: /usr/lib/initcpio/functions: line 811: syntax error near unexpected token `('
bash: /usr/lib/initcpio/functions: line 811: `    rm "$moduledest"/modules.!(*.bin|devname|softdep)'
bash-5.0# type kver # should now be a script
kver is a function
kver () 
{ 
    local kver re='^[[:digit:]]+(\.[[:digit:]]+)+';
    local offset=$(hexdump -s 526 -n 2 -e '"%0d"' "$1");
    [[ $offset = +([0-9]) ]] || return 1;
    read kver _ < <(dd if="$1" bs=1 count=127 skip=$(( offset + 0x200 )) 2>/dev/null);
    [[ $kver =~ $re ]] || return 1;
    printf '%s' "$kver"
}
bash-5.0# set +x # make bash talk a lot
bash-5.0# kver /boot/vmlinuz-linux # run the function that figures the kernel version
Error: [-n]: Cannot open for reading
bash-5.0# localectl
   System Locale: LANG=en_US.UTF-8
                  LANGUAGE=lb_LU:en
                  LC_CTYPE=lb_LU.UTF-8
                  LC_NUMERIC=lb_LU.UTF-8
                  LC_TIME=lb_LU.UTF-8
                  LC_COLLATE=lb_LU.UTF-8
                  LC_MONETARY=lb_LU.UTF-8
                  LC_MESSAGES=lb_LU.UTF-8
                  LC_PAPER=lb_LU.UTF-8
                  LC_NAME=lb_LU.UTF-8
                  LC_ADDRESS=lb_LU.UTF-8
                  LC_TELEPHONE=lb_LU.UTF-8
                  LC_MEASUREMENT=lb_LU.UTF-8
                  LC_IDENTIFICATION=lb_LU.UTF-8
       VC Keymap: fr_CH
      X11 Layout: ch
     X11 Variant: fr
bash-5.0# locale
LANG=en_US.UTF-8
LC_CTYPE=lb_LU.UTF-8
LC_NUMERIC=lb_LU.UTF-8
LC_TIME=lb_LU.UTF-8
LC_COLLATE=lb_LU.UTF-8
LC_MONETARY=lb_LU.UTF-8
LC_MESSAGES=lb_LU.UTF-8
LC_PAPER=lb_LU.UTF-8
LC_NAME=lb_LU.UTF-8
LC_ADDRESS=lb_LU.UTF-8
LC_TELEPHONE=lb_LU.UTF-8
LC_MEASUREMENT=lb_LU.UTF-8
LC_IDENTIFICATION=lb_LU.UTF-8
LC_ALL=
bash-5.0# locale -a
C
en_US.utf8
lb_LU
lb_LU.utf8
POSIX
bash-5.0# 

Offline

#15 2020-01-27 18:59:52

seth
Member
Registered: 2012-09-03
Posts: 57,020

Re: [solved] mkinitcpio fails generating initramfs

export LANG=C
export LC_ALL=C
bash --norc
source /usr/lib/initcpio/functions

Still an error?

Online

#16 2020-01-27 19:14:11

spiri
Member
Registered: 2016-12-31
Posts: 65

Re: [solved] mkinitcpio fails generating initramfs

$ export LANG=C
$ export LC_ALL=C
$ bash --norc
bash-5.0$ source /usr/lib/initcpio/functions
bash: /usr/lib/initcpio/functions: line 811: syntax error near unexpected token `('
bash: /usr/lib/initcpio/functions: line 811: `    rm "$moduledest"/modules.!(*.bin|devname|softdep)'
bash-5.0$ 

Offline

#17 2020-01-27 19:29:49

seth
Member
Registered: 2012-09-03
Posts: 57,020

Re: [solved] mkinitcpio fails generating initramfs

GRUMPF!

I'm very sure this worked fine, but I've to admit that I get the very error on bash atm. (maybe I ran a sub-zsh instead? I'll look into that)
However, the kver() function works fine despite the error, so it's insignificant - sorry for wasting your time on this.

Online

#18 2020-01-27 19:58:55

spiri
Member
Registered: 2016-12-31
Posts: 65

Re: [solved] mkinitcpio fails generating initramfs

What can I do now?

The system needs to do mkinitcpio sometimes.

Last edited by spiri (2020-01-27 19:59:24)

Offline

#19 2020-01-27 20:03:24

seth
Member
Registered: 2012-09-03
Posts: 57,020

Re: [solved] mkinitcpio fails generating initramfs

It still fails somewhere in the kver() call, we need to figure where exactly.
Continuing w/ my earlier fuck-ups, it's "set -x" to get bash debug output ("set +x" disables it) - apparently my brain was broken.
So run that, then "kver /boot/vmlinuz-linux" so we hopefully get a better idea where the read error appears.

Online

#20 2020-01-27 20:14:01

spiri
Member
Registered: 2016-12-31
Posts: 65

Re: [solved] mkinitcpio fails generating initramfs

The error appears in hexdump.

kver is a function
kver () 
{ 
    local kver re='^[[:digit:]]+(\.[[:digit:]]+)+';
    local offset=$(hexdump -s 526 -n 2 -e '"%0d"' "$1");
    [[ $offset = +([0-9]) ]] || return 1;
    read kver _ < <(dd if="$1" bs=1 count=127 skip=$(( offset + 0x200 )) 2>/dev/null);
    [[ $kver =~ $re ]] || return 1;
    printf '%s' "$kver"
}
+ kver /boot/vmlinuz-linux
+ local kver 're=^[[:digit:]]+(\.[[:digit:]]+)+'
++ hexdump -s 526 -n 2 -e '"%0d"' /boot/vmlinuz-linux
Error: [-n]: Cannot open for reading
+ local offset=
+ [[ '' = +([0-9]) ]]
+ return 1

Offline

#21 2020-01-27 20:16:27

seth
Member
Registered: 2012-09-03
Posts: 57,020

Re: [solved] mkinitcpio fails generating initramfs

type hexdump
pacman -Qo `which hexdump`
pacman -Qikk util-linux

This kind of stuff…

Online

#22 2020-01-27 20:24:14

spiri
Member
Registered: 2016-12-31
Posts: 65

Re: [solved] mkinitcpio fails generating initramfs

# type hexdump
hexdump is hashed (/usr/local/bin/hexdump)
# pacman -Qo `which hexdump`
error: No package owns /usr/local/bin/hexdump
# pacman -Qikk util-linux
Name            : util-linux
Version         : 2.35-1
Description     : Miscellaneous system utilities for Linux
Architecture    : x86_64
URL             : https://github.com/karelzak/util-linux
Licenses        : GPL2
Groups          : None
Provides        : rfkill
Depends On      : pam  shadow  coreutils  systemd-libs  libcap-ng  libutil-linux
Optional Deps   : python: python bindings to libmount [installed]
                  words: default dictionary for look
Required By     : apr  arch-install-scripts  base  fakeroot  gupnp  mkinitcpio  ntfs-3g  ostree  rasqal  systemd  tracker  zeromq
Optional For    : None
Conflicts With  : rfkill
Replaces        : rfkill
Installed Size  : 12,97 MiB
Packager        : Christian Hesse <arch@eworm.de>
Build Date      : Dë 21. Jan 2020 14:11:38
Install Date    : So 26. Jan 2020 10:10:53
Install Reason  : Installed as a dependency for another package
Install Script  : No
Validated By    : Signature

warning: util-linux: /usr (UID mismatch)
warning: util-linux: /usr (GID mismatch)
warning: util-linux: /usr/bin (UID mismatch)
warning: util-linux: /usr/bin (GID mismatch)
warning: util-linux: /usr/share (UID mismatch)
warning: util-linux: /usr/share (GID mismatch)
util-linux: 500 total files, 3 altered files

Offline

#23 2020-01-27 20:26:15

seth
Member
Registered: 2012-09-03
Posts: 57,020

Re: [solved] mkinitcpio fails generating initramfs

hexdump is hashed (/usr/local/bin/hexdump)

Well. There's your problem.

pacman -Qo /usr/local/bin/hexdump
file /usr/local/bin/hexdump

Online

#24 2020-01-27 20:29:08

spiri
Member
Registered: 2016-12-31
Posts: 65

Re: [solved] mkinitcpio fails generating initramfs

Oh yes, thank you!

Offline

#25 2020-02-04 06:11:23

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: [solved] mkinitcpio fails generating initramfs

spiri wrote:
seth wrote:

Why would it throw a syntax error at this point?

Because of the parentheses in the line

 rm "$moduledest"/modules.!(*.bin|devname|softdep)

Apparently, they are doing some regex operations although this is not legal in bash.

seth wrote:

GRUMPF!

I'm very sure this worked fine, but I've to admit that I get the very error on bash atm. (maybe I ran a sub-zsh instead? I'll look into that)
However, the kver() function works fine despite the error, so it's insignificant - sorry for wasting your time on this.

Actually this is a perfectly legal bash extglob, but extglobs are disabled by default and must be enabled by running "shopt -s extglob", which in fact /usr/bin/mkinitcpio does ( but /usr/lib/initcpio/functions does not, since it relies on the calling script to do so).

Also, spiri, since I assume your problem is solved now that you removed your nonstandard custom hexdump executable, please edit the first post of the thread and add "[Solved]" to the beginning of the thread title.


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

Board footer

Powered by FluxBB