給Virtual Box內的Linux添加虛擬硬盤

因在建立Linux時候採用了較小的硬盤,後續裝軟件沒法安裝下,同時也但願軟件能夠安裝在單獨的硬盤上,後續能夠嘗試加載到其餘的Linux上使用。因此須要給Virtual Box內的Linux建立一個虛擬硬盤。php

參照文檔http://www.techotopia.com/index.php/Adding_a_New_Disk_Drive_to_an_RHEL_6_Systemnode

1)Virtual Box界面添加一個虛擬硬盤ide

   在Oracle VM Virtual Box管理器內選中須要添加硬盤的虛擬機,如虛擬機正在運行,則須要關閉。在設置->存儲->控制器:SATA後面,點擊添加虛擬硬盤,根據須要選擇硬盤的類型和大小。工具

2)啓動虛擬機,進入Linux系統ui

3)找到已經加載進系統的硬盤spa

   我這裏是添加的第二塊硬盤,因此在下面的命令會返回一個sdb的文件,如添加第三個則是sdc,以此類推:orm

   # cd /dev/ip

   # ls -l sdbci

   brw-rw----. 1 root disk 8, 16 Feb 25 07:27 sdbrem

4)給新硬盤建立Linux分區

   這裏使用fdisk工具對該硬盤進行分區

       # fdisk/dev/sdb

   Devicecontains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

   Buildinga new DOS disklabel with disk identifier 0xa4b37bfb.

   Changeswill remain in memory only, until you decide to write them.

   Afterthat, of course, the previous content won't be recoverable.


   Warning:invalid flag 0x0000 of partition table 4 will be corrected by w(rite)


   WARNING:DOS-compatible mode is deprecated. It's strongly recommended to

        switch off the mode (command 'c') andchange display units to

        sectors(command 'u').

   根據上述的警告建議,關閉DOS兼容模式,將單位設置爲扇區:

       Command(m for help): c

       DOSCompatibility flag is not set

       Command(m for help): u

       Changing display/entry units to sectors

   這時候能夠輸入p來查看當前分區

       Command(m for help): p

       Disk/dev/sdb: 107.4 GB, 107374182400 bytes

       255heads, 63 sectors/track, 13054 cylinders, total 209715200 sectors

       Units =sectors of 1 * 512 = 512 bytes

       Sectorsize (logical/physical): 512 bytes / 512 bytes

       I/O size(minimum/optimal): 512 bytes / 512 bytes

       Diskidentifier: 0xa4b37bfb

        DeviceBoot      Start         End      Blocks  Id  System

因爲是新硬盤,這裏沒有分區。

下面輸入n開始建立新分區

   Command(m for help): n

   Commandaction

      e  extended

      p  primary partition (1-4)

   p(輸入分區類型,p爲主要分區,e爲擴展分區)

   Partitionnumber (1-4): 1(輸入分區的個數)

   First sector (2048-209715199, default 2048):(輸入建立分區的起始扇區)

   Using defaultvalue 2048

   Last sector,+sectors or +size{K,M,G} (2048-209715199, default 209715199):(輸入截止扇區)

   Using default value 209715199

這裏僅建立一個主要分區,建立分區完畢後,需將分區信息寫入硬盤,這時候鍵入w便可寫入硬盤

   Command (m forhelp): w

   The partitiontable has been altered!

   Calling ioctl()to re-read partition table.

   Syncing disks.

分區建立完成,這時候再來查看設備目錄下,sdb開頭的文件會增長一個:

   # ls -l sdb*

   brw-rw----. 1root disk 8, 16 Feb 25 08:12 sdb

   brw-rw----. 1root disk 8, 17 Feb 25 08:12 sdb1

sdb1就是咱們剛纔建立的分區

5)在分區上建立一個文件系統

咱們須要在上面的分區上建立一個文件系統,這樣咱們才能夠用它來存儲文件或者數據。這裏使用工具mkfs.ext4

   #/sbin/mkfs.ext4 -L /cfans /dev/sdb1

   mke2fs1.43-WIP (20-Jun-2013)

   Filesystemlabel=/cfans

   OS type:Linux

   Blocksize=4096 (log=2)

   Fragmentsize=4096 (log=2)

   Stride=0blocks, Stripe width=0 blocks

   6553600inodes, 26214144 blocks

   1310707 blocks(5.00%) reserved for the super user

   Firstdata block=0

   Maximumfilesystem blocks=4294967296

   800 blockgroups

   32768blocks per group, 32768 fragments per group

   8192inodes per group

   Superblockbackups stored on blocks:

       32768, 98304, 163840, 229376, 294912,819200, 884736, 1605632, 2654208,

       4096000, 7962624, 11239424, 20480000,23887872


   Allocatinggroup tables: done

   Writinginode tables: done

   Creatingjournal (32768 blocks): done

   Writing superblocks and filesystem accounting information:done

其中/cfans爲卷標名稱

6)掛載文件系統

將上一步建立的文件系統掛載到Linux系統內。這裏先建立一個掛載點

   # mkdir /cfans

手工掛載文件系統

   # mount /dev/sdb1 /cfans

7)設置該文件系統爲開機自動掛載

編譯/etc/fstab文件加入下面的行:

   LABEL=/cfans   /lonli  ext4    defaults        1      2

相關文章
相關標籤/搜索