I. Background of Use
Linux root directory disk space is not enough, when the virtual machine template was modified to increase disk size or insert a new hard disk, but found that the size of the system has not changed.
The reason for this is that the disk is not formatted and partitions are not added.
II. Operational methods
1. Looking at the disk space size, using the df-h command, we found that the / dev / mapper / vg_node 003-lv_root mounted on the root directory node has only 7.1G capacity.
[root@node-002 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_node003-lv_root 18G 9.3G 7.1G 57% / tmpfs 491M 0 491M 0% /dev/shm /dev/sda1 477M 42M 411M 10% /boot
2. Increase disk space, such as the way VM virtual machines are added in the figure below.
3. Use fdisk-l command to view disk information. When you see that the first line of Disk/dev/sda: 53.7 GB does not match the actual df-h display content, it indicates that the addition of disks is successful.
[root@node-002 ~]# fdisk -l Disk /dev/sda: 53.7 GB, 53687091200 bytes 255 heads, 63 sectors/track, 6527 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00092cf6 Device Boot Start End Blocks Id System /dev/sda1 * 1 64 512000 83 Linux Partition 1 does not end on cylinder boundary. /dev/sda2 64 2611 20458496 8e Linux LVM Disk /dev/mapper/vg_node003-lv_root: 18.8 GB, 18798870528 bytes 255 heads, 63 sectors/track, 2285 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000 Disk /dev/mapper/vg_node003-lv_swap: 2147 MB, 2147483648 bytes 255 heads, 63 sectors/track, 261 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000
4. Create new partitions using fdisk/dev/sda.
Note: Disk naming is different for different operating systems, some of which are / dev/vda. Specific usage refers to the first line of fdisk-l in the third step to display Disk. If the first line of the system is Disk/dev/sda: 53.7 GB, 53687091200 bytes, the command fdisk/dev/sda is used.
Partition according to the following Linux operations.
[root@node-002 ~]# fdisk /dev/vda Command (Enter m for help):m Command operation a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only) Command (Enter m to get help): n #new partition Partition type: p primary (1 primary, 1 extended, 2 free) l logical (numbered from 5) Select (default p): p # Select the primary partition Partition Number (1-4, default 3): 3 # Partition Sequence Number Start sector (499712-314572799, default 49972): partition start return default The default value 499712 will be used Last sector, +sector or+size {K, M, G} (499712-501757, default 50177): The default value 501757 will be used Command (Enter m to get help): n #new partition Partition type: p primary (2 primary, 1 extended, 1 free) l logical (numbered from 5) Select (default p): p # Select the primary partition Selected partition 4 # partition number Initial sector (62912512-314572799, default 62912512): # partition start return default The default value 62912512 will be used Last sector, +sector or+size {K, M, G} (62912512-314572799, default 31452799): The default value 314572799 will be used Command (Enter m for help): t# Modify partition format Partition Number (1-5): 4 # Modify Partition Number Hex code (type L to list codes): 8e# format selection 8e Linux LVM Changed system type of partition 4 to 8e (Linux LVM) Command (Enter m for help): p # Displays partition information Disk /dev/sda: 161.1 GB, 161061273600 bytes 16 heads, 63 sectors/track, 312076 cylinders, total 314572800 sectors Units = sector of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x0001a023 Id System of Starting Point and End Point Block Number of Equipment /dev/sda1 * 2048 499711 248832 83 Linux / Extension of dev/sda2 501758 62912511 31205377 5 /dev/sda3 499712 501757 1023 83 Linux Partition table entries are not in disk order Command (Input m for help): w # Save information The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Busy equipment or resources. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) Syncing disks.
5. Restart the Linux operating system and use the reboot command.
6. Create a physical volume using the pvcreate/dev/sda3 command.
[root@node-002 dev]# pvcreate /dev/sda3 Physical volume "/dev/sda3" successfully created
7. View the new physical volume and size, using the pvdisplay command.
[root@node-002 dev]# pvdisplay --- Physical volume --- PV Name /dev/sda2 VG Name vg_node003 PV Size 19.51 GiB / not usable 3.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 4994 Free PE 0 Allocated PE 4994 PV UUID UC4j5m-rJO4-DroW-E92L-n5Vj-SU0U-PJyfJf "/dev/sda3" is a new physical volume of "30.00 GiB" --- NEW Physical volume --- PV Name /dev/sda3 VG Name PV Size 30.00 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID nng8Gx-51fP-DIBH-YeF4-Sw7B-S0jQ-oGXfpa
8. A new physical volume will be added and loaded into the vg_node003 volume group using the vgextend vg_node003/dev/sda3 command.
[root@node-002 dev]# vgextend vg_node003 /dev/sda3 Volume group "vg_node003" successfully extended
9. View volume group information and use the vgdisplay command.
[root@node-002 dev]# vgdisplay --- Volume group --- VG Name vg_node003 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 49.50 GiB PE Size 4.00 MiB Total PE 12673 Alloc PE / Size 4994 / 19.51 GiB Free PE / Size 7679 / 30.00 GiB VG UUID v37e5T-4iPX-olm0-Claw-8EfO-axHf-evCAfc
10. Increase the size of vg_node 003 and 30G. Use the lvresize-L+30G/dev/mapper/vg_node003-lv_root command.
Note: vg_node 003-lv_root is checked in / dev/mapper
[root@node-002 mapper]# lvresize -L +29.99G /dev/mapper/vg_node003-lv_root Rounding size to boundary between physical extents: 29.99 GiB Size of logical volume vg_node003/lv_root changed from 17.51 GiB (4482 extents) to 47.50 GiB (12160 extents). Logical volume lv_root successfully resized
11. Recognize the size of vg_node003 and use the resize2fs/dev/mapper/vg_node003-lv_root command.
[root@node-002 mapper]# resize2fs /dev/mapper/vg_node003-lv_root resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/mapper/vg_node003-lv_root is mounted on /; on-line resizing required old desc_blocks = 2, new_desc_blocks = 3 Performing an on-line resize of /dev/mapper/vg_node003-lv_root to 12451840 (4k) blocks. The filesystem on /dev/mapper/vg_node003-lv_root is now 12451840 blocks long.
12. Look at the expanded size and use the df-h command.
[root@node-002 mapper]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_node003-lv_root 47G 9.3G 36G 21% / tmpfs 491M 0 491M 0% /dev/shm /dev/sda1 477M 42M 411M 10% /boot
When you see that / dev/mapper/vg_node003-lv_root has been updated to a new size, the increase is successful.
Three, summary
Above is the operation method of expanding the disk space of the root directory of Linux system introduced by Xiaobian. I hope it will be helpful to you. If you have any questions, please leave me a message and Xiaobian will reply to you in time.