Skip to content

Instantly share code, notes, and snippets.

@ansemjo
Created April 26, 2019 10:53
Show Gist options
  • Save ansemjo/bc8eab91c8a680f214ebc7d5685b44a3 to your computer and use it in GitHub Desktop.
Save ansemjo/bc8eab91c8a680f214ebc7d5685b44a3 to your computer and use it in GitHub Desktop.
enable root autologin when starting a container with systemd init
# drop-in override to fix and enable autologin in rootless containers with systemd init
# e.g.:
#
# podman run --rm -it \
# -v .../container-systemd-autologin.conf:/etc/systemd/system/console-getty.service.d/override.conf:ro \
# centos:latest /usr/lib/systemd/systemd
[Service]
ExecStart=
ExecStartPre=-/usr/bin/sed -i '/pam_loginuid.so/d' /etc/pam.d/login
ExecStart=-/sbin/agetty --autologin root --noclear --keep-baud console 115200 38400 9600 vt
@ansemjo
Copy link
Author

ansemjo commented Apr 26, 2019

Example logging of launching a container with systemd as init:

$ podman run --rm -it -v /tmp/autologin.conf:/etc/systemd/system/console-getty.service.d/override.conf:ro centos /usr/lib/systemd/systemd
systemd 219 running in system mode. (+PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 -SECCOMP +BLKID +ELFUTILS +KMOD +IDN)
Detected virtualization other.
Detected architecture x86-64.

Welcome to CentOS Linux 7 (Core)!

Set hostname to <c78c83d3f3d0>.
Initializing machine ID from random generator.
Failed to read AF_UNIX datagram queue length, ignoring: No such file or directory
Failed to install release agent, ignoring: Permission denied
[  OK  ] Reached target Local Encrypted Volumes.
[  OK  ] Reached target Swap.
[  OK  ] Reached target Remote File Systems.
[  OK  ] Started Forward Password Requests to Wall Directory Watch.
[  OK  ] Created slice Root Slice.
[  OK  ] Listening on Delayed Shutdown Socket.
[  OK  ] Created slice User and Session Slice.
[  OK  ] Listening on /dev/initctl Compatibility Named Pipe.
[  OK  ] Listening on Journal Socket.
[  OK  ] Started Dispatch Password Requests to Console Directory Watch.
[  OK  ] Created slice System Slice.
[  OK  ] Reached target Slices.
[  OK  ] Created slice system-getty.slice.
         Mounting FUSE Control File System...
         Starting Journal Service...
[  OK  ] Reached target Local File Systems (Pre).
         Starting Rebuild Hardware Database...
[  OK  ] Reached target Local File Systems.
         Starting Rebuild Journal Catalog...
         Starting Load/Save Random Seed...
[  OK  ] Reached target Paths.
[  OK  ] Started Rebuild Hardware Database.
[  OK  ] Started Load/Save Random Seed.
sys-fs-fuse-connections.mount mount process exited, code=exited status=32
[FAILED] Failed to mount FUSE Control File System.
See 'systemctl status sys-fs-fuse-connections.mount' for details.
Unit sys-fs-fuse-connections.mount entered failed state.
[  OK  ] Started Journal Service.
         Starting Flush Journal to Persistent Storage...
[  OK  ] Started Rebuild Journal Catalog.
         Starting Update is Completed...
[  OK  ] Started Update is Completed.
[  OK  ] Started Flush Journal to Persistent Storage.
         Starting Create Volatile Files and Directories...
[  OK  ] Started Create Volatile Files and Directories.
         Starting Update UTMP about System Boot/Shutdown...
[  OK  ] Started Update UTMP about System Boot/Shutdown.
[  OK  ] Reached target System Initialization.
[  OK  ] Listening on D-Bus System Message Bus Socket.
[  OK  ] Reached target Sockets.
[  OK  ] Reached target Basic System.
[  OK  ] Started D-Bus System Message Bus.
         Starting Login Service...
         Starting Permit User Sessions...
[  OK  ] Started Daily Cleanup of Temporary Directories.
[  OK  ] Reached target Timers.
         Starting Cleanup of Temporary Directories...
[  OK  ] Started Permit User Sessions.
[  OK  ] Started Console Getty.
[  OK  ] Reached target Login Prompts.
[  OK  ] Started Cleanup of Temporary Directories.
[  OK  ] Started Login Service.
[  OK  ] Reached target Multi-User System.
         Starting Update UTMP about System Runlevel Changes...
[  OK  ] Started Update UTMP about System Runlevel Changes.

CentOS Linux 7 (Core)
Kernel 5.0.9-arch1-1-ARCH on an x86_64

c78c83d3f3d0 login: root (automatic login)

[root@c78c83d3f3d0 ~]# systemctl status
● c78c83d3f3d0
    State: degraded
     Jobs: 0 queued
   Failed: 1 units
    Since: Fri 2019-04-26 10:54:10 UTC; 7s ago
   CGroup: /user.slice/user-1000.slice/user@1000.service/gnome-terminal-server.service/c78c83d3f3d021119b09e27fab9c9cea0c91890ed0adeb9d6c2ddfc3d1fc0e87
           ├─1 /usr/lib/systemd/systemd
           ├─user.slice
           │ └─user-0.slice
           │   └─session-2.scope
           │     ├─32 login -- root     
           │     ├─33 -bash
           │     ├─45 systemctl status
           │     └─46 more
           └─system.slice
             ├─systemd-journald.service
             │ └─18 /usr/lib/systemd/systemd-journald
             ├─dbus.service
             │ └─26 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --systemd-activation
             └─systemd-logind.service
               └─27 /usr/lib/systemd/systemd-logind
[root@c78c83d3f3d0 ~]# shutdown now
[  OK  ] Stopped target Timers.
[  OK  ] Stopped Daily Cleanup of Temporary Directories.
         Stopping Session 2 of user root.
         Unmounting /var/log/journal...
[  OK  ] Removed slice system-getty.slice.
[  OK  ] Stopped target Multi-User System.
         Stopping D-Bus System Message Bus...
[  OK  ] Stopped target Login Prompts.
         Stopping Console Getty...
[FAILED] Failed unmounting /var/log/journal.
[  OK  ] Stopped Console Getty.
[  OK  ] Stopped Session 2 of user root.
[  OK  ] Removed slice User Slice of root.
         Stopping Login Service...
         Stopping Permit User Sessions...
[  OK  ] Stopped Login Service.
[  OK  ] Stopped Permit User Sessions.
[  OK  ] Stopped target Remote File Systems.
[  OK  ] Stopped D-Bus System Message Bus.
[  OK  ] Stopped target Basic System.
[  OK  ] Stopped target Sockets.
[  OK  ] Stopped target Slices.
[  OK  ] Removed slice User and Session Slice.
[  OK  ] Stopped target Paths.
[  OK  ] Stopped Dispatch Password Requests to Console Directory Watch.
[  OK  ] Stopped Forward Password Requests to Wall Directory Watch.
[  OK  ] Closed D-Bus System Message Bus Socket.
[  OK  ] Stopped target System Initialization.
[  OK  ] Stopped target Local Encrypted Volumes.
         Stopping Update UTMP about System Boot/Shutdown...
[  OK  ] Stopped Update is Completed.
[  OK  ] Stopped Rebuild Journal Catalog.
         Stopping Load/Save Random Seed...
[  OK  ] Stopped Rebuild Hardware Database.
[  OK  ] Stopped Update UTMP about System Boot/Shutdown.
[  OK  ] Stopped Load/Save Random Seed.
[  OK  ] Stopped Create Volatile Files and Directories.
[  OK  ] Reached target Shutdown.
Syncing filesystems and block devices.
Sending SIGTERM to remaining processes...
Sending SIGKILL to remaining processes...
Powering off.
Exiting container.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment