Skip to content
View in the app

A better way to browse. Learn more.

Unraid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

how do you spin up array from the command line the mdcmd doesnt work

Featured Replies

so i trying to make the array keep spun up between 9am to 9pm and then after that 15 min spin down i got the crontab settings

but when i google how to do the code it doesnt work

ive tried this

root@Tardis:~# /root/mdcmd spinup disk1

bash: /root/mdcmd: No such file or directory

root@Tardis:~# mdcmd

usage: mdcmd <command> [arg ... ]

root@Tardis:~# mdcmd spinup disk1

/usr/local/sbin/mdcmd: line 35: echo: write error: Invalid argument

root@Tardis:~# sudo mdcmd spinup disk1

/usr/local/sbin/mdcmd: line 35: echo: write error: Invalid argument

root@Tardis:~# for disknum in ls /dev/md* | sed "sX/dev/mdXX"; do /root/mdcmd spinup $disknum; done

bash: /root/mdcmd: No such file or directory

bash: /root/mdcmd: No such file or directory

bash: /root/mdcmd: No such file or directory

bash: /root/mdcmd: No such file or directory

bash: /root/mdcmd: No such file or directory

bash: /root/mdcmd: No such file or directory

bash: /root/mdcmd: No such file or directory

root@Tardis:~# for disknum in ls /dev/md* | sed "sX/dev/mdXX"; do mdcmd spinup $disknum; done

/usr/local/sbin/mdcmd: line 35: echo: write error: Invalid argument

/usr/local/sbin/mdcmd: line 35: echo: write error: Invalid argument

/usr/local/sbin/mdcmd: line 35: echo: write error: Invalid argument

/usr/local/sbin/mdcmd: line 35: echo: write error: Invalid argument

/usr/local/sbin/mdcmd: line 35: echo: write error: Invalid argument

/usr/local/sbin/mdcmd: line 35: echo: write error: Invalid argument

/usr/local/sbin/mdcmd: line 35: echo: write error: Invalid argument

root@Tardis:~# ^C

so not sure how you make it work

  • Community Expert
  • Community Expert

alot worng here and using bad AI and comands to do this...

I can help make a stop start scirpt at time..

#!/usr/bin/env bash
set -euo pipefail

#########################################
# CONFIGURATION
#########################################
# Time window for stopping/starting
STOP_TIME="21:10"   # 9:10 PM
START_TIME="08:50"  # 8:50 AM

# Log file for status tracking
LOG_FILE="/var/log/unraid-array-scheduler.log"

#########################################
# INTERNALS
#########################################
CURRENT_TIME=$(date +%H:%M)
CSRF=$(grep -Po '^csrf_token="\K[^"]+' /var/local/emhttp/var.ini || true)
COOKIE=/tmp/unraid.cookies

log() {
  echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*" | tee -a "$LOG_FILE"
}

stop_array() {
  log "Stopping array..."
  curl -sS -k --fail -e "http://localhost/Main" \
    -c "$COOKIE" -b "$COOKIE" \
    --data "startState=STARTED&file=&csrf_token=${CSRF}&cmdStop=Stop" \
    http://localhost/update.htm \
  || curl -sS -k --fail -e "https://localhost/Main" \
    -c "$COOKIE" -b "$COOKIE" \
    --data "startState=STARTED&file=&csrf_token=${CSRF}&cmdStop=Stop" \
    https://localhost/update.htm
  sleep 5
  grep -E '^(mdState|fsState)=' /var/local/emhttp/var.ini | tee -a "$LOG_FILE"
}

start_array() {
  log "Starting array..."
  curl -sS -k --fail -e "http://localhost/Main" \
    -c "$COOKIE" -b "$COOKIE" \
    --data "startState=STOPPED&file=&csrf_token=${CSRF}&cmdStart=Start" \
    http://localhost/update.htm \
  || curl -sS -k --fail -e "https://localhost/Main" \
    -c "$COOKIE" -b "$COOKIE" \
    --data "startState=STOPPED&file=&csrf_token=${CSRF}&cmdStart=Start" \
    https://localhost/update.htm
  sleep 5
  grep -E '^(mdState|fsState)=' /var/local/emhttp/var.ini | tee -a "$LOG_FILE"
}

