Jump to content

how to make the Ubutu Scripts useful in Armbian? / to make the fan of nanopi M4V2 SATA hat always running...


JKS

Recommended Posts

Hi everyone, I am a LINUX beginner. and I have a NanoPi M4V2, and want to build a mini NAS with OpenMediaVault 5 under Armbian (OMV5 can only run in Armbiam/Debian, not available in Ubuntu)
 The M4V2 has a SATA hat, and it can support up to 4 hard drives (2.5 inches size), so the SATA hat is powered separately, and I guess this is why it always gets overheat  :(

 

20190129035937!NanoPi_M4_SATA_HAT-01B.jp

 

This is what it looks like. There is a 12V fan interface (2pin) on this SATA hat, just right biside the power button.

And I found that there are already some solution in the forum of armbian.com, all kinds of scripts, some can drive the Fan according to the CPU's temperature, or even SSD/HDD's temperature, these are so amazing.  And then when I tried these scripts, I realized these PWM fan scripts won't solve the issue I am facing. bacause the SATA hat is getting heater and heater, while at this time the CPU's temperature remains in 100F, and the fan is not running. so I guess if I can let the fan keep running in full speed, this issue would be solved.

 

then I went to the FriendlyARM's Wiki page, and found they did provide a scrips to change working method of the  FAN, 

 

modify the script /usr/bin/start-rk3399-pwm-fan.sh 

 

#!/bin/bash

echo 0 > /sys/class/pwm/pwmchip1/export
sleep 1
echo 0 > /sys/class/pwm/pwmchip1/pwm0/enable
echo 50000 > /sys/class/pwm/pwmchip1/pwm0/period
echo 1 > /sys/class/pwm/pwmchip1/pwm0/enable
echo 45000 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle

 

I have tried this script in ubuntu, which is an official image "Friendly Core" (a branch of Ubuntu 18.04), it was fine.

When system lights up, the fan will keep running, when system is done, the fan will shut down also.

(before I have try the GPIO with another 5V fan, while in this case, the fan wont shutdown even the system is poweroff )

 

And now my problem is, this script can only run under Ubuntu, how can I make it available in Armbian also?

 

Will be really appreciate to hear any response from you. 

 

Thanks,

J.K.

 

 

 

Link to comment
Share on other sites

So, Armbian's M4V2 images base off both Debian and Ubuntu. Sounds like you're using the Debian version.

 

The good news is that what you're trying to do should be compatible with both, but it might be easier to not use their stuff as-is.

 

The easiest way is to add that bit of bash script to /etc/rc.local and make sure the rc-local service is enabled. That should turn your fan on and leave it going on every boot.

 

$ sudo systemctl enable rc-local
$ sudo systemctl start rc-local

 

The rc-local service exists at least on the Ubuntu version. It should exist on Debian as well. But even if it doesn't it's pretty easy to add it.

 

FYI, that little bit of shell script is enabling the PWM channel to loop every 50000 clocks, remaining high 45000 of those clocks (45000/50000 = 90% power). Note that you shouldn't have to enable the PWM more than once.

Link to comment
Share on other sites

@tparys Thanks for your very good suggestion. I have done as your steps, and was trying to slove the problems.

 

now I have got some progress, after a reboot, the fan will keep running for 5 seconds.. it is much better than before now, at least it moved :ph34r:

 

would you please help to review my steps, and see why the fan is not always running.

 

1. I have modified the /etc/rc.local, and then put the scripts in it. as below:

 

  GNU nano 4.8                                         /etc/rc.local                                                    
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

#!/bin/bash

echo 0 > /sys/class/pwm/pwmchip1/export 
sleep 1 
echo 0 > /sys/class/pwm/pwmchip1/pwm0/enable
echo 50000 > /sys/class/pwm/pwmchip1/pwm0/period
echo 1 > /sys/class/pwm/pwmchip1/pwm0/enable
echo 40000 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle


exit 0

 

 

2. While when I try to start the rc-local.service, it says we need to do some configation.

 


root@nanopim4v2:/lib/systemd/system# nano rc.local.service
root@nanopim4v2:/lib/systemd/system# systemctl enable rc-local.service
The unit files have no installation config (WantedBy=, RequiredBy=, Also=,
Alias= settings in the [Install] section, and DefaultInstance= for template
units). This means they are not meant to be enabled using systemctl.
 
Possible reasons for having this kind of units are:
• A unit may be statically enabled by being symlinked from another unit's
  .wants/ or .requires/ directory.
• A unit's purpose may be to act as a helper for some other unit which has
  a requirement dependency on it.
• A unit may be started when needed via activation (socket, path, timer,
  D-Bus, udev, scripted systemctl call, ...).
• In case of template units, the unit is meant to be enabled with some
  instance name specified.
root@nanopim4v2:/lib/systemd/system# 

 

3. Then I modified the local.service file, as below: 

 

nano /lib/systemd/system/rc.local.service

 

[Unit]
Description=/etc/rc.local Compatibility
ConditionFileIsExecutable=/etc/rc.local
After=network.target

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
Alias=rc-local.service

 

4. And after that, I still cannot enable the re-local.service. the system gave the same information, like what we have seen in Step2. 

Then I try the systemctl status, as below:

 

root@nanopim4v2:~# systemctl status rc-local.service
● rc-local.service - /etc/rc.local Compatibility
     Loaded: loaded (/lib/systemd/system/rc-local.service; enabled-runtime; vendor preset: enabled)
    Drop-In: /usr/lib/systemd/system/rc-local.service.d
             └─debian.conf
     Active: failed (Result: exit-code) since Fri 2021-07-30 05:14:03 +08; 9min ago
       Docs: man:systemd-rc-local-generator(8)

Jul 30 05:14:03 nanopim4v2 systemd[1]: Starting /etc/rc.local Compatibility...
Jul 30 05:14:03 nanopim4v2 rc.local[3751]: /etc/rc.local: 16: echo: echo: I/O error
Jul 30 05:14:03 nanopim4v2 systemd[1]: rc-local.service: Control process exited, code=exited, status=1/FAILURE
Jul 30 05:14:03 nanopim4v2 systemd[1]: rc-local.service: Failed with result 'exit-code'.
Jul 30 05:14:03 nanopim4v2 systemd[1]: Failed to start /etc/rc.local Compatibility.

 

 

Now I got confused.. I dont know where I have done wrong. The success looks very close, but still untouchable for me. 

 

If anyone can give any advice, I will really appreciate.

 

Thanks

JK

 

 

 

 

 

Link to comment
Share on other sites

nanopim4v2 rc.local[3751]: /etc/rc.local: 16: echo: echo: I/O error

 

That's the script error, probably line 16. Not sure why it failed. I don't see anything obviously wrong.

 

Depending, it's possible the kernel is still initializing the PWM device at the time it runs. You can add some print statements like "echo HERE" to you script to confirm where it dies. You can try to add a delay like a "sleep 30" at the start of the script, but that's just a guess. Not sure why you'd be getting an I/O error.

 

It's also possible that there's some kernel version differences between the FriendlyElec build and Armbian's kernel, so that scripting might need some changes.

 

For example, I had to do this to turn on the PWM fan on my M4V2 metal case. You may need to experiment a bit.

 

echo 0 > /sys/class/pwm/pwmchip1/export
echo normal > /sys/class/pwm/pwmchip1/pwm0/polarity
echo 50000 > /sys/class/pwm/pwmchip1/pwm0/period
echo 40000 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle
echo 1 > /sys/class/pwm/pwmchip1/pwm0/enable

 

 

Edit: As a note, my M4V2 had pwm0 set as inverted by default. Your settings of 90% power could be interpreted as 10% instead, and may not be enough for the fan to spin.

Link to comment
Share on other sites

This issue is now finally closed. I try the historic version Armbian of M4V2. 

The tested version is Armbian_21.02.1_Nanopim4v2_bionic_current_5.10.12.img.xz , and now everything works fine.

 

I listed my operation log as below, so that if someone needs it in the future, they can refer to it.

 

Step1. modify the rc.local file:

 

root@nanopim4v2:~# nano /etc/rc.local

 

and paste the commend before "exit 0":

 

bash /usr/bin/start-rk3399-pwm-fan.sh

 

sample: 

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

bash /usr/bin/start-rk3399-pwm-fan.sh

exit 0

 

Step2: build/modify the SH file: 

root@nanopim4v2:~# nano /usr/bin/start-rk3399-pwm-fan.sh

 

Sample:

#!/bin/bash
echo 0 > /sys/class/pwm/pwmchip1/export
sleep 1
echo 0 > /sys/class/pwm/pwmchip1/pwm0/enable
echo 50000 > /sys/class/pwm/pwmchip1/pwm0/period
echo 1 > /sys/class/pwm/pwmchip1/pwm0/enable
echo 45000 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle

 

Step3, modify the re-local.service:


root@nanopim4v2:~# nano /lib/systemd/system/rc-local.service

 

And complete the [Install] part.

 

Sample:

#  SPDX-License-Identifier: LGPL-2.1+
#
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

# This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.local is executable.
[Unit]
Description=/etc/rc.local Compatibility
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.local
After=network.target

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no

[Install]
WantedBy=multi-user.target
Alias=rc-local.service

 

Step4: Set rc.local to be executable

root@nanopim4v2:~# chmod +x /etc/rc.local

 

Step5: complete the others system setting, make it run as a system services.

 

root@nanopim4v2:~# systemctl daemon-reload
root@nanopim4v2:~# systemctl enable rc-local
Created symlink /etc/systemd/system/rc-local.service → /lib/systemd/system/rc-local.service.
Created symlink /etc/systemd/system/multi-user.target.wants/rc-local.service → /lib/systemd/system/rc-local.service.
root@nanopim4v2:~# systemctl start rc-local
root@nanopim4v2:~# systemctl status rc-local.service
● rc-local.service - /etc/rc.local Compatibility
   Loaded: loaded (/lib/systemd/system/rc-local.service; enabled; vendor preset: enabled)
  Drop-In: /lib/systemd/system/rc-local.service.d
           └─debian.conf
   Active: active (exited) since Sun 2021-08-01 05:53:32 UTC; 11min ago
     Docs: man:systemd-rc-local-generator(8)
    Tasks: 0 (limit: 4384)
   CGroup: /system.slice/rc-local.service

Aug 01 05:53:32 nanopim4v2 systemd[1]: Starting /etc/rc.local Compatibility...
Aug 01 05:53:32 nanopim4v2 systemd[1]: Started /etc/rc.local Compatibility.

 

 

Special thanks to Mr. @Tparys for his help, especially when I was most helpless...

 

 

 

 

 

Link to comment
Share on other sites

Later I have flash a new image Armbian_21.05.1_Nanopim4v2_buster_current_5.10.35.img, in this image I can install the Open Media Valut 5.

Till now the fan and the OMV5 all works fine. thanks.

 

Augest 2nd, 2021

JK

 

Link to comment
Share on other sites

Glad you got it working. Though I am curious if there's a kernel or configuration difference between the current RK3399 kernel vs the older one you found to work.

 

FYI. You may want to try and freeze your kernel, or be careful about what updates you pull. You fan may stop working one day, and you might just be putting this issue off until then.

 

Link to comment
Share on other sites

On 8/5/2021 at 9:14 AM, loyalthomas said:

 how to make the Ubutu Scripts useful in Armbian? / to make the fan of nanopi M4V2 SATA hat always running.

 

As mentioned earlier in this thread. Easiest is to add script lines to /etc/rc.local and enable rc-local service via systemctl.

 

I also set this up via thermal management in the linux via DTB overlay. I found it nicer as it kicked in almost as soon as the system turned on.

 

https://forum.armbian.com/topic/17022-automatic-kernel-control-of-nanopi-m4-m4v2-metal-case-fan/

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...

Important Information

Terms of Use - Privacy Policy - Guidelines