New partition of virtual machine disk

Record the virtual machine disk expansion

Seeing that the disk space of the notebook is quite large, and then the allocated space was enlarged when it was small when it was installed in advance.

View the size of the file system

Click the Virtual Machine -> Settings -> Disk -> extension , select the extension to the appropriate disk size.

  1. Then check the current file system, storage allocation, and did not see the newly expanded memory being loaded by the system.
[root@localhost ~]# df -hT
Filesystem     Type      Size  Used Avail Use% Mounted on
devtmpfs       devtmpfs  3.8G     0  3.8G   0% /dev
tmpfs          tmpfs     3.9G     0  3.9G   0% /dev/shm
tmpfs          tmpfs     3.9G   13M  3.8G   1% /run
tmpfs          tmpfs     3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda1      xfs        60G  4.1G   56G   7% /
/dev/sda2      xfs        25G  771M   25G   4% /var
tmpfs          tmpfs     781M   32K  781M   1% /run/user/1000
/dev/sr0       iso9660   4.4G  4.4G     0 100% /run/media/root/CentOS 7 x86_64
tmpfs          tmpfs     781M     0  781M   0% /run/user/0

  1. Look at the actual size of the entire disk after expansion, and the size of each partition that has been partitioned.
[root@localhost ~]# fdisk -l 

Disk /dev/sda: 161.1 GB, 161061273600 bytes, 314572800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0009cdd8

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048   125831167    62914560   83  Linux
/dev/sda2       125831168   178259967    26214400   83  Linux
/dev/sda3       178259968   188743679     5241856   82  Linux swap / Solaris
  1. Then divide one more partition in the same disk
[root@localhost ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): p

Disk /dev/sda: 161.1 GB, 161061273600 bytes, 314572800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0009cdd8

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048   125831167    62914560   83  Linux
/dev/sda2       125831168   178259967    26214400   83  Linux
/dev/sda3       178259968   188743679     5241856   82  Linux swap / Solaris

Command (m for help): n
Partition type:
   p   primary (3 primary, 0 extended, 1 free)
   e   extended
Select (default e): p
Selected partition 4
First sector (188743680-314572799, default 188743680): 
Using default value 188743680
Last sector, +sectors or +size{
    
    K,M,G} (188743680-314572799, default 314572799): 
Using default value 314572799
Partition 4 of type Linux and of size 60 GiB is set

  1. Query the situation after partition
Command (m for help): p

Disk /dev/sda: 161.1 GB, 161061273600 bytes, 314572800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0009cdd8

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048   125831167    62914560   83  Linux
/dev/sda2       125831168   178259967    26214400   83  Linux
/dev/sda3       178259968   188743679     5241856   82  Linux swap / Solaris
/dev/sda4       188743680   314572799    62914560   83  Linux

Command (m for help): wp
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.

  1. The later warns that the current system is busy and the old table is still in use. It needs to be restarted to use the new table. Then restart, format the new partition, and create a directory data1, and mount the partition to the current directory.
[root@localhost ~]# reboot
[root@localhost mapper]#  mkfs.xfs /dev/sda4
[root@localhost mapper]# mkdir /data1
[root@localhost mapper]# mount /dev/sda4 /data1
[root@localhost mapper]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        3.8G     0  3.8G   0% /dev
tmpfs           3.9G     0  3.9G   0% /dev/shm
tmpfs           3.9G   13M  3.8G   1% /run
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda1        60G  4.1G   56G   7% /
/dev/sda2        25G  812M   25G   4% /var
tmpfs           781M   12K  781M   1% /run/user/42
tmpfs           781M     0  781M   0% /run/user/0
/dev/sda4        60G   33M   60G   1% /data1

  1. After restarting the system, the disk has to be manually mounted again, so it’s best to mount it automatically after booting.
[root@localhost ~]# vim /etc/fstab
#
# /etc/fstab
# Created by anaconda on Wed Mar 17 16:49:42 2021
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=9311cbde-d447-4a56-8f74-092e065c9420 /                       xfs     defaults        0 0
UUID=489ce9aa-e8e2-4203-98c4-2491f8bd09ec /var                    xfs     defaults        0 0
UUID=a8da9bdf-e3ee-4cb8-b652-5e17632f0a44 swap                    swap    defaults        0 0
/dev/sda4       /data1  xfs     defaults        0       0  

Guess you like

Origin blog.csdn.net/m0_48187193/article/details/114965177