找回密码
 立即注册
img_loading
智能检测中

QQ登录

只需一步,快速开始

搜索
广告投放联系QQ68610888广告投放联系QQ68610888
查看: 5561|回复: 1

WRTSL54GS动手玩 之 OpenWrt篇

[复制链接]
发表于 2009-10-20 11:52 | 显示全部楼层 |阅读模式
本帖最后由 myeyre 于 2009-10-20 12:51 编辑

原帖地址, 请指教:

http://hi.baidu.com/myeyre/blog/ ... eae42ccffca3d3.html

---------------------------------------------------------------------------------------

WRTSL54GS动手玩 之 OpenWrt篇

姐妹篇:
WRTSL54GS动手玩 之 DD-WRT篇: http://hi.baidu.com/myeyre/blog/ ... 98ebf1431694b3.html


1) Boot OpenWrt from external storage

OpenWrt区别于DD-WRT一个很大的地方是可写的文件系统(通过mini_fo Overlay Filesystem在rom上放一个jffs实现), 这给系统配置带来很大的灵活性, 但是虽然号称比NVRAM的方案更优, 这仍刺激我脆弱的小神经, 老担心板子上那块Flash挂掉, 毕竟我们是打算装些软件玩的.

那么先来把/文件系统放到外部存储上.

refer to:
Official OpenWrt Howtos:
http://oldwiki.openwrt.org/UsbStorageHowto.html
http://oldwiki.openwrt.org/OpenWrtDocs(2f)KamikazeConfiguration(2f)BootFromExternalMediaHowTo.html

A better pivotroot for OpenWRT:
http://www2.kaufmanfamily.net:80 ... votroot-for-openwrt
Persistent /var for OpenWRT:
http://www2.kaufmanfamily.net:80 ... ent-var-for-openwrt

#Install kernel modules for USB and ext3
opkg update
opkg install kmod-usb2 kmod-usb-storage kmod-fs-ext3

#
opkg install e2fsprogs swap-utils

#
dd if=/dev/zero of=/mnt/swap bs=1024 count=65536
mkswap /mnt/swap
#swapon /mnt/swap
#swapon /swap



#Mount it
#insmod usbcore ehci-hcd scsi_mod sd_mod usb-storage jbd ext3
mount /dev/discs/disc0/part1 /mnt

#Duplicate the existing tree on the mass storage device
mkdir /tmp/flash
mount -o bind / /tmp/flash   # this is necessary to prevent duplicating /proc /dev and so forth
tar -c -C /tmp/flash -f - . | tar -xv -C /mnt -f -
umount /tmp/flash
rmdir /tmp/flash
#umount /mnt

#mkdir for external and internal mount points
mkdir /ext
mkdir /mnt/int

#and touch a flag to identify it's internal flash
touch /root.int
#or a pivotroot target
touch /mnt/root.ext

#here comes the pivotroot script - tiny modded
cat > /etc/init.d/pivotroot
#!/bin/sh
# From http://oldwiki.openwrt.org/UsbStorageHowto.html - DHK 7/14/09
#
# Greatly enhanced to select among (maybe) several USB Mass Storage devices
# Assumes that the root fs will be on an ext3 filesystem in partition 1,
# and looks for /${external_mntpt} and /jffs in the root directory. Also assumes that
# mounting and checking each candidate device is harmless. Runs e2fsck
# over partitions before mounting them; note that this causes spurious
# date-related complaints every time, since time has not been synchronized
# yet at the time pivotroot is run.
#
# Output from this script is stashed at /tmp/pivotroot.log.
#
# DHK 7/23/2009

#Identify different mount points for internal flash and external storage
internal_mntpt=int
external_mntpt=ext

# Set Power LED flashing while we look for OpenWRT root
if [ -f /etc/diag.sh ]; then
  LED=1
  . /etc/diag.sh
  POW=`cat /proc/diag/led/power`
  set_led power f
fi

# install needed modules for usb and the ext3 filesystem
# We could defer loading the filesystem modules until we know there's a useful partition.
# **NOTE** for usb2.0 replace "uhci" with "ehci_hcd"
# **NOTE** for ohci chipsets replace "uhci" with "usb-ohci"
# **NOTE** for WL-500gP usb-uhci not usb-ohci
echo -n "pivotroot loading kernel modules: "
for module in usbcore ehci-hcd scsi_mod sd_mod usb-storage jbd ext3 ; do {
  echo -n "$module "
  insmod $module
}; done
echo
# this may need to be higher if your disk is slow to initialize
sleep 5s

