记录一下虚拟机磁盘扩容
看到笔记本磁盘空间挺大的,然后事先安装的的时候分配的空间觉得小了就扩大一点。
查看文件系统的大小
在 点击 虚拟机 ->设置->磁盘->扩展,选择扩展到合适的磁盘大小。
- 然后查看一下当前文件系统,存储分配情况,并没看到新扩展的内存被系统加载到。
[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
- 看一下扩展后整个磁盘的实际大小,以及每个已经被分区的大小。
[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
- 再在同一个磁盘里多分一个分区
[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
- 查询分区后情况
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.
- 后面警告说当下系统繁忙,还在使用旧表,需要重启才会用新表,然后重启,格式化新分区,并建个目录data1,将分区挂载到当前目录上
[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
- 因为重启系统后,这个磁盘又得重新手动挂载上去,所以最好还是开机自动挂载
[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