) In the virtual machine environment, the Linux system increases disk space.

Source: Internet
Author: User

Some time ago, a turbolinux system was installed in the VMware esxi virtualization environment. At that time, I did not care about how to plan the disk. I used LVM and thought that it could be scaled at any time. Unexpectedly, the time was not long. The problem occurred and the allocated disk space was full. I thought it would be as convenient as using disk management to add dynamic disks in Windows Server, So I randomly increased the original disk from 10 Gb to 13 Gb In the ESX manager, and there was no left or right to restart and mount the LVM, restart the system.

After the restart, use fdisk-L to see that the space for/dev/SDA has increased, but the original two disks are still/dev/sda1 and/dev/sda2 (LVM ). In LVM logical volume management, the original 10 Gb space is still available, however, you can see the added 3G uninitialized disk instance (unpartitioned space on/dev/SDA) in "uninitialized instance ).

Solution:

Run the sfdisk/dev/SDA command, select N (Add a new partition), select P (primary partition), and select a disk number, then the system will automatically prompt you to select the start block and the last block. Use P (print the partion table) to check whether the disk has been added:

Disk/dev/SDA: 13.9 GB, 13958643712 bytes
255 heads, 63 sectors/track, 1697 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 1305 10377990 8e Linux LVM
/Dev/sda3 1306 1697 3148740 83 Linux
As you can see, the ID of/dev/sda3 is 83. This disk cannot be added to LVM. Select T (change a partition's System ID ), type 8e (Linux lvm id ).

Finally, W is saved and exited. Use sfsik-L to view the new disk.

In this case, an error is prompted when you use the disk initialization tool of LVM or directly use the pvcreate/dev/sda3 command.

Device "/dev/sda3" not found (or ignored by filtering)

The error occurs because the configuration is not modified in runlevel 1 when fdisk is used. This problem can be solved after the system is restarted.

[Root @ turbolinux ~] # Fdisk-l

Disk/dev/SDA: 13.9 GB, 13958643712 bytes
255 heads, 63 sectors/track, 1697 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 1305 10377990 8e Linux LVM
/Dev/sda3 1306 1697 3148740 8e Linux LVM
[Root @ turbolinux ~] # Pvcreate/dev/sda3
Physical Volume "/dev/sda3" successfully created
[Root @ turbolinux ~] # LVM
LVM> pvscan
PV/dev/sda2 VG volgroup00 lvm2 [9.88 GB/640.00 MB free]
PV/dev/sda3 lvm2 [3.00 GB]
Total: 2 [12.88 GB]/in use: 1 [9.88 GB]/in no VG: 1 [3.00 GB]
LVM> vgextend volgroup00/dev/sda3
Volume group "volgroup00" successfully extended
LVM> lvdisplay
--- Logical volume ---
LV name/dev/volgroup00/logvol00
VG name volgroup00
Lv uuid 9tkx5o-7wgm-0bhf-omqy-ey14-ttbl-30j1px
LV write access read/write
LV status available
# Open 1
LV size 7.25 GB
Current le 232
Segments 2
Allocation inherit
Read ahead sectors auto
-Currently sets to 256
Block device 253: 0
LVM> lvextend
Please specify either size or extents but not both.
LVM> lvextend-L + 2g/dev/volgroup00/logvol00
Extending logical volume logvol00 to 9.25 GB
Logical volume logvol00 successfully resized
LVM> lvdisplay
--- Logical volume ---
LV name/dev/volgroup00/logvol00
VG name volgroup00
Lv uuid 9tkx5o-7wgm-0bhf-omqy-ey14-ttbl-30j1px
LV write access read/write
LV status available
# Open 1
LV size 9.25 GB
Current le 296
Segments 3
Allocation inherit
Read ahead sectors auto
-Currently sets to 256
Block device 253: 0

The size of the logical volume has been changed to 9.23g, but the file system has not increased:

[Root @ turbolinux ~] # DF
File System 1 K-block used available % mount point
/Dev/mapper/VolGroup00-LogVol00
7364072 5140148 1843844 74%/
/Dev/sda1 101086 25946 69921 28%/boot
Tmpfs 2073968 0 2073968 0%/dev/SHM

You need to use the resize2fs command to extend the file system to the added space:
[Root @ turbolinux ~] # 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 2424832 (4 K) blocks.
The filesystem on/dev/volgroup00/logvol00 is now 2424832 blocks long.

[Root @ turbolinux ~] # DF-m
File System 1 m-block used available % mount point
/Dev/mapper/VolGroup00-LogVol00
9176 5020 3683 58%/
/Dev/sda1 99 26 69 28%/boot
Tmpfs 2026 0 2026 0%/dev/SHM
[Root @ turbolinux ~] # DF
File System 1 K-block used available % mount point
/Dev/mapper/VolGroup00-LogVol00
9395560 5140156 3770492 58%/
/Dev/sda1 101086 25946 69921 28%/boot
Tmpfs 2073968 0 2073968 0%/dev/SHM
So far, the expansion of the disk space has been completed.

In addition, the swap space is changed as follows:

By default, I do not know why to set the size of swap to 5 GB, so it is not necessary to reduce it. Because swap is in volgroup00, It is very convenient to adjust the size,

The procedure is as follows:

Disable swap first

# Swapoff-V/dev/volgroup00/logvol01

# LVM lvreduce/dev/volgroup00/logvol01-L-1g

# Mkswap/dev/volgroup00/logvol01

Re-open swap

# Swapon-va

Common swap commands:

CAT/proc/SWAPs

Swapon-S

Adjust the swap size:
Dd If =/dev/Zero of = swapfree BS = 32 k count = 8192 (256 MB)
Mkswap swapfree
Swapon/tmp/swapfree

Stop:
Swapoff/tmp/swapfree
Load at startup:
Add the following content to the/etc/fstab file:
/Tmp/swapfree swap defaults 0 0

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.