openwrt x86 編譯部署



著作權歸作者所有。商業轉載請聯系作者獲得授權,非商業轉載請注明出處。
本文鏈接:http://blog.ick.im/posts/2014-10-31-openwrt-x86-compile.html

0.背景

前段時間看到C1037u多網口版本,很是喜歡,替換的4530r,發現玩openwrt x86的人比較少,寫一篇日記,以備后用,有錯誤之處請指出。

0.配置編譯環境

Linux

1.獲取源代碼

svn co svn://svn.openwrt.org/openwrt/trunk/
#svn co svn://svn.openwrt.org/openwrt/branches/barrier_breaker -r42625
svn update
#cp feeds.conf.default feeds.conf
./scripts/feeds update -a
./scripts/feeds install -a

2.一些問題

  • config文件位置:

openwrt config文件:.config
kernel config:build_dir/target-xxxxxxx/linux-x86_generic/linux-x.xx.xx/.config

  • 內核版本更改:

支持內核版本列表: include/kernel-version.mk
更改內核版本位置: target/linux/XXX/Makefile.

3.make menuconfig

這里給出一個基本配置,不過其中Busybox配置,正常使用默認配置即可,不需要Customize busybox options,我為了在日后的initramfs中加入一些overlayfs的功能自己加進去了配置,另外的配置基本是x86必須的。

Target System (x86) #目標平台選擇
Target Images  --->
    [*] ext4    #生成.EXT4.IMG文件
Base system  ---> 
    <*> block-mount
    <*> busybox  ---> #用於今后`initramfs`支持,可以將所有lib編譯到busybox
        [*]   Customize busybox options 
        Busybox Settings  ---> 
            General Configuration  ---> 
                [*] Support --install [-s] to install applet links at runtime
                [*] Don't use /usr
        Linux Module Utilities  ---> 
                [*] modinfo
                [*] Simplified modutils
                [*]   Accept module options on modprobe command line
                [*]   Skip loading of already loaded modules
                (/lib/modules) Default directory containing modules 
        Linux System Utilities  ---> 
                [*] mdev
                [*]   Support /etc/mdev.conf
                [*]     Support subdirs/symlinks
                [*]       Support regular expressions substitutions when renaming
                [*]     Support command execution at device addition/removal
                [*]   Support loading of firmwares 
                [*] findfs
                [*] blkid
                [*]   Print filesystem type 
                [*] losetup
                [*] lspci
                [*] lsusb
                [*] mount 
                [*]   Support specifying devices by label or UUID
                Filesystem/Volume identification  --->
                    [*] Ext filesystem 
                    [*] fat filesystem 
        Networking Utilities  ---> 
                [*] ftpd
                [*]   Enable upload commands
                [*]   Enable workaround for RFC-violating clients
                [*] inetd
                [*] telnetd
                [*]   Support standalone telnetd (not inetd only)
                [*] tcpsvd
                [*] udpsvd
`kernel` modules  --->
    Block Devices  ---> 
        <*> kmod-ata-core
        <*>   kmod-ata-ahci
        <*> kmod-loop
        -*- kmod-scsi-core
        <*> kmod-scsi-generic
    Filesystems  --->
        <*> kmod-fs-ext4
        <*> kmod-fs-ntfs
        <*> kmod-fs-vfat
    Input modules  --->#鍵盤
         -*- kmod-hid
         <*> kmod-hid-generic
         -*- kmod-input-core
         -*- kmod-input-evdev
    Native Language Support  ---> 
        <*> kmod-nls-cp437 #vfat需要這個
        <*> kmod-nls-iso8859-1
        <*> kmod-nls-utf8
    Network Devices  ---> #網卡驅動
        <*> kmod-macvlan
    USB Support  --->
        -*- kmod-usb-core
        <*> kmod-usb-hid #usb鍵盤
        <*> kmod-usb-ohci
        <*> kmod-usb-storage
        <*> kmod-usb2
        <*> kmod-usb3
    Wireless Drivers  --->#wifi卡驅動
Network  ---> 
    <*> hostapd #wifi ap模式
    <*> hostapd-common
    <*> hostapd-utils
    <*> wpa-supplicant
Utilities  --->#自選  fdisk等

4.make kernel_menuconfig

