总的来说,虚拟机下的ubuntu扩容分为三步:
1、虚拟机扩容
2、进入系统对多出来的容量新建分区
3、将新分区挂在到指定目录并完成固化
虚拟机扩容
这点没什么好说,VMware的虚拟机扩容得先删掉所有快照,不然没法扩容只能加磁盘
新建分区
1、将多出来的内存新建分区
mkdir /data
su root
fdisk /dev/sda
Command (m for help): m
Help:
Generic
d delete a partition
F list free unpartitioned space
l list known partition types
n add a new partition
p print the partition table
t change a partition type
v verify the partition table
i print information about a partition
Misc
m print this menu
x extra functionality (experts only)
Script
I load disk layout from sfdisk script file
O dump disk layout to sfdisk script file
Save & Exit
w write table to disk and exit
q quit without saving changes
Create a new label
g create a new empty GPT partition table
G create a new empty SGI (IRIX) partition table
o create a new empty DOS partition table
s create a new empty Sun partition table
Command (m for help): n
Partition number (6-128, default 6):
First sector (41940992-104857566, default 41940992):
Last sector, +sectors or +size{K,M,G,T,P} (41940992-104857566, default 104857566):
Created a new partition 6 of type 'Linux filesystem' and of size 30 GiB.
Command (m for help): p
Disk /dev/sda: 50 GiB, 53687091200 bytes, 104857600 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
Disklabel type: gpt
Disk identifier: D7617B57-3A11-4B5B-B28D-FE5A8EEAD05D
Device Start End Sectors Size Type
/dev/sda1 2048 4095 2048 1M BIOS boot
/dev/sda2 4096 2101247 2097152 1G Linux filesystem
/dev/sda3 2101248 8392703 6291456 3G Linux swap
/dev/sda4 8392704 29364223 20971520 10G Linux filesystem
/dev/sda5 29364224 41940991 12576768 6G Linux filesystem
/dev/sda6 41940992 104857566 62916575 30G Linux filesystem
mkfs -t /dev/sda6
挂载分区
只有将分区挂载到指定目录上,这个空间才能投入使用
mount /dev/sda6 /data
但是这样挂载的目录有一个缺陷,重启后就没了,还得重新挂载,所以需要执行固化
blkid /dev/sda6
/dev/sda6: UUID="01c6810e-738f-47c2-882f-2451b93a163d" TYPE="ext4" PARTUUID="212a7071-d49e-0f41-95df-b7a35eef881b"
复制下UUID的值,后面需要使用
vim /etc/fstab
/dev/disk/by-uuid/bfae9057-2637-4bdb-b355-395ab9ca30f1 none swap sw 0 0
/dev/disk/by-uuid/9bdde825-6d74-45e2-bbf5-0b497e0d0fcf / ext4 defaults 0 1
/dev/disk/by-uuid/40ca4129-cacf-4d8b-a213-fd3c654ca1ce /home ext4 defaults 0 1
/dev/disk/by-uuid/1e0131bc-9662-41b6-81e7-9a5db92f3509 /boot ext4 defaults 0 1
/dev/disk/by-uuid/01c6810e-738f-47c2-882f-2451b93a163d /data ext4 defaults 0 1
/swap.img none swap sw 0 0
保存文件,重启系统,至此完成扩容,重启后就可以在df -lh 中看到相关容量信息了
|