為虛擬機器新增硬碟並進行分割槽

jane_pop發表於2014-09-16
如果你的Linux硬碟空間不足,那麼我們可以新增硬碟並且對其進行分割槽,下面是主要步驟:
1.首先,把虛擬機器中的系統關閉,如果現在不關閉的話,後面新增完硬碟還要重啟。然後選擇
虛擬機器》設定,在彈出的對話方塊中點選硬碟(SCSI),接著點選新增,就會出現新增硬體嚮導:硬碟》
SCSI(S)(推薦)》建立新虛擬磁碟》,設定磁碟大小,預設是20G。選擇將虛擬磁碟拆分成多個檔案。
2.開啟虛擬機器的Linux系統。執行fdisk -l:
[root@localhost ~]# fdisk -l


Disk /dev/sda: 107.3 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes


   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          38      305203+  83  Linux
/dev/sda2              39       12540   100422315   83  Linux
/dev/sda3           12541       13054     4128705   82  Linux swap / Solaris


Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn't contain a valid partition table

可以看到此時多了個sdb,但是並沒有分割槽,下面我們為sdb進行分割槽:
輸入命令fdisk /dev/sdb,在提示下輸入m,就會出現以下列表,根據需要選擇選項完成自己的需要。輸入n,即為增加分割槽,接著輸入p建立主分割槽,再輸入1,下面會提示卷的起始地址和結束地址,回車預設就可以了。最後我們鍵入w儲存並退出。
[root@localhost /]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. 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 2610.
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
First cylinder (1-2610, default 1): 
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610): 
Using default value 2610


Command (m for help): w
The partition table has been altered!


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

3.再次輸入命令fdisk -l就可以看到多了/dev/sdb1了,說明我們已經成功為sdb新增了分割槽。
[root@localhost /]# fdisk -l


Disk /dev/sda: 107.3 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes


   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          38      305203+  83  Linux
/dev/sda2              39       12540   100422315   83  Linux
/dev/sda3           12541       13054     4128705   82  Linux swap / Solaris


Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes


   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        2610    20964793+  83  Linux

4.接著,對新建立的分割槽進行格式化,格式化成ext3的系統:
[root@localhost /]# mkfs.ext3 /dev/sdb1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
2621440 inodes, 5241198 blocks
262059 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
160 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
        4096000


Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done


This filesystem will be automatically checked every 38 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

5.最後,我們就可以把/dev/sdb1掛載到新建的/u02目錄了:
[root@localhost /]# mount /dev/sdb1 /u02
[root@localhost /]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2              93G   18G   71G  21% /
/dev/sda1             289M   16M  259M   6% /boot
tmpfs                1014M     0 1014M   0% /dev/shm
/dev/scd0              23M   23M     0 100% /media/CDROM
/dev/scd1             2.8G  2.8G     0 100% /media/RHEL_5.4 i386 DVD
/dev/sdb1              20G  173M   19G   1% /u02

6.掛載成功之後,會在本次系統啟動過程中生效,如果下次系統重啟了,那麼就會失去這次的掛載。
想要每次啟動系統都自動掛載,可以在/etc/fstab檔案中加入如下一行內容:
/dev/sdb1 /u02 ext3 defaults 0 0

那麼就可以保證即使系統重新啟動/dev/sdb1也會自動掛載


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29800581/viewspace-1270511/,如需轉載,請註明出處,否則將追究法律責任。

相關文章