Barebone My Cloud Gen1: Fix sleep/standby problems and more

The latest firmware for Gen 1 My Cloud, 04.05.00-315, almost never goes to sleep (disk standby). And what’s worse, if it ever goes to sleep, it wake-ups in a couple of seconds.

Here is a guide to turn off almost all of it’s services. The drive stays in standby, and transfer rates jumped from 55MB read 40MB write to 100MB read 85MB write.

First, backup your data!!! I take no responsibility if you break your device or/and lose your data!. This guide is for Gen 1 single-bay My Cloud device with firmware 04.05.00-315.

######################
Optional – Fresh Start
######################

Download the latest firmware, and do a manual firmware update (overwrites system files/folders even it’s the same version). After the update do a “system only” restore.

Go to the Dashboard, rename your device, enable SSH and turn off:
– General: Cloud Access: Remote Access
– General: Mac Backups: Time Machine
– Network: Network Services: DHCP (Use static IP)
– Media: DLNA Media Server: Media Streaming
– Media: iTunes: iTunes Server

################
Disable Services
################

SSH to your device and use following commands to turn off most of the services.

# AFP / Netatalk
service netatalk stop
update-rc.d -f netatalk remove

# Assimilates new drives and starts RAIDs
service assimilateNewDrive.sh stop
update-rc.d -f assimilateNewDrive.sh remove

# Creates thumbnails
service wdphotodbmergerd stop
update-rc.d -f wdphotodbmergerd remove

# Some WD service
service wdmcserverd stop
update-rc.d -f wdmcserverd remove

# Some WD service
service restsdk-serverd stop
update-rc.d -f restsdk-serverd remove

# UPnP server
service twonky stop
update-rc.d -f twonky remove

service itunes stop
update-rc.d -f itunes remove

# NFS support
service nfs-common stop
update-rc.d -f nfs-common remove

service nfs-kernel-server stop
update-rc.d -f nfs-kernel-server remove

# RAID
service mdadm stop
update-rc.d -f mdadm remove

service mdadm-raid stop
update-rc.d -f mdadm-raid remove

service mdadm-waitidle stop
update-rc.d -f mdadm-waitidle remove

# Mounts USB devices
service wdAutoMount stop
update-rc.d -f wdAutoMount remove

# USB
service wdnotifierd stop
update-rc.d -f wdnotifierd remove

# UPnP
service upnp_nas stop
update-rc.d -f upnp_nas remove

# Link Layer Topology Discovery
service lltd stop
update-rc.d -f lltd remove

# Stop logs
service rsyslog stop
update-rc.d -f rsyslog remove

service monitorTemperature stop
update-rc.d -f monitorTemperature remove

service openvpn stop
update-rc.d -f openvpn remove

# Windows Domain Accounts for Samba
service winbind stop
update-rc.d -f winbind remove

# Remote Access related - not sure
service onbrdnetloccommd stop
update-rc.d -f onbrdnetloccommd remove

# FTP
service vsftpd stop
update-rc.d -f vsftpd remove

# WDSafe
service nspt stop
update-rc.d -f nspt remove

# Cron
service cron stop
#update-rc.d -f cron remove

service atop stop
#update-rc.d -f atop remove

# Remote Access related - not sure
service commgrd stop
#update-rc.d -f commgrd remove

# These three always come back, we need to disable them
update-rc.d cron disable
update-rc.d atop disable
update-rc.d commgrd disable

Once you remove/disable services, you can check the /etc/rc2.d to see which services are still enabled.

Files that begin with K are run to terminate (kill) a system service. Files that begin with S are run to start a system service. Scripts are always run in ASCII sort order.

########
Cleanup
########

Delete old caches, logs, cronjobs, etc. Once you do this cleanup and restart your device it may take 10-20 mins to boot. It’s led will blink and it’s a normal file system check. If you’re not using it, you can also delete your Public folder now.

