VMware下Linux虛拟機增加磁盤空間
1、首先在虛拟機執行個體設定中,選擇已有的harddisk,然後點選Utilities中的expand擴充硬碟空間。 比如:現在是15g,調整到16g,點選expand就擴充完成了。 這裡也可以選擇增加一個硬碟。
2、現在硬碟已經加了1g,下面需要到虛拟機裡面将這1g空間挂載上,首先打開虛拟機 用root使用者從終端登入,用指令 fdisk -l檢視 Disk /dev/sdb: 17.1 GB, 17179869184 bytes 255 heads, 63 sectors/track, 2088 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System /dev/sdb1 1 1958 15727603+ 83 Linux
可以看到/dev/sdb 的大小已經是17gb了 如果是新加的硬碟,這裡會新增一個 /dev/sdx x從a開始增加
3、使用fdisk /dev/sdb 進入菜單項 參數:m 列出菜單,p列出分區,n增加分區,w儲存退出
操作如下:依次執行 [[email protected] ~]# fdisk /dev/sdb
The number of cylinders for this disk is set to 2088. There is nothing wrong with that, but this is larger than1024, and could in certain setups cause problems with: 1) software that runs at boot time (e.g., old versions ofLILO) 2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2FDISK)
列出現有的分區 Command (m for help): p
Disk /dev/sdb: 17.1 GB, 17179869184 bytes 255 heads, 63 sectors/track, 2088 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System /dev/sdb1 1 1958 15727603+ 83 Linux
增加分區sdb2 Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 2 First cylinder (1959-2088, default1959): Using default value 1959 Last cylinder or +size or +sizeM or +sizeK (1959-2088, default2088): Using default value 2088
列出分區,發現增加了sdb2 Command (m for help): p
Disk /dev/sdb: 17.1 GB, 17179869184 bytes 255 heads, 63 sectors/track, 2088 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System /dev/sdb1 1 1958 15727603+ 83 Linux /dev/sdb2 1959 2088 1044225 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. You have new mail in /var/spool/mail/root
4、重新開機機器,繼續後面的工作 [[email protected] ~]# reboot
5、重新開機機器後進入root使用者 操作如下: 挂載前的分區情況 [[email protected] ~]# df -h 檔案系統 容量 已用 可用 已用% 挂載點 /dev/sda6 17G 15G 755M 96% / /dev/sda3 4.8G 213M 4.3G 5% /var /dev/sda2 5.7G 2.8G 2.7G 51% /home /dev/sda1 494M 16M 453M 4% /boot tmpfs 710M 0 710M 0%/dev/shm /dev/sdb1 15G 3.5G 11G 25% /home/software .host:/ 30G 16G 14G 54%/mnt/hgfs /dev/hdc 2.9G 2.9G 0 100% /media/RHEL_5.5 i386DVD 格式化分區 [[email protected] ~]# mkfs.ext3 /dev/sdb2 mke2fs 1.39 (29-May-2006) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) 130560 inodes, 261056 blocks 13052 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=268435456 8 block groups 32768 blocks per group, 32768 fragments per group 16320 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376
Writing inode tables: done Creating journal (4096 blocks): done Writing superblocks and filesystem accounting information:done
This filesystem will be automatically checked every 23 mountsor 180 days, whichever comes first. Use tune2fs-c or -i to override.
建立/test目錄并挂載新的分區到這上面 [[email protected] ~]# mkdir /test [[email protected] ~]# mount /dev/sdb2 /test 挂載後的分區情況 [[email protected] ~]# df -h 檔案系統 容量 已用 可用 已用% 挂載點 /dev/sda6 17G 15G 755M 96% / /dev/sda3 4.8G 213M 4.3G 5% /var /dev/sda2 5.7G 2.8G 2.7G 51% /home /dev/sda1 494M 16M 453M 4% /boot tmpfs 710M 0 710M 0%/dev/shm .host:/ 30G 16G 14G 54%/mnt/hgfs /dev/hdc 2.9G 2.9G 0 100% /media/RHEL_5.5 i386DVD /dev/sdb1 15G 3.5G 11G 25% /home/software /dev/sdb2 1004M 18M 936M 2% /test [[email protected] ~]#
6、設定開機自動加載 [[email protected] ~]# vi /etc/fstab 在檔案最後添加下列語句: /dev/sdb2 /test ext3 defaults 0 0 然後儲存重新開機即可