Saturday, April 20, 2024
 Popular · Latest · Hot · Upcoming
-1
rated 0 times [  -1] [ 0]  / answers: 1 / hits: 6298  / 2 Years ago, thu, march 10, 2022, 12:17:33

I would like to have my home Ubuntu server automount USB devices.
Currently, I mannually write


sudo mount /dev/sda1 /media/library

However, I tried to write an Upstart script, start-library.conf in /etc/init, but that did not work. Am I doing something wrong? The contents of that file are:


exec sudo mount /dev/sda1 /media/library

I experimented with stanzas as well, such as


script
sudo mount /dev/sda1 /media/library
end script

But that did not work either.
Am I missing something in the Upstart template? Or does it just not work because those usb devices haven't loaded yet at the time this script exectutes? Can I do something about that? specify the runlevel? If so, which one? Etc. Idk.


More From » usb

 Answers
1

I solved my problem by writing a script and executing that script on boot by rc.local:



  1. Script. Change the label "MYUSB" to the label of your usb device.


#!/bin/bash
# FUNCTION: Mount or unmount usb device to library
# ARGUMENTS: none
# AUTHOR: Jeremy Lanssiers
# COPYRIGHT: 2021 GNU
# VERSION: 1.0
# REQUIRES: mount

# Check arguments

if [ -z "$1" ] || [[ ( $1 != "mount" ) && ( $1 != "umount" ) ]]
then
echo "USAGE: [mount/umount] [device]"
exit 1
fi

# Set variables

DEVICE=$(blkid | egrep -o '/dev/(.*): LABEL="MYUSB"')

DEVICE=$(echo $DEVICE | egrep -o '/dev/[a-zA-Z0-9]{1,10}')

LIBRARY=/media/library

# Mount or unmount library

if [ $1 = "mount" ]
then
mount $DEVICE $LIBRARY
exit 0
fi

if [ $1 = "umount" ]
then
umount $DEVICE $LIBRARY
exit 0
fi

exit 1


  1. rc.local


#!/bin/bash
# /etc/rc.local

# FUNCTION: execute scripts at startup
# ARGUMENTS: none
# AUTHOR: [email protected]
# COPYRIGHT: 2021 GNU
# VERSION: 1.0
# REQUIRES: mount

/opt/mount-lib.sh mount

/etc/sysctl.d
/etc/init.d/procps restart

exit 0

[#2081] Friday, March 11, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
girdleas

Total Points: 1
Total Questions: 112
Total Answers: 114

Location: Lesotho
Member since Wed, Jun 2, 2021
3 Years ago
girdleas questions
;