rm -rf /CacheVolume/netatalk
rm -rf /CacheVolume/cake
rm -rf /CacheVolume/transcodingcache
rm -rf /CacheVolume/twonkymedia
rm -rf /CacheVolume/upgrade
rm -rf /CacheVolume/WDPROT
rm -rf /CacheVolume/update.log
rm -rf /CacheVolume/orion_cm_enabled

# thumbnails etc.
rm -rf /DataVolume/shares/.wdmc
rm -rf /DataVolume/shares/.wdphotos
rm -rf /DataVolume/backup

# empty init file
rm -rf /etc/rc2.d/S98user-start

# delete cronjobs
rm -rf /etc/cron.d/*
rm -rf /etc/cron.daily/*
rm -rf /etc/cron.hourly/*
rm -rf /etc/cron.monthly/*
rm -rf /etc/cron.weekly/*
>/etc/crontab

# delete logs - don't delete apache log folder!
rm -rf /var/log/atop
rm -rf /var/log/apt
rm -rf /var/log/samba
rm -rf /var/log/vsftpd.log
rm -rf /var/log/mycloud.log
rm -rf /var/log/orion_cm.log
rm -rf /var/log/wd*
rm -rf /var/log/*.1
rm -rf /var/log/*.2
rm -rf /var/log/*.1.gz
rm -rf /var/log/*.2.gz
rm -rf /var/log/version.log
rm -rf /var/log/alternatives.log
rm -rf /var/log/bootstrap.log

###############
Optimize ramlog
###############

edit /etc/default/ramlog

RAMDISKTYPE=0
TMPFS_RAMFS_SIZE=10M
KERNEL_RAMDISK_SIZE=MAX
LOGGING=1
LOGNAME=ramlog
VERBOSE=0

Note: keep logging on, otherwise the service fails.

##############
Optimize Samba
##############

edit /etc/init.d/samba

right before

log_daemon_msg "Starting Samba daemons"

add

mount -t tmpfs -o mode=0700,noatime,nodiratime,size=1m tmpfs /etc/samba/msg.sock/

go to stop section (lines 70-97) and add

umount /etc/samba/msg.sock/

right before

log_end_msg 0

edit /etc/samba/smb-global.conf

[global]
  load printers = no
  printable = no
  #log file = /var/log/samba/log.smbd
  #max log size = 50
  #deadtime = 30
  enable core files = no
  security = user
  encrypt passwords = yes
  passdb backend = smbpasswd:/tmp/smbpasswd  
  create mask = 0775
  force create mode = 0775
  directory mask = 0775
  force directory mode = 0775
  local master = yes
  domain master = no
  preferred master = auto
  os level = 5
  use sendfile = yes
  dns proxy = no
  idmap uid = 10000-65000
  idmap gid = 10000-65000
  admin users =
  null passwords = yes
  map to guest = bad user
  guest account = nobody
  force group = share
  unix extensions = no  
  acl check permissions = false
  browseable = yes
  syslog = 1
  socket options = TCP_NODELAY IPTOS_LOWDELAY SO_RCVBUF=2048000 SO_SNDBUF=2048000
  min receivefile size = 16384
  smb encrypt = disabled
  writeable = yes
  delete veto files = true

  ## Note: be careful when setting "dos filemode=yes".  We have seen where Samba does not 
  ## handle this properly (and crashes) upon a rename of a file where the authenticated user is not the owner.
  ##dos filemode = yes

  max protocol = SMB3
  smb2 leases = yes
  #fruit:copyfile= yes

  #changes
  vfs objects = streams_xattr
  disable netbios = yes
  disable spoolss = yes
  deadtime = 10
  keepalive = 60
  log level = 1
  log file = /dev/null

  #debugging
  #max log size = 10240
  #log level = 10
  #log file = /var/log/samba.log

######################
Optimize mDNSResponder
######################

edit /etc/nas/mDNSResponder.conf

remove second and third configurations (_wd-2go._tcp. & _afp._tcp.) and add

Frost
_smb._tcp. local.
445

(Frost is my device name)

edit /etc/init.d/mDNSResponder and comment out both genMDNSResponderConfig commands (lines 26 & 57)

#genMDNSResponderConfig.sh

##################
Optimize monitorio
##################

edit /usr/local/sbin/monitorio.sh

– removed tally (/usr/local/bin/tally doesn’t even exists)
– removed mediacrawler
– removed individual share size calculation
– disabled rotateLogs (run-parts /etc/nas/wakeup.d)
– mount / noatime,nodiratime
– decrease vm.swappiness
– added afp fix (killall cnid_dbd)
– added sleeptime logging (/var/log/monitorio.log)
– added log truncation

#!/bin/bash
#
# (c) 2013 Western Digital Technologies, Inc. All rights reserved.
#
# monitorio - Monitor disk activity, and put system into standby.  Also, monitor to trigger file tally process
##
PATH=/sbin:/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
. /lib/lsb/init-functions
source /etc/priority.conf
source /usr/local/sbin/data-volume-config_helper.sh
[ -f /usr/local/sbin/ledConfig.sh ] && . /usr/local/sbin/ledConfig.sh
source /etc/system.conf

MIN_SINCE_DISK_ACCESS=/tmp/minutes_since_disk_access

# set idle ionice value
ionice -c 3 -p $$
renice -n $monitorio_nice -p $$

wait_system_ready() {
    while [ ! -f "/tmp/ready" ]; do
        logger -s "$0: waiting for system to become ready.."
        sleep 5
    done
}

declare -i sleepcount
declare -i rootdisk_thresh
declare -i enterStandbyTime=0
rm -f /tmp/standby
source /etc/standby.conf

resetSleepCount() {
	sleepcount=0

	# if in emergency run level, set standby threshold to 1 minute, since drive should go into standby as early as possible, otherwise, read config file
	if [ "`getRunLevel.pl`" == "emergency" ]; then
		standby_time=1
		rootdisk_thresh=1
		standby_enable="enabled"
	else
		source /etc/standby.conf	
		rootdisk_thresh=`expr $standby_time - 1`
	fi
}

currentRootDevice=`cat /proc/cmdline | awk -F= 'BEGIN{RS=" "}{ if ($1=="root") print $2 }'`
rootDisk=`basename ${currentRootDevice}`
dataVolumeDisk=`basename ${dataVolumeDevice}`
drivelist=(`internalDrives`)

echo "0" > ${MIN_SINCE_DISK_ACCESS}

# wait for system to become ready
wait_system_ready

### FIX: set drive noatime
mount -o remount,noatime,nodiratime /dev/root /

### FIX: set swappines
sysctl vm.swappiness=10

### FIX: Stop cron
service cron stop

### FIX: Truncate logs
find /var/log/* -size +1M -type f -exec truncate -s 0 '{}' \;

### FIX: see what process or kernel activity is using the disk
if [ "$1" == "debug" ]; then
echo 1 > /proc/sys/vm/block_dump
fi



while :; do

    for i in ${drivelist[@]}; do
            hdparm -C $i | grep -q "standby"
            standby_test=$?
            [ "$standby_test" -eq "1" ] && break
    done

    if [ "$standby_test" -eq "0" ]; then
		if [ "$1" == "debug" ]; then
		echo "debug: still sleeping"
		fi
        sleep 5
        continue
    else
        if [ -f /tmp/standby ]; then
            currentTime=`date +%s`
            timeInStandby=`expr $currentTime - $enterStandbyTime`
			echo "exit standby $(date) (slept $timeInStandby seconds)"|tee -a /var/log/sleep.log
            rm -f /tmp/standby            
            ### This will allow individual components to register for wakupevents
            ### FIX: dont run rotatelogs each time! run-parts /etc/nas/wakeup.d
			if [ "$1" == "debug" ]; then
			dmesg -c
			echo "---- Samba ----"
			tail /var/log/samba.log
			echo "---- Files Accessed ----"
			find /bin/. /CacheVolume/. /DataVolume/. /dev/. /etc/. /home/. /lib/. /media/. /mnt/. /nfs/. /opt/. /root/. /run/. /sbin/. /srv/. /tmp/. /usr/. /var/. -amin -1
			echo "---- Files Modified ----"
			find /bin/. /CacheVolume/. /DataVolume/. /dev/. /etc/. /home/. /lib/. /media/. /mnt/. /nfs/. /opt/. /root/. /run/. /sbin/. /srv/. /tmp/. /usr/. /var/. -mmin -1
			echo "--------"
			fi
        fi
        # Cancel blue color
        ledCtrl.sh LED_EV_DISK_STBY LED_STAT_OK
		
		resetSleepCount

        echo $sleepcount > ${MIN_SINCE_DISK_ACCESS}
        iow_root=`awk -v disk="${rootDisk}" '{if ($3==disk) print $10}' /proc/diskstats`
        ior_datavol=`awk -v disk="${dataVolumeDisk}" '{if ($3==disk) print $6}' /proc/diskstats`
        iow_datavol=`awk -v disk="${dataVolumeDisk}" '{if ($3==disk) print $10}' /proc/diskstats`



        while :; do
            # Wait for 60 seconds
            sleep 60
			if [ "$1" == "debug" ]; then
			echo "debug: check disk activity"
			fi

            iow_root2=`awk -v disk="${rootDisk}" '{if ($3==disk) print $10}' /proc/diskstats`
            ior_datavol2=`awk -v disk="${dataVolumeDisk}" '{if ($3==disk) print $6}' /proc/diskstats`
            iow_datavol2=`awk -v disk="${dataVolumeDisk}" '{if ($3==disk) print $10}' /proc/diskstats`
	
            # use data volume writes until near sleep threshold, then check all disk writes
            old_sleepcount=sleepcount
            if [ $((sleepcount)) -eq $((rootdisk_thresh)) ] && [ "$iow_root" -eq "$iow_root2" ]; then
                sleepcount=$((sleepcount+1))
            elif  [ $((sleepcount)) -lt $((rootdisk_thresh)) ] && [ "$ior_datavol" -eq "$ior_datavol2" ] && [ "$iow_datavol" -eq "$iow_datavol2" ]; then
                sleepcount=$((sleepcount+1))
            else
                resetSleepCount
            fi
            echo $sleepcount > ${MIN_SINCE_DISK_ACCESS}


				if [ "$1" == "debug" ]; then
                [ "$sleepcount" != "0" ] &&  echo "sleepcount: $sleepcount"
                [ "$sleepcount" == "0" ] && echo "Disk activity:"
                echo "... ior_datavol=$ior_datavol      ior_datavol2=$ior_datavol2"
                echo "... iow_datavol=$iow_datavol      iow_datavol2=$iow_datavol2"
                echo "... iow_root=$iow_root    iow_root2=$iow_root2"
				fi



            ior_datavol=$ior_datavol2
            iow_datavol=$iow_datavol2
            iow_root=$iow_root2
            
            smartTestStatus=`getSmartTestStatus.sh | awk '{print $1}'`
            if [ "$standby_enable" == "enabled" ] && [ "$sleepcount" -eq "$standby_time" ] && [ "$smartTestStatus" != "inprogress" ]; then
                touch /tmp/standby
                enterStandbyTime=`date +%s`
				echo "enter standby $(date)"|tee -a /var/log/sleep.log
				### FIX: kill cnid_dbd to prevent every half hour spinup
				#killall cnid_dbd
				sync
				sync
				sync
				dmesg -c > /dev/null
                # turn on solid blue if applicable
                ledCtrl.sh LED_EV_DISK_STBY LED_STAT_IN_PROG
                sleep 15
                for i in ${drivelist[@]}; do
                        hdparm -y $i >/dev/null
                done
                break
            fi
        done
    fi
done

you can also stop the monitorio service and run it from terminal to get more debugging information

service monitorio stop
monitorio.sh debug

Bonus: txt files to copy & paste codes

Most of the credit goes to Bennor, rac8006, and Ralphael at WD Community Forums.

Leave a Reply

Your email address will not be published. Required fields are marked *