虚拟机下ubuntu server扩容方案

总的来说,虚拟机下的ubuntu扩容分为三步:

1、虚拟机扩容

2、进入系统对多出来的容量新建分区

3、将新分区挂在到指定目录并完成固化

虚拟机扩容

这点没什么好说,VMware的虚拟机扩容得先删掉所有快照,不然没法扩容只能加磁盘

新建分区

1、将多出来的内存新建分区

# 新建目录用于挂载新分出来的分区
mkdir /data

# 进如root模式,不进也行,每个命令前加上sudo就行
su root

# 进入fdisk交互式命令行
fdisk /dev/sda
# 输入 m 可以查看命令说明
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
   
# 1、输入 n 新建分区,一切默认回车即可
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.

# 2、输入 p 查看新建分区情况,sda6就是新分区
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

# 3、输入 w 保存分区,此时df -lh还看不到新建的分区

# 4、格式化sda6分区,至此分区新建完成
mkfs -t /dev/sda6

挂载分区

只有将分区挂载到指定目录上,这个空间才能投入使用

mount /dev/sda6 /data

但是这样挂载的目录有一个缺陷,重启后就没了,还得重新挂载,所以需要执行固化

# 1、确定分区uuid
blkid /dev/sda6

/dev/sda6: UUID="01c6810e-738f-47c2-882f-2451b93a163d" TYPE="ext4" PARTUUID="212a7071-d49e-0f41-95df-b7a35eef881b"

复制下UUID的值,后面需要使用

# 2、将分区信息固化到系统配置信息中
vim /etc/fstab

# 参照原文件格式编写

# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
/dev/disk/by-uuid/bfae9057-2637-4bdb-b355-395ab9ca30f1 none swap sw 0 0
# / was on /dev/sda4 during curtin installation
/dev/disk/by-uuid/9bdde825-6d74-45e2-bbf5-0b497e0d0fcf / ext4 defaults 0 1
# /home was on /dev/sda5 during curtin installation
/dev/disk/by-uuid/40ca4129-cacf-4d8b-a213-fd3c654ca1ce /home ext4 defaults 0 1
# /boot was on /dev/sda2 during curtin installation
/dev/disk/by-uuid/1e0131bc-9662-41b6-81e7-9a5db92f3509 /boot ext4 defaults 0 1
# 参照/home的挂载配置,追加上相似的配置信息
/dev/disk/by-uuid/01c6810e-738f-47c2-882f-2451b93a163d /data ext4 defaults 0 1
/swap.img       none    swap    sw      0       0

保存文件,重启系统,至此完成扩容,重启后就可以在df -lh中看到相关容量信息了

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

请叫我徐先生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值