OpenWrt 2: tvorba vlastniho obrazu systemu

Na webu OpenWrt jsou ke stazeni uz hotove obrazy pro ruzne procesorove architektury a konkretni zarizeni. Kdyz vsak potrebujeme neco upravit, musime si pomoct sami. Dale se budu zabyvat pouze nejnovejsi verzi OpenWrt backfire. Jak jsem uz psal minule, pouzivam Router Station od Ubiquity. Proto se zamerim na praci s touto deskou. Pro ostatni bude postup pravdepodobne podobny. 

RouterStation ma Atheros procesor (Atheros AR7161 MIPS 24K running @ 680MHz) architektura ar71xx. Pokud chcete mit nad vsim totalni kontrolu, stahnete si zdrojaky a zkompilujte si vse (celou distribuci) samy. Ovsem to neni taky jednoduche a ani to vetsinou neni potreba.

Ja pouzivam Image Builder. Pomoci tohoto baliku se da zmenit obraz ciloveho systemu. Je mozne pridavat ruzne balicky a menit nastaveni. Samozrejme by slo pouzit vychozi obraz, nahrat ho do RouterStation a potom si vse potrebne nastavit a doinstalovat. Tohle je ale jednodussi. Kdyz budete delat velkou serii, nebo budete chtit svuj obraz uverejnit na Internetu, je tento postup nejlepsi. Dulezite je stahnou Image Builder pro svou architekturu!

Vse se da stahnout tady: http://downloads.openwrt.org/backfire/10.03/ar71xx/

packages/                                          06-Apr-2010 12:58                   -
OpenWrt-ImageBuilder-ar71xx-for-Linux-i686.tar.bz2 03-Apr-2010 18:55           340411713
OpenWrt.config                                     06-Apr-2010 12:10              123802
md5sums                                            06-Apr-2010 13:03                9400
...
openwrt-ar71xx-ubnt-rs-jffs2-factory.bin           06-Apr-2010 13:02             3146136
openwrt-ar71xx-ubnt-rs-jffs2-sysupgrade.bin        06-Apr-2010 13:02             3211264
openwrt-ar71xx-ubnt-rs-squashfs-factory.bin        06-Apr-2010 13:03             2359704
openwrt-ar71xx-ubnt-rs-squashfs-sysupgrade.bin     06-Apr-2010 13:03             2424832
...
 

openwrt-ar71xx-ubnt-rs-jffs2-factory.bin  je vychozi obraz, jestlize se vam vsechno po**re, nahrajte do RouterStation tento obraz a vse bude OK  V adresari packages/ jsou vsechny dostupne balicky. Pro nas bude nejzajimavejsi soubor OpenWrt-ImageBuilder-ar71xx-for-Linux-i686.tar.bz2 ten obsahuje nastroj pro sestaveni vlasniho obrazu.

Stahneme si tedy OpenWrt-ImageBuilder-ar71xx-for-Linux-i686.tar.bz2. Ve svem domovskem adresari si vytvorime slozku openwrt a rozbalime v ni tento soubor:

martin@martin-laptop:~$ mkdir openwrt
martin@martin-laptop:~$ cd openwrt
martin@martin-laptop:~/openwrt$ pwd
/home/martin/openwrt
martin@martin-laptop:~/openwrt$ tar xjf OpenWrt-ImageBuilder-ar71xx-for-Linux-i686.tar.bz2 
martin@martin-laptop:~/openwrt$ ls -lh
celkem 325M
drwxr-xr-x 8 martin martin 4,0K 2010-04-03 20:51 OpenWrt-ImageBuilder-ar71xx-for-Linux-i686
-rw-r--r-- 1 martin martin 325M 2010-06-16 13:26 OpenWrt-ImageBuilder-ar71xx-for-Linux-i686.tar.bz2
martin@martin-laptop:~/openwrt$

Po rozbaleni dostaneme adresar. Prejdeme tedy do neho a zkusime spustit make pro zobrazeni informaci:

martin@martin-laptop:~/openwrt/OpenWrt-ImageBuilder-ar71xx-for-Linux-i686$ make
Available Commands:
 help: This help text
 info: Show a list of available target profiles
 clean: Remove images and temporary build files
 image: Build an image (see below for more information).

Building images:
 By default 'make image' will create an image with the default
 target profile and package set. You can use the following parameters
 to change that: 

 make image PROFILE="<profilename>" # override the default target profile
 make image PACKAGES="<pkg1> [<pkg2> [<pkg3> ...]]" # include extra packages
 make image FILES="<path>" # include extra files from <path>

