Deploy Samba on OpenWRT

买了linksys wrt1200ac很久了,之前只是装了一个openwrt+默认配置,也没启用什么特别功能,感觉还算稳定。不过现在想听一些下载下来的广播,但又不想总是开着PC,所以突然想把这些音频挪到没用的u盘里,并挂在openwrt中,这样任何设备都可以访问了,还剩资源:)

定制OpenWRT

1. 安装中文包

root@OpenWrt:~# opkg update <<< 每次重启后需要缓存安装包列表,这样才能search到所有可用的包
root@OpenWrt:~# opkg list |grep zh-cn <<< 学会如何查找相应的包
root@OpenWrt:~# opkg install luci-i18n-base-zh-cn <<< 安装中文包

2.安装luci的主题

默认只有一种,在默认更新源里,加上默认的一共有4个,最后我还是选择了默认的 -_-

root@OpenWrt:~# opkg list |grep -i theme
luci - git-16.018.33482-3201903-1 - Standard OpenWrt set including full admin with ppp support and the default Bootstrap theme
luci-theme-bootstrap - git-16.018.33482-3201903-1 - Bootstrap Theme (default)
luci-theme-freifunk-bno - git-16.018.33482-3201903-1 - Freifunk Berlin Nordost Theme
luci-theme-freifunk-generic - git-16.018.33482-3201903-1 - Freifunk Generic Theme
luci-theme-openwrt - git-16.018.33482-3201903-1 - LuCI OpenWrt.org theme

root@OpenWrt:~# opkg install luci-theme-openwrt luci-theme-freifunk-bno luci-theme-freifunk-generic

通过挂载点挂载U盘

默认系统不支持NTFS和VFAT格式,另外luci也没有挂载点这个功能,所以需要额外添加,这里要说明下,从网上收集的信息来看,不是特别推荐NTFS格式的存储设备,所以可以还是用ext3或ext4吧,下面是安装一堆东西,包括支持的文件,安装磁盘查看工具和界面挂载工具:

opkg install fdisk block-mount kmod-fs-ext4 e2fsprogs kmod-fs-ntfs mount-utils ntfs-3g blkid usbutils kmod-nls-base kmod-nls-utf8 kmod-usb-core kmod-usb-ohci kmod-usb-uhci kmod-usb2 kmod-usb-storage kmod-usb-storage-extras kmod-ata-marvell-sata

但发现luci挂载不成功,但U盘已经识别出来了,所以通过命令行试试,发现了问题:

root@OpenWrt:~# fdisk -l

Device     Boot Start      End  Sectors  Size Id Type
/dev/sda1          32 15633407 15633376  7.5G  b W95 FAT32

root@OpenWrt:~# df -h
Filesystem                Size      Used Available Use% Mounted on
rootfs                   23.6M      4.2M     18.1M  19% /
/dev/root                 2.5M      2.5M         0 100% /rom
tmpfs                   251.6M    696.0K    250.9M   0% /tmp
/dev/ubi0_1              23.6M      4.2M     18.1M  19% /overlay
overlayfs:/overlay       23.6M      4.2M     18.1M  19% /
ubi1:syscfg              29.6M    312.0K     27.7M   1% /tmp/syscfg
tmpfs                   512.0K         0    512.0K   0% /dev

root@OpenWrt:~# mount /dev/sda1 /usb
mount: wrong fs type, bad option, bad superblock on /dev/sda1,
       missing codepage or helper program, or other error

       In some cases useful info is found in syslog - try
       dmesg | tail or so.
root@OpenWrt:~# dmesg | tail
[   16.749622] ieee80211 phy0: change: 0x62
[   16.856067] br-lan: port 2(wlan0) entered forwarding state
[   16.861618] br-lan: port 2(wlan0) entered forwarding state
[   16.867200] IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready
[   16.934558] ieee80211 phy0: change: 0x20
[   18.020870] br-lan: port 1(eth1) entered forwarding state
[   18.390881] br-lan: port 3(wlan1) entered forwarding state
[   18.860872] br-lan: port 2(wlan0) entered forwarding state
[   91.067631] FAT-fs (sda1): codepage cp437 not found <<<
[  173.558015] FAT-fs (sda1): codepage cp437 not found <<<

所以查找确实的包并安装,挂载恢复正常:

root@OpenWrt:~# opkg list |grep 437
kmod-nls-cp437 - 3.18.23-1 - Kernel module for NLS Codepage 437 (United States, Canada)
root@OpenWrt:~# opkg install kmod-nls-cp437
Installing kmod-nls-cp437 (3.18.23-1) to root...
Downloading http://downloads.openwrt.org/chaos_calmer/15.05.1/mvebu/generic/packages/base/kmod-nls-cp437_3.18.23-1_mvebu.ipk.
Configuring kmod-nls-cp437.
root@OpenWrt:~# 
root@OpenWrt:~# 
root@OpenWrt:~# mount /dev/sda1 /usb
mount: wrong fs type, bad option, bad superblock on /dev/sda1,
       missing codepage or helper program, or other error

       In some cases useful info is found in syslog - try
       dmesg | tail or so.
