星外vps-centos系統掛載硬盤

星外默認centos系統的硬盤是10g,當開通硬盤大於10g的時候就需要,開通後手動的掛載

##本文中紅色部分爲命令,藍色部分爲解釋或是提示##

  1. [root@localhost ~]# fdisk -l  
  2.  
  3. Disk /dev/hda: 21.4 GB, 21474836480 bytes  
  4. 255 heads, 63 sectors/track, 2610 cylinders  
  5. Units = cylinders of 16065 * 512 = 8225280 bytes  
  6.  
  7.    Device Boot      Start         End      Blocks   Id  System  
  8. /dev/hda1   *           1          13      104391   83  Linux  
  9. /dev/hda2              14        1305    10377990   8e  Linux LVM  
  10. [root@localhost ~]# df -h  
  11. 文件系統              容量  已用 可用 已用% 掛載點  
  12. /dev/mapper/VolGroup00-LogVol00  
  13.                       7.7G  1.9G  5.4G  27% /  
  14. /dev/hda1              99M   22M   73M  23% /boot  
  15. tmpfs                 252M     0  252M   0% /dev/shm  

如上所示/dev/dha硬盤總大小是21G,實際VolGroup00-LogVol00只有7.7G的空間

下面的步驟就是把剩餘的空閒硬盤都增加到VolGroup00-LogVol00邏輯卷中

1.使用fdisk創建LVM分區

fdisk /dev/hda

  1. [root@localhost ~]# fdisk /dev/hda  
  2.  
  3. The number of cylinders for this disk is set to 2610.  
  4. There is nothing wrong with that, but this is larger than 1024,  
  5. and could in certain setups cause problems with:  
  6. 1) software that runs at boot time (e.g., old versions of LILO)  
  7. 2) booting and partitioning software from other OSs  
  8.    (e.g., DOS FDISK, OS/2 FDISK)  
  9.  
  10. Command (m for help): n  
  11. Command action 
  12.    e   extended  
  13.    p   primary partition (1-4)  
  14. p  
  15. Partition number (1-4): 3  
  16. First cylinder (1306-2610, default 1306):  
  17. Using default value 1306  
  18. Last cylinder or +size or +sizeM or +sizeK (1306-2610, default 2610):  
  19. Using default value 2610  

輸入n增加分區
輸入p類型設置爲:主分區
輸入3分區編號設置爲3
回車 爲默認大小
回車 爲默認 大小

然後再設置分區的類型 

  1. Command (m for help): t  
  2. Partition number (1-4): 3  
  3. Hex code (type L to list codes): 8e  
  4. Changed system type of partition 3 to 8e (Linux LVM) 

輸入t 設置分區類型
輸入3 3號分區
輸入8e 設置爲LVM

  1. Command (m for help): p  
  2.  
  3. Disk /dev/hda: 21.4 GB, 21474836480 bytes  
  4. 255 heads, 63 sectors/track, 2610 cylinders  
  5. Units = cylinders of 16065 * 512 = 8225280 bytes  
  6.  
  7.    Device Boot      Start         End      Blocks   Id  System  
  8. /dev/hda1   *           1          13      104391   83  Linux  
  9. /dev/hda2              14        1305    10377990   8e  Linux LVM  
  10. /dev/hda3            1306        2610    10482412+  8e  Linux LVM 

輸入p 打印分區表 (可以看到剛剛創建的/dev/hda3)
 

  1. Command (m for help): v  
  2. 13452 unallocated sectors  
  3.  
  4. Command (m for help): w  
  5. The partition table has been altered!  
  6.  
  7. Calling ioctl() to re-read partition table.  
  8.  
  9. WARNING: Re-reading the partition table failed with error 16: 設備或資源忙.  
  10. The kernel still uses the old table.  
  11. The new table will be used at the next reboot.  
  12. Syncing disks.  

輸入v  檢查分區表
輸入w 寫入分區表

藍色部分的內容提示當先的內核依然是使用的舊的分區表,

新寫入的分區表在下次重啓後生效
輸入q  退回fdisk

2.使用rebootinit 6來重啓系統(重要!!!)

此時使用fdisk -l來查看分區是否成功的創建

  1. [root@localhost ~]# fdisk -l  
  2.  
  3. Disk /dev/hda: 21.4 GB, 21474836480 bytes  
  4. 255 heads, 63 sectors/track, 2610 cylinders  
  5. Units = cylinders of 16065 * 512 = 8225280 bytes  
  6.  
  7.    Device Boot      Start         End      Blocks   Id  System  
  8. /dev/hda1   *           1          13      104391   83  Linux  
  9. /dev/hda2              14        1305    10377990   8e  Linux LVM  
  10. /dev/hda3            1306        2610    10482412+  8e  Linux LVM 

3.創建物理卷pv

pvcreate /dev/hda3

  1. [root@localhost ~]# pvcreate /dev/hda3  
  2.   Physical volume "/dev/hda3" successfully created  

查看已經創建的pv
pvscan;pvdisplay

  1. [root@localhost ~]# pvscan  
  2.   PV /dev/hda2   VG VolGroup00      lvm2 [9.88 GB / 0    free]  
  3.   PV /dev/hda3                      lvm2 [10.00 GB]  
  4.   Total: 2 [19.87 GB] / in use: 1 [9.88 GB] / in no VG: 1 [10.00 GB]  

4.添加/dev/hda3到默認的卷組VolGroup00
vgextend VolGroup00 /dev/hda3 

  1. [root@localhost ~]# vgextend VolGroup00 /dev/hda3  
  2.   Volume group "VolGroup00" successfully extended 

查看是否添加正確
vgscan;vgdisplay

5.把所有卷組裏的空閒硬盤增加到/dev/VolGroup00/LogVol00

lvextend -l +100%free /dev/VolGroup00/LogVol00

  1. [root@localhost ~]# lvextend -l +100%free /dev/VolGroup00/LogVol00  
  2.   Extending logical volume LogVol00 to 17.84 GB  
  3.   Logical volume LogVol00 successfully resized  

查看邏輯卷的大小
lvscan;lvdisplay

  1. [root@localhost ~]# lvscan  
  2.   ACTIVE            '/dev/VolGroup00/LogVol00' [17.84 GB] inherit  
  3.   ACTIVE            '/dev/VolGroup00/LogVol01' [2.00 GB] inherit  

/dev/VolGroup00/LogVol00爲當前硬盤

/dev/VolGroup00/LogVol01爲系統交換分區

6.最後使用resize2fs來讓系統識別硬盤
resize2fs /dev/VolGroup00/LogVol00 

  1. [root@localhost ~]# resize2fs /dev/VolGroup00/LogVol00  
  2. resize2fs 1.39 (29-May-2006)  
  3. Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing required  
  4. Performing an on-line resize of /dev/VolGroup00/LogVol00 to 4677632 (4k) blocks.  
  5. The filesystem on /dev/VolGroup00/LogVol00 is now 4677632 blocks long.  

df -h查看添加後的硬盤大小

  1. [root@localhost ~]# df -h  
  2. 文件系統              容量  已用 可用 已用% 掛載點  
  3. /dev/mapper/VolGroup00-LogVol00  
  4.                        18G  1.9G   15G  12% /  
  5. /dev/hda1              99M   22M   73M  23% /boot  
  6. tmpfs                 252M     0  252M   0% /dev/shm  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章