You are not logged in.

#1 2021-01-11 17:36:32

iith4ahm
Member
Registered: 2021-01-11
Posts: 4

Error and no keyboard response with init=/bin/bash

I'm thinking of trying to boot a system with just the kernel and maybe a bootloader, and a single process of my own creation. As a first step, I'm just trying to set init for the kernel with

init=/bin/bash

in the bootloader on my current full-fledged system (arch with I think either gummiboot or systemd-boot). Unfortunately I get an error and I can't interact in any way (not even key echoing)

:: running early hook [udev]
Starting version 247.2-1-arch
:: running hook [udev]
:: Triggering uevents...
:: performing fsck on '/dev/nvmc0n1p2'
/dev/nvmc0n1p2: clean, 422674/15564800 files, 47331349/62252544 blocks
:: mounting /dev/nvme0n1p2' on real root
:: running cleanup hook [udev]
bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell
[root@archlinux /]#

(copied by hand, so it may not be correct character for character)

Searching the internet I found these:
https://lists.gnu.org/archive/html/bug- … 00097.html
https://stackoverflow.com/questions/320 … -ioctl-for (not me, but similar error. I can't even enter a command like it looks like he could)

But it's not clear to me exactly what's going on in my case or how to fix it. Are /dev/console and /dev/tty set up by the kernel or init? Where do the virtual consoles Ctrl-Alt-F# fit into the process? It sounds like init=/bin/bash is a fairly common thing to do, for example to fix a forgotten root password, so I'm wondering if this issue is more with a (usb) keyboard detection or driver. Are the keyboards typically set up with systemd/udev and I'm bypassing that? Do I need to add a keyboard driver to my initramfs?

Does anyone know what's going on? Thank you

Last edited by iith4ahm (2021-01-11 17:38:10)

Offline

#2 2021-01-11 22:00:56

seth
Member
Registered: 2012-09-03
Posts: 18,269

Re: Error and no keyboard response with init=/bin/bash

https://forums.gentoo.org/viewtopic-t-1 … art-0.html
https://wiki.gentoo.org/wiki/Custom_Ini … ob_control

The input likely fails because no sysfs/dev/devpts is setup (see the init script in the gentoo thread)

Offline

#3 2021-01-12 15:46:25

iith4ahm
Member
Registered: 2021-01-11
Posts: 4

Re: Error and no keyboard response with init=/bin/bash

The input likely fails because no sysfs/dev/devpts is setup (see the init script in the gentoo thread)

Thanks Seth. What do you mean by "no sysfs/dev/devpts" is setup? I leaned that I can run commands in the init script and they will show on the screen - I just can't interact with the keyboard. /dev, /sys, and /proc seem to be populated when the script is run. Does that mean they are "set up"?

If I run (from the gentoo script, but I swapped out an echo command for tty)

#!/bin/bash
export PATH=/bin:/sbin:/usr/bin:/usr/sbin
export HOME=/root

mount -t proc none /proc
mount -t sysfs none /sys
mount -t devtmpfs none /dev

tty

bash

I get the original output with the addition of

mount: /sys: none already mounted on /proc.
mount: /dev: none already mounted on /proc
not a tty

Running the bash program and redirecting stdin, stdout and stderr to /dev/tty7 got rid of the bash error, but I still could not do anything. I tried doing the same thing and running it in the background with

/bin/bash </dev/tty7 >/dev/tty7 2>&1 &

but that caused a "kernel panic - not syncing: Attempted to kill init!". I'm guessing init is not supposed to finish.

Also, if it could be related to what's going on:
When I boot my system up normally, it doesn't go right into a display manager or a console. It leaves me with the output of the kernel and/or systemd. I can't type anything. If I press Ctl-Alt-1 it does nothing just like when I run my custom init. However, if I first press Ctl-Alt-2 I do get a virtual terminal, and then when I press Ctl-Alt-1 gnome starts up. It's been this way for a while. The difference with my init script is that I can't Ctl-Alt-anything.

Last edited by iith4ahm (2021-01-12 15:47:04)

Offline

#4 2021-01-13 12:33:52

seth
Member
Registered: 2012-09-03
Posts: 18,269

Re: Error and no keyboard response with init=/bin/bash

What do you mean by "no sysfs/dev/devpts" is setup?

/dev, /sys, and /proc seem to be populated when the script is run.

That. Unfortunately.

When I boot my system up normally, it doesn't go right into a display manager or a console. It leaves me with the output of the kernel and/or systemd. I can't type anything. If I press Ctl-Alt-1 it does nothing just like when I run my custom init. However, if I first press Ctl-Alt-2 I do get a virtual terminal, and then when I press Ctl-Alt-1 gnome starts up.

Could be either an entropy issue or the GPU stalls.

Did you try

setsid sh -c 'exec sh </dev/tty1 >/dev/tty1 2>&1'

(do NOT fork the command!)
The important part is setsid and you may have to pass absolute paths.

Offline

#5 2021-01-13 20:24:52

iith4ahm
Member
Registered: 2021-01-11
Posts: 4

Re: Error and no keyboard response with init=/bin/bash

#!/bin/bash
setsid sh -c 'exec sh </dev/tty1 >/dev/tty1 2>&1'

gives me

sh-5.1#

with the same unresponsive keyboard. If I try to run that command with init= instead of from a bash script I get

ERROR: Root device mounted successfully, but setsid does not exist.
Bailing out, you are on your own. Good luck.

