Does anyone know the command to run systemctl commands in chroot environment.
Example run in kickstart post
systemctl restart NetworkManager
systemctl enable NetworkManager
Does anyone know the command to run systemctl commands in chroot environment.
Example run in kickstart post
systemctl restart NetworkManager
systemctl enable NetworkManager
What’s your goal? The preset for the NM service is already “enabled”. Maybe share your ks to get the context …
My goal is start and enable the service at the end of my post install in the kickstart so that when the system reboots it is active.
NetworkManager was just an example. I have other services that the command systemctl is not recognised in the post install of kickstart.
Kickstart has the services
option for that: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9/html/performing_an_advanced_rhel_9_installation/kickstart-commands-and-options-reference_installing-rhel-as-an-experienced-user#services_kickstart-commands-for-system-configuration
I’m using the services service in the pre section but was not sure I can use this in the chroot environment for post section.
One of my services gets added in the post to /usr/local/lib/systemd/system so that is why I need to enable and start the service in the post section.
echo "enable yourdaemon.service" > /usr/lib/systemd/user-preset/95-my-default.preset
Here’s a simple example post section that enables firewalld and enables the service
%post --log=/root/ks-post.log
dnf install -y firewalld >> /root/fw.log 2>> /root/fw.err
systemctl enable firewalld >> /root/fw.log 2>> /root/fw.err
%end
After reboot, I can see that firewalld is enabled and fw.err file shows the output of systemctl enable
[root@vmtest ~]# cat fw.err
Created symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service -> /usr/lib/systemd/system/firewalld.service.
Created symlink /etc/systemd/system/multi-user.target.wants/firewalld.service -> /usr/lib/systemd/system/firewalld.service.
I’d expect this to be enough. “systemctl restart” won’t work, as you are in chrooted environment (Plus you don’t care if system is started now, you want it to be started after reboot)