Linux虛擬盤製作簡易方法實踐

來源:互聯網
上載者:User
文章目錄
  • 一. 概述

Linux虛擬盤製作簡易方法實踐

關鍵字

 

 

Ramdisk VFS 虛擬盤 busybox

 

 

 

 

使用busybox製作linux虛擬盤的方法,以及Andoid虛擬盤的整合

 

一. 概述

1、 安裝busybox工具

Busybox有多個版本,一般都可用,此處用的是1.7.3,位於ftp://server28/共用軟體/linux下應用軟體目錄下busybox-1.7.3.tar.gz

拷貝到使用者目錄後解壓縮:tar –zxvf busybox-1.7.3.tar.gz

開啟包中的Makefile檔案,搜尋cross找到交叉編譯器所在,設定為和編譯linux源碼同樣版本的交叉編譯器,儲存makefile

先使用Make defconfig命令獲得config,再使用make menuconfig開啟,設定一些選項如下:

General Configuration裡選上

Show verbose applet usage messages

Runtime SUID/SGID configuration via /etc/busybox.conf

Build Options裡選上

Build BusyBox as a static binary (no shared libs)

Installation Options裡選上

Don't use /usr

即可,儲存退出,此時編譯還有一些編譯錯誤,開啟applets目錄下applets.c,將第一段代碼屏蔽,(上面地址下載的包已經將這個C檔案修改好)

#if 0

/* Apparently uclibc defines __GLIBC__ (compat trick?). Oh well. */

#if ENABLE_STATIC && defined(__GLIBC__) && !defined(__UCLIBC__)

#warning Static linking against glibc produces buggy executables

#warning (glibc does not cope well with ld --gc-sections).

#warning See sources.redhat.com/bugzilla/show_bug.cgi?id=3400

#warning Note that glibc is unsuitable for static linking anyway.

#warning If you still want to do it, remove -Wl,--gc-sections

#warning from top-level Makefile and remove this warning.

#error Aborting compilation.

#endif

#endif

儲存config退出,使用make編譯好後,make install即可自動安裝完畢。

下面的方法給出了在一個已有的虛擬盤基礎上修改製作新虛擬盤的方法:

2、 開啟一個已有的虛擬盤檔案

找到一個已有的虛擬盤,如開發板程式碼封裝中的ramdisk.gz,將其拷貝解壓縮,解壓出來的是一個獨立的檔案ramdisk,這個檔案就是將要製作的虛擬盤的藍本。

目前的目錄下(假設為/mnt)建立一個root的檔案夾:mkdir root

sudo –s –H

將ramdisk映射到root目錄中:

mount ramdisk /mnt/root -o loop

此時,root目錄下的內容就是虛擬盤中的目錄結構了。

因為unmount之後root裡面的內容都會消失,因此可先拷貝一個備份出來:

cp –rvf root/ fs/

則fs目錄下都是虛擬盤的內容,然後umount虛擬盤:

umount /mnt/root

此後,便可以任意修改fs/目錄下的目錄,添加和修改所需檔案等。

拷貝busybox

#cp -a 你的目錄/_install/* /mnt/fs

這樣,busybox裡產生的shell都到了fs目錄下。

做完各種修改後,便可以以fs目錄為基礎建立虛擬盤

3、建立ramdisk虛擬盤

1)建立新的ramdisk大小為40M

dd if=/dev/zero of=ramdisk bs=1k count=40960

2)格式為ext2

/sbin/mke2fs -F -m 0 ramdisk

3)禁止check

/sbin/tune2fs -c 0 ramdisk

4)掛載,先建立一個目錄如名為diy:

mkdir -p /mnt/diy

mount -o loop ramdisk /mnt/diy

5拷貝根檔案系統,將fs中的內容全部拷貝到所建立的diy目錄

#cp -a /mnt/fs/* /mnt/ diy /

6解掛和壓縮

#umount /mnt/diy/

#gzip -v9 ramdisk

至此,目前的目錄下產生的ramdisk.tar.gz即為新的虛擬盤。

有關Andoid虛擬盤製作待補充

相關文章

聯繫我們

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