PART1=`find /dev/scsi -name part1`

if [ -z $PART1 ]; then
  echo No partitions, skipping pivotroot
else
  # Look for a mountable USB stick with, maybe, OpenWRT on it
  for dev in `find /dev/scsi -name part1`; do
##I'd rather run fsck manually
#    echo pivotroot checking $dev
#    e2fsck -p $dev
#    fsck=$?
#    echo fsck status is $fsck
#    if [ $fsck -eq 2 ]; then
#      echo Corrected errors on $dev, need to reboot
#      sleep 5
#      reboot
#    elif [ $fsck -eq 1 ]; then
#      echo Corrected errors on $dev
#    elif [ $fsck -gt 2 ]; then
#      echo No usable filesystem on $dev
#      continue
#    fi
    echo Mounting $dev
    mount -t ext3 $dev /${external_mntpt}
    mt=$?
    if [ $mt -eq 0 ]; then
      if [ -x /${external_mntpt}/sbin/init -a -d /${external_mntpt}/jffs -a -d /${external_mntpt}/${internal_mntpt} -a -f /${external_mntpt}/root.ext ]; then
        echo Found OpenWRT root on $dev
        # Side-effect - leave /${external_mntpt} mounted
        break;
      else
        echo "Missing /sbin/init, /jffs, /${external_mntpt}/${internal_mntpt}, or /${external_mntpt}/root.ext (mount status was $mt)"
        [ -x /${external_mntpt}/sbin/init ]         || echo Failed -x /sbin/init
        [ -d /${external_mntpt}/${internal_mntpt} ] || echo Failed -x /${external_mntpt}/${internal_mntpt}
        [ -d /${external_mntpt}/jffs ]              || echo Failed -x /jffs
        [ -f /${external_mntpt}/root.ext ]          || echo Failed -f /${external_mntpt}/root.ext
        umount $dev
      fi
    else
      echo mount status is $mt
    fi
  done

  # if everything looks ok, do the pivot root
  [ -x /${external_mntpt}/sbin/init ] && {
          mount -o move /proc /${external_mntpt}/proc && \
          pivot_root /${external_mntpt} /${external_mntpt}/${internal_mntpt} && {
                  #We are in the new root now
                  mount -o move /${internal_mntpt}/dev /dev
                  mount -o move /${internal_mntpt}/tmp /tmp
                  mount -o move /${internal_mntpt}/jffs2 /jffs2 2>&-
                  mount -o move /${internal_mntpt}/sys /sys 2>&-
                  swapon /swap
          }
  }
fi

# Restore Power LED to previous state
[ $LED -eq 1 ] && set_led power $POW
^D


cat >> /etc/init.d/rcS
# Improved from http://oldwiki.openwrt.org/UsbStorageHowto.html
# Switch the root filesystem to USB, if present
# DHK 7/14/09
if [ $2 == "boot" -a -x /etc/init.d/pivotroot ] ; then
        /etc/init.d/pivotroot > /tmp/pivotroot.log 2>&-
fi

^D

#to boot from external storage
chmod a+x /etc/init.d/pivotroot

##or internal flash
#chmod a-x /int/etc/init.d/pivotroot


#
echo "  *
  * You are operating on internal flash!!
  *
---------------------------------------------------" >> /etc/banner
cat /etc/banner

echo "  *
  * You are operating on external storage!!
  *
---------------------------------------------------" >> /mnt/etc/banner
cat /mnt/etc/banner


#Persistent /var for OpenWRT
cd /mnt; rm var; mkdir -p var/etc

##I'd leave scripts still cause I didn't see any difference(??)
#/mnt/etc/init.d/boot
#/mnt/etc/init.d/syslog

reboot

2) Samba

opkg install samba3

cd /etc/samba/
rm smb.conf

cat > /etc/samba/smb.conf

xxxed, check the original url

#启动
/etc/init.d/samba start

没带nmbd?? 通过IP地址访问
\\192.168.10.1\

