This extension method requires support for LVM
1, change the virtual machine configuration
Virtual Machine -> Settings -> Hard Disk -> Disk capacity expansion
fdisk -l and found a bigger hard disk space
[root@thj Desktop]# fdisk -l Disk /dev/sda: 42.9 GB, 42949672960 bytes 255 heads, 63 sectors/track, 5221 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: 0x000812b5 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_thj-lv_root: 18.9 GB, 18865979392 bytes 255 heads, 63 sectors/track, 2293 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_thj-lv_swap: 2080 MB, 2080374784 bytes 255 heads, 63 sectors/track, 252 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
2, create a partition
[root@thj Desktop]# fdisk /dev/sda WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): p #查看分区表信息 Disk /dev/sda: 42.9 GB, 42949672960 bytes 255 heads, 63 sectors/track, 5221 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: 0x000812b5 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 Command (m forHelp): n- # Create a new partition the Command Action E Extended P Primary Partition ( . 1 - . 4 ) P # Create a primary partition the Partition Number ( . 1 - . 4 ): . 3 First Cylinder ( 2611 - 5221 , default 2611 ): the Using default value 2611 # default like Last Cylinder, + or + Cylinders size {K, M, G} ( 2611 - 5221 , default 5221 ): the Usingdefault value 5221 #默认就好 Command (m for help): p #查看分区表 Disk /dev/sda: 42.9 GB, 42949672960 bytes 255 heads, 63 sectors/track, 5221 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: 0x000812b5 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 /dev/sda3 2611 5221 20966162+ 83 Linux 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 or after you run partprobe(8) or kpartx(8) Syncing disks.
After setting, reboot reboot the system
3, format the partition
[root@thj Desktop]# mkfs.ext3 /dev/sda3 mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 1310720 inodes, 5241540 blocks 262077 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296 160 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 21 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
4, the LVM was added, and mount to the root directory
- vgs view volume set of circumstances
[Desktop THJ the root @] # Vgs VG of the Attr #PV #LV #SN VSize vfree vg_thj . 1 2 0 WZ - N- . 19 .51g 0 // vg_thj a volume group (here will be different in different systems)
- Create a physical volume (LVM partitions), and the physical volume vg_thj join the group
[root @ THJ Desktop] # LVM LVM > the pvcreate / dev / sda3 // create a hard partition LVM Physical Volume " / dev / sda3 " successfully the Created LVM > vgextend vg_thj / dev / sda3 // added to the root directory of the same group LVM Group Volume " vg_thj " successfully Extended
- View lv path
[root@thj Desktop]# lvdisplay --- Logical volume --- LV Path /dev/vg_thj/lv_root //root对应的lv path LV Name lv_root VG Name vg_thj LV UUID FMlzw9-r8dt-2Oa1-mS0W-brnn-YsDm-g3ld5S LV Write Access read/write LV Creation host, time thj.localthj, 2018-09-10 10:47:47 +0800 LV Status available # open 1 LV Size 17.57 GiB Current LE 4498 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 --- Logical volume --- LV Path /dev/vg_thj/lv_swap LV Name lv_swap VG Name vg_thj LV UUID lLgahm-QUMF-XHiN-jZJc-F5ve-YycI-FmEVdr LV Write Access read/write LV Creation host, time thj.localthj, 2018-09-10 10:47:50 +0800 LV Status available # open 1 LV Size 1.94 GiB Current LE 496 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1
- Extended lv path
[root@thj Desktop]# lvextend -L +19.99G /dev/vg_thj/lv_root Rounding size to boundary between physical extents: 19.99 GiB. Size of logical volume vg_thj/lv_root changed from 17.57 GiB (4498 extents) to 37.56 GiB (9616 extents). Logical volume lv_root successfully resized.
- Reset master partition size
[root@thj Desktop]# resize2fs /dev/vg_thj/lv_root resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/vg_thj/lv_root is mounted on /; on-line resizing required old desc_blocks = 2, new_desc_blocks = 3 Performing an on-line resize of /dev/vg_thj/lv_root to 9846784 (4k) blocks. The filesystem on /dev/vg_thj/lv_root is now 9846784 blocks long.
Sometimes the error:
[root@thj Desktop]# lvextend -L +19G /dev/vg_thj/lv_root Couldn't find device with uuid N0xspW-ZOct-v7pH-GHRN-G1Ck-0CnJ-ghqEKZ. Cannot change VG vg_thj while PVs are missing. Consider vgreduce --removemissing. Cannot process volume group vg_thj
Reference https://blog.51cto.com/yl497103815/1180426
- After viewing the extended file system
[root@thj Desktop]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_thj-lv_root 37G 12G 24G 33% / tmpfs 491M 228K 491M 1% /dev/shm /dev/sda1 477M 36M 417M 8% /boot