current_state() {
  grep -Po '^mdState="\K[^"]+' /var/local/emhttp/var.ini 2>/dev/null || echo "UNKNOWN"
}

#########################################
# MAIN LOGIC
#########################################
STATE=$(current_state)
log "Current time: $CURRENT_TIME | Array state: $STATE"

if [[ "$CURRENT_TIME" == "$STOP_TIME" ]]; then
  if [[ "$STATE" == "STARTED" ]]; then
    stop_array
  else
    log "Array already stopped. No action needed."
  fi
elif [[ "$CURRENT_TIME" == "$START_TIME" ]]; then
  if [[ "$STATE" == "STOPPED" ]]; then
    start_array
  else
    log "Array already started. No action needed."
  fi
else
  log "No action scheduled for $CURRENT_TIME."
fi

Cron every 30 min to run and check...
*/30 * * * *
some other plugins for spin down and other are needed... as stopping the array kills vms, docker s etc...

but if something running like a database or other task the disk will not spin down...

Edited by bmartino1

  • Author

@bmartino1 so i looked at the link that is just for stop and starting the array but thats not what i want

what i trying to do is keep the array disks always spun up and not go to standby mode.

sorry if my dislexia screwed things up in my orginal post i was saying i wanna keep the array disks spun up between 9am to 9pm after that it can go into standby mode after 15 min

and that i already got the crontab to run every 10 min between 9 to 9

  • Author

so like

/root/mdcmd spinup disk1

should make disk 1 spin up but doesnt

and this line

for disknum in ls /dev/md* | sed "sX/dev/mdXX"; do /root/mdcmd spinup $disknum; done

supposed to spin up all the drives from standby but it complains about the mdcmd

  • Community Expert
1 minute ago, comet424 said:

@bmartino1 so i looked at the link that is just for stop and starting the array but thats not what i want

what i trying to do is keep the array disks always spun up and not go to standby mode.

sorry if my dislexia screwed things up in my orginal post i was saying i wanna keep the array disks spun up between 9am to 9pm after that it can go into standby mode after 15 min

and that i already got the crontab to run every 10 min between 9 to 9

understood, thsi coudl still be adapted as standby/sleep states.

esentail we still want a array stop start durring the time. and introduce a sleep comand and when on to start the array..

untested code as I don't nomalry hit nor use the spin up spin down buttons...



#!/usr/bin/env bash
set -euo pipefail

#########################################
# CONFIGURATION
#########################################
# Active spin-up window (24-hour format)
START_HOUR=9     # 9 AM
STOP_HOUR=21     # 9 PM

# Log file
LOG_FILE="/var/log/unraid-keep-spunup.log"

#########################################
# INTERNALS
#########################################
HOUR=$(date +%H)
CSRF=$(grep -Po '^csrf_token="\K[^"]+' /var/local/emhttp/var.ini || true)
COOKIE=/tmp/unraid.cookies

log() {
  echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*" | tee -a "$LOG_FILE"
}

spin_up_all() {
  log "Spinning up all array disks..."
  curl -sS -k --fail -e "http://localhost/Main" \
    -c "$COOKIE" -b "$COOKIE" \
    --data "csrf_token=${CSRF}&cmdSpinupAll=Spinup" \
    http://localhost/update.htm \
  || curl -sS -k --fail -e "https://localhost/Main" \
    -c "$COOKIE" -b "$COOKIE" \
    --data "csrf_token=${CSRF}&cmdSpinupAll=Spinup" \
    https://localhost/update.htm
}

#########################################
# MAIN LOGIC
#########################################
if (( HOUR >= START_HOUR && HOUR < STOP_HOUR )); then
  spin_up_all
else
  log "Outside active window (array may spindown normally)."
fi

I belve this is what you want regardign to spin up of the disk only...

In the User Scripts plugin, schedule it for:

*/10 9-21 * * *

→ runs every 10 minutes between 9 AM and 9 PM.

  • Author

k that code doesnt work i copy and pasted the line

root@Tardis:~# log "Spinning up all array disks..."

curl -sS -k --fail -e "http://localhost/Main" \

-c "$COOKIE" -b "$COOKIE" \

--data "csrf_token=${CSRF}&cmdSpinupAll=Spinup" \

http://localhost/update.htm \

|| curl -sS -k --fail -e "https://localhost/Main" \

-c "$COOKIE" -b "$COOKIE" \

--data "csrf_token=${CSRF}&cmdSpinupAll=Spinup" \

https://localhost/update.htm

bash: log: command not found

curl: option -c: blank argument where content is expected

curl: try 'curl --help' or 'curl --manual' for more information

curl: option -c: blank argument where content is expected

curl: try 'curl --help' or 'curl --manual' for more information

root@Tardis:~# curl -sS -k --fail -e "http://localhost/Main" -c "$COOKIE" -b "$COOKIE" --data "csrf_token=${CSRF}&cmdSpinupAll=Spinup" http://localhost/update.htm || curl -sS -k --fail -e "https://localhost/Main" -c "$COOKIE" -b "$COOKIE" --data "csrf_token=${CSRF}&cmdSpinupAll=Spinup" https://localhost/update.htm

curl: option -c: blank argument where content is expected

curl: try 'curl --help' or 'curl --manual' for more information

curl: option -c: blank argument where content is expected

curl: try 'curl --help' or 'curl --manual' for more information

root@Tardis:~#

  • Author

but i guess its gotta be in the script to run so ill try a copy and paste in a script

  • Community Expert

I need to think more on that as I nromal aviod and turn off sleep states as if the machien is going to do the task budget and set it up to be 24/7

from runnign or using sleep states and to other disk activity. I'm not quite sure how to aproch this even form the termal runnign spin up and down comands as this can hurt active didsk doing tasks... I need to re reveiwe the urniad dos on spin up and down...
https://forums.unraid.net/topic/129313-how-do-i-automate-spinning-down-specific-disks/


I also think this may be semi in the web UI with disk settings...

  • Author

@bmartino1

supposedly from the google AI search

you just type

for disknum in ls /dev/md* | sed "sX/dev/mdXX"; do /root/mdcmd spinup $disknum; done

and that spins up the array of all the disks but it doesnt like the mdcmd

  • Community Expert

as I'm using a ZFS SYSTEM.. I have no disk 1 to test this should be the comand to spin down disk 1 as if you hit the spin down

#!/usr/bin/env bash

set -euo pipefail

CSRF=$(grep -Po '^csrf_token="\K[^"]+' /var/local/emhttp/var.ini)

COOKIE=/tmp/unraid.cookies

curl -sS -k --fail -e "http://localhost/Main" \

-c "$COOKIE" -b "$COOKIE" \

--data "csrf_token=${CSRF}&cmdSpindown=disk1" \

http://localhost/update.htm \

|| \

curl -sS -k --fail -e "https://localhost/Main" \

-c "$COOKIE" -b "$COOKIE" \

--data "csrf_token=${CSRF}&cmdSpindown=disk1" \

https://localhost/update.htm

  • Community Expert
Just now, comet424 said:

@bmartino1

supposedly from the google AI search

you just type

for disknum in ls /dev/md* | sed "sX/dev/mdXX"; do /root/mdcmd spinup $disknum; done

and that spins up the array of all the disks but it doesnt like the mdcmd

is bad old data in v6 that never worked ... the mdctl is form debain mdadm stuff that unraid donw't use to make its software raid. unraid uses scritps taht run under the emhttp and slackware system vars to make the array parity and other software raid. that would be a good quick data to try with debain not unraid slackware

  • Author

ill try that what i currently have

/root/mdcmd spinup disk1

/root/mdcmd spinup disk2

/root/mdcmd spinup disk3

/root/mdcmd spinup disk4

/root/mdcmd spinup disk5

/root/mdcmd spinup disk6

/root/mdcmd spinup disk7

but that doesnt work

  • Author

ah ok.. so these commands are obsolete then..

ill try your code there

  • Author

so it didnt like that code

