該文引自http://www.latelee.org/using-gnu-linux/ubuntu-debootstrap.html
debootstrap是debian/ubuntu下的一個工具,用來構建一套基本的系統(根文件系統)。生成的目錄符合Linux文件系統標准(FHS),即包含了/boot、/etc、/bin、/usr等等目錄,但它比發行版本的Linux體積小很多,當然功能也沒那么強大,因此,只能說是“基本的系統”。
fedora下(centos亦可用)有類似功能的工具:febootstrap。觀察這兩個工具名稱,可以看到debootstrap使用debian前綴“de”,而febootstrap使用fedora前綴“fe”,bootstrap含義為“引導”,並如果做過LFS的話,對它了解會比較多,而在編譯gcc編譯器時也有涉及到這個概念。不過debootstrap或febootstrap似乎沒有表達出“引導”的意思。
制作根文件系統,在PC上最全面的莫過於LFS(linux form scratch,從頭做一個linux系統),而嵌入式中,busybox是不二之選。當然,隨着芯片的強大及一些linux發行版本的進化,也有桌面系統直接用於嵌入式領域中,比如ubuntu,就有支持硬件浮點的工具直接下載。
ubuntu默認沒有安裝debootstrap,安裝十分簡單,執行下列命令即可:
# sudo apt-get install debootstrap
使用也十分簡單,命令格式為:
sudo debootstrap –arch [平台] [發行版本代號] [目錄]
比如下面的命令
sudo debootstrap –arch i386 trusty /mnt
即是構建x86(32位)平台ubuntu最新發行版14.04(代號為trusty)的基本系統,存放到/mnt目錄下。
當前debootstrap支持的發行版本可以在/usr/share/debootstrap/scripts查看,而各發行版代號,可以到http://en.wikipedia.org/wiki/List_of_Ubuntu_releases查看。比如gutsy是7.10的代號,precise是12.04的代號,等等。
輸入上述命令后,就會從網絡下載相關的文件,當看到
I: Configuring python-central…
I: Configuring ubuntu-minimal…
I: Configuring libc-bin…
I: Configuring initramfs-tools…
I: Base system installed successfully.
即表示成功。如果看到
E: Failed getting release file
http://archive.ubuntu.com/ubuntu/dists/trusty/Release
或卡在
I: Retrieving Release
則可能是網絡原因。
下載的文件在/mnt/var下,如:
$ tree
.
├── debootstrap
│ ├── debootstrap.log
│ └── debpaths
└── var
├── cache
│ └── apt
│ └── archives
│ ├── adduser_3.113+nmu3ubuntu3_all.deb
│ ├── apt_1.0.1ubuntu2_i386.deb
其中adduser_3.113是14.04對應的adduser。從這里也可以確認其下載的是哪一發行版的軟件。
下面使用chroot進入/mnt目錄,並查看linux版本。
latelee@ubuntu:~$ cd /mnt/
latelee@ubuntu: /mnt$ ls
bin boot dev etc home lib media mnt opt proc root run sbin srv sys tmp usr var
latelee@ubuntu: /mnt$ sudo -s
[sudo] password for latelee:
root@ubuntu: /mnt# chroot .
root@ubuntu:/# ls
bin boot dev etc home lib media mnt opt proc root run sbin srv sys tmp usr var
root@ubuntu:/# cat etc/issue
Ubuntu 14.04 LTS \n \l
root@ubuntu:/# ls /proc/ -l
total 0
root@ubuntu:/# ifconfig
Warning: cannot open /proc/net/dev (No such file or directory). Limited output.
root@ubuntu:/# uname -a
Linux ubuntu 3.13.0-32-generic #57-Ubuntu SMP Tue Jul 15 03:51:12 UTC 2014 i686 i686 i686 GNU/Linux
因為當然系統使用的並不這個新的系統,因此/proc並沒有內容,而內核依然是當前系統所用的版本。
使用光盤不成功
W: Failure trying to run: chroot /home/latelee/test_sys mount -t proc proc /proc
W: See /home/latelee/test_sys/debootstrap/debootstrap.log for details
注:
本文並沒有過多技術含量,僅是在學習過程中碰見了debootstrap而寫點筆記。本文所用環境均是虛擬機vmware。
附錄:
未完事宜:
限於時間,目前還沒有實際啟動新的系統。
一些涉及到ubuntu根文件系統構建的資源:
https://wiki.ubuntu.com/DebootstrapChroot
https://help.ubuntu.com/10.04/installation-guide/i386/linux-upgrade.html
http://www.thegeekstuff.com/2010/01/debootstrap-minimal-debian-ubuntu-installation/
https://help.ubuntu.com/lts/installation-guide/i386/index.html
查看ubuntu各發行版本wiki:
http://en.wikipedia.org/wiki/List_of_Ubuntu_releases
查看ubuntu安裝包:
后記:本想寫稍有點技術含量的文章,把過程所涉及到的知識點都提及,但發現自己文筆不復如前,還是按流水賬那樣寫出來比較暢快些。
本文固定鏈接: http://www.latelee.org/using-gnu-linux/ubuntu-debootstrap.html