Sometimes you may encounter a situation where a virtual hard disk is assigned to VMware at the beginning. After Linux is installed, the virtual hard disk capacity becomes insufficient and the space needs to be expanded as the number of applications increases. The following describes how to add Linux File System space in VMware.
I installed fedora 9 in VMware, but other Linux systems should be similar.
First, adjust the virtual hard disk size in VMware (select hard disk (SCSI) in the hardware tab of "Virtual Machine Settings", and select expand in utilities on the right to expand ), you can also directly add a new virtual hard disk.
Start Linux and type DF-h to view disk information:
[root@localhost ~]# df -hFilesystem Size Used Avail Use% Mounted on/dev/mapper/VolGroup00-LogVol00 29G 26G 2.3G 92% //dev/sda1 190M 13M 168M 7% /boottmpfs 506M 48K 506M 1% /dev/shmgvfs-fuse-daemon 29G 26G 2.3G 92% /root/.gvfs
We can see that the new hard disk capacity is not reflected in Linux. Use fdisk-L to view partition table information. My information is:
[root@localhost ~]# fdisk -lDisk /dev/sda: 42.9 GB, 42949672960 bytes255 heads, 63 sectors/track, 5221 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesDisk identifier: 0x000f1526 Device Boot Start End Blocks Id System/dev/sda1 * 1 25 200781 83 Linux/dev/sda2 26 3916 31254457+ 8e Linux LVM
Note that disk/dev/SDA has more than 40 Gb space (Extended Through vmware), but the two devices/dev/sda1 and/dev/sda2 add up to more than 30 GB, 10 Gb space is not used.
Start with adjusting the partition table and use fdisk to adjust the partition table. This process requires human-computer interaction. I will add comments to describe the input.
[Root @ localhost ~] # Fdisk/dev/sdathe Number of cylinders for this disk is set to 5221. there is nothing wrong with that, but this is larger than 1024, and cocould 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 // select n to create a partition command Action E extended P primary partit Ion (1-4) E // select e to create an extended partition Partition Number (1-4 ): 3 // select 3 because both 1 and 2 are occupied (/dev/dsa1 and/dev/dsa2) first cylinder (3917-5221, default 3917 ): // start the cylindrical part of the partition. Press enter and use the default value using default value 3917 last cylinder or + size or + sizem or + sizek (3917-5221, default 5221 ): // The partition size. Press enter and use the default value (indicating that all space is available). Using default value 5221 command (M for help ): N // create a logical partition based on the extended partition command action l logical (5 or over) P primary partition (1-4) L // select L to create a logical partition first cylinder (3917-5221, default 3917 ): // press ENTER using default value 3917 last cylinder or + size or + sizem or + sizek (3917-5221, default 5221 ): // press ENTER using default value 5221 command (M for help): P // select P to view the new partition table. The Disk/dev/SDA: 42.9 GB has been created successfully, 42949672960 bytes255 heads, 63 sectors/track, 5221 cylindersunits = cylinders of 16065*512 = 8225280 bytesdisk identifier: 0x000f1526 Device Boot start end blocks ID system/dev/sda1 * 1 25 200781 83 Linux/dev/sda2 26 3916 31254457 + 8e Linux LVM/dev/sda3 3917 5221 10482412 + 5 extended/dev/ sda5 3917 5221 10482381 83 linuxcommand (M for help): W // select W to save 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.
The/dev/sda3 extended partition and/dev/sda5 logical partition are added. If a hard disk is added, you can create a primary partition directly, which is simpler.
Type the partprobe command to update the hard disk partition table data read in the Linux Kernel when the hard disk partition changes.
[root@localhost ~]# partprobe
We use ext3 to format the new partition/dev/sda5.
[root@localhost ~]# mkfs -t ext3 /dev/sda5mke2fs 1.40.8 (13-Mar-2008)Warning: 256-byte inodes not usable on older systemsFilesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)655360 inodes, 2620595 blocks131029 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=268435456080 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupSuperblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632Writing inode tables: done Creating journal (32768 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 32 mounts or180 days, whichever comes first. Use tune2fs -c or -i to override.
After formatting, add the new partition to LVM (logical volume manager) for future management.
Run the pvdisplay command to view the physical volume information of LVM.
[root@localhost ~]# pvdisplay --- Physical volume --- PV Name /dev/sda2 VG Name VolGroup00 PV Size 29.81 GB / not usable 25.93 MB Allocatable yes PE Size (KByte) 32768 Total PE 953 Free PE 1 Allocated PE 952 PV UUID gjFDfY-J0vK-7YKm-uo32-eiQZ-YO3D-PFbp1A
As you can see, only/dev/sda2 is added to the volgroup00 volume group of LVM.
Use our new/dev/sda5 to create the LVM physical volume. The command is pvcreate.
[root@localhost ~]# pvcreate /dev/sda5 Physical volume "/dev/sda5" successfully created
Created successfully, and then type pvdisplay to view
[root@localhost ~]# pvdisplay --- Physical volume --- PV Name /dev/sda2 VG Name VolGroup00 PV Size 29.81 GB / not usable 25.93 MB Allocatable yes PE Size (KByte) 32768 Total PE 953 Free PE 1 Allocated PE 952 PV UUID gjFDfY-J0vK-7YKm-uo32-eiQZ-YO3D-PFbp1A "/dev/sda5" is a new physical volume of "10.00 GB" --- NEW Physical volume --- PV Name /dev/sda5 VG Name PV Size 10.00 GB Allocatable NO PE Size (KByte) 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID WiG7f0-jGuq-HCUR-3MCZ-d8V0-rwV9-rEF2wg
The new physical volume has been created but is not added to any volume group. Now we add it to the volgroup00 volume group.
[root@localhost ~]# vgextend VolGroup00 /dev/sda5 Volume group "VolGroup00" successfully extended
Added successfully. Type lvdisplay to view the current logical volume information.
[root@localhost ~]# lvdisplay --- Logical volume --- LV Name /dev/VolGroup00/LogVol00 VG Name VolGroup00 LV UUID nvo0P1-8kmf-f9jJ-X4ii-RHUD-VvwK-AvIm36 LV Write Access read/write LV Status available # open 1 LV Size 29.25 GB Current LE 936 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 --- Logical volume --- LV Name /dev/VolGroup00/LogVol01 VG Name VolGroup00 LV UUID 2hi7f1-SPdo-FQdX-s4gE-Y74F-rgzQ-KAO55X LV Write Access read/write LV Status available # open 1 LV Size 512.00 MB Current LE 16 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1
We want to extend the logical volume named/dev/volgroup00/logvol00 and use the lvextend command
[root@localhost ~]# lvextend /dev/VolGroup00/LogVol00 /dev/sda5 Extending logical volume LogVol01 to 10.47 GB Logical volume LogVol01 successfully resized
Expanded successfully. Enter lvdisplay to view the information, as shown below:
[root@localhost ~]# lvdisplay --- Logical volume --- LV Name /dev/VolGroup00/LogVol00 VG Name VolGroup00 LV UUID nvo0P1-8kmf-f9jJ-X4ii-RHUD-VvwK-AvIm36 LV Write Access read/write LV Status available # open 1 LV Size 39.22 GB Current LE 1255 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 --- Logical volume --- LV Name /dev/VolGroup00/LogVol01 VG Name VolGroup00 LV UUID 2hi7f1-SPdo-FQdX-s4gE-Y74F-rgzQ-KAO55X LV Write Access read/write LV Status available # open 1 LV Size 32.00 MB Current LE 1 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1
Logvol00 is increased by 10 Gb. However, if you type DF-H, we will find that our space is still unavailable.
[root@localhost ~]# df -hFilesystem Size Used Avail Use% Mounted on/dev/mapper/VolGroup00-LogVol00 29G 26G 2.3G 92% //dev/sda1 190M 13M 168M 7% /boottmpfs 506M 48K 506M 1% /dev/shmgvfs-fuse-daemon 29G 26G 2.3G 92% /root/.gvfs
You need to use the resize2fs tool to adjust the Linux File System size. If your Linux kernel version is 2.6 or later, you can directly adjust it. Otherwise, you need to adjust umount-Related Devices first. The kernel version of Fedora 9 is 2.6.25. OK, we adjusted the/dev/mapper/VolGroup00-LogVol00 file system listed in the DF command directly
[root@localhost ~]# resize2fs /dev/mapper/VolGroup00-LogVol00resize2fs 1.40.8 (13-Mar-2008)Filesystem at /dev/mapper/VolGroup00-LogVol00 is mounted on /; on-line resizing requiredold desc_blocks = 2, new_desc_blocks = 3Performing an on-line resize of /dev/mapper/VolGroup00-LogVol00 to 10280960 (4k) blocks.The filesystem on /dev/mapper/VolGroup00-LogVol00 is now 10280960 blocks long.
Enter the DF-H command to view details.
[root@localhost ~]# df -hFilesystem Size Used Avail Use% Mounted on/dev/mapper/VolGroup00-LogVol00 39G 26G 12G 69% //dev/sda1 190M 13M 168M 7% /boottmpfs 506M 48K 506M 1% /dev/shmgvfs-fuse-daemon 39G 26G 12G 69% /root/.gvfs
So far, our file system has been expanded.