I have a Raspberry Pi 2 in my hand and a spare mobile hard drive. I am thinking of using the Raspberry Pi and the mobile hard drive to build a low-cost NAS. Just a while ago, I was struggling with how to download and build Nextcloud offline. Installing Aria2 on Raspberry Pi is also a very simple matter.

Then, mount the mobile hard disk on the Raspberry Pi, use Aria2 to download the resources to the hard disk offline, and then use the Kodi player to read the characteristics of the files in the SFTP, FTP or HTTP server and play them directly on the Raspberry Pi. Video on hard drive. Such a simple home video shared NAS storage is completed.

In actual use, it works well. If you don't have money to buy a professional NAS storage device, it's good to make comprehensive use of the Raspberry Pi, mobile hard disk, network cable, etc. that are "eating dust". The Raspberry Pi installation process is quite simple. This article is mainly to sort out some problems I encountered during the operation, such as mobile hard disk mounting, USB wireless network card, read permissions, etc.

Raspberry Pi Ten issues in creating low-cost NAS storage - Mount hard drive offline download

For more articles about building network storage and cloud disks, interested friends can also read:

  1. Nextcloud offline download construction method-integrate Aria2, AriaNg, and Aria2 WebUI to achieve offline downloading
  2. Lsyncd builds synchronization mirror-use Lsyncd to achieve real-time synchronization between local and remote servers
  3. Linux VPS mounts Google Drive and Dropbox-realizes VPS host data synchronization and backup

1. Raspberry Pi software installation and uninstallation commands

The official system of Raspberry Pi, Raspbain Jessie With PIXEL, is deeply customized based on Debain 8, so you can directly use the commands we use on Linux VPS. For example, there is no problem in setting up the LNMP environment. Here are some commonly used commands:

List of commonly used apt commands

apt-cache search # ------(package 搜索包)
apt-cache show #------(package 获取包的相关信息,如说明、大小、版本等)
sudo apt-get install # ------(package 安装包)
sudo apt-get install # -----(package - - reinstall 重新安装包)
sudo apt-get -f install # -----(强制安装?#"-f = --fix-missing"当是修复安装吧...)
sudo apt-get remove #-----(package 删除包)
sudo apt-get remove -purge # ------(package 删除包,包括删除配置文件等)
sudo apt-get autoremove --purge # ----(package 删除包及其依赖的软件包+配置文件等(只对6.10有效,强烈推荐))
sudo apt-get update #------更新源
sudo apt-get upgrade #------更新已安装的包
sudo apt-get dist-upgrade # ---------升级系统
sudo apt-get dselect-upgrade #------使用 dselect 升级
apt-cache depends #-------(package 了解使用依赖)
apt-cache rdepends # ------(package 了解某个具体的依赖?#当是查看该包被哪些包依赖吧...)
sudo apt-get build-dep # ------(package 安装相关的编译环境)
apt-get source #------(package 下载该包的源代码)
sudo apt-get clean && sudo apt-get autoclean # --------清理下载文件的存档 && 只清理过时的包
sudo apt-get check #-------检查是否有损坏的依赖

If you encounter errors such as slow speed or non-existent source when using apt-get, you may need to change the source. Please refer to the second part of this article (wzfou.com).

aptitude command

aptitude, like apt-get, is an extremely powerful package management tool in Debian and its derivatives. Unlike apt-get, aptitude is better at handling dependency issues. For example, when aptitude deletes a package, it will also delete the packages it depends on. In this way, useless packages will not remain in the system, and the entire system will be cleaner. The following are some commonly used aptitude commands summarized by the author for reference only.

aptitude update 更新可用的包列表
aptitude upgrade 升级可用的包
aptitude dist-upgrade 将系统升级到新的发行版
aptitude install pkgname 安装包
aptitude remove pkgname 删除包
aptitude purge pkgname 删除包及其配置文件
aptitude search string 搜索包
aptitude show pkgname 显示包的详细信息
aptitude clean 删除下载的包文件
aptitude autoclean 仅删除过期的包文件

Of course, you can also use aptitude in text interface mode.

deb package

dpkg -i xxx.deb #安装deb软件包 
dpkg -r xxx.deb #删除软件包 
dpkg -r –purge xxx.deb  # 连同配置文件一起删除 
== dpkg -P xxx.deb  # 彻底的卸载,包括软件的配置文件
dpkg -info xxx.deb   # 查看软件包信息
dpkg -L xxx.deb # 查看软件安装到什么地方
dpkg -l # 查看系统中已安装软件包信息 
dpkg -s package # 查看软件包的详细情况,包括版本,依赖之类的
dpkg -S keyword     #搜索所属的包内容
dpkg -c package.deb  #列出 deb 包的内容
dpkg -C #查找只有部分安装的软件包信息
dpkg -p package-name    #显示包的具体信息
dpkg –unpack package.deb     #解开 deb 包的内容
dpkg –configure package  #配置包 
dpkg-reconfigure xxx # 重新配置软件包 

# 清除所有已删除包的残馀配置文件
dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P
# 如果报如下错误,证明你的系统中没有残留配置文件了,无须担心。
dpkg: –purge needs at least one package name argument

dpkg –clear-avail #删除软件包的Avaliable信息
dpkg –help      #显示帮助信息
dpkg –compare-versions ver1 op ver2 #比较同一个包的不同版本之间的差别
dpkg –licence (or) dpkg –license    #显示dpkg的Licence
dpkg –version #显示dpkg的版本号
dpkg -b direc×y [filename]  #建立一个deb文件

Those installed by dpkg can be uninstalled with apt, and vice versa.

2. How to change the update source of Raspberry Pi

Raspberry Pi The update source that comes with Raspberry Pi cannot be opened in China. We can replace it with a domestic image. First edit the /etc/apt/sources.list file. It is recommended to edit it with the nano command that comes with the system. The command is as follows:

sudo nano /etc/apt/sources.list

Enter the editing interface, delete the original content, and paste the following content:

deb http://mirrors.aliyun.com/raspbian/raspbian/ jessie main non-free contrib rpi
deb-src http://mirrors.aliyun.com/raspbian/raspbian/ jessie main non-free contrib rpi

Update software index list

sudo apt-get update

Compare index lists to update dependencies

sudo apt-get upgrade -y

Additional: After completing the above operation, you also need to comment out the source of raspi.list in the sources.list.d folder. More mirror sources can be found here: http://www.raspbian.org/RaspbianMirrors

3. Enable root login account on Raspberry Pi

Changing the update source of Raspberry Pi can solve the software dependency problem, but sometimes we need Root permissions to install certain software. When root privileges are required, it is executed via sudo by the default account, Raspbian on the Raspberry pi system. The default host name is raspberrypi, the default user is pi, and the password is raspberry

For convenience, it is recommended to enable the ROOT account as soon as possible. You only need to execute the following two commands:

// Re-open the root account. You can log in as the pi user. After executing this command, the system will prompt you to enter the root password twice. Enter the password you want.

pi@raspberrypi:~$ sudo passwd root
Enter new UNIX password:   #输入第一遍密码
Retype new UNIX password:  #输入第二遍密码

// Enable root account login

pi@raspberrypi:~$ sudo passwd --unlock root
passwd: password expiry information changed.

Enter the first line of code above and the second line is the code that prompts the error. The reason is that the new version of s-s-h closes root login by default. You can modify the configuration file of s-s-h.

pi@raspberrypi:~$ sudo nano /etc/ssh/sshd_config

Ctrl + W shortcut key to search for PermitRootLogin without-password, modify PermitRootLogin without-password to PermitRootLogin yes, Ctrl + O shortcut key to save, Ctrl + O shortcut key Exit the Nano editor. After execution, use the reboot command to reboot, so that the root account can be unlocked.

4. Manually mount the mobile hard disk or U disk on Raspberry Pi

The operating system provided by the Raspberry Pi official website can now automatically mount a mobile hard drive or USB flash drive. If you are using another operating system that cannot automatically recognize and mount the hard drive or USB flash drive, you can mount it manually. Usually we create a new directory under the /mnt or /media directory as the mount point. for example:

sudo mkdir /mnt/1GB_USB_flash
sudo mount -o uid=pi,gid=pi /dev/sda1 /mnt/1GB_USB_flash // 用完之后卸载
sudo umount /mnt/1GB_USB_flash 

sda1 depends on your actual situation, a represents the first hard disk, and 1 represents the first partition.

Mount exFAT formatted hard drive

Mount itself can support FAT-formatted U disks, but if your U disk or mobile hard disk uses exFAT format, mount will say it is not supported. It doesn't matter, mount will be supported after installing the exfat-fuse software.

sudo apt-get install exfat-fuse 

If you want to automatically mount the system at boot instead of manually executing it every time, you can edit the /etc/fstab file. For example, add a line at the end:

/dev/sda1 /mnt/usbdisk vfat rw,defaults 0 0

Mount the hard disk in NTFS format (mount in read-write mode)

By default, hard disks mounted in NTFS format only have read-only permissions, which requires the use of other tools.

#安装所需软件包
sudo apt-get install fuse-utils ntfs-3g
#加载内核模块
modprobe fuse
#编辑fstab让移动硬盘开机自动挂载
sudo nano /etc/fstab
#在最后一行添加如下内容
/dev/sda1 /mnt/myusbdrive ntfs-3g defaults,noexec,umask=0000 0 0
#保存重启,即可生效 

Mount FAT32 formatted hard drive

#创建挂载点
sudo mkdir /mnt/myusbdrive
#编辑fstab让移动硬盘开机自动挂载
sudo nano /etc/fstab
#在最后一行添加如下内容
/dev/sda1 /mnt/myusbdrive auto defaults,noexec,umask=0000 0 0
#保存重启,即可生效 

illustrate:

sda1 depends on your actual situation, a represents the first hard disk, and 1 represents the first partition.
umask=0000 0 0
The first four 0s are for everyone, readable, writable and executable.
The last two 0s, the first one represents dump, 0 means no backup
The second one represents the order of fsck checking, 0 means not checking
Uninstall: sudo umount /mnt/myusbdrive

To check the mounting status, use the following command. cd /mnt/myusbdrive, then: ls

5. Insufficient power supply to the Raspberry Pi mobile hard drive

When I used Raspberry Pi 2 to connect a mobile hard drive, I encountered a problem of insufficient power supply. The main manifestation was that the mounting was unstable and the mobile hard drive suffered from "clicking". Current solutions include:

Hardware method: Buying a USB-HUB is equivalent to providing a current source for the mobile hard disk.

Software method 1: Change the Raspberry Pi configuration. The path is: boot/config.txt, which contains some initial configurations of the Raspberry Pi. Just add max_usb_current=1 at the end. Open the terminal, enter the boot folder, and execute the following: sudo nano config.txt

Then add max_usb_current=1, ctrl+x to save. Enter reboot to restart, plug in the mobile hard disk, if it is not recognized, plug it in a few more times.

Software method 2: Add safe_mode_gpio=4 at the end of the file in software method 1. 

Software method 3: Format your mobile hard disk into ext format, either ext3 or 4. In this way, the Raspberry Pi can be recognized when it is plugged in.

The formatting method is as follows:

First, if the mobile hard disk is already mounted, unmount it: sudo umount /xxxmnt/xxxusb_flash. Then execute sudo fdisk -l to check the serial number of your USB flash drive, which is usually /dev/sdb. The USB partition is usually /dev/ sdb1.

Finally, perform the formatting operation:

sudo mkfs.ext4 /dev/sda1 # 格式化为ext4分区 
sudo mkfs.ext3 /dev/sda1 # 格式化为ext3分区 
sudo mkfs.ext2 /dev/sda1 #格式化为ext2分区

Special note: After formatting your mobile hard disk, everything on it will be cleared. It is best to make a backup before formatting.

6. Raspberry Pi integrates Aria2 and AriaNg offline download

Raspberry Pi integrates Aria2, AriaNg, and Aria2 WebUI to achieve offline downloading. The method is very simple. Reference: Installing Aria2 on VPS.

7. Set up FTP server (vsftpd) on Raspberry Pi

If you use a player like Kodi, you can directly use SFTP to log in and browse files, but we can also use FTP login to read files. First install vsftpd server on Raspberry Pi (about 400KB)

sudo apt-get install vsftpd

Start ftp service

sudo service vsftpd start

Edit the configuration file of vsftdp

sudo nano /etc/vsftpd.conf

Find the following line and define it

anonymous_enable=NO  
表示:不允许匿名访问

local_enable=YES   
设定本地用户可以访问

write_enable=YES
设定可以进行写操作

local_umask=022
设定上传后文件的权限掩码

chroot_local_user=YES

Modify the access directory and add a new line

local_root=/var/www/
# anon_root=/var/www/tmp
# local_root 针对系统用户;anon_root 针对匿名用户

Note: The FTP user root directory permission is 555 (dr-xr-xr-x). If the permission is set to 777, the user cannot log in.

Restart the vsftpd service

sudo service vsftpd restart

Test it, OK. Connect to the Raspberry Pi system through ftp, username: pi, password is raspberry

8. Set up NAS server (Samba) on Raspberry Pi

Install samba and samba-common-bin

sudo apt-get install samba samba-common-bin
sudo apt-get install netatalk (可选,用于支持AFP)
sudo apt-get install avahi-daemon(可选,用于支持网内的计算机自动发现)

Configure the /etc/samba/smb.conf file

sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.backup
sudo vi /etc/samba/smb.conf

[share]  
#共享文件的名称,将在网络上以此名称显示
path = /samba                     #共享文件的路径
valid users = root pi             #允许访问的用户,比如我的raspi有
                                  #root 和 pi 两个用户
browseable = yes                  #允许浏览                                 
public = yes                      #共享开放                             
writable = yes                    #可写

Start Restart

sudo smbd
sudo smbd restart

9. Enable USB wireless network card on Raspberry Pi

Raspberry Pi 2 uses Raspbain Jessie With PIXEL Raspberry Pi official system, based on Debain 8, with PIXEL graphical interface, download the latest version: https://downloads.raspberrypi.org/raspbian_latest.

After my testing, the latest version of Raspbain Jessie operating system supports 360/Xiaomi/Baidu portable wifi. If you happen to have one, you can plug it in and use the USB wireless network card.

10. Summary

When I was building low-cost NAS storage on Raspberry Pi, the first problem I encountered was the problem of mounting the mobile hard disk. Although the default NFT format can be mounted on the Raspberry Pi, because it is a Windows hard disk format, Permissions cannot be modified in Linux, which ultimately results in Aria2 being unable to write data to the hard disk during offline download.

After going around in a big circle, I finally decided to format the mobile hard disk as Ext4 so that the Raspberry Pi can directly recognize and mount it. You can use Ext2 Volume Manager, Ext2Fsd and other software to read Ext4 format mobile hard disk on Windows, which supports reading and writing in Windows ext2/ext3 file system.

Leave a Reply