導語:本文主要聚焦在如何使用 Yocto 在 Ubuntu 上建立一個最小化的 Linux 發行版。Yocto 項目在嵌入式 Linux 的世界非常著名,這是因為它用起來非常靈活、友善。Yocto 的目标是為嵌入式軟硬體開發商建立自己的 Linux 發行版。本文我們将會建立一個可以運作在 QEMU 上的最小化的 Linux,并且在 QEMU 上實際運作。
開發機注意:
a、最少 4-6 GB 記憶體
b、最新版的 Ubuntu 系統(本文使用了 16.04 LTS)
c、磁盤剩餘空間至少 60-80 GB
d、在建立 Linux 發行版之前先安裝下面的軟體包
e、下載下傳最新的 Yocto(Poky 是其最小開發環境)穩定分支
f、在使用yocto時使用普通賬号(非root)
詳細步驟
1、Ubuntu修改apt-get源,首先備份系統自帶apt-get源配置檔案/etc/apt/sources.list
cp /etc/apt/sources.list /etc/apt/sources.list.bak
2、編輯源配置檔案/etc/apt/sources.list,替換内容為:
#阿裡雲源
deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
#清華大學源
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security multiverse
3、更新測試一下
apt-get update
4、安裝相關工具
apt-get install wget git-core unzip make gcc g++ build-essential subversion sed autoconf automake texi2html texinfo coreutils diffstat python-pysqlite2 docbook-utils libsdl1.2-dev libxml-parser-perl libgl1-mesa-dev libglu1-mesa-dev xsltproc desktop-file-utils chrpath groff libtool xterm gawk fop
5、下載下傳poky(建立一個工作目錄,下載下傳poky)
git clone git://git.yoctoproject.org/poky.git
6、下載下傳完成之後進入 poky目錄,然後運作下面的指令為 Yocto 開發環境設定(設定/導出)一些環境變量。
source oe-init-build-env
或者
. ./oe-init-build-env
如下所示,在運作了 open embedded (oe) 的建構環境腳本之後,終端裡的路徑會自動切換到 build 目錄,以便進行之後行發行版的的配置和建構。
7、進入conf目錄,修改配置檔案 local.conf。這是 Yocto 用來設定目标機器細節和 SDK 的目标架構的配置檔案。
如下所示,放開下列注釋。
#注釋掉其它#MACHINE ?= 隻保留下面一行
MACHINE ?= "qemux86-64"
#解開下列注釋
DL_DIR ?= "${TOPDIR}/downloads"
SSTATE_DIR ?= "${TOPDIR}/sstate-cache"
TMPDIR ?= "${TOPDIR}/tmp"
PACKAGE_CLASSES ?= "package_rpm"
SDKMACHINE ?= "i686"
EXTRA_IMAGE_FEATURES ?= "debug-tweaks"
8、修改好配置之後,開始編譯建構(運作下面指令,這一過程可能會報錯,注意檢查磁盤空間,另外不能使用root使用者)
bitbake core-image-minimal
失敗提示不能使用root使用者
正常編譯會有進度條,最後成功也有相應的資訊
編譯好的新鏡像位于 build/tmp/deploy/images/qemux86-64
9、運作編譯好的發行版linux
runqemu qemux86-64
會彈出一個信的終端視窗,這個就是剛剛編譯好的linux(下圖黑色視窗)
參考資料:
ubuntu鏡像修改:https://www.cnblogs.com/scotth/p/6533397.html
yocto操作:https://www.linuxprobe.com/ubuntu-yocto-linux.html
yocto介紹:https://blog.csdn.net/yanghanxing110/article/details/77737471