NAS Server Configuration

Steps

1. Install Kali

UEFI boot mode is recommended; otherwise there is a chance that after installation you end up stuck on a black screen with a _ blinking in the top-left corner when booting. That means the boot is broken, and the cause is unknown. Anyway, switch to UEFI boot in the BIOS and then install it again, and you will be able to enter the system.

2. Pre-process the Hard Drive

If you are using an old hard drive, consider deleting the partitions and then creating new partitions formatted as the ext4 file system as needed. If you run into problems with the steps below, try rebooting to refresh the file system.

  • View partitions

    1
    
    sudo fdisk -l
    

    Here, for example, sda, sdb represent whole hard drives, while sda1, sda2 are the different partitions on the drive sda.

  • Delete partitions (be careful with deletion operations)

    Be extremely careful. My hand slipped in the past two days, and I deleted the /etc on the server and the /dev on the NAS…

    Delete the specified partition:

    1
    
    sudo fdisk /dev/sdb # 要删分区的硬盘。
    

    Then type m to view the help, d to delete; you will need to select the partition number. If you want to delete all the partitions of a whole hard drive, just delete them one by one with the defaults; you can also directly format the whole hard drive, see below for the steps. After deleting, remember to type w to save, otherwise the partitions will not be deleted.

  • Create new partitions

    The same partition operation commands:

    1
    
    sudo fdisk /dev/sdb
    

    Type n to create a new partition, type p to create a primary partition, enter the partition number, and the following steps determine the partition start position and partition size. If you have no special needs, just accept all defaults and make one partition over the whole hard drive.

    When done, remember to type w to save as well.

  • Format partitions (be careful with deletion operations)

    The command to format the specified partition is as follows:

    1
    
    sudo mkfs.ext4 /dev/sdb1
    

    The command to format the whole hard drive:

    1
    
    sudo mkfs.ext4 /dev/sdb
    

    It will ask for confirmation; don’t let your hand slip.

3. Mount the Hard Drive

  • Create a new mount point

    1
    
    mkdir -p /mnt/HDD_1
    
  • Temporary mount; canceled at shutdown

    1
    
    mount /dev/sdb1 /mnt/HDD_1
    
  • Unmount a partition

    1
    
    umount /dev/sdb1
    
  • Configure auto-mount at boot

    First view the UUID of the partition:

    1
    
    sudo blkid
    

    The output is as follows:

    1
    
    /dev/sdb1: UUID="11263962-9715-473f-9421-0b604e895aaa" TYPE="ext4"
    

    Configure auto-mount:

    1
    
    nano /etc/fstab
    

    Add a line:

    1
    
    UUID=11263962-9715-473f-9421-0b604e895aaa /mnt/HDD_1 ext4 defaults 0 0
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    
    <fs spec> <fs file> <fs vfstype> <fs mntops> <fs freq> <fs passno>
    
    具体说明,以挂载/dev/sdb1为例:
    <fs spec>:   分区定位,可以给UUID或LABEL,例如:UUID=6E9ADAC29ADA85CD或LABEL=software
    <fs file>:   具体挂载点的位置,例如:/mnt/HDD_1
    <fs vfstype>:挂载磁盘类型,linux分区一般为ext4,windows分区一般为ntfs
    <fs mntops>: 挂载参数,一般为defaults
    <fs freq>:   磁盘检查,默认为0
    <fs passno>: 磁盘检查,默认为0,不需要检查
    

    Test the mount and see whether all the partitions have been successfully mounted.

    1
    
    sudo mount -a
    

    If there is a problem and you have rebooted, it may cause the system partition to fail to auto-mount and the system to fail to boot; the solution is to enter recovery mode and modify /etc/fstab.

4. Enable Samba

Before this, if you are not using the root user, other users will only have read-only permissions later, so depending on your needs, consider giving all users read, write and execute permissions:

1
sudo chmod 777 /mnt/HDD_1
  • Install Samba

    1
    
    sudo apt install samba
    
  • Configure Samba

    1
    
    nano /etc/samba/smb.conf
    

    If the default configuration is not needed, you can delete it all; configure it as follows:

    1
    2
    3
    4
    5
    
    [HDD_1]                 # 展示的共享名
      path = /mnt/3TB_HDD_1 # 共享路径
      browseable = yes      # 允许浏览
      writeable = yes       # 允许写入
      read only = no        # 关闭只读
    
  • Add an SMB account

    1
    
    sudo smbpasswd -a <用户名> # 必须是系统中存在的用户名,譬如当前用户名。
    
  • Start the smb service

    1
    2
    
    sudo systemctl restart smbd.service
    sudo systemctl restart nmbd.service
    
  • Enable auto-start at boot

    1
    2
    
    sudo systemctl enable smbd.service
    sudo systemctl enable nmbd.service
    

Done. Now you can connect to the NAS over SMB and enjoy life.