افزایش حجم هارد در سرور مجازی CentOS
Background: I had an existing CentOS machine as a virtual machine running on VMWare ESX Server and it was running out of space so for future reference I did the following. Incidentally my disk is sda with the new partition create on the extra space as sda3.
I first increased the disk using the vSphere Client:
Then on the actual host (‘myhost’ in this example) I checked the existing partitions:
[root@myhost ~]# fdisk -l
Disk /dev/sda: 107.3 GB, 107374182400 bytes
۲۵۵ heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytesDevice Boot Start End Blocks Id System
/dev/sda1 * ۱ ۱۳ ۱۰۴۳۹۱ ۸۳ Linux
/dev/sda2 ۱۴ ۱۹۵۸ ۱۵۶۲۳۲۱۲+ ۸e Linux LVM
I then ran fdisk on the disk to create a new partition (‘n’) as primary partition 3 (change as necessary).
[root@myhost ~]# fdisk /dev/sda
The number of cylinders for this disk is set to 13054.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
۱) software that runs at boot time (e.g., old versions of LILO)
۲) 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 (1959-13054, default 1959):
Using default value 1959
Last cylinder or +size or +sizeM or +sizeK (1959-13054, default 13054):
Using default value 13054
I printed the partition table (see below) and could see the new partition
Command (m for help): p
Disk /dev/sda: 107.3 GB, 107374182400 bytes
۲۵۵ heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytesDevice Boot Start End Blocks Id System
/dev/sda1 * ۱ ۱۳ ۱۰۴۳۹۱ ۸۳ Linux
/dev/sda2 ۱۴ ۱۹۵۸ ۱۵۶۲۳۲۱۲+ ۸e Linux LVM
/dev/sda3 ۱۹۵۹ ۱۳۰۵۴ ۸۹۱۲۸۶۲۰ ۸۳ Linux
But I need the partition type to be 8e Linux LVM so…
Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 8e
Changed system type of partition 3 to 8e (Linux LVM)
Printing the partition table shows me what I wanted.
Command (m for help): p
Disk /dev/sda: 107.3 GB, 107374182400 bytes
۲۵۵ heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytesDevice Boot Start End Blocks Id System
/dev/sda1 * ۱ ۱۳ ۱۰۴۳۹۱ ۸۳ Linux
/dev/sda2 ۱۴ ۱۹۵۸ ۱۵۶۲۳۲۱۲+ ۸e Linux LVM
/dev/sda3 ۱۹۵۹ ۱۳۰۵۴ ۸۹۱۲۸۶۲۰ ۸e Linux LVM
And save the changes (be careful!)
Command (m for help): w
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.
So reboot.
[root@myhost ~]# shutdown -r now
And now for the LVM commands. Scan the Physical Volumes:
[root@myhost ~]# pvscan
PV /dev/sda2 VG VolGroup00 lvm2 [14.88 GB / 0 free]
Total: 1 [14.88 GB] / in use: 1 [14.88 GB] / in no VG: 0 [0 ]
And Create a new Physical Volume from /dev/sda3
[root@myhost ~]# pvcreate /dev/sda3
Physical volume “/dev/sda3″ successfully created
Extend the Volume Group 00 to include /dev/sda3:
[root@myhost ~]# vgextend VolGroup00 /dev/sda3
Volume group “VolGroup00″ successfully extended
Scan again and we can see /dev/sda3 included:
[root@myhost ~]# pvscan
PV /dev/sda2 VG VolGroup00 lvm2 [14.88 GB / 0 free]
PV /dev/sda3 VG VolGroup00 lvm2 [84.97 GB / 84.97 GB free]
Total: 2 [99.84 GB] / in use: 2 [99.84 GB] / in no VG: 0 [0 ]
Now extend the Logical Volume to extend (-L) the logical volume size by adding (+) 84 GigaBytes:
[root@myhost ~]# lvextend -L+84G /dev/VolGroup00/LogVol00
Extending logical volume LogVol00 to 87.00 GB
Logical volume LogVol00 successfully resized
And now just to extend the ext3 filesystem to take account of that extra space.
[root@myhost ~]# 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 22806528 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol00 is now 22806528 blocks long.
Check that it worked and is now bigger.
[root@myhost ~]# df -h
Happy days.