目的是為了加入x86的多核心以及大內存支持

Processor type and features  --->
    [*] Symmetric multi-processing support
    Processor family (Core 2/newer Xeon)  --->#自行選擇處理器平台
    [*] Supported processor vendors  --->#自行選擇處理器平台
    (2) Maximum number of CPUs #自行編輯
    [*] SMT (Hyperthreading) scheduler support#超線程支持
    [*] Multi-core scheduler support 
    High Memory Support (4GB)  --->

5.make

編譯

make -j 100 download #下載包,openwrt是基於源碼+patch形式,下載過程比較慢,最好在牆外
make clean 
make -j 5 V=99
#編譯某個包
make packages/xxx/clean
make packages/xxx/compile
make packages/xxx/install

6.安裝

  • 固件簡介

      ls bin/x86
    

    會看到有以下一些文件,與官方編譯的固件名稱完全相同,這里大概解釋下:

    openwrt-x86-generic-combined-ext4.img.gz
    包含vmlinuz、rootfs(ext4)、引導信息以及相關分區信息的img,一般是兩個分區,可以把它看成是硬盤鏡像,直接dd到某個磁盤
    openwrt-x86-generic-rootfs-ext4.img.gz
    rootfs分區鏡像,可以直接dd到某個分區,或者mount -o到某個目錄
    openwrt-x86-generic-rootfs-squashfs.img
    同上
    openwrt-x86-generic-vmlinuz
    kernel
    openwrt-x86-generic-Generic-rootfs.tar.gz
    rootfs用gz打包后的文件

    可以看出,要讓系統啟動,需要引導器(x86是使用grub,好比是路由中的uboot,當然uboot管的內容更多)、kernelrootfs三者。

  • 簡易部署

如果你的磁盤(U盤)只用於openwrt系統,可以使用最簡單的用combined.img直接dd到目標盤,這樣的好處是簡單,壞處是如果你的sdb(磁盤/U盤)很大,就帶來空間浪費,雖然可以在rootfs中存數據,但是下次升級系統就帶來不必要的麻煩,命令行如下:

gunzip bin/x86/openwrt-x86-generic-combined-ext4.img.gz
dd if=bin/x86/openwrt-x86-generic-combined-ext4.img of=/dev/sdb #根據自己情況選擇磁盤
  • 自定義部署

    適合有一定基礎的兄弟,大致步驟:

    • 0.建立分區、文件系統;
    • 1.用dd將rootfs.ext4.img寫入到分區;
    • 2.復制vmlinuz到分區;
    • 3.安裝引導
      • 如果主板是bios,我習慣用grub4dos,參見無憂啟動
      • 如果主板是efi,我習慣用grub2,需要efi文件系統(fat文件系統),在分區的時候要記得加入,參照個大linux發行版。
    • 4.編輯menu.lst;
    • 6.啟動

7.關於initramfs && overlayfs

  • overlayfs:

由於openwrt x86一般都是安裝在U盤/TF卡/硬盤等介質上,默認是ext文件系統,就沒有使用overlayfs,如果要使用overlayfs就得用squashfs。由於從路由過度過來,我個人對overlayfs頗有好感,着手在x86的ext4上加入overlayfs支持。稍后,會單獨寫一篇關於x86下overlayfs的文檔。

  • initramfs:

按照如下編譯選項配置,其編譯生成的vmlinuz是一個帶initramfskernel,當然可以在也可以在Use external cpio中選擇自定義initramfs目錄,如果沒選擇Use external cpio,openwrt則會將整個rootfs當作initramfs編譯進vmlinuz.

    Target Images --->
        [*] ramdisk #其實就是initramfs
        ()    Use external cpio#選擇外部cpio,作為initramfs

如果用gurb加載它,則整個系統會在ramfs上運行,所有配置在重啟后都將不被保留,一般需要在這個上面啟動到另一個kernel(kexec)或者switch_root 到另一個rootfs(真實的磁盤)環境,ramdisk(initramfs)。因此一般是不勾選編譯選項中的ramdisk選項,自己着手來做initramfs,加入一些hook(比如加入overlayfs支持、switch_root到其他rootfs、干脆直接kexec到其他kernel),用gurb的initrd加載,就可以完成系統啟動。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM