此文搭建的NAS不能通過外網訪問,只能以區域網為例。
1. 硬體環境
(1)樹莓派3B
(2)希捷NAS硬碟4T
2.環境搭建
2.1 硬碟分區
(1) 樹莓派外界硬碟時不會自動掛載
(2)查看磁碟信息
(3)分區
新購的NAS硬碟還沒使用過,需進行分區;若直接掛載會出現下面錯誤:
root@raspberrypi:/homeroot@raspberrypi:/home/pimount: /home/pi/seagate_disk0: wrong fs type, bad option, bad superblock on /dev/sda, missing codepage or helper program, or other error.注意:MBR 分區表類型最大支持2T,對於大於2T的硬碟需要使用GPT分區。fdisk只對mbr分區有效,需使用parted分區
root@raspberrypi:/home/pi# parted /dev/sdaGNU Parted 3.2Using /dev/sdaWelcome to GNU Parted! Type 'help' to view a list of commands.(parted) pModel: ST4000VN 008-2DR166 (scsi)Disk /dev/sda: 4001GBSector size (logical/physical): 512B/512BPartition Table: gptDisk Flags:
Number Start End Size File system Name Flags 1 17.4kB 16.8MB 16.8MB Microsoft reserved partition msftres
(parted) mkpartPartition name? []? nas_disk0_1File system type? [ext2]? ext4Start? 16.8MEnd? 3T(parted) pModel: ST4000VN 008-2DR166 (scsi)Disk /dev/sda: 4001GBSector size (logical/physical): 512B/512BPartition Table: gptDisk Flags:
Number Start End Size File system Name Flags 1 17.4kB 16.8MB 16.8MB Microsoft reserved partition msftres 2 16.8MB 3000GB 3000GB ext4 nas_disk0_1
(parted) mkpartPartition name? []? nas_disk0_2File system type? [ext2]? ext4Start? 3TEnd? 100%(parted) pModel: ST4000VN 008-2DR166 (scsi)Disk /dev/sda: 4001GBSector size (logical/physical): 512B/512BPartition Table: gptDisk Flags:
Number Start End Size File system Name Flags 1 17.4kB 16.8MB 16.8MB Microsoft reserved partition msftres 2 16.8MB 3000GB 3000GB ext4 nas_disk0_1 3 3000GB 4001GB 1001GB ext4 nas_disk0_2
(parted) quit2.2 硬碟格式化
(1)格式化分區
查看格式化前磁碟信息
root@raspberrypi:/home/pi# fdisk -lDisk /dev/sda: 3.7 TiB, 4000787030016 bytes, 7814037168 sectorsDisk model: 008-2DR166Units: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: gptDisk identifier: 0EE1BB69-B9E5-4D98-913F-F8CA05130040
Device Start End Sectors Size Type/dev/sda1 34 32767 32734 16M Microsoft reserved/dev/sda2 32768 5859375103 5859342336 2.7T Linux filesystem/dev/sda3 5859375104 7814035455 1954660352 932.1G Linux filesystemmkfs.ext4進行格式化
root@raspberrypi:/home/pimke2fs 1.44.5 (15-Dec-2018)Creating filesystem with 732417792 4k blocks and 183107584 inodesFilesystem UUID: d66befd2-41b8-4529-b59e-d3b1376e1ef5Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 102400000, 214990848, 512000000, 550731776, 644972544
Allocating group tables: doneWriting inode tables: doneroot@raspberrypi:/home/pimke2fs 1.44.5 (15-Dec-2018)Creating filesystem with 244332544 4k blocks and 61087744 inodesFilesystem UUID: 97f77f54-511f-48e8-808b-6fc503e80bd5Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 102400000, 214990848
Allocating group tables: doneWriting inode tables: doneCreating journal (262144 blocks):doneWriting superblocks and filesystem accounting information: done(2)掛載
創建掛載目錄
root@raspberrypi:/home/piroot@raspberrypi:/home/piroot@raspberrypi:/home/piseagate_disk0_1 seagate_disk0_2查看blockid
root@raspberrypi:/home/pi/dev/mmcblk0p1: LABEL_FATBOOT="boot" LABEL="boot" UUID="F661-303B" TYPE="vfat" PARTUUID="1c45f296-01"/dev/mmcblk0p2: LABEL="rootfs" UUID="8d008fde-f12a-47f7-8519-197ea707d3d4" TYPE="ext4" PARTUUID="1c45f296-02"/dev/mmcblk0: PTUUID="1c45f296" PTTYPE="dos"/dev/sda1: PARTLABEL="Microsoft reserved partition" PARTUUID="c356012f-fbb8-4fb5-a358-802513b6353b"/dev/sda2: UUID="d66befd2-41b8-4529-b59e-d3b1376e1ef5" TYPE="ext4" PARTLABEL="nas_disk0_1" PARTUUID="a5c876bb-ee34-429a-a261-e219372786de"/dev/sda3: UUID="97f77f54-511f-48e8-808b-6fc503e80bd5" TYPE="ext4" PARTLABEL="nas_disk0_2" PARTUUID="c2f9e2f5-1457-4fff-b9d4-ef04675390d1"編輯/etc/fstab,設置開機自動掛載
UUID=d66befd2-41b8-4529-b59e-d3b1376e1ef5 /home/pi/seagate_disk0_1 ext4 defaults 0 0UUID=97f77f54-511f-48e8-808b-6fc503e80bd5 /home/pi/seagate_disk0_2 ext4 defaults 0 0查看掛載信息
root@raspberrypi:/home/piFilesystem Size Used Avail Use% Mounted on/dev/root 29G 1.2G 27G 5% /devtmpfs 459M 0 459M 0% /devtmpfs 464M 0 464M 0% /dev/shmtmpfs 464M 6.2M 457M 2% /runtmpfs 5.0M 4.0K 5.0M 1% /run/locktmpfs 464M 0 464M 0% /sys/fs/cgroup/dev/mmcblk0p1 253M 40M 214M 16% /boottmpfs 93M 0 93M 0% /run/user/1000/dev/sda2 2.7T 89M 2.6T 1% /home/pi/seagate_disk0_1/dev/sda3 917G 77M 870G 1% /home/pi/seagate_disk0_2