[GUIDE] How to Install Debian Linux on the My Cloud PR4100 NAS


#22

Ok, its not working - is still shutting down…

i gonne retry it tomorrow again


#23

Okay. Maybe remove the systemd service file for now and make sure there are no reboot requests anymore.
First get it running manually and add the service file later… and remove the shutdown access from sudoers for now.


#24

But how can i run it manually?
If i am booting without the wdhwd.service file

sudo -u wdhwd python3 -m wdhwdaemon.daemon
/usr/bin/python3: Error while finding module specification for 'wdhwdaemon.daemon' (ImportError: No module named 'wdhwdaemon')

in the file temperature.py i found the line

_CORETEMP_FILENAME_BASE = "/sys/class/hwmon/hwmon0/temp{0:d}_{1}"

in daemon.py its asking for the numbers d of CPUs the system has.
in our case this number would be 4 and with (0:4) there would be 5 CPUs

i checked my hwmon directory and for me the cpucore is in hwmon1 (not hwmon0) and the temp* files are from 2 to 5 (so first is temp2_input and so on)
so i changed hwmon0 to hwmon1 and temp(0:d) to temp(2:5)
(hwmon0 name is acpitz and in the folder there is temp1)
or should i leave it like before?

in the daemon.log i get

ERROR - WdHwDaemon: Daemon failed with PMCCommandRejectedException
ERROR - FanControllerImpl: Overheat condition requires immediate shutdown

#25

The {0:d} is just to format the first argument as a digit, see below.

_CORETEMP_FILENAME_BASE = "/sys/class/hwmon/hwmon0/temp{0:d}_{1}"
_CORETEMP_CORE_OFFSET = 2
...
 file_name = _CORETEMP_FILENAME_BASE.format(_CORETEMP_CORE_OFFSET + cpu_index,
                                               value_type)

Indeed, you need to use hwmon1. I see I had disabled CPU temperature monitoring in my setup and just relied on the other sensors. Sorry about that.

I’m now running the non-root systemd config and this diff

root@ptr-eiwxtdwig27a15tzjnm:/usr/local/lib/wdhwd# git diff
diff --git a/wdhwlib/fancontroller.py b/wdhwlib/fancontroller.py
index 896c3e5..7e27aef 100644
--- a/wdhwlib/fancontroller.py
+++ b/wdhwlib/fancontroller.py
@@ -615,6 +615,7 @@ class FanController(FanControllerCallback):
                         level = monitor.level
                         if level is not None:
                             if global_level < level:
+                                _logger.info("ZZZ %s got temp %s lvl %s", monitor._log_name, monitor.temperature, level)
                                 global_level = level
                     
                     fan_speed_change = False
diff --git a/wdhwlib/temperature.py b/wdhwlib/temperature.py
index 9a5d49f..a81b2aa 100644
--- a/wdhwlib/temperature.py
+++ b/wdhwlib/temperature.py
@@ -35,7 +35,7 @@ _logger = logging.getLogger(__name__)
 _CPUINFO_FILENAME = "/proc/cpuinfo"
 _CPUINFO_REGEX_CORES = re.compile(r"^cpu\s+cores.*:\s*([0-9]+)\s*$")
 
-_CORETEMP_FILENAME_BASE = "/sys/class/hwmon/hwmon0/temp{0:d}_{1}"
+_CORETEMP_FILENAME_BASE = "/sys/class/hwmon/hwmon1/temp{0:d}_{1}"
 _CORETEMP_CORE_OFFSET = 2
 _CORETEMP_TYPE_JUNCTION_VALUE = "input"
 _CORETEMP_TYPE_JUNCTION_REGULAR_MAX = "max"
@@ -56,7 +56,7 @@ _SMBUS_MEMORY_SPD_TEMP_ADDRESS = 0x18
 _SMBUS_MEMORY_SPD_TEMP_REG_TEMPERATURE = 5
 
 _HDSMART_COMMAND_BASE = ["/usr/bin/sudo", "-n", "/usr/sbin/hddtemp", "-n", "-u", "C"]
-HDSMART_DISKS = ["/dev/sda", "/dev/sdb"]
+HDSMART_DISKS = ["/dev/sda", "/dev/sdb", "/dev/sdc", "/dev/sdd"]
 _HDSMART_REGEX_TEMPERATURE = re.compile(r"^([0-9]+)[^0-9]*$")

To run the daemon manually, go to the /usr/local/lib/wdhwd directory (or wherever you installed the repo) first.

/usr/local/lib/wdhwd# ls
LICENSE  messagequeue  README.md  scripts  threadedserial  threadedsockets  tlv	tools  wdhwdaemon  wdhwlib
/usr/local/lib/wdhwd# sudo python3 -m wdhwdaemon.daemon

In a separate window check the logs

tailf /var/log/wdhwd/daemon.log

#26

Ok, i changed the stuff back, set the hwmon to 1 and started the deamon by hand with the result:

christian@unassigned-hostname:/usr/local/lib/wdhwd$ sudo python3 -m wdhwdaemon.daemon
2018-07-30 13:39:51,747 - __main__ - ERROR - WdHwDaemon: Daemon failed with PMCCommandRejectedException: ; exiting
Traceback (most recent call last):
  File "/usr/lib/python3.5/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/wdhwd/wdhwdaemon/daemon.py", line 915, in <module>
    ret = d.main(sys.argv)
  File "/usr/local/lib/wdhwd/wdhwdaemon/daemon.py", line 802, in main
    pmc_version = pmc.getVersion()
  File "/usr/local/lib/wdhwd/wdhwlib/wdpmcprotocol.py", line 428, in getVersion
    return self.__processor.transceiveCommand(_PMC_COMMAND_VERSION)
  File "/usr/local/lib/wdhwd/wdhwlib/wdpmcprotocol.py", line 351, in transceiveCommand
    raise PMCCommandRejectedException()
