VMware虚拟机Debian扩展磁盘

一、 版本

  • VMware:Workstation 17 Pro
  • 虚拟机:Debian11

二、 VMware虚拟机扩展

  • 虚拟机关机状态
  • 快照或者备份:以免扩容失败导致文件丢失
  • 虚拟机------设置------硬盘------磁盘使用工具------扩展------扩展磁盘容量------设置为想要的大小

三、 虚拟机Debian系统扩展

  1. 开机进入虚拟机系统:删除分区、设置分区(重新创建主分区和swap分区,swap分区给4G,主分区96G。以下大小都是扇区单元表示,每个单元512个字节)、设置启动信息

    powershell 复制代码
    hslong@debian:~$ sudo fdisk /dev/sda   #输入执行重新分区
    
    Welcome to fdisk (util-linux 2.36.1).
    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: 100 GiB, 107374182400 bytes, 209715200 sectors
    Disk model: VMware Virtual S
    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: dos
    Disk identifier: 0xcdff7fa8
    
    Device     Boot     Start       End   Sectors  Size Id Type
    /dev/sda1  *         2048 123828223 123826176   59G 83 Linux
    /dev/sda2       123830270 125827071   1996802  975M  5 Extended
    /dev/sda5       123830272 125827071   1996800  975M 82 Linux swap / Solaris
    
    Command (m for help): d  #输入删除分区
    Partition number (1,2,5, default 5): 2  #删除分区2
    
    Partition 2 has been deleted.
    
    Command (m for help): d #输入显示操作信息
    Selected partition 1
    Partition 1 has been deleted.
    
    Command (m for help): n  #输入查看分区类型
    Partition type
       p   primary (0 primary, 0 extended, 4 free)
       e   extended (container for logical partitions)
    Select (default p): p  #输入选择分区类型
    Partition number (1-4, default 1):   #回车默认1进行分区
    First sector (2048-209715199, default 2048):  #回车默认
    Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-209715199, default 209715199): 201326592  #设置96G(96*1024*1024*1024/512)
    
    Created a new partition 1 of type 'Linux' and of size 96 GiB.
    Partition #1 contains a ext4 signature.
    
    Do you want to remove the signature? [Y]es/[N]o: y  #输入确认
    
    The signature will be removed by a write command.
    
    Command (m for help): n #输入查看分区类型
    Partition type
       p   primary (1 primary, 0 extended, 3 free)
       e   extended (container for logical partitions)
    Select (default p): p #输入选择分区类型
    Partition number (2-4, default 2): 2 #输入进行2分区
    First sector (201326593-209715199, default 201328640):   #回车默认
    Last sector, +/-sectors or +/-size{K,M,G,T,P} (201328640-209715199, default 209715199):  #回车默认
    
    Created a new partition 2 of type 'Linux' and of size 4 GiB.  #剩余4G
    
    Command (m for help): t  #输入
    Partition number (1,2, default 2):  #回车默认
    Hex code or alias (type L to list all): 82  #输入
    
    Changed type of partition 'Linux' to 'Linux swap / Solaris'.
    
    Command (m for help): a  #输入设置启用分区
    Partition number (1,2, default 2): 1  #输入启用分区1
    
    The bootable flag on partition 1 is enabled now.
    
    Command (m for help): p #查看分区信息
    Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 sectors
    Disk model: VMware Virtual S
    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: dos
    Disk identifier: 0xcdff7fa8
    
    Device     Boot     Start       End   Sectors Size Id Type
    /dev/sda1  *         2048 201326592 201324545  96G 83 Linux
    /dev/sda2       201328640 209715199   8386560   4G 82 Linux swap / Solaris
    
    Filesystem/RAID signature on partition 1 will be wiped.
    
    Command (m for help): w  #保存分区设置,以下提示后,重启系统
    The partition table has been altered.
    Failed to remove partition 5 from system: 设备或资源忙
    Failed to update system information about partition 1: 设备或资源忙
    
    The kernel still uses the old partitions. The new table will be used at the next reboot. 
    Syncing disks.
  2. 重启虚拟机系统

  3. resize2fs 命令扩大分区

    powershell 复制代码
    hslong@debian:~$ sudo resize2fs /dev/sda1 #输入执行扩大分区
    [sudo] hslong 的密码:
    resize2fs 1.46.2 (28-Feb-2021)
    Filesystem at /dev/sda1 is mounted on /; on-line resizing required
    old_desc_blocks = 8, new_desc_blocks = 12
    The filesystem on /dev/sda1 is now 25165568 (4k) blocks long.
    
    hslong@debian:~$ df -h  #输入查看已经完成
    文件系统        容量  已用  可用 已用% 挂载点
    udev            4.9G     0  4.9G    0% /dev
    tmpfs           992M  2.9M  989M    1% /run
    /dev/sda1        95G   43G   48G   48% /
    tmpfs           4.9G     0  4.9G    0% /dev/shm
    tmpfs           5.0M  4.0K  5.0M    1% /run/lock
    tmpfs           992M   96K  992M    1% /run/user/116
    tmpfs           992M   68K  992M    1% /run/user/1000

四、 重建swap分区信息

  • 新建交互分区

    powershell 复制代码
    hslong@debian:~$ sudo blkid  #输入查看交互分区,没有UUID
    /dev/sr0: BLOCK_SIZE="2048" UUID="2022-12-17-12-02-38-00" LABEL="Debian 11.6.0 amd64 1" TYPE="iso9660" PTUUID="5880e2de" PTTYPE="dos"
    /dev/sda1: UUID="f83080bb-7084-4727-a2dc-557ae5e5fe9e" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="cdff7fa8-01"
    /dev/sda2: PARTUUID="cdff7fa8-02"
    hslong@debian:~$ sudo mkswap /dev/sda2 #重新创建swap信息,会产生UUID
    Setting up swapspace version 1, size = 4 GiB (4293914624 bytes)
    no label, UUID=53d8ea82-bbef-4ad1-867e-70c5963bcfca
  • 修改 /etc/fstab 文件,将里面的 swap 分区信息的 uuid 换成新生成的uuid

    • sudo vi /etc/fstab
  • 运行 sudo swapon /dev/sda2 启用 swap

    • sudo swapon /dev/sda2
  • 查看新交互分区信息

    powershell 复制代码
    	hslong@debian:~$ sudo swapon -s 
    	Filename				Type		Size	Used	Priority
    	/dev/sda2                              	partition	4193276	0	-2
    	hslong@debian:~$ free -m
    	               total        used        free      shared  buff/cache   available
    	内存:       9913         748        8524           9         640        8914
    	交换:       4094           0        4094
    	hslong@debian:~$ 
    	```
相关推荐
苹果醋34 分钟前
React源码02 - 基础知识 React API 一览
java·运维·spring boot·mysql·nginx
Hello.Reader23 分钟前
深入解析 Apache APISIX
java·apache
日记跟新中42 分钟前
Ubuntu20.04 修改root密码
linux·运维·服务器
菠萝蚊鸭44 分钟前
Dhatim FastExcel 读写 Excel 文件
java·excel·fastexcel
唐小旭1 小时前
服务器建立-错误:pyenv环境建立后python版本不对
运维·服务器·python
BUG 4041 小时前
Linux——Shell
linux·运维·服务器
旭东怪1 小时前
EasyPoi 使用$fe:模板语法生成Word动态行
java·前端·word
007php0071 小时前
Go语言zero项目部署后启动失败问题分析与解决
java·服务器·网络·python·golang·php·ai编程
∝请叫*我简单先生1 小时前
java如何使用poi-tl在word模板里渲染多张图片
java·后端·poi-tl