OK.

3) LAMP

#
opkg update
opkg install apache

vi /etc/apache/httpd.conf
Listen 8000

apachectl start

It works! :)

#no php module provided??

opkg install lighttpd php5 lighttpd-mod-fastcgi php5-fastcgi

居然需要手工配置??
echo 'include_shell "cat /etc/lighttpd-*.conf"' > /etc/lighttpd.conf

echo > lighttpd-php-fcgi.conf
server.modules += (
        "mod_fastcgi"
)

### fastcgi module
# read fastcgi.txt for more info
fastcgi.server = (
        ".php" => (
                "localhost" => (
                        "socket" => "/tmp/php-fcgi.socket",
                        "bin-path" => "/usr/bin/php-fcgi"
                )
        )
)
^D


cat > /www/i.php
<?php
        phpinfo();
?>
^D


OK

#no mysql provided:(


4) Optware


echo "src/gz optware-openwrt-brcm24 http://ipkg.nslu2-linux.org/feed ... cm24/cross/unstable" >> /etc/opkg.conf

opkg install ipkg-opt

vi /etc/opkg.conf
dd

vi /etc/profile
export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/opt/bin:/opt/sbin:/opt/usr/bin:/opt/usr/sbin

vi /etc/ipkg.conf
ipkg-opt update


ipkg install lighttpd php php-fastcgi mysql php-mysql

#mysql still doesn't work.


5) P2P

跟DD下大同小异, opkg和ipkg-opt应该都OK, 暂时不搞了.

目前为止OpenWrt的包管理给我的印象是很粗糙, 不仅软件版本低, 而且功能缺失, 配置文件布局很傻... 即便Optware也孤零零一个unstable在那里... 以前的良好印象几乎消失殆尽了.


6) USB Soundcard and UVC Webcam

这似乎是OpenWrt给我良好印象的原因, 可以方便的安装驱动模块, 但是目前 2.4 内核下我的摄像头驱动不起来, 2.6 内核下bcm无线驱动不起来... 也不细写了, 把以前的命令粘一下.

#注意: 我用的是Kamikaze brcm47xx 2.6内核的

#声卡
opkg install kmod-usb-audio

opkg install madplay

#播放本地文件
madplay -a -30 -v --tty-control *mp3

#网络广播
wget -O - http://scenemusic.unfy.org/necta | madplay -a -30 -

#摄像头
opkg install kmod-video-uvc

##not working??
#opkg install uvc_streamer
#opkg install mjpg-streamer

opkg install motion

#works
http://192.168.1.1:8081/

#注意: motion默认会保存抓图.


7) 打住吧先. 有空再说.
预计2025年7月5日或6日期间将对服务器进行停机维护,大概需要6小时左右,请及时做好数据备份。 |
只谈技术、莫论政事!(点击见详情) | 恩山无线论坛欢迎您的来访,请互相尊重、友善交流,建议保持一颗平常心看待网友的评论,切勿过度反应。
发表于 2012-10-9 13:10 来自手机 | 显示全部楼层
感谢,技术哥.
预计2025年7月5日或6日期间将对服务器进行停机维护,大概需要6小时左右,请及时做好数据备份。 |
只谈技术、莫论政事!(点击见详情) | 恩山无线论坛欢迎您的来访,请互相尊重、友善交流,建议保持一颗平常心看待网友的评论,切勿过度反应。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

欢迎大家光临恩山无线论坛

只谈技术、莫论政事!切勿转播谣言!为了你也为了他人。
只谈技术、莫论政事!(点击见详情) 切记不要随意传播谣言,把自己的日子过安稳了就行,为了自己好也为了大家好。 恩山无线论坛欢迎您的来访,请互相尊重、友善交流,建议保持一颗平常心看待网友的评论,切勿过度反应。

查看 »

有疑问请添加管理员QQ86788181|手机版|小黑屋|Archiver|恩山无线论坛(常州市恩山计算机开发有限公司版权所有) ( 苏ICP备05084872号 )

GMT+8, 2025-7-4 19:47

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

| 江苏省互联网有害信息举报中心 举报信箱:js12377 | @jischina.com.cn 举报电话:025-88802724 本站不良内容举报信箱:68610888@qq.com

快速回复 返回顶部 返回列表