wdhwlib.wdpmcprotocol.PMCCommandRejectedException

And i didnt understood this. i just cloned the files from github, copied to an usb drive and copied to my debian home folder on the nas. the last change/fix was von july 14th - this is what i can see in github.


#27

The daemon starts with a sanity check on the PMC.
It seems like the uart communication is not working yet.
Are you able to run this?

sudo python3
import serial
s = serial.Serial('/dev/ttyS2')
s.write(b'STA\r')     # edit: used to be r'STA\r' ... but it should be bytes, not a regex
s.readline()

And what do you get for this?

sudo stty -g -F /dev/ttyS2                                                                              :(
0:0:cbd:0:3:1c:7f:15:4:0:0:0:11:13:1a:0:12:f:17:16:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0

Regarding git, the version from july is fine.


#28

here the result

>>> s.write(r'STA\r')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 518, in write
    d = to_bytes(data)
  File "/usr/lib/python3/dist-packages/serial/serialutil.py", line 63, in to_bytes
    raise TypeError('unicode strings are not supported, please encode to bytes: {!r}'.format(seq))
TypeError: unicode strings are not supported, please encode to bytes: 'STA\\r'
>>> s.readline()

s.readline() is not responding.
after ctrl+D

>>> s.readline()
^CTraceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/serial/serialposix.py", line 472, in read
    ready, _, _ = select.select([self.fd, self.pipe_abort_read_r], [], [], timeout.time_left())
KeyboardInterrupt
>>> 

for

sudo stty -g -F /dev/ttyS2   

the output is the same

0:0:cbd:0:3:1c:7f:15:4:0:0:0:11:13:1a:0:12:f:17:16:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0

EDIT:
if i put .encode() to the command

>>> s.write(r'STA\r'.encode())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 's' is not defined

#29

oh sorry. I meant b'STA\r'
Oneliner

sudo python3 -c 'import serial; s=serial.Serial("/dev/ttyS2"); s.write(b"STA\r\r"); print(s.readline())'

#30

ok, interesting.
after running the command (even with r instead of b) with the .encode() the daemon is now starting probably.
till now the two shutdown calls are disabled.
i will activate the systemd service again, restart, see if its working and afterwards uncomment the two shutdown calls

EDIT:

result:

christian@unassigned-hostname:~$ sudo python3 -c 'import serial; s=serial.Serial("/dev/ttyS2"); s.write(b"STA\r\r"); print(s.readline())'
b'STA=6c\n'

#31

That looks good. The daemon should work now. You can also query the version (VER) instead of the status (STA). Sometimes the serial connection gets a bit messed up during the debugging and querying the status usually helps. Just make sure you clear the buffer (readline). On a healthy normal boot, everything should be fine, but sending an empty '\r' can always help.

ExecStartPre=/bin/echo -ne 'LN1=Look hot\r' > /dev/ttyS2
ExecStartPre=/bin/echo -ne 'LN2=Stay cool\r' > /dev/ttyS2

#32

i took this two lines from your wdhwd.service file right after you posted your files into my file (and everything else as well)

after two painfull days it is really working now.

thank you so much for your help !!


#33

No problem. Enjoy the box now that it’s fully powered!
I’ll try to update the holes in my guide the coming days with the info we gathered.


#34

My setup is now the PR2100 with 2x 3TB WD RED inside, on sda 32GB for Debian, 10GB swap, and a ~6TB software RAID0 made with mdadm.

using the UART Port is very very helpful


#35

If you’ve got WD reds, you can’t use hdparm to manage disk spindown.
This blog post explains how to setup hd-idle

https://withblue.ink/2016/07/15/what-i-learnt-from-using-wd-red-disks-to-build-a-home-nas.html


#36

Thanks a lot!


#37

Thank you so much for sharing this! I bought a PR4100 because of your post.

I’m super impressed at how you figured all of this out. I’ve been trying to replicate your results with Ubuntu for the last few hours and failing.

Has anyone done this with Ubuntu? It’s not a big deal but I have a slight preference for it over Debian because it comes with ZFS binaries.

BTW I installed a SSD in the first bay for boot using this 2.5" drive adapter: https://www.amazon.com/gp/product/B00H91BXJU/ref=oh_aui_detailpage_o01_s00?ie=UTF8&psc=1


#38

You didn’t say where it fails… what have you done so far?
Preseed config should be the same, so what is the output of

lspci -k -s 00:1e
ls -l /sys/class/tty/*/device/driver
sudo dmesg | grep tty

I’m using zfs on debian with the kernel headers as above and then

apt-get install zfs-dkms zfsutils-linux

#39

I tried using http://archive.ubuntu.com/ubuntu/dists/bionic-updates/main/installer-amd64/current/images/netboot/mini.iso in place of …/debian-cd/current/amd64/iso-cd/debian-9.2.1-amd64-netinst.iso. SSH never came up and I don’t have a UART port cable to diagnose why.

I did install Debian successfully with ZFS, thank you. I found this guide to be helpful: https://unix.stackexchange.com/a/396160/48189


#40

From https://help.ubuntu.com/community/Installation/MinimalCD

mini system in UEFI mode
While the minimal iso image is handy, it isn’t useful for installing on UEFI-based systems that you want to run in UEFI mode. The mini iso lacks the proper files for booting the computer in UEFI mode. Thus, the computer will boot in BIOS compatibility mode, and the installation will be in BIOS mode.

I’d use the ubuntu server iso.


#41

It should be fairly simple to install Ubuntu Server, but the required steps would likey be different from the Debian installation outlined in the OP. The desktop version of Ubuntu won’t work because it’s generally not compiled/configured to run in headless mode without a monitor/keyboard.