給EXSI虛擬機中linux硬盤擴容


   今天公司同事過來給我說要求把公司的exsi服務器上的一台虛擬機硬盤擴大,好吧,連上exsi后,直接在原來的硬盤40G上加了20G,等我添加完后,同事才告訴我那台是linux的系統,好吧,只能連上ssh來更改了.下面就是我用另外一台虛擬機來做的實驗.
   系統:centos 5.x
1.exsi擴容圖
擴容前:
點擊查看原圖
擴容后:
點擊查看原圖

2.分區前准備
yum -y install parted

ps:CentOS最小化安裝默認是沒有partprobe命令,所以我們要用yum安裝

3.查看目前硬盤狀態
[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       38G  3.2G   33G   9% /
/dev/sda1              99M   12M   82M  13% /boot
tmpfs                 506M     0  506M   0% /dev/shm


[root@localhost ~]# fdisk -l
Disk /dev/sda: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 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        5221    41833260   8e  Linux LVM

4.開始對硬盤擴容
[root@localhost ~]# fdisk /dev/sda
The number of cylinders for this disk is set to 7832.
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
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (5222-7832, default 5222): 
Using default value 5222
Last cylinder or +size or +sizeM or +sizeK (5222-7832, default 7832): 
Using default value 7832

Command (m for help): t  (修改分區類型為 Linux LVM, 8e)
Partition number (1-4): 3
Hex code (type L to list codes): 8e
Changed system type of partition 3 to 8e (Linux LVM)

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

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.

然后再執行:
[root@localhost ~]# fdisk -l
Disk /dev/sda: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 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        5221    41833260   8e  Linux LVM
/dev/sda3            5222        7832    20972857+  8e  Linux

可以看到sda3已經出現了,表示為可用的狀態.下面繼續:
[root@localhost ~]# partprobe
[root@localhost ~]# partprobe /dev/sda3

ps:使用fdisk工具只是將分區信息寫到磁盤,如果需要mkfs磁盤分區則需要重啟系統,而使用partprobe則可以使kernel重新讀取分區信息,從而避免重啟系統.

5.創建物理卷及加入組
[root@localhost ~]# pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created
[root@localhost ~]# vgextend VolGroup00 /dev/sda3
  Volume group "VolGroup00" successfully extended

查看物理卷情況
[root@localhost ~]# vgdisplay
  --- Volume group ---
  VG Name               VolGroup00
  System ID             
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               59.88 GB
  PE Size               32.00 MB
  Total PE              1916
  Alloc PE / Size       1276 / 39.88 GB
  Free  PE / Size       640 / 20.00 GB
  VG UUID               qLjCMX-FZv2-Neha-Nze0-rAoq-p1R0-QV5pLu

[root@localhost ~]# lvresize -L +20G /dev/VolGroup00/LogVol00
  Extending logical volume LogVol00 to 58.88 GB
  Logical volume LogVol00 successfully resized

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

6.驗證
[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       58G  3.2G   51G   6% /
/dev/sda1              99M   12M   82M  13% /boot
tmpfs                 506M     0  506M   0% /dev/shm

好了,可以看到已經把新增加的容量添加進去了.

 






免責聲明!

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



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