original post: http://geeks.noeit.com/mount-an-smb-network-drive-on-raspberry-pi/
In this tutorial we will describe how to connect your Raspberry Pi to a network drive and permanently mount it to your system. Even though this article uses a Raspberry Pi as an example to connect to an SMB drive, the steps used can be applied to any Debian based system, such as Ubuntu.
If you have a Raspberry Pi you might have noticed that the storage possibilities are kind of limited unless you have some external storage. Even though you can get SD cards with 64+gb of storage, you probably want more if you have a lot of music and movies that you are streaming through your Pi.
There are several choices when it comes to storage for your Pi, such as network drives, flash drives, or external USB HDDs. Using a network drive you can not only access your files from the Pi, but from any computer connected to your network, which is very convenient.
Prerequisites
Before we start, I will assume you already
have a network drive connected to your LAN, and
know its LAN IP address
Note: remember to change all text in red to your own values.
Installation
In order to mount the drive, you need to have cifs-utils installed on your system. If you are running a newer version of Raspbian or RaspBMC you should already have this installed. You can check whether it is installed or not by running the following command:
dpkg -s cifs-utils
If it is installed, it should output something like this:
If it says that it’s not installed, you need to install it:
sudo apt-get install cifs-utils
Mounting unprotected (guest) network folders
You might have public folders on your network drive that can be accessed by anyone without having to provide any credentials. These are mounted in the same way as password-protected folders (we will mount these in the next section), but with a few different options.
First, let’s create a directory on the Pi where we want to mount the directory. You will need a separate directory for each network folder that you want to mount. I will create the folders in the /media folder:
sudo mkdir -p /media/networkshare/public
Then edit your /etc/fstab file (with root privileges) and add this line:
The first part is the IP of your network drive, and the public folder you want to mount.
The second part is the folder on your local machine where you want to mount the network share.
The third part indicates what type of drive you want to mount (cifs).
The last part is the set of options you can pass, and here’s an explanation of the ones we are using:
guest is basically telling the network drive that it’s a public share, and you don’t need a password to access it (not to confuse with username),
uid=1000 makes the Pi user with this id the owner of the mounted share, allowing them to rename files,
gid=1000 is the same as uid but for the user’s group,
iocharset=utf8 allows access to files with names in non-English languages.
Note: If there is any space in the server path, you need to replace it by \040, for example //192.168.0.18/My\040Documents
To find the uid and gid for your username, use the following command:
id username
Now that we have added this to our /etc/fstab, we need to (re)mount all entries listed in /etc/fstab:
sudo mount -a
Now you can access your network drive from /media/networkshare/public (or wherever you chose to mount it).
Mount password-protected network folders
Mounting a password-protected share is very similar to mounting a public ones, with some minor changes to the options we pass. Let’s start by making a new folder where we want to mount the password-protected share:
sudo mkdir -p /media/networkshare/protected
Again, open /etc/fstab (with root privileges), and add this line:
While this is a perfectly valid way of mounting your protected folder, it’s not very secure. Since /etc/fstab is readable by everyone, so are your credentials in it. So, let’s make it more secure by using a credentials file. This file will contain nothing else but your username and password, but we will make readable only to you. This way, other users on the system won’t be able to see your credentials.
Using a text editor, create a file that will contain the credentials for your protected network share:
vim ~/.smbcredentials
Enter your username and password for the protected share in the file:
username=msusername
password=mspassword
Save the file.
Change the permissions of the file to make sure only you can read it:
chmod 600 ~/.smbcredentials
Then edit your /etc/fstab file and change the line where we are mounting the protected share to look like this:
source:
http://php.net/manual/en/ref.sockets.php
http://www.rkrishardy.com/2009/12/permission-denied-13-when-opening-socket-in-php-apache/
<?php
/**
* Wake-on-LAN
*
* @return boolean
* TRUE: Socked was created successfully and the message has been sent.
* FALSE: Something went wrong
*
* @param string|array $mac You will WAKE-UP this WOL-enabled computer, you
* need to add the MAC-address here. Mac can be
* array too.
*
* @param string|array $addr You will send and broadcast to this address.
* Normally you need to use the 255.255.255.255
* address, so I made it as the default. You don't need to do anything with this.
*
* If you get permission denied errors when using
* 255.255.255.255 have permission denied problems
* you can set $addr = false to get the broadcast
* address from the network interface using the
* ifconfig command.
*
* $addr can be array with broadcast IP values
*
* Example 1:
* When the message has been sent you will see the message "Done...."
* if ( wake_on_lan('00:00:00:00:00:00'))
* echo 'Done...';
* else
* echo 'Error while sending';
*/
function wake_on_lan($mac, $addr=false, $port=7) {
if ($addr === false){
exec("ifconfig | grep Bcast | cut -d \":\" -f 3 | cut -d \" \" -f 1",$addr);
$addr=array_flip(array_flip($addr));
}
if(is_array($addr)){
$last_ret = false;
for ($i = 0; $i < count($addr); $i++)
if ($addr[$i] !== false) {
$last_ret = wake_on_lan($mac, $addr[$i], $port);
}
return $last_ret;
}
if (is_array($mac)){
$ret = array();
foreach($mac as $k =< $v)
$ret[$k] = wake_on_lan($v, $addr, $port);
return $ret;
}
//Check if it's an real MAC-address and split it into an array
$mac = strtoupper($mac);
if (!preg_match("/([A-F0-9]{1,2}[-:]){5}[A-F0-9]{1,2}/", $mac, $maccheck))
return false;
$addr_byte = preg_split("/[-:]/", $maccheck[0]);
//Creating hardware adress
$hw_addr = '';
for ($a = 0; $a < 6; $a++)//Changing mac adres from HEXEDECIMAL to DECIMAL
$hw_addr .= chr(hexdec($addr_byte[$a]));
//Create package data
$msg = str_repeat(chr(255),6);
for ($a = 1; $a <= 16; $a++)
$msg .= $hw_addr;
//Sending data
if (function_exists('socket_create')){
//socket_create exists
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); //Can create the socket
if ($sock){
$sock_data = socket_set_option($sock, SOL_SOCKET, SO_BROADCAST, 1); //Set
if ($sock_data){
$sock_data = socket_sendto($sock, $msg, strlen($msg), 0, $addr,$port); //Send data
if ($sock_data){
socket_close($sock); //Close socket
unset($sock);
return true;
}
}
}
@socket_close($sock);
unset($sock);
}
$sock=fsockopen("udp://" . $addr, $port);
if($sock){
$ret=fwrite($sock,$msg);
fclose($sock);
}
if($ret)
return true;
return false;
}
if (@wake_on_lan('00:00:00:00:00:00')) {
echo 'Done...';
} else {
echo 'Error while sending';
}
?>
I am trying to play videos automatically when the Raspberry Pi boots. I decided to use crontab for that:
@reboot /storage/.config/autostart.sh
The autostart.sh file contains the following code:
xbmc-send -a “PlayMedia(/storage/videos/)”
The Raspberry Pi successfully automatically starts to play videos from /storage/videos/ directory when it reboots.
Hope that helps.
This is like asking “How do I fix my car when it won’t start?” Your question is way to broad to answer. The process will remain basically the same form case to case. Here are some steps that you can go through to figure this out.
GOOGLE
Using Terminal, shell, SSH, etc., figure out the command that will start the video as desired.
Update April 2014: The browser debugger is now integrated in the “Browser Toolbox” and you no longer need to set about:config prefs. Just use the developer tools configuration/settings panel: “enable chrome debugging” and “enable remote debugging”. The “Browser Toolbox” will then be available in the developer tools panel.
Chromebug has not worked for me for many months. I think it’s just been silently abandoned but thankfully on Firefox 19 or later, it’s possible to use the built-in JS debugger on the browser itself. Go to about:config and set the following two prefs:
If possible, I’d suggest using Aurora for your debugging because the built-in debugger was a little limited when first launched and keeps getting better with every release.
pn532_SPI.setDataMode(SPI_MODE0);
pn532_SPI.setBitOrder(LSBFIRST);
/*Set the SPI frequency to be one sixteenth of the
frequency of the system clock*/
pn532_SPI.setClockDivider(SPI_CLOCK_DIV16);
uint32_t versiondata = nfc.getFirmwareVersion();
if (! versiondata) {
#ifdef NFC_DEMO_DEBUG
Serial.print(“Didn’t find PN53x board”);
#endif
//while (1); // halt
return;
// skip NFC, continue other step without NFC
}
#ifdef NFC_DEMO_DEBUG
// Got ok data, print it out!
Serial.print(“Found chip PN5”);
Serial.println((versiondata>>24) & 0xFF, HEX);
Serial.print(“Firmware ver. “);
Serial.print((versiondata>>16) & 0xFF, DEC);
Serial.print(‘.’);
Serial.println((versiondata>>8) & 0xFF, DEC);
Serial.print(“Supports “);
Serial.println(versiondata & 0xFF, HEX);
#endif
// configure board to read RFID tags and cards
nfc.SAMConfig();
}
void NFCReading()
{
uint32_t id;
// look for MiFare type cards
id = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A);
if (id != 0) {
#ifdef NFC_DEMO_DEBUG
Serial.print(“Read card #”);
Serial.println(id);
#endif
}
}
void WebPrint(EthernetClient client)
{
if (client) {
// an http request ends with a blank line
boolean current_line_is_blank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if we’ve gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so we can send a reply
if (c == ‘\n’ && current_line_is_blank) {
// send a standard http response header
client.println(“HTTP/1.1 200 OK”);
client.println(“Content-Type: text/html”);
client.println();
// output the value of each analog input pin
client.print(“welcome to tinyos”);
client.println(“<br />”);
client.print(“//*************************************”);
client.println(“<br />”);
client.print(“www.tinyos.net.cn”);
client.println(“<br />”);
client.print(“//*************************************”);
client.println(“<br />”);
for (int i = 0; i < 6; i++) {
client.print(“analog input “);
client.print(i);
client.print(” is “);
client.print(analogRead(i));
client.println(“<br />”);
}
break;
}
if (c == ‘\n’) {
// we’re starting a new line
current_line_is_blank = true;
} else if (c != ‘\r’) {
// we’ve gotten a character on the current line
current_line_is_blank = false;
}
}
}
client.stop();
}
}
#define ETH_SS 10
#define NFC_SS 5
void enablePN() {
digitalWrite(ETH_SS, HIGH);
digitalWrite(NFC_SS, LOW);
SPI.setDataMode(SPI_MODE0);
SPI.setBitOrder(LSBFIRST);
SPI.setClockDivider(SPI_CLOCK_DIV16);
delay(10);
}