[HowTo] OpenWRT on x86 PC

来源:互联网 发布:浅析网络舆论监督 编辑:程序博客网 时间:2024/05/21 09:11

In order to get more familiar with the lightest and awesome distro that OWRT is, I had to install it on my PC or in VMWare.
And there are not much information for almost beginners like me... So I will write here what I do with 8.09 version.

Note : This HowTo is based on the Slitaz 2.0 distro, the next lightest distro after OWRT : http://www.slitaz.org
"SliTaz is an open source and free operating system providing a fully featured desktop or server in less than 30 Mb."
Great for old PC with 192 MB Ram min and small HDD. Thanks Slitaz (and Erjo how help me) !
Slitaz is also available as a core distro (without Xorg) : only 6 MB and only 128 MB Ram !
See the slitaz-2.0-base.iso version here : http://mirror.slitaz.org/iso/2.0/flavors/


[HowTo] Install OpenWRT on x86 PC

1 -
 Get the image here : http://downloads.openwrt.org/kamikaze/8.09/x86/

Some informations first : The openwrt-x86-XXX.fs files contain only the rootfs partition whereas the openwrt-x86-XXX.image.kernel files contain the kernel partition.

I download the openwrt-x86-ext2.image file. It produces a standard installation, like any Linux distro. Try this first !
(If you want to see how jffs with mini_fo works like in a router, you can use the openwrt-x86-squashfs.image. I didn't try yet the jffs2 files...)

Copy the image on a USB key.

2 - Copy the image on HDD :

For this, download the LiveCD Linux distro Slitaz : you don't need to install it.

Boot your PC with the Slitaz CD and login as tux (No PWD). The disk where to install OWRT (I'll say it is /dev/hda) will be detected automatically by Slitaz (Note : I don't have tested this with SATA HDD).
Insert USB key, it'll appear in the file manager (in the dir /media/USB2 or something like that, depends on your key)
Open a console and get root via "su -" and the root pwd which is : root.
Copy the image on HDD : "dd if=/media/USB2/openwrt-x86-ext2.image of=/dev/hda bs=1M count=100"
That's all folks !

3 - Boot on HDD and enjoy OWRT
:)


Now, for those who want to make a "LiveUSB Key" installation of OWRT, you need the ramdisk image of OpenWRT. It's not available in the download repository so you will first need to compile it. Here's my method :
[HowTo] Compile OpenWRT

1 -
 Install Slitaz 2.0 on a dedicated 4 GB min HDD (in a VM, for example) :

Boot your PC on the Slitaz CD and login as tux (no PWD).
Open a console and get root via "su -" and the root pwd which is : root.
Partition your HDD with "fdisk /dev/hda", type "n" to add a new partition hda1 and "w" to write the partition table.
Launch "slitaz-installer" as root and follow instructions. You can get help with Slitaz on forum (http://forum.slitaz.org).
Slitaz is now installed on /dev/hda1.

Now, you will need to install some more packages. Run this as root : "tazpkg recharge; tazpkg get-install slitaz-toolchain".
Do the same "tazpkg get-install XXX" for : bash, ncurses-dev, zlib-dev, gawk, flex, bzip2, python, tar, findutils, wget, patch, diffutils, perl, coreutils. Though it's not checked by prereq.mk, the m4 package is necessary to compile 8.09.1 sources (for the trunk compilation, no m4 package but you'll need the subversion package).

Note : you can also install sakura package (another xterm) to help copy and paste in console.

2 - Get sources of OpenWRT 8.09 and compile it :

Now you can get, configure and compile OWRT as normal user Tux :
Download and go into the extracted tar.bz2 sources directory (from http://downloads.openwrt.org/kamikaze/8.09.1/).
("svn co svn://svn.openwrt.org/openwrt/trunk owrt; cd owrt" for the trunk)
"make menuconfig"
Select in the target system menu, the X86 generic PC. Then in the target image menu, select generating a ramdisk file.
Save configuration before exit then run "make".

After a quite long time, the result of compilation is in /owrt/trunk/bin. The ramdisk file is a very little file called openwrt-x86-vmlinuz, containing the kernel and ramdisk rootfs.

Here is my own build :
stock 8.09.1 Ramdisk
(R15955 of the trunk)

Nota : You can find another HowTo here with Ubuntu/VMWare for WhiteRussian : http://forum.openwrt.org/viewtopic.php?id=8410.
You can also find generic help for building OWRT there, as usual : http://downloads.openwrt.org/kamikaze/docs/openwrt.html

3 - Install OpenWRT image on a USB key :
We're going to install Slitaz on an existing FAT USB key and add the OWRT image to it.
So in Slitaz, launch "tazusbbox" as root. Select the source to install (CDRom) and the USB key for destination (certainly /dev/sda1). Then generate.
That's it : Slitaz is installed on the key. Try it, that's great !

Next, copy the ramdisk file as vmlinuz in a OWRT directory on the USB key. Then modify the file boot/syslinux/syslinux.cfg as this :

Code:

display syslinux.msglabel slitaz    kernel /boot/bzImage    append initrd=/boot/rootfs.gz rw root=/dev/null vga=normal autologin home=2C3F-6155include common.cfglabel owrt    kernel /OWRT/vmlinuz    append console=tty0 reboot=biosdefault owrttimeout 20

With this, Openwrt will boot as default after 3 seconds (Slitaz is still available). You can enjoy OpenWRT on any PC, boot in 2 seconds. But your modification will not remain after a reboot...


Next one, my method to :
[HowTo] Make "LiveUSB Key" OpenWRT

Needed : The steps above are supposed to be done.

1 - Create a rootfs addon to modify the stock ramdisk :

The modifications will be made via another initrd append to the first one (see here : http://www.mjmwired.net/kernel/Document … fs.txt#210). I called it modUSB.gz.

I create a modUSB directory in my home where will be the rootfs modifications.
Add an opkg directory where you can place all the packages you want to add to the stock ramdisk.
So I download (from http://downloads.openwrt.org/kamikaze/8 … /packages/) and place :
* In opkg/std, the packages needed to have the ext3 and loop support :
kmod-fs-ext3_2.6.25.20-x86-1_i386.ipk
kmod-loop_2.6.25.20-x86-1_i386.ipk
* In opkg/fat, all the packages needed to see VFAT partition on the key :
kmod-fs-vfat_2.6.25.20-x86-1_i386.ipk
kmod-nls-base_2.6.25.20-x86-1_i386.ipk
kmod-nls-cp437_2.6.25.20-x86-1_i386.ipk
kmod-nls-iso8859-1_2.6.25.20-x86-1_i386.ipk
* In opkg/usb2, all the packages needed to have USB2 support for the key :
kmod-scsi-core_2.6.25.20-x86-1_i386.ipk
kmod-usb-core_2.6.25.20-x86-1_i386.ipk
kmod-usb-storage_2.6.25.20-x86-1_i386.ipk
kmod-usb2_2.6.25.20-x86-1_i386.ipk

* And everything else you need...

Then I use this little script to create the modUSB.gz :

Code:

#!/bin/sh(cd modUSB; find . | cpio -o -H newc | gzip -9) > modUSB.gz

2 - Modify the init script to add the loop function :

The stock one is in the OWRT directory, there : target/linux/generic-2.6/base-files/init.
I made it a little more simpler, faster and add loop function and ability to use opkg added to the directory called "modUSB".

Code:

#!/bin/sh# Copyright (C) 2006 OpenWrt.org## ModUSB# Copie du rootfs initialmkdir /modUSB/tmpcp -a /* /modUSB/tmp 2>/dev/nullrm -r /modUSB/tmp/modUSB/tmp# Changement du clavier si besoin[ -n "$lang" ] && loadkmap < /modUSB/$lang.kmapINITRAMFS=1. /etc/preinit# if we have no root parameter, just go to running from ramfs[ -z $rootfs ] && {  export NOMOUNT="No Root"  exec /sbin/init}#if we have a failsafe boot selected, dont bother#trying to find or wait for a root mount point[ -z "$FAILSAFE" ] || {  exec /bin/busybox init}# Chargement des packages presents dans /modUSBopkg install /modUSB/opkg/*.ipk >/dev/nullopkg install /modUSB/opkg/*/*.ipk >/dev/null# Load the modules we have in initramfs, this should# make the media accessible, but, it may take some time. /etc/functions.shload_modules /etc/modules /etc/modules.d/*#wait 10 seconds for the disc to show up#usb stick typically takes 4 to 6 seconds#till it's readable#it's quite possible the disc never shows up#if we netbooted this kernelCOUNTER=0while [ ! -e ${rootfs%-loop} ]; do  sleep 1; echo -e "\nWaiting for device ${rootfs%-loop}"  let COUNTER=COUNTER+1  [ $COUNTER -eq 9 ] && {    export FAILSAFE="NoDisc"    exec /bin/busybox init  }done# Test si mode loop : rootfs=XXX-loop[ "$rootfs" != "${rootfs%-loop}" ] && loop=/tmp/mnt/FsOWRT# now we'll try mount it, again with a timeout# This will fail if the inserted stick is formatted# in a manner we dont understande2fsck -p ${rootfs%-loop}COUNTER=0[ -z $loop ] || mkdir -p /tmp/mntwhile ! mount ${rootfs%-loop} ${loop:+/tmp}/mnt; do  sleep 1  let COUNTER=COUNTER+1  [ $COUNTER -eq 9 ] && {    export FAILSAFE="MountFail"    exec /bin/busybox init  }done[ -z $loop ] || {# Montage du filesystem en loop (apres initialisation si besoin)[ ! -f $loop ] && mke2fs -V >/dev/null && {  dd if=/dev/zero of=$loop bs=1024 count=49152  mke2fs -q -j -F $loop}cp /modUSB/FsOWRT.bz2 $loop.bz2[ ! -f $loop -a -f $loop.bz2  ] && {  cp $loop.bz2 $loop.1.bz2  bunzip2 $loop.bz2  mv $loop.1.bz2 $loop.bz2}COUNTER=0while ! mount -t ext3 -o noatime,sync $loop /mnt; do  sleep 1  let COUNTER=COUNTER+1  [ $COUNTER -eq 9 ] && {    export FAILSAFE="LoopMountFail"    exec /bin/busybox init  }done[ ! -e /mnt/etc/banner ] && rm -r /mnt/* && mv /modUSB/tmp/* /mnt# Nettoyagefor i in `ls /modUSB/opkg/e2fs | sed 's/_.*//'`; do opkg remove $i; donerm -r /modUSB/opkg}rm -r /modUSB/tmp#It mounted, lets look for a postinit file, again, give it time#I've seen this take 6 seconds to actually completeCOUNTER=0while [ ! -e /mnt/etc/banner ]; do  sleep 1  let COUNTER=COUNTER+1  [ $COUNTER -eq 9 ] && {    export FAILSAFE="No Openwrt FS"    exec /bin/busybox init  }doneunset rootfs loopfor i in proc dev "dev/pts" tmp sys; do  mount -o move /$i /mnt/$idonekillall -q hotplug2exec switch_root -c /dev/console /mnt /sbin/init

3 - Modify your OpenWRT installation on your USB key :

Modify the file boot/syslinux/syslinux.cfg to add the rootfs directive with loop : for example /dev/sda1-loop for a key that the system see in sda1. Add also the initrd directive to take the modUSB.gz into account. I also add a "lang" parameter (see below for the keyboard layout).

In bold, are the modifications :
label owrt
    kernel /OWRT/vmlinuz
    append initrd=/OWRT/modUSB.gz lang=fr-latin1 rootfs=/dev/sda1-loop console=tty0 reboot=bios

With this, Openwrt boot in 12 seconds from the USB key on my not so new notebook.
I can now enjoy OpenWRT on any PC, and all my modifications remain after a reboot...

You can find my modUSB.gz here.


[HowTo] Change keyboard layout in OpenWRT

When you have no network and have to use OWRT console, it's a pain to use the default US keyboard with a french one...

So you'll have to add the loadkmap utility to busybox via the .config located in the root of the OpenWRT sources. Search for the loadkmap word and change the line "# CONFIG_BUSYBOX_CONFIG_LOADKMAP is not set" to "CONFIG_BUSYBOX_CONFIG_LOADKMAP=y". Then launch the compilation of your ramdisk image as usual.
If you have already compile it, you can re-compile only busybox and get the new ramdisk image with :
"make package/busybox/clean; make package/busybox/install; make target/install"

The busybox package is only 0.1 Kbytes larger with this. Now add, for example, the fr-latin1.kmap to your rootfs (you can find it in the /usr/share/kmap dir of the slitaz distro). To use it, just try "loadkmap < fr-latin1.kmap". Et voila, no more headake ;)

If needed, I can provide the 8.09.1 ramdisk with loadkmap inside.


[HowTo] Add cpio archive creation in OpenWRT

Will be interesting for next step...
Like above, via the .config located in the root of the OpenWRT sources.

Search for the CONFIG_CPIO word and change the line "# CONFIG_BUSYBOX_CONFIG_CPIO is not set" to "CONFIG_BUSYBOX_CONFIG_CPIO=y". After this, add the line "CONFIG_BUSYBOX_CONFIG_FEATURE_CPIO_O=y".
Re-compile only busybox and get the new ramdisk image with :
"make package/busybox/clean; make package/busybox/install; make target/install"

The busybox package is only 0.75 Kbytes larger with this.

If needed, I can provide the 8.09.1 ramdisk with cpio and loadkmap inside.




Next HowTo to come, if I succeed it, I'll try next to had informations how to modify the ramdisk image in order to have a /jffs file on the USB key and save all your modifications there (based on this : http://oldwiki.openwrt.org/ReplaceJFFS2 … Media.html). 

Stay tune ;)

A+

PS : no support via PM, forum is here for everyone's use.

Last edited by fxmx86 (2009-07-03 23:35:52)


原创粉丝点击