Script location: /tmp/user.scripts/tmpScripts/Keep Hard Drives Spun Up/script
Note that closing this window will abort the execution of this script
curl: (2) no URL specified
curl: try 'curl --help' or 'curl --manual' for more information

  • Community Expert

@comet424 The ‘mdcmd’ command that is in Unraid is a custom version and not the standard Linux variant so you cannot assume it works like it would on other Linux systems.

  • Author

@itimpi i wouldnt know i googled how to keep array disks spun up in unraid command line

and the google AI spit out those commands for unraid..

but since didnt work thats why i figured id ask here how to do it

Edited by comet424

  • Community Expert

apologies as I'm at a trail and error at this point with code scripting...

try to spin them all down...
one copy paste...


#!/usr/bin/env bash

set -euo pipefail

CSRF=$(grep -Po '^csrf_token="\K[^"]+' /var/local/emhttp/var.ini)

COOKIE=/tmp/unraid.cookies

# Try HTTP first, then HTTPS

curl -sS -k --fail -e "http://localhost/Main" \

-c "$COOKIE" -b "$COOKIE" \

--data "csrf_token=${CSRF}&cmdSpindownAll=Spindown" \

http://localhost/update.htm \

|| \

curl -sS -k --fail -e "https://localhost/Main" \

-c "$COOKIE" -b "$COOKIE" \

--data "csrf_token=${CSRF}&cmdSpindownAll=Spindown" \

https://localhost/update.htm


Behavior

  • Tells Unraid’s emhttpd backend to issue spindown commands to every array + pool disk.

  • Exactly mirrors the “Spin Down All” button on the Main page.

  • Safe to run any time — it won’t stop the array or unmount anything.

You can schedule this with cron or the User Scripts plugin for after-hours power saving.

I remember other termianl comands that afected spin up and down via termanl but untests and lost onth forum. Sorry I can't be of much help...
as I would have to go thoguht the unraid githbu web ui and try to find the coamnd they run adn add it to the data line of this script to do what it would do as if you hit the button inthe main page...

urnaid web ui github
https://github.com/unraid/webgui/blob/master/emhttp/plugins/dynamix/Main.page

GitHub
No image preview

webgui/emhttp/plugins/dynamix/scripts at master · unraid/...

Unraid Web UI. Contribute to unraid/webgui development by creating an account on GitHub.

either that or a higher dev/mod may know...


  • Author

@bmartino1 ya that code didnt help either 

Script location: /tmp/user.scripts/tmpScripts/Keep Hard Drives Spun Up/script
Note that closing this window will abort the execution of this script
curl: (2) no URL specified
curl: try 'curl --help' or 'curl --manual' for more information

ok ill check out that link

  • Author

@bmartino1 that link didnt help either  just only shows about clicking the circles 

but i appreciate your help.. i also going to try google more someone has had to solve this issue 

  • Author

and ive tried also the 

hdparm -y /dev/sdb

but it didnt like that command either

  • Author

just running 

hdparm       

it doesnt even have an option to spin up a drive   

the -y  puts the drive in standby mode

google ai  is nice  but sometimes crap lol

  • Community Expert

hdparm -y /dev/sd{b,c,d,e,g,h}

etc is a Hard dis parameter taht is lower level then what urnaid spin up and spin down does...

that won't reflecet itn eh web ui as well and require hdparm to wake up sometimes.

even if the comand worked to

what makes this smei hard is finding what uraid calls the comadns now...

Unraid ≥ 6.12 uses this format for the GUI “Spin Down All” and “Spin Up All” buttons:

Action

POST field

Comment

Spin down all

cmdSpinDownAll=SpinDownAll

note the capital D and A

Spin up all

cmdSpinUpAll=SpinUpAll

same pattern

I'm not finding the odler form data on spin down spin up as well.

  • Community Expert

so i would go to settings > disk settings and let teh disk go into a spun down state when they are idle for 15 min.. this mean no dockers, no file copy no disk activty and they will spin down..

image.png

you may want to enable spin groups and setup spin groups
image.png

I rember a feature chat from the dev checking if people used theses... so they kept it as this would be ther only other area that I can think of that can edite or messs with spin up spin down...

Edited by bmartino1

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...

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.