Skip to main content
Topic solved
This topic has been marked as solved and requires no further attention.
Topic: [SOLVED] Hostname sometimes resetting to "artixlinux" (Read 1221 times) previous topic - next topic
0 Members and 2 Guests are viewing this topic.

[SOLVED] Hostname sometimes resetting to "artixlinux"

Hi, I have checked that my hostname is correct in both /etc/hostname and /etc/conf.d/hostname.

But sometimes (around 50% of my reboots), I end up with "artixlinux" instead of the expected one.

I never had this problem until very recently.

I regularly update using pacman -Syu, and also I changed my motherboard recently, so either or a combination of those could be the cause.

Re: Hostname sometimes resetting to "artixlinux"

Reply #1
What's your init? You might have found a race condition in the scripts.

Re: Hostname sometimes resetting to "artixlinux"

Reply #2
I'm on openrc!

Right now I am in a session where the boot did not provoke the wrong hostname, but in any case
here is the "boot" section of my openrc service list (sysrqon, sideled and powerbuttonled are home-made ones):

Code: [Select]
$ sudo rc-status boot
Runlevel: boot
 hwclock                                                                                                              [  started  ]
 modules                                                                                                              [  started  ]
 dmcrypt                                                                                                              [  started  ]
 fsck                                                                                                                 [  started  ]
 root                                                                                                                 [  started  ]
 mtab                                                                                                                 [  started  ]
 swap                                                                                                                 [  started  ]
 localmount                                                                                                           [  started  ]
 sysctl                                                                                                               [  started  ]
 bootmisc                                                                                                             [  started  ]
 net.lo                                                                                                               [  started  ]
 opensysusers                                                                                                         [  started  ]
 termencoding                                                                                                         [  started  ]
 save-termencoding                                                                                                    [  started  ]
 procfs                                                                                                               [  started  ]
 binfmt                                                                                                               [  started  ]
 keymaps                                                                                                              [  started  ]
 save-keymaps                                                                                                         [  started  ]
 opentmpfiles-setup                                                                                                   [  started  ]
 sysrqon                                                                                                              [  started  ]
 powerbuttonled                                                                                                       [  crashed  ]
 seatd                                                                                                    [  started 00:30:21 (0) ]
 sideled                                                                                                              [  started  ]
 loopback                                                                                                             [  started  ]
 seedrng                                                                                                              [  started  ]
 hostname                                                                                                             [  started  ]

Re: Hostname sometimes resetting to "artixlinux"

Reply #3
Ok so I have a solution for you to try out: taking debug output from the hostname service itself.

OpenRC writes a log of what it ran and what the services themselves outputted in /var/log/rc.log

Make a backup copy of /etc/init.d/hostname and put the following line at the top after the shebang(#!/usr/bin/openrc-run):
Code: [Select]
set -x

This will enable debug output for the service and will be written to /var/log/rc.log next time you boot.

Send us the debug output for the hostname service next time it goes wrong.

Re: Hostname sometimes resetting to "artixlinux"

Reply #4
Thanks a lot!!
Let me try and I will report the result back here.

Re: Hostname sometimes resetting to "artixlinux"

Reply #5
Ok, so, I got the log, and the interesting part is this:

Code: [Select]
+ '[' -z myhostname ']'
+ ebegin 'Setting hostname to myhostname from /etc/hostname'
 * Setting hostname to myhostname from /etc/hostname ...
+ hostname myhostname
+ eend 0 'Failed to set the hostname'

Here is the corresponding part in /etc/init.d/hostname, from the line
 if [ -z "$h" ]; then 

Code: [Select]
start()
{
  local h source
  if read -r h _ 2> /dev/null < /etc/hostname; then
    source="/etc/hostname"
  elif [ -n "${hostname}" ]; then
    h=${hostname}
    source="/etc/conf.d/${RC_SVCNAME}"
  fi
  if [ -z "$h" ]; then
    einfo "Using default system hostname"
    return 0
  fi
  ebegin "Setting hostname to $h from $source"
  hostname "$h"
  eend $? "Failed to set the hostname"
}

I have no idea why the command   hostname myhostname   would fail!!

Here is the full part of the log produced by   set -x   :

Code: [Select]
++ description='Sets the hostname of the machine.'
+ yesno ''
+ '[' -z '' ']'
+ return 1
+ for _cmd in "$@"
+ '[' start '!=' status -a start '!=' describe ']'
+ '[' -n '' ']'
++ command -v cgroup_add_service
+ '[' cgroup_add_service = cgroup_add_service ']'
+ grep -qs /sys/fs/cgroup /proc/1/mountinfo
+ '[' -d /sys/fs/cgroup -a '!' -w /sys/fs/cgroup ']'
+ cgroup_add_service
+ for d in /sys/fs/cgroup/*
+ '[' -w /sys/fs/cgroup/blkio/tasks ']'
+ printf %d 0
+ for d in /sys/fs/cgroup/*
+ '[' -w /sys/fs/cgroup/cpu/tasks ']'
+ printf %d 0
+ for d in /sys/fs/cgroup/*
+ '[' -w /sys/fs/cgroup/cpuacct/tasks ']'
+ printf %d 0
+ for d in /sys/fs/cgroup/*
+ '[' -w /sys/fs/cgroup/cpuset/tasks ']'
+ printf %d 0
+ for d in /sys/fs/cgroup/*
+ '[' -w /sys/fs/cgroup/devices/tasks ']'
+ printf %d 0
+ for d in /sys/fs/cgroup/*
+ '[' -w /sys/fs/cgroup/freezer/tasks ']'
+ printf %d 0
+ for d in /sys/fs/cgroup/*
+ '[' -w /sys/fs/cgroup/hugetlb/tasks ']'
+ printf %d 0
+ for d in /sys/fs/cgroup/*
+ '[' -w /sys/fs/cgroup/memory/tasks ']'
+ printf %d 0
+ for d in /sys/fs/cgroup/*
+ '[' -w /sys/fs/cgroup/misc/tasks ']'
+ printf %d 0
+ for d in /sys/fs/cgroup/*
+ '[' -w /sys/fs/cgroup/net_cls/tasks ']'
+ printf %d 0
+ for d in /sys/fs/cgroup/*
+ '[' -w /sys/fs/cgroup/net_prio/tasks ']'
+ printf %d 0
+ for d in /sys/fs/cgroup/*
+ '[' -w /sys/fs/cgroup/openrc/tasks ']'
+ printf %d 0
+ for d in /sys/fs/cgroup/*
+ '[' -w /sys/fs/cgroup/perf_event/tasks ']'
+ printf %d 0
+ for d in /sys/fs/cgroup/*
+ '[' -w /sys/fs/cgroup/pids/tasks ']'
+ printf %d 0
+ for d in /sys/fs/cgroup/*
+ '[' -w /sys/fs/cgroup/rdma/tasks ']'
+ printf %d 0
+ for d in /sys/fs/cgroup/*
+ '[' -w /sys/fs/cgroup/unified/tasks ']'
+ openrc_cgroup=/sys/fs/cgroup/openrc
+ '[' -d /sys/fs/cgroup/openrc ']'
+ cgroup=/sys/fs/cgroup/openrc/hostname
+ mkdir -p /sys/fs/cgroup/openrc/hostname
+ '[' -w /sys/fs/cgroup/openrc/hostname/tasks ']'
+ printf %d 0
++ command -v cgroup_set_limits
+ '[' cgroup_set_limits = cgroup_set_limits ']'
+ cgroup_set_limits
+ local blkio=
+ '[' -n '' ']'
+ local cpu=
+ '[' -n '' ']'
+ local cpuacct=
+ '[' -n '' ']'
+ local cpuset=
+ '[' -n '' ']'
+ local devices=
+ '[' -n '' ']'
+ local hugetlb=
+ '[' -n '' ']'
+ local memory=
+ '[' -n '' ']'
+ local net_cls=
+ '[' -n '' ']'
+ local net_prio=
+ '[' -n '' ']'
+ local pids=
+ '[' -n '' ']'
+ return 0
++ command -v cgroup2_set_limits
+ '[' cgroup2_set_limits = cgroup2_set_limits ']'
+ '[' start = start ']'
+ cgroup2_set_limits
+ local cgroup_path
++ cgroup2_find_path
++ grep -qw cgroup2 /proc/filesystems
++ case "${rc_cgroup_mode:-hybrid}" in
++ printf /sys/fs/cgroup/unified
++ return 0
+ cgroup_path=/sys/fs/cgroup/unified
+ '[' -z /sys/fs/cgroup/unified ']'
+ mountinfo -q /sys/fs/cgroup/unified
+ rc_cgroup_path=/sys/fs/cgroup/unified/hostname
+ '[' '!' -d /sys/fs/cgroup/unified/hostname ']'
+ mkdir /sys/fs/cgroup/unified/hostname
+ '[' -f /sys/fs/cgroup/unified/hostname/cgroup.procs ']'
+ printf 0
+ '[' -z '' ']'
+ return 0
+ break
+ eval 'printf '\''%s\n'\'' '
++ printf '%s\n'
+ read _d
+ '[' -n '' ']'
+ read _d
+ '[' 0 -ne 0 ']'
+ unset _d
+ eval 'printf '\''%s\n'\'' '
+ read _f
++ printf '%s\n'
+ '[' -n '' ']'
+ read _f
+ '[' 0 -ne 0 ']'
+ unset _f
+ '[' -n '' ']'
+ '[' -n start ']'
+ '[' start = depend ']'
+ for _cmd in describe start stop status ${extra_commands:-$opts} $extra_started_commands $extra_stopped_commands
+ '[' describe = start ']'
+ for _cmd in describe start stop status ${extra_commands:-$opts} $extra_started_commands $extra_stopped_commands
+ '[' start = start ']'
++ command -v start
+ '[' start = start ']'
+ yesno
+ '[' -z '' ']'
+ return 1
+ for _cmd in $extra_stopped_commands
+ '[' cgroup_cleanup = start ']'
+ unset _cmd
+ case $1 in
+ verify_boot
+ '[' '!' -e /run/openrc/softlevel ']'
+ return 0
++ command -v start_pre
+ '[' '' = start_pre ']'
+ start
+ local h source
+ read -r h _
+ source=/etc/hostname
+ '[' -z myhostname ']'
+ ebegin 'Setting hostname to myhostname from /etc/hostname'
 * Setting hostname to myhostname from /etc/hostname ...
+ hostname myhostname
+ eend 0 'Failed to set the hostname'
 [ ok ]
++ command -v start_post
+ '[' '' = start_post ']'
++ command -v cgroup_cleanup
+ '[' cgroup_cleanup = cgroup_cleanup ']'
+ '[' start = stop ']'
++ command -v cgroup2_remove
+ '[' cgroup2_remove = cgroup2_remove ']'
+ '[' start = stop ']'
+ '[' -z '' ']'
+ cgroup2_remove
+ local cgroup_path rc_cgroup_path
++ cgroup2_find_path
++ grep -qw cgroup2 /proc/filesystems
++ case "${rc_cgroup_mode:-hybrid}" in
++ printf /sys/fs/cgroup/unified
++ return 0
+ cgroup_path=/sys/fs/cgroup/unified
+ '[' -z /sys/fs/cgroup/unified ']'
+ rc_cgroup_path=/sys/fs/cgroup/unified/hostname
+ '[' '!' -d /sys/fs/cgroup/unified/hostname ']'
+ '[' '!' -e /sys/fs/cgroup/unified/hostname/cgroup.events ']'
+ grep -qx 1864 /sys/fs/cgroup/unified/hostname/cgroup.procs
+ printf %d 0
+ local key populated vvalue
+ read -r key value
+ case "${key}" in
+ populated=0
+ read -r key value
+ case "${key}" in
+ read -r key value
+ '[' 0 = 1 ']'
+ rmdir /sys/fs/cgroup/unified/hostname
+ return 0
+ shift
+ continue 2
+ '[' -n '' ']'
+ exit 0

There seem to be a lot of cgroup incantations mixed in, maybe that's the problem...

And, for reference, here is the full   /etc/init.d/hostname file:

Code: [Select]
#!/usr/bin/openrc-run
set -x
# Copyright (c) 2007-2015 The OpenRC Authors.
# See the Authors file at the top-level directory of this distribution and
# https://github.com/OpenRC/openrc/blob/HEAD/AUTHORS
#
# This file is part of OpenRC. It is subject to the license terms in
# the LICENSE file found in the top-level directory of this
# distribution and at https://github.com/OpenRC/openrc/blob/HEAD/LICENSE
# This file may not be copied, modified, propagated, or distributed
# except according to the terms contained in the LICENSE file.

description="Sets the hostname of the machine."

depend()
{
after clock
keyword -docker -lxc -prefix -systemd-nspawn
}

start()
{
local h source
if read -r h _ 2> /dev/null < /etc/hostname; then
source="/etc/hostname"
elif [ -n "${hostname}" ]; then
h=${hostname}
source="/etc/conf.d/${RC_SVCNAME}"
fi
if [ -z "$h" ]; then
einfo "Using default system hostname"
return 0
fi
ebegin "Setting hostname to $h from $source"
hostname "$h"
eend $? "Failed to set the hostname"
}

Re: Hostname sometimes resetting to "artixlinux"

Reply #6
>I have no idea why the command   hostname myhostname   would fail!!

It didn't, that zero in eend 0 is the exit status of the hostname command, which means the command did its job. That string after eend only gets printed if the exit status is something other than zero.

> There seem to be a lot of cgroup incantations mixed in, maybe that's the problem...

That's normal, OpenRC makes extensive use of cgroups.

Re: Hostname sometimes resetting to "artixlinux"

Reply #7
Ah! My bad... so it seems to be successful, but it still ends up with "artixlinux" as the hostname...

Maybe I should add some echo command at the end of every openrc service to show if it has modified the hostname...

Re: Hostname sometimes resetting to "artixlinux"

Reply #8
I'd be curious where the 'artixlinux' hostname is coming from ?
Try
Code: [Select]
sudo grep -r artixlinux /etc
for maybe a clue as to where it is coming from ?

I seem to remember networkmanager has a penchant for mucking about with hostnames.
Is it installed and/or enabled ?


Re: Hostname sometimes resetting to "artixlinux"

Reply #9
@gripped It's the compiled-in kernel default for artix: https://gitea.artixlinux.org/packagesL/linux/src/commit/60a19fd9d4fa6411ffec384f6c504d30132f6aff/x86_64/core/config#L49

I guess it's just hostname's changes just aren't being recorded for some reason, but what you said (another program resetting it to artixlinux) is possible.

Re: Hostname sometimes resetting to "artixlinux"

Reply #10
A little hacky, but should get the job done.

This is an openrc service, add it to the default runlevel.

Basically what it does it sleeps for 20 seconds, checks the hostname to see if it is equal to 'artixlinux' and if it is, resets it to your desired hostname.
Code: [Select]
#!/usr/bin/openrc-run

depend()
{
after local
keyword -shutdown
}

start()
{
{
sleep 20s
if [ "$(hostname)" = 'artixlinux' ]; then
hostname "$(cat /etc/hostname)"
fi
} &
}

Edit: I changed it a little bit so the entire boot process doesn't get stalled for 20s and the hostname will be set according to your /etc/hostname instead of manually setting it in the service.

Re: Hostname sometimes resetting to "artixlinux"

Reply #11
It might still show the artixlinux hostname in the ttys though (or even after login if boot is fast enough).

Figuring if there's a race condition (and if not, who's resetting it) or trying to set hostname through other means like cat /etc/hostname > /proc/sys/kernel/hostname would be better IMO.

@Ale Is the wrong hostname present after a GUI login? Does restarting the hostname service fix it when you open a new terminal?

Re: Hostname sometimes resetting to "artixlinux"

Reply #12
Sorry for the long delay, I have new data to help understanding what happens!

So, the problem does not occur only (sometimes) at boot, it can (and does) also happen in the middle of using the laptop, or even when it is unattended at the lockscreen.

If I am using it, then suddenly all new X applications fail to start (expected, as the hostname is required for socket connectivity), and if I was at the lockscreen, no way to get the password prompt to appear (but the mouse shows itself when I move it and disappears immediately after).

In all cases, I am able to go to the TTYs. There, by pressing ctrl-d, I can check (with the TTY prompt) that the hostname is now "artixlinux".

If the problem happens while I'm in a normal working session (usually XFce), I can still use the xfce-terminal that is already open.

So I typed some commands to try to understand what was happening:

Code: [Select]
[username@artixlinux ~]$ cat /etc/hostname
goodhostname
[username@artixlinux ~]$ cat /etc/conf.d/hostname
# Hostname fallback if /etc/hostname does not exist
hostname="goodhostname"
[username@artixlinux ~]$ cat /proc/sys/kernel/hostname
artixlinux
[username@artixlinux ~]$ xrandr --listproviders
Authorization required, but no authorization protocol specified

Can't open display :0.0
[username@artixlinux ~]$


You can see that the kernel itself is returning the wrong hostname, but everything else is fine.

Now I am wondering if that can have something to do with DHCP or internet connectivity, as sometimes (but not everytime) it happened coincidentally after that I changed the network settings, like disabled or reenabled wlan0, or connected eth0, etc.

Re: Hostname sometimes resetting to "artixlinux"

Reply #13
It might still show the artixlinux hostname in the ttys though (or even after login if boot is fast enough).

Figuring if there's a race condition (and if not, who's resetting it) or trying to set hostname through other means like cat /etc/hostname > /proc/sys/kernel/hostname would be better IMO.

@Ale Is the wrong hostname present after a GUI login? Does restarting the hostname service fix it when you open a new terminal?

Thank you, I will try the cat method next time this happens!!

I will try to make it happen more often by manipulating the network a little bit more, maybe it'll trigger the problem...

Re: Hostname sometimes resetting to "artixlinux"

Reply #14
If I am using it, then suddenly all new X applications fail to start (expected, as the hostname is required for socket connectivity)

I did ask before if you had networkmanager enabled?
There have been threads in the past about this exact behaviour and I'm fairly sure it's always been networkmanager causing the hostname change. There is something you can add to a config file to stop it. I'll see if I can find it.

Edit:
https://forum.artixlinux.org/index.php/topic,3017.msg21421.html#msg21421