sh: can't access tty: job control turned off
[rootfs ]# _

Again with no ability to interact. I'm assuming the kernel would have needed a full path name.

Could be either an entropy issue or the GPU stalls.

Do you think this could be the cause of everything? There are a lot of yellow NVIDIA message in journalctl. I will update below:

Extract:

Jan 13 14:25:36 lava /usr/lib/gdm-x-session[495]: (EE) Screen 0 deleted because of no matching config section.
Jan 13 14:25:36 lava /usr/lib/gdm-x-session[495]: (II) UnloadModule: "modesetting"
Jan 13 14:25:36 lava /usr/lib/gdm-x-session[495]: (EE) Device(s) detected, but none match those in the config file.
Jan 13 14:25:36 lava /usr/lib/gdm-x-session[495]: (EE)
Jan 13 14:25:36 lava /usr/lib/gdm-x-session[495]: Fatal server error:
Jan 13 14:25:36 lava /usr/lib/gdm-x-session[495]: (EE) no screens found(EE)
Jan 13 14:25:36 lava /usr/lib/gdm-x-session[495]: (EE)
Jan 13 14:25:36 lava /usr/lib/gdm-x-session[495]: Please consult the The X.Org Foundation support
Jan 13 14:25:36 lava /usr/lib/gdm-x-session[495]:          at http://wiki.x.org
Jan 13 14:25:36 lava /usr/lib/gdm-x-session[495]:  for help.
Jan 13 14:25:36 lava /usr/lib/gdm-x-session[495]: (EE) Please also check the log file at "/var/log/Xorg.0.log" for additional information.
Jan 13 14:25:36 lava /usr/lib/gdm-x-session[495]: (EE)
Jan 13 14:25:36 lava /usr/lib/gdm-x-session[495]: (EE) Server terminated with error (1). Closing log file.
Jan 13 14:25:36 lava /usr/lib/gdm-x-session[493]: Unable to run X server

Do you think if I sort out these driver/X issues my init=/bin/bash problem will take care of itself?

But why are X and systemd running in the first place? Aren't they in userspace, and I'm bypassing them by passing the init kernel parameter? -Oh, since I'm using systemd-boot, does that let systemd start doing its thing right away and not wait for the kernel to start it? If I switch bootloaders should I get a systemd/X free system, and maybe the kernel will get me a responsive tty?

Last edited by iith4ahm (2021-01-13 21:13:05)

Offline

#6 2021-01-13 23:13:09

seth
Member
Registered: 2012-09-03
Posts: 18,269

Re: Error and no keyboard response with init=/bin/bash

It should rid you of the error message?

About the keyboard: you could have the script print "lsmod" and compare that to a normal session (in case you rely on some explicitly loaded modules for the keyboard)

Is this an integrated keyboard or an external one? Do you have a replacement option (ie. another keyboard to attach)?

Offline

#7 2021-01-21 00:54:07

iith4ahm
Member
Registered: 2021-01-11
Posts: 4

Re: Error and no keyboard response with init=/bin/bash

Thank you seth.

I installed Arch Linux in virtualized QEMU drive, and I can set init=/bin/bash just fine and the keyboard works (although I still get the errors from bash about inappropriate ioctl). So I'll blame the root problem on some driver/nvidia issue.

If I try to set init=/home/init (my custom script) I get an error about the file not existing and ls shows the following. /dev/sda2 (I think my main partition) is mounted to /new_root instead of /. Is this expected?

ERROR: Root device mounted successfully, but /home/init does not exist.
Bailing out, you are on your own. Good luck.

sh: can't access tty; job control turned off
[rootfs ]# ls
VERSION        dev        init_functions   proc       sys
bin            etc        lib              root       tmp
buildconfig    hooks      lib64            run        usr
config         init       new_root         sbin       var
[rootfs ]# mount
none on / type rootfs (rw)
proc on ...
sys...
...
/dev/sda2 on /newroot type ext4 (rw,relatime)

Also, follow up question: Even the base installation of arch (or presumably most distros) has tons of files. This makes me feel like I don't understand everything that my system does. Is it reasonable to compile or find some binaries for bash, pam, sshd, nginx, and python and a few others, to have a web server with only a kernel and a few binaries? Then a simple init script to start them? Would this be worth it for a simple secure server I can wrap my head all the way around, or am I better off just using debian and "apt upgrade"ing regularly and not worrying about if I understand it all?

Last edited by iith4ahm (2021-01-21 03:23:42)

Offline

#8 2021-01-21 08:15:59

seth
Member
Registered: 2012-09-03
Posts: 18,269

Re: Error and no keyboard response with init=/bin/bash

/home is probably on an extra mount?

The failing input could be due to a missing kernel module that requires explicit loading.

seth before already wrote:

About the keyboard: you could have the script print "lsmod" and compare that to a normal session (in case you rely on some explicitly loaded modules for the keyboard)

Can you enter commands blindly (and just not get a visual reaction)?


Is it reasonable to compile or find some binaries for bash, pam, sshd, nginx, and python and a few others, to have a web server with only a kernel and a few binaries?

You probably want busybox in that case, but "it depends".
Whatever isn't there doesn't have to be hardened, but you'll also have to maintain the system, care for security updates, ensure your custom setup and config doesn't create weaknesses.

We're kinda close to violating board rules, but I'd rather take a look at sth. like alpinelinux before trying to invent YAD (yet another distro) - unless you have a *very* specific and unique usecase.

Offline

Board footer

Powered by FluxBB