Linux的VM虛擬機擴展磁盤空間
(1)vmware軟件中編輯虛擬機設置中又擴容的選項,這裏不做介紹。
(2)啓動VM環境下的linux操作系統,添加新分區,需要root賬號身份。
3.1 【fdisk -l】 extend 對應的是sda4,說明新創建的分區將會是sda4
3.2 輸入【fdisk /dev/sda】
3.2.2輸入命令【n】添加新分區。(這時候可能會報“No free sectors available”,參考最後的解決辦法)
3.2.3輸入n後直接輸入命令【p】創建主分區。
3.2.4輸入【回車】,選擇默認大小,這樣不浪費空間!!
3.2.5輸入【回車】。
3.2.6輸入【w】,保持修改
3.3 輸入【reboot】 重啓linux,必須reboot,否則/dev/sda4無法格式化。
3.4 這時在/dev/目錄下,才能看到了新的分區比如/dev/sda4
3.5 【mkfs.ext3 /dev/sda4】格式化
3.6 在根目錄下創建disk4目錄
3.7 【mount /dev/sda4 /disk4/】將分區mount到/disk4/上
3.8 在vim修改/etc/fstab文件,加入【/dev/sda4 /disk4 ext3 defaults 0 0】一行,並保存,實現開機自動mount。
至此,新增加的磁盤空間容量,即可在disk4上體現,並且重新開機自動mount該分區,追加磁盤空間的工作完畢。
附解決辦法
Linux擴容時新建分區報錯No free sectors available
擴展後執行fdisk -l查看是否成功
[root@localhost ~ ]# fdisk - l
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 6 48163 + 83 Linux
/ dev / sda2 7 515 4088542 + 83 Linux
/ dev / sda3 516 1239 5815530 83 Linux
/ dev / sda4 1240 1305 530145 5 Extended
/ dev / sda5 1240 1305 530113 + 82 Linux swap / Solaris
可見sda已經擴展成爲16G,但是沒分配給文件系統
繼續執行fdisk /dev/sda進行新建磁盤
[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): n
No free sectors available
前面執行fdisk -l的時候明明最後纔是1305柱面,而且應該有1958柱面,爲什麼說沒有空閒的扇區。
再看看fdisk -l執行結果,原來是/dev/sda5分配了作爲swap分區,找到原因了就容易解決!!!!!!!
1.關閉swap分區# swapoff /dev/sda5
2.刪除sda4和sda5.
[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): d
Partition number ( 1 - 5 ): 5
Command (m for help): d
Partition number ( 1 - 5 ): 4
3.建立擴展分區4,建立分區sda5,寫入
Command (m for help): n
Command action
e extended
p primary partition ( 1 - 4 )
e
Selected partition 4
First cylinder ( 1240 - 1958 , default 1240 ):
Using default value 1240
Last cylinder or + size or + sizeM or + sizeK ( 1240 - 1958 , default 1958 ):
Using default value 1958
Command (m for help): n
First cylinder ( 1240 - 1958 , default 1240 ):
Using default value 1240
Last cylinder or + size or + sizeM or + sizeK ( 1240 - 1958 , default 1958 ):
Using default value 1958
Command (m for help): w
The partition table has been altered !
然後重複執行文章最初的那些內容