jarrodr
Posts: 19
Joined: Tue Jun 19, 2012 4:55 pm
Location: South Africa

Writing a startup script

Mon Nov 25, 2013 8:04 pm

Hi guys,

I'm a total noob to Linux. How can I write a simple startup script to mount my USB HDD?
I have the command to mount the HDD, but I want it to execute on boot time.

sudo mount -t auto /dev/sda5 /media/USBHDD1

NotBlaine
Posts: 3
Joined: Mon Nov 25, 2013 7:26 pm

Re: Writing a startup script

Mon Nov 25, 2013 8:18 pm

It's not terribly hard.

There is a folder. You can get there by typing the following:

Code: Select all

cd /etc/init.d
In there are all the scripts that run when the computer starts.

If you're like me and can never remember the proper formating on the scripts, just google it.

Make a script file:

Code: Select all

sudo nano myMountScript.sh

Code: Select all

#!/bin/bash
sudo mount -t auto /dev/sda5 /media/USBHDD1
Close, save, make it executable.

Code: Select all

sudo chmod +x myMountScript.sh
Unless that doesn't work, because I didn't google proper shell script format... I'm usually doing python scripts.

**edit, forgot to 'sudo' before I 'nano'd...**
Last edited by NotBlaine on Tue Nov 26, 2013 2:21 pm, edited 1 time in total.

User avatar
JRV
Posts: 270
Joined: Mon Apr 02, 2012 1:39 pm
Location: Minneapolis, MN

Re: Writing a startup script

Mon Nov 25, 2013 8:32 pm

If you do it by editing /etc/fstab you won't have to enter the password to sudo each time:

How to edit /etc/fstab:
http://www.brighthub.com/computing/linu ... 13750.aspx

jarrodr
Posts: 19
Joined: Tue Jun 19, 2012 4:55 pm
Location: South Africa

Re: Writing a startup script

Sun Dec 01, 2013 4:08 pm

Thanks guys.

@JRV: I've tried the fstab and it doesn't seem to mount the folder.

@ NotBlaine: Thanks, used your method and it worked.

#!/bin/bash
#umount the HDD and mount to folder
sudo umount /dev/sda5
sudo mount -t auto /dev/sda5 /media/USBHDD1
#update SABnzbd config to point to correct folders
sed -i 's:download_dir = Downloads/incomplete:download_dir = /media/USBHDD1/Dow$
sed -i 's:nzb_backup_dir = "":nzb_backup_dir = /media/USBHDD1/Downloads/SABnzbd$
#for the above change to take place
sudo service sabnzbdplus restart

Return to “Raspberry Pi OS”