root@OpenWrt:~# 
root@OpenWrt:~# dmesg | tail
[   16.856067] br-lan: port 2(wlan0) entered forwarding state
[   16.861618] br-lan: port 2(wlan0) entered forwarding state
[   16.867200] IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready
[   16.934558] ieee80211 phy0: change: 0x20
[   18.020870] br-lan: port 1(eth1) entered forwarding state
[   18.390881] br-lan: port 3(wlan1) entered forwarding state
[   18.860872] br-lan: port 2(wlan0) entered forwarding state
[   91.067631] FAT-fs (sda1): codepage cp437 not found
[  173.558015] FAT-fs (sda1): codepage cp437 not found
[  633.644659] FAT-fs (sda1): IO charset iso8859-1 not found <<<

root@OpenWrt:~# opkg list |grep 8859-1
kmod-nls-iso8859-1 - 3.18.23-1 - Kernel module for NLS ISO 8859-1 (Latin 1)
kmod-nls-iso8859-13 - 3.18.23-1 - Kernel module for NLS ISO 8859-13 (Latin 7; Baltic)
kmod-nls-iso8859-15 - 3.18.23-1 - Kernel module for NLS ISO 8859-15 (Latin 9)

root@OpenWrt:~# opkg install kmod-nls-iso8859-1
Installing kmod-nls-iso8859-1 (3.18.23-1) to root...
Downloading http://downloads.openwrt.org/chaos_calmer/15.05.1/mvebu/generic/packages/base/kmod-nls-iso8859-1_3.18.23-1_mvebu.ipk.
Configuring kmod-nls-iso8859-1.
root@OpenWrt:~# 
root@OpenWrt:~# mount /dev/sda1 /usb
root@OpenWrt:~# 

重启后,通过luci配置好挂载信息后,即使重启,也会自动挂载:

安装Samba

root@OpenWrt:/tmp# opkg list |grep -i samba  <<< 查看跟samba相关的包
root@OpenWrt:/tmp# opkg install samba36-server luci-app-samba luci-i18n-samba-zh-cn

通过luci来设置共享目录:

解决中文乱码问题

网上查了很多,简单总结下,默认openwrt应该支持中文,关键你是用什么姿势挂载u盘,所以需要在挂载时加些参数,如下所示:

解决不能编辑文件的问题

这应该跟挂载的属性相关,查了下,把rw,sync加到option里后,没想到一直报下面错误:

[  296.655222] FAT-fs (sda1): error, fat_get_cluster: invalid cluster chain (i_pos 0)
[  296.662867] FAT-fs (sda1): Filesystem has been set read-only
[  296.757175] FAT-fs (sda1): error, fat_get_cluster: invalid cluster chain (i_pos 0)
[  296.805345] FAT-fs (sda1): error, fat_get_cluster: invalid cluster chain (i_pos 0)
[  296.877589] FAT-fs (sda1): error, fat_get_cluster: invalid cluster chain (i_pos 0)
[  296.960368] FAT-fs (sda1): error, fat_get_cluster: invalid cluster chain (i_pos 0)

1. install brew, visit http://brew.sh/
2. install e2fsprogs using brew install e2fsprogs
3. figure out the name of your partition or drive using diskutil list — in my case, my partition had was on disk2 and had the identifier of disk2s1
4. sudo $(brew –prefix e2fsprogs)/sbin/mkfs.ext3 /dev/disk2s1 but you may need to change the drive from disk2s1 to the partition or drive that you want to format. This command will ask you to verify the name of the partition, just to be sure 🙂

YONZHAO2-M-Q4TL:dev zhaoyong$ diskutil list
/dev/disk0 (internal, physical):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *500.3 GB   disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:          Apple_CoreStorage Macintosh HD            499.4 GB   disk0s2
   3:                 Apple_Boot Recovery HD             650.0 MB   disk0s3

/dev/disk1 (internal, virtual):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:                            Macintosh HD           +499.1 GB   disk1
                                 Logical Volume on disk0s2
                                 A7856010-7DE9-462F-9541-4FC10BD251DC
                                 Unlocked Encrypted

/dev/disk2 (disk image):
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     Apple_partition_scheme                        +20.0 MB    disk2
   1:        Apple_partition_map                         32.3 KB    disk2s1
   2:                  Apple_HFS Flash Player            19.9 MB    disk2s2

/dev/disk3 (external, physical):<<<
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *8.0 GB     disk3
   1:                 DOS_FAT_32 NO NAME                 8.0 GB     disk3s1

YONZHAO2-M-Q4TL:dev zhaoyong$ sudo $(brew --prefix e2fsprogs)/sbin/mkfs.ext4 /dev/disk3 <<<
mke2fs 1.42.13 (17-May-2015)
Creating filesystem with 1954176 4k blocks and 488640 inodes
Filesystem UUID: 9d8e960d-de50-4f6b-89f3-eb266e4b89ea
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): 
done
Writing superblocks and filesystem accounting information: done

最终挂载非常简单,也支持中文

本文出自 Frank's Blog

版权声明:


本文链接:Deploy Samba on OpenWRT
版权声明:本文为原创文章,仅代表个人观点,版权归 Frank Zhao 所有,转载时请注明本文出处及文章链接
你可以留言,或者trackback 从你的网站

留言哦

blonde teen swallows load.xxx videos