首页 > 系统相关 >VMWare Linux系统磁盘扩容

VMWare Linux系统磁盘扩容

时间:2022-11-13 09:55:58浏览次数:42  
标签:centos bytes dev Linux 磁盘 512 root VMWare

VMWare Linux系统磁盘扩容

当我们在VMware Linux虚拟机安装软件的时候,发现磁盘不够了,可以考虑给磁盘扩容,而不是重建虚拟机。

1. 修改磁盘容量

img

点击编辑虚拟设置

img

选择 磁盘=》扩展

img

点击“扩展

img

点击 确定

2. 添加分区

启动系统后,执行以下操作

2.1. 磁盘分区

[root@oracle ~]# 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): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

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 (41943040-83886079, default 41943040):
Using default value 41943040
Last sector, +sectors or +size{K,M,G} (41943040-83886079, default 83886079):
Using default value 83886079
Partition 4 of type Linux and of size 20 GiB is set

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

2.2. 查看新的磁盘分区类型

[root@oracle ~]# fdisk -l

Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 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: 0x000a9a6f

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048        6143        2048   83  Linux
/dev/sda2   *        6144     2103295     1048576   83  Linux
/dev/sda3         2103296    41943039    19919872   8e  Linux LVM
/dev/sda4        41943040    83886079    20971520   83  Linux

Disk /dev/mapper/centos-root: 19.3 GB, 19323158528 bytes, 37740544 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 /dev/mapper/centos-swap: 1073 MB, 1073741824 bytes, 2097152 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

sda4是新创建的分区,修改其Id与/dev/sda3的Id一致。

2.3. 修改磁盘分区类型

[root@oracle ~]# 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): t
Partition number (1-4, default 4):
Hex code (type L to list all codes): L

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris
 1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx
 5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data
 6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility
 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt
 9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access
 a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi eb  BeOS fs
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT
 f  W95 Ext'd (LBA) 54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC b
11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f1  SpeedStor
12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f4  SpeedStor
14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f2  DOS secondary
16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      fb  VMware VMFS
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fd  Linux raid auto
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep
1c  Hidden W95 FAT3 75  PC/IX           be  Solaris boot    ff  BBT
1e  Hidden W95 FAT1 80  Old Minix
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

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

修改后分区类型

[root@oracle ~]# fdisk -l

Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 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: 0x000a9a6f

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048        6143        2048   83  Linux
/dev/sda2   *        6144     2103295     1048576   83  Linux
/dev/sda3         2103296    41943039    19919872   8e  Linux LVM
/dev/sda4        41943040    83886079    20971520   8e  Linux LVM

Disk /dev/mapper/centos-root: 19.3 GB, 19323158528 bytes, 37740544 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 /dev/mapper/centos-swap: 1073 MB, 1073741824 bytes, 2097152 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

3. 磁盘扩容

重启系统后,开始扩充分区

3.1 查看磁盘分区卷组

[root@oracle ~]# lvs
  LV   VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root centos -wi-ao---- <18.00g
  swap centos -wi-ao----   1.00g
[root@oracle ~]# vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <19.00 GiB
  PE Size               4.00 MiB
  Total PE              4863
  Alloc PE / Size       4863 / <19.00 GiB
  Free  PE / Size       0 / 0
  VG UUID               gp2KXC-VUTG-0C01-aAed-31UC-HkVO-qi3gus

[root@oracle ~]#

3.2 扩展逻辑卷

  • 创建物理卷

    [root@oracle ~]# pvcreate  /dev/sda4
      Physical volume "/dev/sda4" successfully created.
    
  • 扩充卷组

    [root@oracle ~]# vgextend centos /dev/sda4
      Volume group "centos" successfully extended
    
     [root@oracle ~]# vgdisplay
      --- Volume group ---
      VG Name               centos
      System ID
      Format                lvm2
      Metadata Areas        2
      Metadata Sequence No  4
      VG Access             read/write
      VG Status             resizable
      MAX LV                0
      Cur LV                2
      Open LV               2
      Max PV                0
      Cur PV                2
      Act PV                2
      VG Size               38.99 GiB
      PE Size               4.00 MiB
      Total PE              9982
      Alloc PE / Size       4863 / <19.00 GiB
      Free  PE / Size       5119 / <20.00 GiB
      VG UUID               gp2KXC-VUTG-0C01-aAed-31UC-HkVO-qi3gus
    
  • 扩充逻辑卷

 [root@oracle ~]# vgextend centos /dev/sda4
  Volume group "centos" successfully extended

 [root@oracle ~]# vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               38.99 GiB
  PE Size               4.00 MiB
  Total PE              9982
  Alloc PE / Size       4863 / <19.00 GiB
  Free  PE / Size       5119 / <20.00 GiB
  VG UUID               gp2KXC-VUTG-0C01-aAed-31UC-HkVO-qi3gus
