You are not logged in.
Hello,
I'm in the process of setting up systemd on my laptop. I think I got everything set up correctly, except for the rc.local conversion. I searched some on these forums and the general suggestion was to convert it to systemd's tmpfiles. I opened up its manpage but I can't find how to do this correctly.
This is my current rc.local:
# Control HDD
hdparm -S 0 -B 254 -a 2048 /dev/sda > /dev/null
# Set CPU governor
for i in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do echo "ondemand" > $i; done
echo "1" > /sys/devices/system/cpu/sched_smt_power_savings
# Turn off eth0
ifconfig eth0 down > /dev/nullAFAIK, I can't use tmpfiles to set up hdparm and ifconfig. I think I can use it to set the CPU governor, but I don't know how to convert the for i in...; do part.
Can you help me?
Last edited by Unia (2012-08-24 15:50:31)
If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres
Offline
You shouldn't need the line with the "for" statement any more. ondemand has been the kernel default governor for a little while now.
Offline
One way allows you to not get rid of rc.local with systemd. See https://wiki.archlinux.org/index.php/Sy … s#rc.local
If you have built castles in the air, your work need not be lost; that is where they should be. Now put foundations under them.
Henry David Thoreau
Registered Linux User: #559057
Offline
One way allows you to not get rid of rc.local with systemd. See https://wiki.archlinux.org/index.php/Sy … s#rc.local
Yes, I've seen that - but I'd like to have a pure, systemd-only setup.
You shouldn't need the line with the "for" statement any more. ondemand has been the kernel default governor for a little while now.
Oke, thanks. But for practice, how would I convert this to a systemd-tmpfile?
If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres
Offline
Oke, thanks. But for practice, how would I convert this to a systemd-tmpfile?
The tmpfiles.d manual should have all the info you need to convert that. You would have to explicitly set the governor for each cpu though, of course. These are just config files read in by the tmpfiles service, it's not a script.
Last edited by neilzium (2012-08-24 03:17:25)
Offline
That had indeed already crossed my mind, but I hoped there was a 'cleaner' way of doing it.
But how would I do the hdparm and ifconfig parts?
If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres
Offline
You can create a udev rule to execute hdparm with the desired parameters.
Create a file /etc/udev/rules.d/61-hdparm.rules with the following contents:
ACTION=="add", KERNEL=="sda", RUN+="/sbin/hdparm -S 0 -B 254 -a 2048 /dev/sda"Offline
You can create a udev rule to execute hdparm with the desired parameters.
Create a file /etc/udev/rules.d/61-hdparm.rules with the following contents:
ACTION=="add", KERNEL=="sda", RUN+="/sbin/hdparm -S 0 -B 254 -a 2048 /dev/sda"
Thanks, I have never had to deal with udev rules before so I didn't think of this. However, the Wiki page only talks about devices and such, not setting application with parameters. So, before I do this I have one question: is this what udev rules are intended for, or is it just making advantage of the udev system because it is an option?
EDIT: Oh, and I have a powersave script (currently it uses pm-utils, so I also gotta set this over to systemd) which overrides the hdparm variable when I am on battery. Can I, when I set hdparm at boot with a udev rule, still use this script to override it, or will udev automatically restore it to the value I have set in the rule?
Last edited by Unia (2012-08-24 10:33:32)
If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres
Offline
I have tried to set the CPU governor with a tmpfile, but somehow it's not working. This is the /etc/tmpfiles.d/cpufreq.conf:
w /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor - - - - ondemand
w /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor - - - - powersave
w /sys/devices/system/cpu/cpu2/cpufreq/scaling_governor - - - - ondemand
w /sys/devices/system/cpu/cpu3/cpufreq/scaling_governor - - - - ondemand
w /sys/devices/system/cpu/sched_smt_power_savings - - - - 1But when I reboot and I use cat to check those files, they're all set to ondemand (I set cpu1 to powersave for testing purposes, since apparently the default governor is ondemand) What's wrong with my tmpfile?
If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres
Offline
You could create a service that would run your script at boot. See wiki for creating unit files.
If you have built castles in the air, your work need not be lost; that is where they should be. Now put foundations under them.
Henry David Thoreau
Registered Linux User: #559057
Offline
You could create a service that would run your script at boot. See wiki for creating unit files.
No, it needs only to run when I unplug AC and when I plug it in. But this is not what I opened this topic for, so can we please stay on topic? (I do appreciate your input, but I would like to keep this topic clear)
Or did you mean a service to run /etc/rc.local?
Last edited by Unia (2012-08-24 12:04:57)
If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres
Offline
As far as i understand your first post you want to have alternative to rc.local. Rc.local just executes commands on boot and doesn't scan for AC/BAT state - ACPI and laptop-mode-tool can do that or if you create some script that will change specific file when cable is plugged or unplugged. So i think you could run your script on boot through creating your own service. Just my 2 cents here.
If you have built castles in the air, your work need not be lost; that is where they should be. Now put foundations under them.
Henry David Thoreau
Registered Linux User: #559057
Offline
As far as i understand your first post you want to have alternative to rc.local. Rc.local just executes commands on boot and doesn't scan for AC/BAT state - ACPI and laptop-mode-tool can do that or if you create some script that will change specific file when cable is plugged or unplugged. So i think you could run your script on boot through creating your own service. Just my 2 cents here.
Yea, I misunderstood you, sorry. I thought you were talking about my powersave script, but you were talking about rc.local instead.
I have gotten the cpufreq tmpfile to work. Apparantly, I had to run systemd-tmpfiles --create <name>.conf in order for it to work. The wiki doesn't list this, though.
So all I have to do now is figure out how to run hdparm and ifconfig at boot. As I asked before, are udev rules intended to do this, or should I look for another solution?
If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres
Offline
Like i said you could create your own ***.service file and enable it on boot and this service would run a script containing commands hdparm and ifconfig.
If you have built castles in the air, your work need not be lost; that is where they should be. Now put foundations under them.
Henry David Thoreau
Registered Linux User: #559057
Offline
Like i said you could create your own ***.service file and enable it on boot and this service would run a script containing commands hdparm and ifconfig.
I feel so stupid now! Why didn't I think of that .... will look into it and see if I can get it to work.
Thanks!
If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres
Offline
Almost there! I got the hdparm.service file to work, but the ifconfig.service always fails. Also, the cpufreq tmpfile that I created won't run at boot, I have to do it manually all the time. So, two more questions:
1. Can I somehow get the cpufreq tmpfile to run automatically at boot? There's something about tmpfiles I'm missing, I think.
2. Why is my ifconfig.service failing? Here you can see the file I made:
[Unit]
Description=Turns off eth0 at boot. Handmade
[Service]
ExecStart=/sbin/ifconfig eth0 down
[Install]
WantedBy=multi-user.targetAnd here's what systemctl status ifconfig says:
┌─[jente @ lappy ~] 15:01:33
└─■ systemctl status ifconfig
ifconfig.service - Turns off eth0 at boot. Handmade
Loaded: loaded (/etc/systemd/system/ifconfig.service; enabled)
Active: failed (Result: exit-code) since Fri, 24 Aug 2012 14:59:54 +0200; 1min 44s ago
Process: 255 ExecStart=/sbin/ifconfig eth0 down (code=exited, status=255)
CGroup: name=systemd:/system/ifconfig.serviceIf you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres
Offline
Can I somehow get the cpufreq tmpfile to run automatically at boot? There's something about tmpfiles I'm missing, I think.
I still don't get why you are even messing with cpufreq. as mentioned, ondemand is the default and you don't have to do anything to make it work. If you want to set another governor, you can also use cpupower which provides a systemd service file. the tmpfile should actually work as far as I can see, but imho the cpupower service may be a little bit more simple here.
Why is my ifconfig.service failing?
1. you are missing Type=oneshot and (although that may not be what is causing the error)
2. ifconfig is deprecated, don't use it. use "ip" from iproute2
3. What exactly is this for anyway? if you don't use eth0 it should be down by default as long as you didn't configure a network manager (netcfg, dhcpcd etc.) to set it up?! What am I missing?
you may also want to add Requires=dev-sda.device and After=dev-sda.device to your hdparm.service . the udev method should also work. not sure what is the better method here.
Offline
I have never write my own service file so for me this is new and i will try to help you by my best effort since this will be a good learning practise.
I think that ifconfig doesn't work because probably it needs network.target but i am not sure. Add in your service file:
Requires=network.target
After=network.targetBut i am not sure.
If you have built castles in the air, your work need not be lost; that is where they should be. Now put foundations under them.
Henry David Thoreau
Registered Linux User: #559057
Offline
Man... on this concept SysV init is definitely easier towards the end-user. I am messing with cpufreq because I want to be sure ondemand is set.
About the ifconfig. I turn it off for powersaving. AFAIK, "ip" can't turn eth0 down as ifconfig can.
Lastly, what is the difference between "requires=dev-sda.service" or "after=dev-sda.service"?
EDIT: @Shark,
I do not use the network daemon, only netcfg. Or is this something different?
Last edited by Unia (2012-08-24 13:33:08)
If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres
Offline
I think you could specifiy after netcfg.service then or what it is called.
EDIT: After and Requires i think should be under UNIT section.
EDIT2: cpupower provides the native service file.
Last edited by Shark (2012-08-24 13:37:18)
If you have built castles in the air, your work need not be lost; that is where they should be. Now put foundations under them.
Henry David Thoreau
Registered Linux User: #559057
Offline
Man... on this concept SysV init is definitely easier towards the end-user. I am messing with cpufreq because I want to be sure ondemand is set.
You don't have to make sure. it is set by default - you don't have to do anything - no tmpfile, no service file, no nothing! Don't mess with stuff that just works.
About the ifconfig. I turn it off for powersaving. AFAIK, "ip" can't turn eth0 down as ifconfig can.
I don't think turning off eth0 will save power if there is no traffic on the NIC anyway (but feel free to correct me). And "ip" can just as well disable an interface, "ip" completely replaces ifconfig.
/sbin/ip link set dev eth0 downWhat may save power is if you blacklist the module for your ethernet interface so the device isn't even loaded.
Lastly, what is the difference between "requires=dev-sda.service" or "after=dev-sda.service"?
Requires says "i need this device", After says "start me after this device is ready". Ready doesn't imply After.
If you don't specify this, the service may be started before /dev/sda is ready, so hdparm will fail.
Offline
Oke, I got it. For now though I'll keep using SysV init.
Thanks for all your help, guys!
If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres
Offline
Why? Haven't you had any progress by creating service file?
If you have built castles in the air, your work need not be lost; that is where they should be. Now put foundations under them.
Henry David Thoreau
Registered Linux User: #559057
Offline
Why? Haven't you had any progress by creating service file?
I did, but at least to me SysV init is much more simpler. I mean, I can specify the DAEMONS I want in rc.conf, MODULES in another file, rc.local here, rc.local.shutdown there and it all "just works".
With systemd, I have to enable services and whatnot, make units, make tmpfiles, enable units, enable tmpfiles.... and for example, my sleep button isn't recognized to HandleSleepKey doesn't work, and also I'd have to edit my powersave script to work in some other way, because systemd doesn't make use of pm-utils.
No, I'm sure systemd is a viable alternative and if it ever gets the default, I will happily adopt it. But for not, I will stick with SysV init in combination with e4rat. Still, that's the fastest bootup I have had. (and yes, I did try systemd's readahead)
Though, thanks again for all the help I got here ![]()
If you can't sit by a cozy fire with your code in hand enjoying its simplicity and clarity, it needs more work. --Carlos Torres
Offline
All right. I was quite happy that you had this problem (yeah yeah, i am selfish
because i was searching for solutions i wouldn't otherwise. It was quite a good experience for me to reading all the articles. So, enjoy and see ya in the Arch Forums ![]()
If you have built castles in the air, your work need not be lost; that is where they should be. Now put foundations under them.
Henry David Thoreau
Registered Linux User: #559057
Offline