歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> 在VMWare中增加Linux文件系統空間

在VMWare中增加Linux文件系統空間

日期:2017/2/28 16:06:32   编辑:Linux教程

有時候會遇到這樣的情況:剛開始給VMWare分配了一個虛擬硬盤,安裝Linux後,隨著工作中使用得越來越多,虛擬硬盤容量逐漸變得不夠用,需要擴充空間。下面說明如何在VMWare中增加Linux的文件系統空間。

我的VMWare中安裝的是Fedora 9,不過其它Linux應該大同小異。

首先在VMWare中調整虛擬硬盤的大小(在“Virtual Machine Settings”的Hardware選項卡裡選擇“Hard Disk(SCSI)”,在右側的Utilities裡選擇Expand進行擴展)。

啟動Linux,鍵入df -h查看磁盤信息:

  1. [root@localhost ~]# df -h
  2. Filesystem Size Used Avail Use% Mounted on
  3. /dev/mapper/VolGroup00-LogVol00
  4. 29G 26G 2.3G 92% /
  5. /dev/sda1 190M 13M 168M 7% /boot
  6. tmpfs 506M 48K 506M 1% /dev/shm
  7. gvfs-fuse-daemon 29G 26G 2.3G 92% /root/.gvfs

可以看到新增加的硬盤容量並沒有體現在Linux中。使用fdisk -l查看分區表信息。www.linuxidc.com 我的信息是:

  1. [root@localhost ~]# fdisk -l
  2. Disk /dev/sda: 42.9 GB, 42949672960 bytes
  3. 255 heads, 63 sectors/track, 5221 cylinders
  4. Units = cylinders of 16065 * 512 = 8225280 bytes
  5. Disk identifier: 0x000f1526
  6. Device Boot Start End Blocks Id System
  7. /dev/sda1 * 1 25 200781 83 Linux
  8. /dev/sda2 26 3916 31254457+ 8e Linux LVM

注意Disk /Dev/sda有40多G空間(剛剛通過VMWare擴展的),但兩個Device /dev/sda1和/dev/sda2加起來只有30多G,有10G空間沒有被使用。

從調整分區表入手,調整分區表用fdisk。這個過程需要人機交互,我在需要輸入的地方加注釋來說明

  1. [root@localhost ~]# fdisk /dev/sda
  2. The number of cylinders for this disk is set to 5221.
  3. There is nothing wrong with that, but this is larger than 1024,
  4. and could in certain setups cause problems with:
  5. 1) software that runs at boot time (e.g., old versions of LILO)
  6. 2) booting and partitioning software from other OSs
  7. (e.g., DOS FDISK, OS/2 FDISK)
  8. Command (m for help): n //選擇n表示新建分區
  9. Command action
  10. e extended
  11. p primary partition (1-4)
  12. e //選擇e表示建立擴展分區
  13. Partition number (1-4): 3 //選擇3是因為1和2都被占了(/dev/dsa1和/dev/dsa2)
  14. First cylinder (3917-5221, default 3917): //此分區起始柱面,直接按回車,使用默認值
  15. Using default value 3917
  16. Last cylinder or +size or +sizeM or +sizeK (3917-5221, default 5221): //此分區大小,直接按回車,使用默認值(表明包含所有剩余空間)
  17. Using default value 5221
  18. Command (m for help): n //在擴展分區基礎上新建邏輯分區
  19. Command action
  20. l logical (5 or over)
  21. p primary partition (1-4)
  22. l //選擇l表示新建邏輯分區
  23. First cylinder (3917-5221, default 3917): //直接按回車
  24. Using default value 3917
  25. Last cylinder or +size or +sizeM or +sizeK (3917-5221, default 5221): //直接按回車
  26. Using default value 5221
  27. Command (m for help): p //選擇p查看新的分區表,發現已經新建成功
  28. Disk /dev/sda: 42.9 GB, 42949672960 bytes
  29. 255 heads, 63 sectors/track, 5221 cylinders
  30. Units = cylinders of 16065 * 512 = 8225280 bytes
  31. Disk identifier: 0x000f1526
  32. Device Boot Start End Blocks Id System
  33. /dev/sda1 * 1 25 200781 83 Linux
  34. /dev/sda2 26 3916 31254457+ 8e Linux LVM
  35. /dev/sda3 3917 5221 10482412+ 5 Extended
  36. /dev/sda5 3917 5221 10482381 83 Linux
  37. Command (m for help): w //選擇w保存
  38. The partition table has been altered!
  39. Calling ioctl() to re-read partition table.
  40. WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
  41. The kernel still uses the old table.
  42. The new table will be used at the next reboot.
  43. Syncing disks.

可以看到新增了/dev/sda3擴展分區和/dev/sda5邏輯分區。

鍵入partprobe命令,這個命令用於在硬盤分區發生改變時,www.linuxidc.com 更新Linux內核中讀取的硬盤分區表數據。

  1. [root@localhost ~]# partprobe

我們使用ext3格式化/dev/sda5這個新的分區

  1. [root@localhost ~]# mkfs -t ext3 /dev/sda5
  2. mke2fs 1.40.8 (13-Mar-2008)
  3. Warning: 256-byte inodes not usable on older systems
  4. Filesystem label=
  5. OS type: Linux
  6. Block size=4096 (log=2)
  7. Fragment size=4096 (log=2)
  8. 655360 inodes, 2620595 blocks
  9. 131029 blocks (5.00%) reserved for the super user
  10. First data block=0
  11. Maximum filesystem blocks=2684354560
  12. 80 block groups
  13. 32768 blocks per group, 32768 fragments per group
  14. 8192 inodes per group
  15. Superblock backups stored on blocks:
  16. 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
  17. Writing inode tables: done
  18. Creating journal (32768 blocks): done
  19. Writing superblocks and filesystem accounting information: done
  20. This filesystem will be automatically checked every 32 mounts or
  21. 180 days, whichever comes first. Use tune2fs -c or -i to override.
Copyright © Linux教程網 All Rights Reserved