原文地址http://blog.csdn.net/qinpeng_zbdx/article/details/8577212
说明
本篇博客是上一篇博客的继续,完成之后的挂载USB设备、配置ftp服务以及支持脱机下载。
挂载USB设备
废话就不说了,直接讲步骤。
首先把U盘插在wr703n的usb端口上,然后使用putty登陆路由器,输入命令:
ls /dev
查找是否有名为sda、sda1的文件。在这里sda是指整个U盘,而sda1指的是第一个分区。查找到后,说明U盘已经为系统所识别了。接下来,就需要把U盘进行格式化与分区,以满足我们的需要。
首先安装工具软件,命令如下:
opkg update
opkg install fdisk swap-utils
fdisk用于格式化U盘以及进行分区,swap-utils用于创建swap(内存交换空间)。
依次键入以下命令:
fdisk /dev/sda // 对sda,即我们的U盘,进行相关分区、格式化操作
p // 显示U盘分区状况
d // 删除分区,之后需要你输入删除的分区号,建议使用该命令删除所有分区,然后重新分区
n // 新增分区
在最后输入+4G,以创建4个G的分区sda1作为系统挂载点
再输入n,在最后输入+256M,以创建256M的swap。
输入t,选择修改sda2的分区格式,输入ID,82,修改为swap格式。
之后,输入w更新分区表。
输入free查看内存使用状况,这时看到没有swap。
输入:mkswap /dev/sda2 // 构建swap格式
swapon /dev/sda2 // 启动swap
然后再使用free查看内存使用状况,可以看到swap已经启用。
接下来是比较有意思的,就是把我们的OpenWrt复制到U盘,然后设置从U盘启动我们的系统。
首先,安装如下软件:
opkg update
opkg install block-mount kmod-usb-storage kmod-fs-ext4 e2fsprogs
如果想要一次性把U盘格式化为ext4格式,可以使用mkfs.ext4 /dev/sda1,当然这个是和之前说的互补的。
然后,就把整个OpenWrt系统拷贝到我们的U盘,并进行一些设置。命令如下:
mount /dev/sda1 /mnt // 挂载U盘第一个分区到/mnt
mkdir /tmp/root // 在/tmp目录下创建名叫root的一个目录
mount -o bind / /tmp/root // 挂载并同步系统根目录“/”到/tmp/root
cp /tmp/root/* /mnt -a // 拷贝/tmp/root下所有文件到“/mnt”,这个其实就是你的U盘了
umount /tmp/root // 卸载/tmp/root
umount /mnt // 卸载/mnt
通过以上命令,就创建了能够启动OpenWrt系统的U盘,然后修改/etc/config/fstab文件,如下:
config mount
option target /mnt
option device /dev/sda1
option fstype ext4
option options rw,sync
option enabled 1
option enabled_fsck 1
option is_rootfs 1
输入reboot,重启完成后输入df,查看挂载点。OK
提示:也可以通过修改/etc/banner,来提示我们是从USB启动的。比如,在最后加一句提示语:
Boot From USB!
同样修改文件/etc/config/fstab,设置自动加载swap,
config swap
device /dev/sda2
enabled 1
然后重启fstab服务,并设置其自启动。
/etc/init.d/fstab restart
/etc/init.d/fstab enable
也可以通过创建swap文件的方式来建立内存交换空间,首先,通过命令:
dd if=/dev/zero of=/tmp/swap bs=1M count=128
来新增一个128M的文件在tmp下面。
然后,把该文件格式化为swap文件格式,
mkswap /tmp/swap
最后启动该swap,
swapon /tmp/swap
好了,这就是如何设置从U盘启动OpenWrt,以及建立内存交换区。经过这一步,大大提高了OpenWrt应用的范围,允许我们做更多的事情。
配置ftp服务
listen=YES
#不允许匿名用户登陆
anonymous_enable=NO
#允许本地用户登陆
local_enable=YES
#允许上传
write_enable=YES
local_umask=022
check_shell=NO
#本地用户主目录
local_root=/ftp/test
#限制用户只能访问主目录
chroot_local_user=YES
accept_timeout=60
idle_session_timeout=300
max_clients=600
max_per_ip=5
#dirmessage_enable=YES
#设置响应语句
ftpd_banner=Welcome to blah FTP service.qp
session_support=NO
#syslog_enable=YES
#userlist_enable=YES
#userlist_deny=NO
#userlist_file=/etc/vsftpd.users
#xferlog_enable=YES
#xferlog_file=/var/log/vsftpd.log
#xferlog_std_format=YES
借由Transmission实现脱机下载
- config transmission
- option enabled 1
- option config_dir '/mnt/sda3/transmission'
- #option user 'nobody'
- #配置重点
- #关于计划时段的配置,配置在特定时间的下载状况
- #也可以通过点击web界面的小乌龟来启用
- option alt_speed_down 250
- option alt_speed_enabled true
- option alt_speed_time_begin 930
- option alt_speed_time_day 127
- option alt_speed_time_enabled true
- option alt_speed_time_end 1410
- option alt_speed_up 50
- #----------------
- option bind_address_ipv4 '0.0.0.0'
- option bind_address_ipv6 '::'
- option blocklist_enabled false
- option blocklist_url ''
- option cache_size_mb 2
- option dht_enabled true
- option download_dir '/mnt/sda3/transmission/done'
- option download_queue_enabled true
- option download_queue_size 4
- option encryption 1
- option idle_seeding_limit 30
- option idle_seeding_limit_enabled false
- option incomplete_dir '/mnt/sda3/transmission/incomplete'
- option incomplete_dir_enabled false
- option lazy_bitfield_enabled true
- option lpd_enabled false
- option message_level 1
- option peer_congestion_algorithm ''
- option peer_limit_global 80
- option peer_limit_per_torrent 60
- option peer_port 51413
- option peer_port_random_high 65535
- option peer_port_random_low 49152
- option peer_port_random_on_start false
- option peer_socket_tos 'default'
- option pex_enabled true
- option port_forwarding_enabled true
- option preallocation 1
- option prefetch_enabled true
- option queue_stalled_enabled true
- option queue_stalled_minutes 30
- option ratio_limit 2.0000
- option ratio_limit_enabled false
- option rename_partial_files true
- #配置重点
- #关于用户名、密码
- option rpc_authentication_required true
- option rpc_bind_address '0.0.0.0'
- option rpc_enabled true
- option rpc_password 'qinpeng'
- option rpc_port 9091
- option rpc_url '/transmission/'
- option rpc_username 'qp'
- #----------------
- option rpc_whitelist '127.0.0.1,192.168.1.*'
- option rpc_whitelist_enabled false
- option scrape_paused_torrents_enabled true
- option script_torrent_done_enabled false
- option script_torrent_done_filename ''
- option seed_queue_enabled false
- option seed_queue_size 10
- #配置重点
- #此处配置平时下载状态
- option speed_limit_down 260
- option speed_limit_down_enabled true #开启平时下载速度限制
- option speed_limit_up 30 #基于TCP特性,低于40性能佳
- option speed_limit_up_enabled true
- #----------------
- option start_added_torrents true
- option trash_original_torrent_files false
- option umask 18
- option upload_slots_per_torrent 14
- option utp_enabled true
- option scrape_paused_torrents true
- option watch_dir_enabled false
- option watch_dir ''
config transmission
option enabled 1
option config_dir '/mnt/sda3/transmission'
#option user 'nobody'
#配置重点
#关于计划时段的配置,配置在特定时间的下载状况
#也可以通过点击web界面的小乌龟来启用
option alt_speed_down 250
option alt_speed_enabled true
option alt_speed_time_begin 930
option alt_speed_time_day 127
option alt_speed_time_enabled true
option alt_speed_time_end 1410
option alt_speed_up 50
#----------------
option bind_address_ipv4 '0.0.0.0'
option bind_address_ipv6 '::'
option blocklist_enabled false
option blocklist_url ''
option cache_size_mb 2
option dht_enabled true
option download_dir '/mnt/sda3/transmission/done'
option download_queue_enabled true
option download_queue_size 4
option encryption 1
option idle_seeding_limit 30
option idle_seeding_limit_enabled false
option incomplete_dir '/mnt/sda3/transmission/incomplete'
option incomplete_dir_enabled false
option lazy_bitfield_enabled true
option lpd_enabled false
option message_level 1
option peer_congestion_algorithm ''
option peer_limit_global 80
option peer_limit_per_torrent 60
option peer_port 51413
option peer_port_random_high 65535
option peer_port_random_low 49152
option peer_port_random_on_start false
option peer_socket_tos 'default'
option pex_enabled true
option port_forwarding_enabled true
option preallocation 1
option prefetch_enabled true
option queue_stalled_enabled true
option queue_stalled_minutes 30
option ratio_limit 2.0000
option ratio_limit_enabled false
option rename_partial_files true
#配置重点
#关于用户名、密码
option rpc_authentication_required true
option rpc_bind_address '0.0.0.0'
option rpc_enabled true
option rpc_password 'qinpeng'
option rpc_port 9091
option rpc_url '/transmission/'
option rpc_username 'qp'
#----------------
option rpc_whitelist '127.0.0.1,192.168.1.*'
option rpc_whitelist_enabled false
option scrape_paused_torrents_enabled true
option script_torrent_done_enabled false
option script_torrent_done_filename ''
option seed_queue_enabled false
option seed_queue_size 10
#配置重点
#此处配置平时下载状态
option speed_limit_down 260
option speed_limit_down_enabled true #开启平时下载速度限制
option speed_limit_up 30 #基于TCP特性,低于40性能佳
option speed_limit_up_enabled true
#----------------
option start_added_torrents true
option trash_original_torrent_files false
option umask 18
option upload_slots_per_torrent 14
option utp_enabled true
option scrape_paused_torrents true
option watch_dir_enabled false
option watch_dir ''
/root/.config/transmission-daemon/settings.json
- {
- "alt-speed-down": 50,
- "alt-speed-enabled": false,
- "alt-speed-time-begin": 540,
- "alt-speed-time-day": 127,
- "alt-speed-time-enabled": false,
- "alt-speed-time-end": 1020,
- "alt-speed-up": 50,
- "bind-address-ipv4": "0.0.0.0",
- "bind-address-ipv6": "::",
- "blocklist-enabled": false,
- "blocklist-url": "http://www.example.com/blocklist",
- "cache-size-mb": 2,
- "dht-enabled": true,
- "download-dir": "/root/Downloads",
- "download-queue-enabled": true,
- "download-queue-size": 5,
- "encryption": 0,
- "idle-seeding-limit": 30,
- "idle-seeding-limit-enabled": false,
- "incomplete-dir": "/root/Downloads",
- "incomplete-dir-enabled": false,
- "lpd-enabled": false,
- "message-level": 2,
- "peer-congestion-algorithm": "",
- "peer-limit-global": 240,
- "peer-limit-per-torrent": 60,
- "peer-port": 51413,
- "peer-port-random-high": 65535,
- "peer-port-random-low": 49152,
- "peer-port-random-on-start": false,
- "peer-socket-tos": "default",
- "pex-enabled": true,
- "port-forwarding-enabled": true,
- "preallocation": 1,
- "prefetch-enabled": 0,
- "queue-stalled-enabled": true,
- "queue-stalled-minutes": 30,
- "ratio-limit": 2,
- "ratio-limit-enabled": false,
- "rename-partial-files": true,
- "rpc-authentication-required": false,
- "rpc-bind-address": "0.0.0.0",
- "rpc-enabled": true,
- "rpc-password": "{273bb11b4ab7f9e9180fa9d3d2fca9ad41f18c2ed1zmxIkB",
- "rpc-port": 9091,
- "rpc-url": "/transmission/",
- "rpc-username": "",
- "rpc-whitelist": "0.0.0.0",
- "rpc-whitelist-enabled": true,
- "scrape-paused-torrents-enabled": true,
- "script-torrent-done-enabled": false,
- "script-torrent-done-filename": "",
- "seed-queue-enabled": false,
- "seed-queue-size": 10,
- "speed-limit-down": 100,
- "speed-limit-down-enabled": false,
- "speed-limit-up": 100,
- "speed-limit-up-enabled": false,
- "start-added-torrents": true,
- "trash-original-torrent-files": false,
- "umask": 18,
- "upload-slots-per-torrent": 14,
- "utp-enabled": true
- }<SPAN style="FONT-FAMILY: Microsoft YaHei; FONT-SIZE: 18px">
- </SPAN>
{
"alt-speed-down": 50,
"alt-speed-enabled": false,
"alt-speed-time-begin": 540,
"alt-speed-time-day": 127,
"alt-speed-time-enabled": false,
"alt-speed-time-end": 1020,
"alt-speed-up": 50,
"bind-address-ipv4": "0.0.0.0",
"bind-address-ipv6": "::",
"blocklist-enabled": false,
"blocklist-url": "http://www.example.com/blocklist",
"cache-size-mb": 2,
"dht-enabled": true,
"download-dir": "/root/Downloads",
"download-queue-enabled": true,
"download-queue-size": 5,
"encryption": 0,
"idle-seeding-limit": 30,
"idle-seeding-limit-enabled": false,
"incomplete-dir": "/root/Downloads",
"incomplete-dir-enabled": false,
"lpd-enabled": false,
"message-level": 2,
"peer-congestion-algorithm": "",
"peer-limit-global": 240,
"peer-limit-per-torrent": 60,
"peer-port": 51413,
"peer-port-random-high": 65535,
"peer-port-random-low": 49152,
"peer-port-random-on-start": false,
"peer-socket-tos": "default",
"pex-enabled": true,
"port-forwarding-enabled": true,
"preallocation": 1,
"prefetch-enabled": 0,
"queue-stalled-enabled": true,
"queue-stalled-minutes": 30,
"ratio-limit": 2,
"ratio-limit-enabled": false,
"rename-partial-files": true,
"rpc-authentication-required": false,
"rpc-bind-address": "0.0.0.0",
"rpc-enabled": true,
"rpc-password": "{273bb11b4ab7f9e9180fa9d3d2fca9ad41f18c2ed1zmxIkB",
"rpc-port": 9091,
"rpc-url": "/transmission/",
"rpc-username": "",
"rpc-whitelist": "0.0.0.0",
"rpc-whitelist-enabled": true,
"scrape-paused-torrents-enabled": true,
"script-torrent-done-enabled": false,
"script-torrent-done-filename": "",
"seed-queue-enabled": false,
"seed-queue-size": 10,
"speed-limit-down": 100,
"speed-limit-down-enabled": false,
"speed-limit-up": 100,
"speed-limit-up-enabled": false,
"start-added-torrents": true,
"trash-original-torrent-files": false,
"umask": 18,
"upload-slots-per-torrent": 14,
"utp-enabled": true
}
补充说明:上面路径中的sda3是我所挂载的U盘的第三个分区,专门用于下载。
3,完成后,输入以下命令: