External USB drive and Raspberry Pi
- connection as a NAS drive
Raspberry Pi can be successfully used as a server to connect a hard drive. This allows us to share music, films or documents with all users on our local network. The example shows how to connect the drive to the Raspberry Pi (this involves changing the USB output current) and then use it as a network drive.
The example uses the following elements:
Software installation
In our case, RaspberryPi will be operated remotely from the PC during the entire configuration process.
At the beginning we connect Raspberry to the same network as our computer. Then we need to know the IP address that was given to our device. To do this, we log on to Raspberry. Default login: pi, password: raspberry. Then, using the command ifconfig we read the IP:
In my case, it's 192.168.1.123.
Then we install the SSH client, PuTTY, on the computer from which we will operate Raspberry. After starting, enter the previously read IP in the Host Name (or IP address ) window. The connection type is SSH. You can also save the session so that you don't have to re-enter the address every time.
Click the Open button and log in to RaspberryPi.
We will start with a software update. To do this, enter the commands:
-
sudo apt-get update
-
sudo apt-get upgrade
Now we can start installing Samba. It will allow us to share files on the local network.
-
- installation of Sambasudo apt-get install samba samba-common-bin
-
- Adding a user (in place of pi, we give our own name) together with the password required to log on to the network drivesudo smbpasswd -a pi
-
s
udo nano /etc/samba/smb.conf
- We search . # security = userand then remove the # character from the beginning of the line.
-
If you also want to write information to the disk, and not just read it, then in the section [homes] We change read only = yeson read only = no
Connecting a hard drive
Most likely, to connect the drive via USB with RaspberryPi, we will need to increase the power on the USB port. The default is 600 mA, which may not be enough for the drive. However, you can change it to 1200 mA. To do this we open the file /boot/config.txt
-
sudo nano /boot/config.txt
At the end we add two lines:
max_usb_current=1
safe_mode_gpio=4
Then we restart Raspberry and check if our drive has been detected:
-
sudo fdisk -l
In order to mount the disk we have to create a proper directory and mount an external disk in it:
-
sudo mkdir /media/disk_zew
- - creates a disk_zew directory in the /media directory
-
sudo mount -t auto /dev/sda1 /media/disk_zew
- Mount the disk in the disk_zew directory. In place /" dev/sda1 enter the disk path read earlier
If there are any files on the disk we can check if the system can see our disk with the command
-
ls /media/disk_zew
Now, after each reboot, the drive should be mounted manually. To do this we automatically change /etc/fstab file
-
sudo nano /etc/fstab
At the end, add the following line:*dev/sda1 *media/disk_call auto defaults 0 2
To check that everything works properly, we restart Raspberry
-
sudo reboot
Then, using the command ls /media/disk_zew
we check to see if the drive is visible.
Setting drive visibility on the network
To do this, we return to the file /"etc/samba/smb.conf
-
s
udo nano /etc/samba/smb.conf
- at the end, we add the following section:
[Disk_Zew]
comment=Discussion made available
path = /media/disk_zew
valid users = @users
force group = users
create mask = 0660
directory mask = 0771
read only = no
Now you have to reboot the Samba server.
-
sudo /etc/init.d/samba restart
At this point, our Raspberry has become visible in a Windows network environment
Now we can enter the shared disk with the user and password to Samba (not to Raspbian)