首先ssh登录路由。
一、对u盘分区
root@OpenWrt :~# fdisk /dev/sda
Command (m for help): n #输入n新建一个分区,回车
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): #默认主分区,直接回车
Using default response p.
Partition number (1-4, default 1): #分区编号,默认,直接回车
First sector (2048-8235007, default 2048): #起始扇区,默认,直接回车
Last sector, +sectors or +size{K,M,G,T,P} (2048-8235007, default 8235007): +1G #输入+1G回车,分区大小设定为1GiB
Created a new partition 1 of type 'Linux' and of size 1 GiB.
#其他分区与上类似,省略。。。。。。
Command (m for help): w #按w回车保存退出
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
二、格式化分区
root @OpenWrt :~# mkfs.ext4 /dev/sda1 -O ^has_journal,extent -L hg255d
在EXT4文件系统下,使用"-O ^hasjournal,extent"参数格式化可以提高读取大文件的性能。
三、拷贝根目录“/”下的所有文件到U盘
root @OpenWrt :~# mount /dev/sda1 /mnt -t ext4 #挂载U盘第一个分区到/mnt
root @OpenWrt :~# mkdir /tmp/root #/tmp下创建root目录
root @OpenWrt :~# mount -o bind / /tmp/root #挂载并同步系统根目录“/”到/tmp/root
root @OpenWrt :~# cp -a /tmp/root/* /mnt/ #拷贝/tmp/root下所有文件到U盘
root @OpenWrt :~# umount /tmp/root #卸载/tmp/root
修改/mnt/etc/banner,如此便可知道是不是从U盘启动了。
root @OpenWrt :~# vi /mnt/etc/banner
_______ ________ __
| |.-----.-----.-----.| | | |.----.| |_
| - || _ | -__| || | | || _|| _|
|_______|| __|_____|__|__||________||__| |____|
|__| W I R E L E S S F R E E D O M
-----------------------------------------------------
BARRIER BREAKER (Bleeding Edge, r41302)
From USB device... #添加的标识
-----------------------------------------------------
* 1/2 oz Galliano Pour all ingredients into
* 4 oz cold Coffee an irish coffee mug filled
* 1 1/2 oz Dark Rum with crushed ice. Stir.
* 2 tsp. Creme de Cacao
-----------------------------------------------------
root @OpenWrt :~# umount /dev/sda1 #卸载/dev/sda1
四、修改/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 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 device '/dev/sda2'
option fstype 'ext4'
option enabled '1'
option options 'rw,sync'
option target '/'
五、重启路由
重启路由后,ssh登录路由。打印的banner信息中看到我们加的标识就代表已经把系统搬到U盘里了。