通常在 VMWare 中預設的 Ubuntu 安裝應該只會有 8G 的硬碟,每次我都會為了如何擴充在煩惱。而每次 Clone 一個新的環境,總是要把之前 /home 目錄下的資料與程式備份下來,這也是件很煩惱的事。


後來想一想,乾脆新增一個硬碟,然後把這個新硬碟 mount 到 /home,從此再也沒有這些煩惱。 更好的是,我還可以把 Apache 與 MySQL 的資料與設定目錄都指定到這個新的硬碟中,到時候只要重新 ln 回去就可以了。


 

作法如下:


首先,在 VMWare 中新增硬碟,隨便你自己要設多大。


Ubuntu 開機後,開終端機就可以開始操作了:



$sudo fdisk -l | grep "Disk /dev" (列出這台虛擬機器中現有的硬碟)
Disk /dev/sdb doesn't contain a valid partition table
Disk /dev/sda: 8589 MB, 8589934592 bytes
Disk /dev/sdb: 68.7 GB, 68719476736 bytes


這個是你的硬碟列表, /dev/sdb 代表第二顆的 SCSI 硬碟。你的也有可能是 /dev/hdb,這個代表 IDE 的第二顆磁碟機。因為這時還沒設定任何磁碟分割,所以會有第一行的錯誤訊息。



知道你的新硬碟代號後,再來就透過 fdisk 來做磁碟分割:



$sudo fdisk /dev/sdb (透過 fdisk 來對剛剛新增的硬碟 sdb 做分割)
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x5f491e37.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

The number of cylinders for this disk is set to 8354.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): m (列出支援的指令)
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help): n (建立新分割)
Command action
   e   extended
   p   primary partition (1-4)
p (建立主要分割)
Partition number (1-4): 1 (主要分割磁區代號為 1)
First cylinder (1-8354, default 1): 1 (選擇預設)
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-8354, default 8354): 8354 (選擇預設)
Using default value 8354

Command (m for help): w (寫入磁碟分割,並且離開)
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.



這樣應該就可以把新的硬碟磁碟分割好了。再來就是 format 硬碟:



$sudo mkfs.ext3 /dev/sdb1 (其中sbd1就是剛剛分割出來的磁區。如果不確定,可以用 sudo fdisk -l 來看)



格式化好之後,我們要先把這個磁碟機暫時 mount 到任何一個目錄,然後把 /home 底下的東西都複製這個磁碟機中,複製完再把這個硬碟 unmount:


$sudo mount /dev/sdb1 /opt (先把新硬碟 mount 到/opt)
$sudo cp -vax /home/* /opt (然後把 /home 複製到新硬碟)
$sudo umount /dev/sdb1 (unmount 新硬碟)

最後再這個磁碟機加入 /etc/fstab 中,讓他以後開機就自動 mount。


....
/dev/sdb1 /home ext3 defaults,errors=remount-ro 1 0

加入後,透過 mount 就可以把 /home 用 /dev/sdb1 來取代了。


$sudo mount -a (未重開機時,可以用這個指令來執行剛剛對 /etc/fstab 的修改)

這樣就 Okay了。


另外 想直接加顆硬碟也OK


1.新增虛擬的硬碟給vmware,功能列VM->settings->add->HardDisk
進去linux時,用fdisk -l會看到dev/sdb 尚未格式化,
所以下fdisk /dev/sdb 輸入n新增一個partition,輸入p看是否有此partition ,輸入w寫入
2.格式化 mkfs -t ext3 /dev/sdb1
3.掛載mount /dev/sdb1 /(你要放的位置)


http://blog.markplace.net/marks_place/15/2008/11/01/389

arrow
arrow
    全站熱搜

    立你斯 發表在 痞客邦 留言(0) 人氣()