openwrt x86 编译日记

3,908次阅读
没有评论

背景
前段时间看到 D425C 多网口版本,很是喜欢,替换的 rt-n16,发现玩 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 clean
make -j 5 V=99
#编译某个包
make packages/xxx/clean
make packages/xxx/compile
make packages/xxx/install

6. 安装
openwrt-x86-generic-combined-ext4.img.gz:包含 vmlinuz、rootfs(ext4)、引导信息以及相关分区信息的 img,一般是两个分区,可以把它看成是硬盘镜像,直接 dd 到某个磁盘
openwrt-x86-generic-combined-squashfs.img:同上,只不过使用的是 squashfs+overlayfs 文件系统架构
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 管的内容更多)、kernel、rootfs 三者。
0)如果你的磁盘(U 盘)只用于 openwrt 系统,可以使用最简单的用 combined:

ls bin/x86/
gunzip bin/x86/openwrt-x86-generic-combined-ext4.img.gz
dd if=bin/x86/openwrt-x86-generic-combined-ext4.img of=/dev/sdb #根据自己情况选择磁盘 

这样的好处是简单,坏处是如果你的 sdb(磁盘 / U 盘)很大,本来可以多分区,虽然可以在 rootfs 中存数据,但是下次升级系统就带来不必要的麻烦。
1)自己部署
大 致步骤:0. 分区 /mkfs;1. 用 dd 将 rootfs.ext4.img 写入到分区;3. 复制 vmlinuz 到分区;4. 安装引导,如果是 bios,我 习惯用 grub4dos,如果是 efi 那就用 grub2,并且需要 efi 文件系统,在分区的时候要记得加入;5;编辑 menu.lst;6. 启动
7. 关于 initramfs && overlayfs:
overlayfs:由于 openwrt x86 一般都是安装在 U 盘 /TF 卡 / 硬盘等介质上,默认是 ext 文件系统,就没有使用 overlayfs,如果要使用 overlayfs 就得用 squashfs。由于从路由过度过来,我个人对 overlayfs 颇有好感,着手在 x86 的 ext4 上加入 overlayfs 支持。稍后,会单独写一篇关于 x86 下 overlayfs 的文档。
initramfs:openwrt 编译中如果在 Target Images 总勾上 ramdisk(这里的 ramdisk 就是 initramfs),其实生产的 vmlinuz 就是一个带 initramfs(这个 initramfs 是整个本来要写进磁盘的 rootfs,如果你选用的包越多,这个 rootfs 也就越大)的 kernel,当然也可以在也可以在 source cpio 中选择 cpio 目录,如 果用 gurb 加载它,则整个系统会在 ramfs 上运行,所有配置在重启后都将不被保留,一般需要在这个上面启动到另一个 kernel(kexec)或者 switch_root 到另一个 root(真实的磁盘)环境,ramdisk(initramfs)。因此一般是不勾选编译选项中的 ramdisk 选项,自己着手来做 initramfs,加入一些 hook(比如加入 overlayfs 支持、switch_root 到其他 rootfs、干脆直接 kexec 到 其他 kernel),用 gurb 加载它,就可以完成系统启动。

正文完
 0
评论(没有评论)
验证码