schroot的安裝與使用

來源:互聯網
上載者:User
什麼是schroot

schroot使得使用者可以在不同的chroot下執行互動命令

Schroot allows users to execute commands or interactive shells in different ——debian wiki schroot和chroot的不同


chroot只能被root使用者使用,schroot可以被普通使用者使用 schroot 在chroot的基礎上還提供了permissions checking, environmental setup(如filesystem mount)等

A chroot may be used directly as root by running chroot(8), but normal users are not able to use this command. schroot allows access to chroots for normal users using the same mechanism, but with permissions checking and allowing additional automated setup of the chroot environment, such as mounting additional filesystems and other configuration tasks. This automated setup is done through the action of setup scripts which may be customised and extended to perform any actions required. ——askubuntu schroot安裝和使用 安裝

schroot的安裝很簡單,直接參考官方文檔即可,此處省略 使用 schroot的使用分為三步: Step1 : 下載目標系統的基礎檔案系統 Step2 : 配置掛載目錄 Step3 : 切換到目標系統
以下將分別對這三步進行具體介紹,並在最後介紹一點小技巧。 Step 1: 下載目標系統的基礎檔案系統

按照官方文檔中的說明,在下載基礎檔案系統時,需要利用release指定目標系統的發行版本,利用--arch指定架構,相應地會在/var/lib/schroot/chroots/路徑下產生相應目錄。 Step 2: 配置掛載目錄

在不配置掛載目錄的情況下,切換後的schroot運行環境將是全新的檔案系統環境,無法感知並訪問host主機中的檔案。為了能夠訪問host主機中的檔案,需要將host中的目錄掛載到schroot環境中,具體操作如下:

$ sudo vim /etc/schroot/sbuild/fstab # 開啟fstab設定檔# 將特定目錄掛載到schroot環境中# 以普通使用者的home目錄為例,將以下條目寫入fstab中並儲存/home/<username>                 /home/<username>  none  rw,bind  0  0
Step 3: 切換到目標系統

參考官方文檔,此處省略。 小技巧

這個小技巧在官方文檔中有所涉及,但講述得不是很清楚,這裡單獨拿出來講解。 需求

基礎檔案系統往往缺乏各種軟體包。舉例來說,連最基本的sudo都無法執行。在此情況下,使用者需要執行以下操作:

$ su #切換到root使用者# apt-get install sudo #安裝sudo軟體包$ exit #切換為普通使用者$ sudo apt-get install ... #繼續安裝其他軟體包

花了很長時間終於將所需的軟體包安裝完畢了,完成部分工作後可能需要先退出當前的schroot環境(可能是因為下班了,甚至突然死機了( ´▽`))。
當利用mk-sbuild命令再次進入該schroot環境時,你會發現剛剛裝的所有軟體包都沒有了,需要重新安裝一遍。 方法

此處的小技巧正是用來解決上述問題的。通過在切換到目標檔案時,指定source標籤,即可將所安裝的軟體儲存到基礎檔案系統中,具體的操作如下所示:

$ sudo schroot -c source:xenial-i386 #以xenial-i386為例#以下安裝軟體包按照普通流程...

後面每次進入該schroot環境,這些軟體包都是安裝好了的。 結束語

schroot常用於類比運行環境,或進行交叉編譯。如在64-bit的系統中編譯產生32-bit的可執行應用程式,askubuntu中就涉及到相關的問答。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.