OpenWRT/LEDE 分区并挂载移动硬盘
去年年初,为了体验4k的“塞尔达传说-旷野之息”,我升级了我的电脑,并在18年不断完善,目前经过optane加速的4T硬盘,速度提升非常显著,很是喜欢。但电脑里有些录音,以及家庭照片,想随时观看,而不想开电脑,另外也起到备份的作用(数据无价),所以一直在考虑采购一台NAS,但感觉现在的NAS及配件(硬盘)功能比较弱(其实就是没米。。。),所以就考虑利用现有资源,把1T的闲置移动硬盘挂载到 WRT1200路由器下,这样 Win/Mac/手机 通过sshfs/samba远程挂载目录,这样可以体验简易NAS,等时机成熟了再考虑NAS,此篇主要总结如何挂载移动硬盘,由于环境版本的不同,总结中的内容可能跟读者遇到的会有少许差异,如遇到问题,可自行google或baidu
有时候通过LEDE的luci直接挂载不起作用,也弄不明白为啥,所以还是CLI最靠谱。另外在openwrt里,移动硬盘的格式最好是ext3或ext4,这样效果高,问题少。另外就是最开始我想用sshfs,但后来发现windows访问sshfs效果非常不好,所以对于windows,就换回了samba服务器,速度不错,可以达到平均60MB/s 上下
另外Samba配置,可以参考我之前的文章 Deploy Samba on OpenWRT
1. 国内更新源,这样就可以随便更新软件了
src/gz arm_core https://mirrors.ustc.edu.cn/lede/releases/17.01.6/targets/mvebu/generic/packages src/gz arm_base https://mirrors.ustc.edu.cn/lede/releases/17.01.6/packages/arm_cortex-a9_vfpv3/base src/gz arm_luci https://mirrors.ustc.edu.cn/lede/releases/17.01.6/packages/arm_cortex-a9_vfpv3/luci src/gz arm_packages https://mirrors.ustc.edu.cn/lede/releases/17.01.6/packages/arm_cortex-a9_vfpv3/packages src/gz arm_routing https://mirrors.ustc.edu.cn/lede/releases/17.01.6/packages/arm_cortex-a9_vfpv3/routing src/gz arm_telephony https://mirrors.ustc.edu.cn/lede/releases/17.01.6/packages/arm_cortex-a9_vfpv3/telephony
2. 通过“fdisk -l”来查看插入的移动硬盘
root@LEDE:~# fdisk -l ...... Disk /dev/sda: 931.5 GiB, 1000204885504 bytes, 1953525167 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x4f051cc7 Device Boot Start End Sectors Size Id Type /dev/sda1 2048 1953525166 1953523119 931.5G 83 Linux root@LEDE:~# root@LEDE:~# df -T Filesystem Type 1K-blocks Used Available Use% Mounted on /dev/root squashfs 22528 22528 0 100% /rom tmpfs tmpfs 256608 10172 246436 4% /tmp /dev/ubi0_1 ubifs 5732 5380 24 100% /overlay overlayfs:/overlay overlay 5732 5380 24 100% / ubi1:syscfg ubifs 30276 248 28448 1% /tmp/syscfg tmpfs tmpfs 512 0 512 0% /dev
3. 重建移动硬盘的分区,并用ext4格式化
8G给/overlay,用于软件安装的空间;其余都给/extdisk,存放文件的空间
root@LEDE:~# fdisk /dev/sda
Welcome to fdisk (util-linux 2.29.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p
Disk /dev/sda: 931.5 GiB, 1000204885504 bytes, 1953525167 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x4f051cc7
Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 1953525166 1953523119 931.5G 83 Linux
Command (m for help): d
Selected partition 1
Partition 1 has been deleted.
Command (m for help): p
Disk /dev/sda: 931.5 GiB, 1000204885504 bytes, 1953525167 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x4f051cc7
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-1953525166, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-1953525166, default 1953525166): +8G
Created a new partition 1 of type 'Linux' and of size 8 GiB.
Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p):
Using default response p.
Partition number (2-4, default 2):
First sector (16779264-1953525166, default 16779264):
Last sector, +sectors or +size{K,M,G,T,P} (16779264-1953525166, default 1953525166):
Created a new partition 2 of type 'Linux' and of size 923.5 GiB.
Command (m for help): p
Disk /dev/sda: 931.5 GiB, 1000204885504 bytes, 1953525167 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x4f051cc7
Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 16779263 16777216 8G 83 Linux
/dev/sda2 16779264 1953525166 1936745903 923.5G 83 Linux
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
root@LEDE:~# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2
root@LEDE:~# mkfs.ext4 /dev/sda1
mke2fs 1.43.4 (31-Jan-2017)
Creating filesystem with 2097152 4k blocks and 524288 inodes
Filesystem UUID: 580b4d58-b30d-4d88-bd16-6456c9217658
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
root@LEDE:~# mkfs.ext4 /dev/sda2
mke2fs 1.43.4 (31-Jan-2017)
Creating filesystem with 242093237 4k blocks and 60530688 inodes
Filesystem UUID: 143409e7-a88c-4f49-ac96-b0f9687ca5c5
Superblock 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: done
Writing inode tables: done
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done
4. 确认两个分区的信息
root@LEDE:/overlay# block info /dev/sda* /dev/sda1: UUID="580b4d58-b30d-4d88-bd16-6456c9217658" VERSION="1.0" TYPE="ext4" /dev/sda2: UUID="143409e7-a88c-4f49-ac96-b0f9687ca5c5" VERSION="1.0" TYPE="ext4"
5. 手动修改fstab(注意用Tab隔开,而不是空格),使其每次重启后自动挂载
root@LEDE:/overlay# more /etc/config/fstab config 'global' option anon_swap '0' option anon_mount '0' option auto_swap '1' option auto_mount '1' option delay_root '5' option check_fs '0' config 'mount' option 'target' '/overlay' option 'device' '/dev/sda1' option 'fstype' 'ext4' option 'options' 'rw,async' option 'enabled' '1' #<<< option 'enabled_fsck' '0' config 'mount' option 'target' '/extdisk' option 'device' '/dev/sda2' option 'fstype' 'ext4' option 'options' 'rw,async' option 'enabled' '1' #<<< option 'enabled_fsck' '0'