VMware下LINUX的虛擬機增加磁盤空間


先關閉虛擬機電源,做如下設置:“ 虛擬機”--“虛擬機設置”--“磁盤”--“擴展”

 

 

可以隨意添加你需要增到到的磁盤大小(如15Gb,表示磁盤總量,包含原來的磁盤容量); 再重啟電源進入系統做如下步驟設置。

1. 啟動虛擬機系統,用root登錄(后續所有步驟都應以root用戶身份登錄操作),在 命令行用fdisk -l查看。由於這里是直接修改了原始空間大小,因此可以看到/dev/sda空間改變為16.1GB(原磁盤空間從10G增加到15G)。如果是從VMware菜單里增加虛擬硬盤,則會多出一個/dev/sd?,這里的?代表硬盤編號,第一個硬盤編號為a即sda,第二個就是sdb,第三個是sdc,以此類推,一般來說,如果以前沒有增加過硬盤,那么原來的硬盤就是sda,通過VMware菜單增加的虛擬硬盤編號就是sdb。如果添加的第二塊硬盤是IDE硬盤,就應該看到hdb,如果是 SCSI硬盤,看到的就應該是sdb。

2.使用fdisk /dev/sda進入菜單項,m是列出菜單,p是列出分區表,n是增加分區,w是保存並推出。由於這里增加的磁盤只有5G,因此5G划為一個區。

[root@localhost ~]# fdisk /dev/sda

The number of cylinders for this disk is set to 1958.
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)

Command (m for help): p

Disk /dev/sda: 16.1 GB, 16106127360 bytes
255 heads, 63 sectors/track, 1958 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        1305    10377990   8e  Linux LVM

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (1306-1958, default 1306): +1306
Last cylinder or +size or +sizeM or +sizeK (1306-1958, default 1958): +1958
Value out of range.
Last cylinder or +size or +sizeM or +sizeK (1306-1958, default 1958): 
Using default value 1958

Command (m for help): p

Disk /dev/sda: 16.1 GB, 16106127360 bytes
255 heads, 63 sectors/track, 1958 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        1305    10377990   8e  Linux LVM
/dev/sda3            1306        1958     5245222+  83  Linux

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

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: 設備或資源忙.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
/dev/sda3            1306        1958     5245222+  83  Linux

[root@localhost ~]# reboot                              #需reboot一下機器繼續如下步驟

[root@localhost ~]# df -h                                                                #掛載前的分區情況
文件系統              容量  已用 可用 已用% 掛載點
/dev/mapper/VolGroup00-LogVol00
                      8.6G  2.8G  5.4G  35% /
/dev/sda1              99M   12M   82M  13% /boot
tmpfs                 125M     0  125M   0% /dev/shm

3.  使用mkfs.ext3 /dev/sda3    格式化分區

[root@localhost ~]# mkfs.ext3 /dev/sda3
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
656000 inodes, 1311305 blocks
65565 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1346371584
41 block groups
32768 blocks per group, 32768 fragments per group
16000 inodes per group
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736

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

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

[root@localhost ~]# cd /
[root@localhost /]# mkdir /cm                       #增加一個/cm

[root@localhost /]# mount /dev/sda3 /cm           #掛載分區到   /cm         
[root@localhost /]# df -h                                     #掛載后的分區情況
文件系統              容量  已用 可用 已用% 掛載點
/dev/mapper/VolGroup00-LogVol00
                      8.6G  2.8G  5.4G  35% /
/dev/sda1              99M   12M   82M  13% /boot
tmpfs                 125M     0  125M   0% /dev/shm
/dev/sda3             5.0G  139M  4.6G   3% /cm

4.設置開機自動加載     

創建加載點:mkdir /cm 掛載之后,      修改vi /etc/fstab  分區表文件,

在文件最后加上      /dev/sda3  /cm   ext3    defaults    0 0     然后保存,重啟即可。  

(注意:修改分區表如果有誤,將導致進不了linux桌面系統,但這時系統會進入commandline模式,我們可以在commandline模式下對有誤的fstab進行修復更改,不過默認情況下這個commandline模式會是Read-Only file system,這意味着你的任何修改操作都是不允許的,但可以通過命令 mount / -o remount,rw  來解除這個限制)。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM