Today, my colleagues from the company asked me to extend the hard drive of a virtual machine on the exsi server. After connecting to the exsi server, I directly added 20 GB to the original 40 GB hard drive, my colleague told me that it was a linux system after I added it. Well, I can only change it through ssh. the following is my experiment with another virtual machine.
System: centos 5.x
1. exsi resizing diagram
Before resizing:
After expansion:
2. Preparations before partitioning
Yum-y install parted
Ps: The partprobe command is not used by default for minimizing CentOS installation. Therefore, we need to install it using yum.
3. View the current hard disk status
[Root @ localhost ~] # Df-h
Filesystem Size Used Avail Use % Mounted on
/Dev/mapper/VolGroup00-LogVol00
38G 3.2G 33G 9%/
/Dev/sda1 99 M 12 M 82 M 13%/boot
Tmpfs 506 M 0 506 M 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. Start resizing the hard disk
[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 coshould in certain setups cause problems:
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 (change the partition type to 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.
Then execute:
[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
We can see that sda3 has already appeared, indicating that it is available. Continue below:
[Root @ localhost ~] # Partprobe
[Root @ localhost ~] # Partprobe/dev/sda3
Ps: the fdisk tool only writes partition information to the disk. If mkfs disk partition is required, the system needs to be restarted. If partprobe is used, the kernel can read partition information again to avoid restarting the system.
5. Create a physical volume and add it to the group
[Root @ localhost ~] # Pvcreate/dev/sda3
Physical volume "/dev/sda3" successfully created
[Root @ localhost ~] # Vgextend VolGroup00/dev/sda3
Volume group "VolGroup00" successfully extended
View physical volumes
[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
Ming an on-line resize of/dev/VolGroup00/LogVol00 to 15433728 (4 k) blocks.
The filesystem on/dev/VolGroup00/LogVol00 is now 15433728 blocks long.
6. Verify
[Root @ localhost ~] # Df-h
Filesystem Size Used Avail Use % Mounted on
/Dev/mapper/VolGroup00-LogVol00
8G 3.2G 51G 6%/
/Dev/sda1 99 M 12 M 82 M 13%/boot
Tmpfs 506 M 0 506 M 0%/dev/shm
Now, we can see that the new capacity has been added.