martin@martin-laptop:~/openwrt/OpenWrt-ImageBuilder-ar71xx-for-Linux-i686$ 
 

Nyni si vypiseme prikazem make info dostupne profily:

martin@martin-laptop:~/openwrt/OpenWrt-ImageBuilder-ar71xx-for-Linux-i686$ make info
Current Target: "ar71xx"
Default Packages: base-files libc libgcc busybox dropbear mtd uci opkg udevtrigger 
Mhotplug2 dnsmasq iptables ppp ppp-mod-pppoe kmod-ipt-nathelper firewall kmod-leds-gpio
kmod-input-core kmod-input-polldev kmod-input-gpio-buttons kmod-button-hotplug swconfig
Available Profiles: ... UBNTRS:
Ubiquiti RouterStation
Packages: kmod-usb-core kmod-usb-ohci kmod-usb2
UBNTRSPRO: Ubiquiti RouterStation Pro Packages: kmod-usb-core kmod-usb-ohci kmod-usb2 UBNT:
Ubiquiti Products
Packages: kmod-usb-core kmod-usb-ohci kmod-usb2 Default: Default Profile (no WiFi) Packages: ... martin@martin-laptop:~/openwrt/OpenWrt-ImageBuilder-ar71xx-for-Linux-i686$

Z tohoto vypisu je videt architektura, vychozi balicky, ktere se vzdy pouziji a seznam profilu. Pro RouterStation je to UBNT.

Profily nas ale nazajimaji. My si budeme chit pridat vlasni balicky a soubory s nastavenim. V adresari packages/ jsou vsechny dostupne balicky, ktere muzeme pouzit. Ted je potreba rict make co chceme, podle make info:

...
make image PACKAGES="<pkg1> [<pkg2> [<pkg3> ...]]" # include extra packages
make image FILES="<path>" # include extra files from <path>
...

Balicek (z adresare packages/) se jmenuje napr. tar_1.22-1_ar71xx.ipk ale mi budeme uvadet nazev tar, u syslog-ng_1.6.12-2_ar71xx.ipk uvedeme syslog-ng
Dale budeme chtit nahradit soubor /etc/config/network, ve kterem je nastavena sit. vytvorime si tedy v adresari ImageBuilderu adresar nastaveni a v nem odpovidajici adresarovou strukturu a soubory:

martin@martin-laptop:~/openwrt/OpenWrt-ImageBuilder-ar71xx-for-Linux-i686$ mkdir nastaveni
martin@martin-laptop:~/openwrt/OpenWrt-ImageBuilder-ar71xx-for-Linux-i686$ cd nastaveni/
martin@martin-laptop:~/openwrt/OpenWrt-ImageBuilder-ar71xx-for-Linux-i686/nastaveni$ mkdir -p etc/config
martin@martin-laptop:~/openwrt/OpenWrt-ImageBuilder-ar71xx-for-Linux-i686/nastaveni$ cd etc/config/
martin@martin-laptop:~/openwrt/OpenWrt-ImageBuilder-ar71xx-for-Linux-i686/nastaveni/etc/config$ nano network
martin@martin-laptop:~/openwrt/OpenWrt-ImageBuilder-ar71xx-for-Linux-i686/nastaveni/etc/config$ cat network 
# moje nastaveni :-)
config interface loopback
 option ifname lo
 option proto static
 option ipaddr 127.0.0.1
 option netmask 255.0.0.0

config interface wan
 option ifname eth0 
 option proto dhcp

config interface lan
 option ifname "eth0 eth1"
 option type  bridge
 option proto static
 option ipaddr 192.168.1.20
 option netmask 255.255.255.0
 option dns 192.168.1.1
 option gateway 192.168.1.1

martin@martin-laptop:~/openwrt/OpenWrt-ImageBuilder-ar71xx-for-Linux-i686/nastaveni/etc/config$ cd ../../../
martin@martin-laptop:~/openwrt/OpenWrt-ImageBuilder-ar71xx-for-Linux-i686$ 

Nyni se muzeme pustit do samotneho sestaveni, nejdrive spustime make clean (vycisti nepovedene blbosti) a pote uz samotny make, kteremu v parametrech predame nazvy balicku a cestu k nastaveni:

