標籤:
該文引自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版本。
[email protected]:~$ cd /mnt/
[email protected]: /mnt$ ls
bin boot dev etc home lib media mnt opt proc root run sbin srv sys tmp usr var
[email protected]: /mnt$ sudo -s
[sudo] password for latelee:
[email protected]: /mnt# chroot .
[email protected]:/# ls
bin boot dev etc home lib media mnt opt proc root run sbin srv sys tmp usr var
[email protected]:/# cat etc/issue
Ubuntu 14.04 LTS \n \l
[email protected]:/# ls /proc/ -l
total 0
[email protected]:/# ifconfig
Warning: cannot open /proc/net/dev (No such file or directory). Limited output.
[email protected]:/# 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根檔案系統構建的資源:
http://www.virtuatopia.com/index.php/Building_a_Debian_or_Ubuntu_Xen_Guest_Root_Filesystem_using_debootstrap
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/
http://askubuntu.com/questions/442610/debootstrap-warning-during-installation-12-04-lts-server-vmware-virtual-mach
https://help.ubuntu.com/lts/installation-guide/i386/index.html
查看ubuntu各發行版本wiki:
http://en.wikipedia.org/wiki/List_of_Ubuntu_releases
查看ubuntu安裝包:
http://packages.ubuntu.com/
後記:本想寫稍有點技術含量的文章,把過程所涉及到的知識點都提及,但發現自己文筆不複如前,還是按流水賬那樣寫出來比較暢快些。
本文固定連結: http://www.latelee.org/using-gnu-linux/ubuntu-debootstrap.html
ubuntu系統debootstrap的使用