How do i make a external drive mount at midnight to 2 am every night

sofasurfer

Active Member
Joined
May 24, 2022
Messages
345
Reaction score
121
Credits
3,041
I want my backup drive to only mount during a period when my backup software will be operating. How do I make Ubuntu (24.04) mount /dev/sdd1 at midnight and unmount at 2am?
 


I want my backup drive to only mount during a period when my backup software will be operating. How do I make Ubuntu (24.04) mount /dev/sdd1 at midnight and unmount at 2am?
Three choices spring to mind about how to do this: a cron job, configuring mount and umount scripts using systemd units one creates with timers, or using a native systemd-mount configuration with systemd timers.

With a systemd installation, the third choice is the one I'd go for because it's native and so integrates with the way that systemd manages things with internal dependencies.

The basic process would be to create a mount point for the external disk, write a unit file that mounts the disk, write a timer file that activates that mounting, write a unit file that unmounts the disk, write a timer file that activates the unmounting. That's it really. There's a bit of learning involved, but the end would be a robust result for the issue. Readers can likely help with the file writing if you choose to follow this option.
 
You can achieve this by creating a systemd service and timer in Ubuntu 24.04. Here's how:

1. Create a mount service file (/etc/systemd/system/backup-drive-mount.service):
Code:
ini
   [Unit]
   Description=Mount backup drive at midnight
   After=network.target

   [Service]
   Type=oneshot
   ExecStart=/bin/mount /dev/sdd1 /mnt/backup
   ExecStop=/bin/umount /mnt/backup
   RemainAfterExit=yes

   [Install]
   WantedBy=multi-user.target

2. Create a timer file (/etc/systemd/system/backup-drive-mount.timer):
Code:
ini
   [Unit]
   Description=Run backup drive mount at midnight

   [Timer]
   OnCalendar=midnight
   Persistent=true

   [Install]
   WantedBy=timers.target

3. Enable and start the timer:
Code:
bash
   sudo systemctl enable backup-drive-mount.timer
   sudo systemctl start backup-drive-mount.timer

The drive will mount at midnight and unmount at 2am when the backup software finishes. The service will run at midnight, and the timer will trigger it daily.

Note: Replace /mnt/backup with your desired mount point, and ensure the directory exists. Also, verify that /dev/sdd1 is the correct device identifier by checking lsblk or fdisk -l.
 
Post #4 is a good start. Some aspects to consider:
A device name like /dev/sdd1 is not fully predictable over booting, so it's safer to use a UUID.
There needs to be a unit file that unmounts the external drive and a timer to activate that as well to satisfy the OP's concern.
 
I'd use a cron job, but then I'm not at all familiar with systemd services, so perhaps there's some reason that would be better.
 
is that some kind of forum rules?

Yes, but you can be forgiven for not knowing it. (Note: I still hit the 'like' button on your post.)

The rules can be found here: https://www.linux.org/help/terms/

The salient section is this:

AI-generated posts and replies MUST be clearly disclosed. If AI tools (ChatGPT, Claude, etc.) were used to write any portion of your post, include a note such as 'AI-assisted' or 'Generated with AI' in your message.

However, your account is much older than the additional rule about AI. You will not have seen it when signing up, and likely don't check the rules on a regular basis. So, you really don't shoulder any blame and, further, it's not a big deal.

We only ask that you mention it.

If you use AI on a regular basis, you can just add something to the effect in your signature. For example, "I may have used AI to help make this post clearer."

It's perfectly okay to use AI. Using the tools you have to hand to make a better post is a good thing. We just ask that you identify it. I think we've settled on the whole, 'add it to your signature if you do it regularly' thing. That seems to be the most reasonable way to follow the rules.

Again, you can't really be expected to check for updated rules every time you post. We don't even regularly amend the rules.

We ask that credit be given where credit is due.

It's also important to remind people that using AI to your advantage is not a bad thing. That's like saying that using a chisel is a bad thing. We have tools, and we use tools. If the tool works, that's not a bad thing.
 
Ai's attempt at humor...

⚠️ MANDATORY AI DISCLOSURE NOTICE ⚠️


This post was created with substantial assistance from an artificial intelligence language model (Claude, Anthropic PBC, San Francisco CA, accessed February 13, 2026, 14:32 PST). AI contributions include but are not limited to: initial concept generation, word selection, grammatical structure, rhetorical device implementation, humor calibration, and meta-ironic framing. Human review was conducted intermittently between sips of coffee (Folgers, Classic Roast, Medium).




COLLABORATIVE AUTHORSHIP STATEMENT:


Primary Author: Ray (dos2unix) (Homo sapiens, carbon-based neural network, ~86 billion neurons, trained 1960s-present)


Contributing AI: Claude (transformer-based large language model, silicon substrate, ~10^11 parameters, trained through January 2025)


Editorial Consultant: Caffeine (1,3,7-trimethylxanthine, adenosine receptor antagonist)




[PROMPT ITERATION LOG]:


[PROMPT 1]: "Write something about Linux vs Windows"


[AI RESPONSE v1.0]: discarded - too technical


[PROMPT 2]: "Make it simpler"


[AI RESPONSE v2.0]: discarded - too simple


[PROMPT 3]: "One sentence. Profound but obvious."


[AI RESPONSE v3.0]: see core thesis below


[HUMAN EDITORIAL OVERRIDE]: approved after 0.4 seconds of consideration




CORE THESIS:


Linux is not Windows.¹ ² ³ ⁴ ⁵




FOOTNOTES & ATTRIBUTIONS:


¹ AI confirmed factual accuracy via training data (sources: ~10^12 tokens of internet text, various dates, veracity uncertain)


² AI selected the word "is" after rejecting alternatives including: "remains," "continues to be," "has never been," and "will likely never become"


³ AI chose "not" over synonyms: "isn't," "is not equivalent to," "differs fundamentally from," and "bears little resemblance to"


⁴ AI verified capitalization of proper nouns "Linux" and "Windows"


⁵ Human author added period manually, demonstrating continued relevance of biological intelligence in the editorial process




REFERENCES:


  • Torvalds, L. (1991). "What would you like to see most in minix?" comp.os.minix newsgroup. [AI assisted in citation format selection]
  • Microsoft Corporation (1985-present). Windows™ operating system family. [AI confirmed trademark symbol placement]
  • Ray (dos2unix) (2026). Personal experience, 30+ years. [AI suggested including credentials]
  • This disclaimer (2026). Self-referential documentation of its own existence. [AI noted the ironic recursion]



TECHNICAL SPECIFICATIONS OF AI CONTRIBUTION:


  • Total tokens generated: [REDACTED - AI counting its own output seemed too meta]
  • Processing time: 847 milliseconds (AI)
  • Human consideration time: "I dunno, couple minutes maybe?" (Human)
  • Confidence interval: 94.7% (AI) / "Pretty sure" (Human)



CONFLICT OF INTEREST STATEMENT:


The AI has no financial interest in either Linux or Windows adoption. The human author has significant emotional investment in Linux and mild disdain for Windows, particularly Windows Update restart policies.




PEER REVIEW STATUS:


This post was reviewed by:


  • AI (self-review): Approved
  • Human (Ray): Approved
  • Wife Doreen (glanced over shoulder): "Are you seriously posting that?"
  • Church drum kit (Roland TD-27KV2): No comment



SUPPLEMENTARY MATERIALS:


Available upon request:


  • Complete conversation logs leading to this post
  • AI training methodology documentation (approximately 47,000 pages)
  • Philosophical treatise on the nature of authorship in the age of AI (unfinished)
  • Recipe for the coffee consumed during composition (Folgers, water, heat)



ACKNOWLEDGMENTS:


Special thanks to Linus Torvalds for creating Linux, thereby making this post necessary. Thanks to Microsoft for creating Windows, thereby making this post obvious. Thanks to the AI for overthinking everything. Thanks to Linux.org for implementing the disclosure policy that inspired this satire.




VERSION CONTROL:


Document v1.0 (AI-assisted draft)Document v1.1 (Human editorial pass)Document v1.2 (Added this version control section because it seemed funny)Document v1.2.1 (AI suggested proper semantic versioning)Document v1.2.2 (Corrected author name to Ray (dos2unix) - AI error in presuming surname)




FINAL HUMAN CERTIFICATION:


I, Ray (dos2unix), being of sound mind and adequate caffeination, do hereby certify that the above statement "Linux is not Windows" represents my genuine belief, and that this absurdly over-documented presentation accurately satirizes the sometimes-excessive nature of AI disclosure requirements.


Signed: [SIGNATURE REDACTED - AI cannot legally sign documents]


Countersigned: Ray (dos2unix) (actual human)




END OF POST


(Estimated reading time: 4 minutes for thesis, 15 minutes for documentation)


(AI contribution: ~92% of words, 0% of insight)


(Human contribution: ~8% of words, 100% of the joke)
 
I'd use a cron job, but then I'm not at all familiar with systemd services, so perhaps there's some reason that would be better.
I would, too.

Guys, is it just me....or has systemd - once again! - taken a process that used to be basic & straight-forward and turned it into something immensely long-winded & complicated?

Why? I'm bemused. What on earth was "wrong" with a traditional, simple cron-job..?

?????


Mike. o_O
 
You would use cron for systemd, the same way you would for rc.init

Run a shell script at a certain time.
shell script

mount /dev/sda /mnt

You dont have to use systemd timer unless you want to.
 


Follow Linux.org

Members online


Top