martin@martin-laptop:~/openwrt/OpenWrt-ImageBuilder-ar71xx-for-Linux-i686$ make clean
rm -rf tmp /home/martin/openwrt/OpenWrt-ImageBuilder-ar71xx-for-Linux-i686/build_dir/
target-mips_r2_uClibc-0.9.30.1/root-ar71xx /home/martin/openwrt/
OpenWrt-ImageBuilder-ar71xx-for-Linux-i686/bin/ar71xx
martin@martin-laptop:~/openwrt/OpenWrt-ImageBuilder-ar71xx-for-Linux-i686$ make 
image PACKAGES="kmod-usb-core kmod-usb-ohci kmod-usb2 kmod-usb-acm python mc"
FILES="/home/martin/openwrt/OpenWrt-ImageBuilder-ar71xx-for-Linux-i686/nastaveni"
Building images for ar71xx - Atheros AP81 reference board Packages: base-files busybox dnsmasq dropbear firewall hotplug2 iptables kernel kmod-button-hotplug kmod-input-core kmod-input-gpio-buttons kmod-input-polldev kmod-ipt-nathelper kmod-leds-gpio kmod-usb-acm kmod-usb-core kmod-usb-ohci kmod-usb2 libc libgcc mc mtd opkg ppp ppp-mod-pppoe python swconfig uci udevtrigger make[1]: Entering directory `/home/martin/openwrt/OpenWrt-ImageBuilder-ar71xx-for-Linux-i686' Building package index... (cd /home/martin/openwrt/OpenWrt-ImageBuilder-ar71xx-for-Linux-i686/packages; /home/martin/openwrt/OpenWrt-ImageBuilder-ar71xx-for-Linux-i686/scripts/ ipkg-make-index.sh . > Packages && \ gzip -9c Packages > Packages.gz \ ) >/dev/null 2>/dev/null ...

Nyni uz jenom staci cekat. Format prikazu je vic nez jasny:
make image PACKAGES="kmod-usb-core kmod-usb-ohci kmod-usb2 kmod-usb-acm python mc" FILES="/home/martin/openwrt/OpenWrt-ImageBuilder-ar71xx-for-Linux-i686/nastaveni"

Kdyz mame hodne balicku, muzeme si to trochu usnadnit. Vytvorime si soubor, nazveme ho treba balicky a tam je vsechny napiseme na jeden radek oddelene mezerou. Pri volani make misto seznamu vypiseme obsah souboru PACKAGES="`cat balicky` :

martin@martin-laptop:~/openwrt/OpenWrt-ImageBuilder-ar71xx-for-Linux-i686$ nano balicky 
martin@martin-laptop:~/openwrt/OpenWrt-ImageBuilder-ar71xx-for-Linux-i686$ cat balicky 
kmod-usb-core kmod-usb-ohci kmod-usb2 kmod-madwifi wpad-mini kmod-usb-acm bluez-hcidump 
bluez-libs bluez-utils bmon kmod-bluetooth pyserial python-bluez python mc 
martin@martin-laptop:~/openwrt/OpenWrt-ImageBuilder-ar71xx-for-Linux-i686$ make 
image PACKAGES="`cat balicky`" FILES="/home/martin/openwrt/
OpenWrt-ImageBuilder-ar71xx-for-Linux-i686/nastaveni" Building images for ar71xx - Atheros AP81 reference board Packages: base-files bluez-hcidump bluez-libs bluez-utils bmon busybox dnsmasq dropbear firewall hotplug2 iptables kernel kmod-bluetooth kmod-button-hotplug kmod-input-core kmod-input-gpio-buttons kmod-input-polldev kmod-ipt-nathelper kmod-leds-gpio kmod-madwifi kmod-usb-acm kmod-usb-core kmod-usb-ohci kmod-usb2 libc libgcc mc mtd opkg ppp ppp-mod-pppoe pyserial python python-bluez swconfig uci udevtrigger wpad-mini make[1]: Entering directory `/home/martin/openwrt/OpenWrt-ImageBuilder-ar71xx-for-Linux-i686' Building package index... (cd /home/martin/openwrt/OpenWrt-ImageBuilder-ar71xx-for-Linux-i686/packages; /home/martin/openwrt/OpenWrt-ImageBuilder-ar71xx-for-Linux-i686/scripts/ ipkg-make-index.sh . > Packages && \ gzip -9c Packages > Packages.gz \ ) >/dev/null 2>/dev/null ...

a zase pul dne cekat 

Skoro vzdy, kdyz vybereme velke mnozstvi balicku, skonci ImageBuilder chybou:

...
-32 -f /home/martin/openwrt/OpenWrt-ImageBuilder-ar71xx-for-Linux-i686/build_dir/linux-ar71xx/root.jffs2-64k
mjn3's trx replacement - v0.81.1
fread failure or file "/home/martin/openwrt/OpenWrt-ImageBuilder-ar71xx-
for-Linux-i686/build_dir/linux-ar71xx/root.jffs2-64k" too large
make[2]: *** [install] Error 1
make[2]: Leaving directory `/home/martin/openwrt/OpenWrt-ImageBuilder-ar71xx-for-Linux-i686/target/linux/ar71xx/image'
make[1]: *** [build_image] Error 2
make[1]: Leaving directory `/home/martin/openwrt/OpenWrt-ImageBuilder-ar71xx-for-Linux-i686'
make: *** [image] Error 2
martin@martin-laptop:~/openwrt/OpenWrt-ImageBuilder-ar71xx-for-Linux-i686$ 
Duvod je jasny, obraz je moc velky. ImageBuilder totiz nesestavuje obraz jenom pro RouterStation, ale pro vsechny ar71xx zarizeni. Takze se stane, ze ikdyz ma RouterStation 16MB flash, nektere jine zarizeni muze mit treba jenom 5MB flash.
Vetsinou neni duvod kazit si radost, chyba vetsinou nastane az po sestaveni obrazu pro RouterStation, ktery potrebujeme. To si muzeme snadno overit v adresari bin/ar71xx/.  

V adresari build_dir/  se nachazi  podklady pro sestaveni. V adresari build_dir/target-mips_r2_uClibc-0.9.30.1/root-ar71xx/ je vse, co obsahuje nas obraz:

martin@martin-laptop:~/openwrt/OpenWrt-ImageBuilder-ar71xx-for-Linux-i686$ ls -lh 
build_dir/target-mips_r2_uClibc-0.9.30.1/root-ar71xx/
celkem 60K drwxr-xr-x 2 martin martin 4,0K 2010-03-31 05:30 bin drwxr-xr-x 2 martin martin 4,0K 2010-04-02 17:18 dev drwxr-xr-x 14 martin martin 4,0K 2010-06-16 16:02 etc -rwxr-xr-x 1 martin martin 1,9K 2010-03-19 21:08 init drwxr-xr-x 12 martin martin 4,0K 2010-03-31 21:05 lib drwxr-xr-x 2 martin martin 4,0K 2010-04-02 17:18 mnt drwxr-xr-x 2 martin martin 4,0K 2010-04-02 17:18 overlay drwxr-xr-x 2 martin martin 4,0K 2010-04-02 17:18 proc drwxr-xr-x 2 martin martin 4,0K 2010-04-02 17:18 rom drwxr-xr-x 2 martin martin 4,0K 2010-04-02 17:18 root drwxr-xr-x 2 martin martin 4,0K 2010-03-28 15:18 sbin drwxr-xr-x 2 martin martin 4,0K 2010-04-02 17:18 sys drwxr-xr-x 2 martin martin 4,0K 2010-04-02 17:18 tmp drwxr-xr-x 6 martin martin 4,0K 2010-03-31 21:05 usr lrwxrwxrwx 1 martin martin 4 2010-06-16 16:24 var -> /tmp drwxr-xr-x 2 martin martin 4,0K 2010-04-02 17:18 www martin@martin-laptop:~/openwrt/OpenWrt-ImageBuilder-ar71xx-for-Linux-i686$

To je ale spis pro kontrolu, nejdulezitejsi je adresar bin/ar71xx/ prave ten obsahuje vysledne obrazy, ktere budeme nahravat do zarizeni:

martin@martin-laptop:~/openwrt/OpenWrt-ImageBuilder-ar71xx-for-Linux-i686$ ls -lh bin/ar71xx/
celkem 162M
...
-rw-r--r-- 1 martin martin 9,6M 2010-06-16 16:25 openwrt-ar71xx-ubnt-rs-jffs2-factory.bin
-rw-r--r-- 1 martin martin 9,6M 2010-06-16 16:25 openwrt-ar71xx-ubnt-rs-jffs2-sysupgrade.bin
...
martin@martin-laptop:~/openwrt/OpenWrt-ImageBuilder-ar71xx-for-Linux-i686$

Obrazu tam bude asi hodne, nas vsak zajima pouze  openwrt-ar71xx-ubnt-rs-jffs2-factory.bin. Prave ten budeme nahravat do sveho RouterStation. Kdyby tam tento soubor nebyl, stala se nekde chyba. Nejpravdepodobnejsi je, ze jsme vybrali moc balicku a vysledny obraz tak byl moc velky.

A to je vse  Nyni uz staci jenom nahrat soubor do zarizeni a melo by to fungovat. Chapu, ze je postup hodne neprehledny, ale psal jsem to narychlo. Funkcni to ale je a to je hlavni.

 

Dalsi clanky o OpenWrt.

 

Napsat komentář

Vaše e-mailová adresa nebude zveřejněna. Vyžadované informace jsou označeny *