BusyBox構建根檔案系統

來源:互聯網
上載者:User

BusyBox構建根檔案系統

BusyBox是一個複合了大量簡易版Linux工具的程式,嵌入式系統中使用它可以快速建立一個相對簡易的根檔案系統。

1.下載busybox
官網 www.busybox.net
目前(2015.8.8)的最新穩定版為1.23.2

BusyBox各版本下載

2.編譯busybox
編譯busybox前,請安裝好交叉工具鏈,比如我這裡是omapl138的工具鏈,安裝位置/opt/arm-linux-gcc/omapl138/bin/,因為編譯器首碼和另外一個編譯器的相同,每次使用前設定環境變數

PATH=$PATH:/opt/arm-linux-gcc/omapl138/bin/
cd ~/buildspace
tar xf ~/Downloads/busybox-1.23.2.tar.bz2
cd  busybox-1.23.2
make menuconfig
make
make install

menuconfig時,
Busybox Settings  --->
  Build Options  --->
    ()  Cross Compiler prefix          填入交叉工具鏈的首碼,這裡是arm-none-linux-gnueab-
  Installation Options("make install" behavior) ->
    What kind of applet links to install (as soft-links) 
    (./_install) BusyBox installation prefix     安裝路徑,我喜歡用這個預設值
其他選項一般預設就夠用。
3.構建根檔案系統目錄
以root使用者建立根目錄,拷貝busybox檔案,建立幾個目錄

sudo -s
mkdir /home/rootfs
cd /home/rootfs
cp -r ~/biuldspace/busybox-1.23.2/_install/* .
mkdir dev etc lib mnt opt var tmp proc sys root

建立兩個基本裝置檔案

mknod dev/console c 5 1
mknod dev/null c 1 3

建立/linuxrc的初始化設定檔/etc/inittab
該檔案中指定linuxrc初始化完成後運行/etc/init.d.rcS指令碼。然後在ttyS2運行一個shell,該shell不需要登陸。

::sysinit:/etc/init.d/rcS

::ctrlaltdel:/sbin/reboot
::shutdown:/sbin/swapoff -a
::shutdown:/bin/umount -a -r
::restart:/sbin/init

ttyS2::respawn:-/bin/sh

 /etc/init.d/rcS的內容。在rcS檔案中,必須使用絕對路徑,因為環境變數還沒有初始化......

mount -a                      # 掛載在/etc/fstab中定義的所有掛載點
echo /sbin/mdev > /proc/sys/kernel/hotplug  # 設定熱插拔事件處理常式為mdev
mdev -s                       #裝置節點維護程式mdev初始化
mkdir /dev/pts                   #為telnetd建立pts目錄
mount -t devpts devpts /dev/pts          #掛載pts目錄
/bin/hostname -F /etc/hostname          # 設定主機名稱。/etc/hostname 的內容為主機名稱字串

mkdir /var/run                    #ifup需要該目錄
/sbin/ifup -a                    #根據/etc/network/interface設定網卡

/usr/sbin/telnetd &                #運行telnetd
#後台運行你的程式

/etc/fstab的內容

tmpfs /dev tmpfs  defaults 0 0
proc /proc proc defaults 0 0
sysfs /sys sysfs defaults 0 0
tmpfs /var tmpfs defaults 0 0
tmpfs /tmp tmpfs defaults 0 0

建立ifup需要的檔案夾

cd /home/rootfs/etc/
mkdir network
cd  network
mkdir if-down.d  if-post-down.d  if-pre-up.d  if-up.d

/etc/network/interfaces 的內容

auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address 192.168.0.5
netmask 255.255.255.0
gateway 192.168.0.1

/etc/passwd 的內容

root::0:0:root:/root:/bin/sh

/etc/profile 的內容

PS1='\u@\h:\w \$ '            #設定終端提示符
PATH=$PATH:/usr/local/bin        #設定搜尋路徑
export TERM=vt102             #termcap的環境變數,gdb -tui需要
export TERMINFO=/usr/share/terminfo

 拷貝動態庫

cd /opt/arm-linux-gcc/omap_4.3.3/arm-none-linux-gnueabi/libc
cp lib/* /home/rootfs/lib/
cp usr/lib/libstdc++.* /home/rootfs/lib/

製作ubi鏡像檔案

if [ -e ubifs.img ]; then rm ubifs.img; fi
if [ -e ubi.img ]; then rm ubi.img; fi
rootfs=/home/rootfs
mkfs.ubifs -v -r ${rootfs} -m 2048 -e 126976 -c 3717 -o ubifs.img -F
ubinize -v -o ubi.img -O 2048 -m 2048 -p 128KiB -s 512 ubinize.cfg
rm ubifs.img

其中,mkfs.ubifs需要加-F參數,否則ubi檔案系統很可能在啟動一次後就壞掉。-F參數的意思是在第一次啟動時清空空閑地區。

ubinize.cfg的內容

[rootfs]
mode=ubi
image=ubifs.img
vol_id=0
vol_type=dynamic
vol_name=rootfs
vol_flags=autoresize

mkfs.ubifs是建立單個卷(類似邏輯分區)的鏡像,ubinize是建立一個可以包含多個卷的鏡像(類似擴充分區)。ubinize.cfg中,[]內為卷的名字。

移植Busybox與構建根檔案系統

本文永久更新連結地址:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.