1

I would like to accomplish the following on Arch Linux: start dhcpcd in the background on boot while simultaneously automatically logging myself in and starting the X window server.

Here's what I've tried so far. First, I enabled automatic login using the following drop in snippet to getty@tty1:

[Service]
ExecStart=
ExecStart=-/usr/bin/agetty --autologin username --noclear %I $TERM

I also added exec startx to my .bash_profile file. Together, these successfully log me in on boot and start X

Next, I enabled the dhcpcd service using systemctl: sudo systemctl enable dhcpcd@enp4s0.service (enp4s0 is my ethernet port). This successfully starts dhcpcd and then logs me in. However, the login prompt is delayed by about 10 seconds while the connection is set up, which is a little annoying. I would like dhcpcd connection to happen in the background while I am presented with an X environment.

So, I added After=getty@tty1 to the dhcpcd service file by running sudo systemctl edit dhcpcd@enp4s0.service and creating the following snippet:

[Unit]
After=getty@tty1.service

After this, I am no longer presented with a login screen on boot, and checking the logs reveals that systemd detected a dependency loop and never started getty.

Presumably this is because getty has the type "idle," which means it starts last in the job order. So I set Type=simple in the getty service file. However, I now receive the error that unprivileged users are not allowed to login on boot and never get to a login prompt. I am unsure how to proceed.

I realize one solution is to just put the dhcpcd in my bash_profile. However, is there any way to accomplish what I want using systemd alone? I may want to run other services this way in the future and I would prefer not to clutter up my bash_profile.

  • Please edit your question and show us your current dhcpcd service file. – terdon Dec 8 '19 at 14:57
  • @terdon Thank you for the advice. I edited my question to add this detail. Please let me know if there's anything I can do to improve it further. – alligator Dec 8 '19 at 21:12
1

I found the answer on the Arch Wiki.

The solution is to use instead the following drop in snippet for dhcpcd.

[Service]
ExecStart=
ExecStart=/usr/bin/dhcpcd -b -q %I

The -b flag starts dhcpcd in the background, and the -q makes it "quiet" so that its output does not pollute the terminal (except for errors and warnings).

By default, dhcpcd has the type forking and is called with the -w flag by systemd. The -w flag prevents it from forking until it acquires an IP, and because it has Type=forking, it won't background itself and continue the boot process until that happens, which takes a few seconds. This explains the ~10 second boot delay. By backgrounding immediately with -b, we prevent this delay.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.