9

If I do:

git clone git://git.buildroot.net/buildroot
cd buildroot
git checkout 2016.05
make qemu_x86_defconfig
make BR2_JLEVEL=2
qemu-system-x86_64 -M pc -kernel output/images/bzImage -drive file=output/images/rootfs.ext2,if=virtio,format=raw -append root=/dev/vda -net nic,model=virtio -net user

I have to type root into QEMU before I can use the shell.

How to configure buildroot to skip that and login directly?

Tested on Ubuntu 16.04.

1 Answer 1

13

::respawn:-/bin/sh

Using BR2_ROOTFS_OVERLAY, modify the guest /etc/inittab to contain:

::respawn:-/bin/sh

instead of the default line of form:

console::respawn:/sbin/getty -L console 0 vt100

You can copy the default inittab from output/target/etc/inittab after the build to modify the above line from it.

I found this while studying the examples/inittab in Busybox 1_28_3 and found this, tried it out, and it worked, so it is the best solution I've found so far.

Don't forget the leading dash -, or job control actions such as Ctrl + C don't work as mentioned below.

The leading dash - gets magically parsed by BusyBox' init: https://github.com/mirror/busybox/blob/1_28_3/init/init.c#L439 and sets up the TTY for the command that follows.

BusyBox also appends the - to the beginning or arg[0], which /bin/sh interprets as indicating a login shell, which makes it source some init files such as /etc/profile. See also: https://stackoverflow.com/a/42291142/895245

The following is equivalent since console is the default value:

console::respawn:-/bin/sh

To login as another user by default, you can use instead:

::respawn:-/bin/login -f user0

Here is a sample setup.

Previous answer: getty -l

After almost two years, I've found it! :-)

Using BR2_ROOTFS_OVERLAY, override / create the following files:

/etc/inittab: start from https://github.com/buildroot/buildroot/blob/2018.02/package/busybox/inittab and edit the console line to be:

console::respawn:/sbin/getty -n -L -l /loginroot.sh console 0 vt100

/loginroot.sh:

#!/bin/sh
exec /bin/login root

/bin/login is the default executable if -l is not given. What we did it to create an executable that calls /bin/login with the user root already specified.

This makes init try to log in as the root user by default, and then since the default password is empty (BR2_TARGET_GENERIC_ROOT_PASSWD), it automatically logs in.

This technique basically re-implements the -a <user> option present in Ubuntu 14.04's getty, which BusyBox' implementation doesn't have.

Then, to login as a different user, just run:

/bin/login

Here is a sample setup.

Previous previous answer: console::respawn:/bin/sh

I've asked on the mailing list and Thomas Petazzoni replied that the:

/etc/inittab

should contain:

console::respawn:/bin/sh

instead of:

console::respawn:/sbin/getty -n -L  console 0 vt100 # GENERIC_SERIAL

With qemu_x86_defconfig, the inittab is being used by Busybox' init system, due to BR2_INIT_BUSYBOX=y.

This method does have a downside however: just after login, the message shows:

/bin/sh can't access tty; job control turned off

and as advertised, things like Ctrl+C will have no effect.

1
  • Modifying inittab is fine, but I would prefer a solution that only modifies getty. I need to be able to toggle this autologin option, not have it all the time. I can use scripting logic within a custom getty to accomplish this, but not if the solution is strictly within inittab Feb 19, 2021 at 17:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .