Use raspberry pie and idle hard disk to build a personal network disk at home

Time:2021-10-19

Because I upgraded my personal laptop, I replaced a 2.5-inch 1t mechanical hard disk. I think it’s idle. It’s better to use it to play with a NAS. I can store some personal files and movie blockbusters and share them with everyone at home. Next, follow my footsteps and see how to achieve it

1. Preliminary preparation

  • Raspberry pie (brush the official system, see Baidu for details)
  • Idle hard disk (it can be 2.5 inches or 3.5 inches, but only if the hard disk shell has been purchased and can support USB connection)
  • Router

2. Router MAC address binding

Let’s talk about what this step is for. As we all know, your raspberry pie will connect to your home router through the routerDHCPThe service is assigned to youIP, but thisIPWhen the lease term comes, it will be replaced by itself. For once and for all, as long as the MAC address is bound, it can never be replacedIP, the following steps are described:

  • Enter the background pageUse raspberry pie and idle hard disk to build a personal network disk at home
  • Find the DHCP service from the function settings. Here, the basic router operation mode is to find the corresponding DHCP service option

Use raspberry pie and idle hard disk to build a personal network disk at home

  • Set your own MAC address and IP address and add them. If you don’t know the MAC address of your raspberry pie, don’t worry. The following will teach you how to find the MAC address

    Use raspberry pie and idle hard disk to build a personal network disk at home

  • Enter the terminal management and check the raspberry pie terminal, and you can see the corresponding MAC addressUse raspberry pie and idle hard disk to build a personal network disk at home

3. ConfigurationsambaFile sharing service

  • SSH login

    ssh  [email protected] address
  • installsambaservice

    sudo apt-get install samba -y
  • editsambaconfiguration file

    sudo vim /etc/samba/smb.conf
  • Add the following at the end of the file, as shown in the figure

     [share]
        comment = Do not arbitrarily modify the database file
        path = /home/pi/share_files
        public = no
        writable = yes 

Use raspberry pie and idle hard disk to build a personal network disk at home

  • restartsambaservice

    sudo service smbd restart
  • Create a shared folder in your home directory (topiUser identity (created)

    mkdir -p ~/share_files
  • Configure the login user, because the samba service needs an entity user corresponding to the virtual user

    sudo pdbedit -a -u pi 

4. Configure the hard disk to be automatically mounted to the shared directory

  • Connect your hard drive to raspberry pie and see what you want to hang on the partitionUUID, the partition we want to mount here is/dev/sda2

    sudo blkid

Use raspberry pie and idle hard disk to build a personal network disk at home

UUID is circled in the figure above. Write it down

  • edit/etc/fstab, add the following to the last line. The UUID below is the UUID you found above

    PARTUUID=UUID /home/pi/share_files ntfs umask=000,uid=pi,gid=pi 0 0

5. Solve the problem that raspberry pie does not support writing to NTFS file system

After doing the above work, in theory, you have successfully built the NAS network disk, but the drawback is that after you connect the network disk, you can’t write files, because the raspberry pie kernel doesn’t supportntfsWe need to make a small patch for the write operation of the file system in format:

  • Install nfts-3g module

    sudo apt-get install ntfs-3g -y
  • Update kernel module

    sudo modprobe fuse
  • Restart the system

    sudo reboot

6. Enjoy

  • Connect SMB service under Linux computer. Take Ubuntu as an example. I have clicked remember password here, so I am not required to fill in the user name and password. You will be prompted to enter the user name and password for the first connection, so the user name you need to fill in ispi, the password is the password you just set

Use raspberry pie and idle hard disk to build a personal network disk at home

  • Connect the SMB service on the Android phone, download an ES file browser from the app store, and operate as follows:

Use raspberry pie and idle hard disk to build a personal network disk at home

  • Windows connection SMB service,win+rCall out window, enter in the window\\IP address \ share, just enter the user name and password

Finally, recently, many friends came to me for helpLinux learning RoadmapSo I stayed up late in my spare time for a month and sorted out an e-book according to my own experience. Whether you are interviewing or self-improvement, I believe it will help you!

Free to everyone, just ask everyone to give me a praise!

E-book | learning roadmap for Linux Development

I also hope some friends can join me and make this e-book more perfect!

Have you got anything? I hope the old fellow will take three strikes to show this article to more people.

Recommended reading: