理论知识
参考http://wiki.openwrt.org/doc/howto/extroot/extroot.theory
1. 安装必要的包
root@SmartRouter:/# opkg install kmod-usb-core kmod-usb-ohci kmod-usb-uhci kmod-usb2 --force-depends
root@SmartRouter:/# opkg install kmod-usb-storage kmod-usb-storage-extras kmod-fs-ext4 kmod-fs-vfat kmod-nls-utf8 kmod-nls-cp437 --force-depends
root@SmartRouter:/# opkg install usbutils fdisk block-mount e2fsprogs blkid --force-depends
上面的kmod-fs-ext4 等很多安装出现与kernel不一致的提示,使用 --force-depends 进行安装
mkfs.ext4 /dev/sda2 后 mount device 发现如下错误,折腾半天软件reboot也未果
openwrt mount: mounting /dev/sda2 on /mnt failed: Invalid argument
dmesg 发现 y 很多 fat: Unknown symbol __blockdev_direct_IO (err 0)
怀疑这张sd卡是有很多坏道的,在手机上也是时而认时而不认
更换一个新的sd卡
分区保存时
Re-reading the partition table failed.: Invalid argument
原来是因为写成了 fdisk /dev/sda1 而应该是fdisk /dev/sda
==============================================
mkfs.ext4 /dev/sda2
mkdir /mnt/extroot
mount /dev/sda1 /mnt/extroot
tar -C /overlay -cvf - . | tar -C /mnt/extroot -xf -
umount /mnt/extroot/
root@OpenWrt:/# blkid
/dev/mtdblock2: TYPE="squashfs"
/dev/sda2: UUID="5fb06bd1-12f3-434a-a8b7-12bc89f2f868" TYPE="ext4
block detect > /etc/config/fstab # block-mount 一定要装,不然不会自动mount 而且block detect 命令没有
vi /etc/config/fstab
root@OpenWrt:~# cat /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 'swap'
option device '/dev/sda1'
option enabled '0'
config 'mount'
option target '/overlay'
# option uuid 'a6395b9e-1654-4cce-8d65-580b275774d6'
option uuid '786c2745-2ad0-48b1-9c1c-f436d7f0e2c9'
option enabled '1'
重启后/dev/sda2 on /overlay type ext4 (rw,relatime,data=ordered)
root@OpenWrt:~# mount
rootfs on / type rootfs (rw)
/dev/root on /rom type squashfs (ro,relatime)
proc on /proc type proc (rw,noatime)
sysfs on /sys type sysfs (rw,noatime)
tmpfs on /tmp type tmpfs (rw,nosuid,nodev,noatime)
/dev/sda2 on /overlay type ext4 (rw,relatime,data=ordered)
overlayfs:/overlay on / type overlay (rw,noatime,lowerdir=/,upperdir=/overlay/upper,workdir=/overlay/work)
tmpfs on /dev type tmpfs (rw,relatime,size=512k,mode=755)
devpts on /dev/pts type devpts (rw,relatime,mode=600)
debugfs on /sys/kernel/debug type debugfs (rw,noatime)
root@OpenWrt:~# df
Filesystem 1K-blocks Used Available Use% Mounted on
rootfs 5443728 21992 5122168 0% /
/dev/root 3328 3328 0 100% /rom
tmpfs 30592 56 30536 0% /tmp
/dev/sda2 5443728 21992 5122168 0% /overlay
overlayfs:/overlay 5443728 21992 5122168 0% /
tmpfs 512 0 512 0% /dev
===============================================
查看swap发现 swap没有生效
root@OpenWrt:~# free
total used free shared buffers
Mem: 61188 24984 36204 56 3216
-/+ buffers: 21768 39420
Swap: 0 0 0
解决方法:
mkswap /dev/sda1
swapon /dev/sda1
======================================================
为了访问最初的boot目录 ,将它mount到/overlay-boot目录 ,一定要在extroot下创建overlay-boot 一定要在extroot下安装 block-mount,否则/etc/config/fstab 中的内容不执行
config 'mount'
option target /overlay-boot
option device /dev/mtdblock3
option fstype jffs2
option options rw,sync
option enable 1
option enabled_fsck 0
这样就可以访问最初的fstab了,CC版本好像多了一个upper 目录
root@OpenWrt:~# cat /overlay-boot/upper/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 'swap'
option device '/dev/sda1'
option enabled '1'
config 'mount'
option target '/overlay'
# option uuid 'a6395b9e-1654-4cce-8d65-580b275774d6'
option uuid '5fb06bd1-12f3-434a-a8b7-12bc89f2f868'
option enabled '1'
config 'mount'
option target /overlay-boot
option device /dev/mtdblock3
option fstype jffs2
option options rw,sync
option enable 1
option enabled_fsck 0
参考资料
http://wiki.openwrt.org/doc/howto/extroot