[root@oracle ~]# lvextend -L +18.5G /dev/centos/root /dev/sda4
  Size of logical volume centos/root changed from <18.00 GiB (4607 extents) to <36.50 GiB (9343 extents).
  Logical volume centos/root successfully resized.

3.3 修改文件系统大小

  • 查看文件系统类型
[root@oracle ~]# df -Th
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        37G   14G   24G  37% /
devtmpfs                devtmpfs  898M     0  898M   0% /dev
tmpfs                   tmpfs     910M     0  910M   0% /dev/shm
tmpfs                   tmpfs     910M  9.6M  901M   2% /run
tmpfs                   tmpfs     910M     0  910M   0% /sys/fs/cgroup
/dev/sda2               xfs      1014M  148M  867M  15% /boot
tmpfs                   tmpfs     182M     0  182M   0% /run/user/0
  • 修改文件系统大小
[root@oracle ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=1179392 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=4717568, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 4717568 to 9567232

:如果文件系统是ext4,使用resize2fs修改文件系统大小。

4. 扩容完毕

标签:centos,bytes,dev,Linux,磁盘,512,root,VMWare
From: https://www.cnblogs.com/shiqiang-lee/p/16885421.html

相关文章

  • 计算机基础和Linux安装
    计算机基础和Linux安装1.计算机系统一个完整的计算机系统由硬件系统和软件系统两大部分组成。1.1冯·诺伊曼体系结构8个二进制位(bit,b)为1个字节(byte,B)。00000000......
  • L01.linux技术-bond-----交换机对应配置
    通常情况下,虚拟机的聚合模式bond4对应交换机的动态聚合(LACP),虚拟机的bond0对应交换机的静态聚合,虚拟机如果是主备模式,那么交换机不需要做聚合,只需要划分接口vlan即可。......
  • Linux 服务管理
    查看运行级别:runlevel修改运行级别:init运行级别默认运行级别:vim/etc/inittab服务自启动:指让服务在系统开机后随之启动服务查看服务自启动状态:chkconfig--list源码包......
  • L01.linux技术-bond
    一、bonding技术bonding(绑定)是一种linux系统下的网卡绑定技术,可以把服务器上n个物理网卡在系统内部抽象(绑定)成一个逻辑上的网卡,能够提升网络吞吐量、实现网络冗余、负......
  • 卡巴斯基发布2016年2季度DDoS报告:Linux僵尸网络“挑大梁”
     据外媒报道,Linux僵尸网络已占2016年2季度发起的“分布式拒绝服务攻击”(DDoS)中的70.2%。过去三个月时间里,安全研究人员发掘出了运行基于Linux的固件、能够发起DDoS攻击、......
  • 《Unix/Linux系统编程》第十三章学习笔记
    第13章TCP/IP和网络编程摘要本章论述了TCP/IP和网络编程,分为两个部分。第一部分论述了TCP/IP协议及其应用,具体包括TCP/IP栈、IP地址、主机名、DNS、IP数据包和路由器......
  • Linux的Anaconda换阿里源
    简介Anaconda是一个用于科学计算的Python发行版,支持Linux,Mac,Windows,包含了众多流行的科学计算、数据分析的Python包。下载地址:​​https://mirrors.aliyun.com/anacond......
  • Linux系统中输入设备的应用编程实现
       大家好,今天主要来聊一聊,如何使用Linux系统下的输入设备进行应用编程。目录​​第一:什么是输入设备​​​​第二:读取数据的流程​​​​第三:应用程序该如何解析​​​......
  • Linux系统中线程同步方式中的条件变量操作方法
      大家好,今天主要和大家聊一聊,如何使用Linux中线程同步方式中的条件变量。    第一:条件变量基本简介   条件变量是线程可用的另一种同步机制,条件变量用于自动阻......
  • 增加虚拟机容量之linux硬盘格式在线从mbr转为gpt格式
    1、安装gdiskyuminstall-ygdisk 2、3、以上操作完毕后,检查一下数据(正常不会丢数据的)4、扩容yuminstallcloud-utils-growpartyuminstallxfsprogs扩展磁盘,扩容文件系......