centos中給EXSI虛擬機器中linux硬碟擴容

來源:互聯網
上載者:User

今天公司同事過來給我說要求把公司的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

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.