首页 > 其他分享 >虚拟机sda扩容后,重新分区,扩充root

虚拟机sda扩容后,重新分区,扩充root

时间:2022-12-28 10:56:44浏览次数:47  
标签:02 ambari centos 虚拟机 partition sda table root

虚拟机sda扩容后,重新分区,扩充root

[root@santiagod ~]# ssh [email protected]
The authenticity of host '192.168.3.176 (192.168.3.176)' can't be established.
ECDSA key fingerprint is SHA256:LVOeZ5SO52YLiajCs99Ng/hxDz4iTs3kBqnILOV4oCA.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.3.176' (ECDSA) to the list of known hosts.
[email protected]'s password: 
Last login: Wed Dec 28 10:14:53 2022
[root@ambari-02 ~]# lsblk #查看硬盘剩余空间
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0   500G  0 disk 
├─sda1            8:1    0     1G  0 part /boot
└─sda2            8:2    0   199G  0 part 
  ├─centos-root 253:0    0 191.1G  0 lvm  /
  └─centos-swap 253:1    0   7.9G  0 lvm  [SWAP]
sr0              11:0    1  1024M  0 rom  
[root@ambari-02 ~]# 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 (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p  #尽量选择主分区
Partition number (3,4, default 3):  #默认直接回车
First sector (419430400-1048575999, default 419430400):   #默认直接回车
Using default value 419430400
Last sector, +sectors or +size{K,M,G} (419430400-1048575999, default 1048575999):  #默认直接回车,分配所有剩余空间
Using default value 1048575999
Partition 3 of type Linux and of size 300 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.
[root@ambari-02 ~]# partprobe /dev/sda   #重新读取分区
[root@ambari-02 ~]# lsblk  #查看新分区是否已就位
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0   500G  0 disk 
├─sda1            8:1    0     1G  0 part /boot
├─sda2            8:2    0   199G  0 part 
│ ├─centos-root 253:0    0 191.1G  0 lvm  /
│ └─centos-swap 253:1    0   7.9G  0 lvm  [SWAP]
└─sda3            8:3    0   300G  0 part 
sr0              11:0    1  1024M  0 rom  
[root@ambari-02 ~]# vgextend /dev/sda3  
  No command with matching syntax recognised.  Run 'vgextend --help' for more information.
  Correct command syntax is:
  vgextend VG PV ...

[root@ambari-02 ~]# 
[root@ambari-02 ~]# vgs  #查看卷组名
  VG     #PV #LV #SN Attr   VSize    VFree
  centos   1   2   0 wz--n- <199.00g 4.00m
[root@ambari-02 ~]# vgextend centos /dev/sda3  #扩充卷组
  Physical volume "/dev/sda3" successfully created.
  Volume group "centos" successfully extended
[root@ambari-02 ~]# lvs #查看逻辑卷名
  LV   VG     Attr       LSize    Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root centos -wi-ao---- <191.12g                                                    
  swap centos -wi-ao----   <7.88g                                                    
[root@ambari-02 ~]# lvresize -l +100%free  /dev/mapper/centos-root -f  #将卷组全部额外空间扩充逻辑卷
  Size of logical volume centos/root changed from <191.12 GiB (48926 extents) to <491.12 GiB (125726 extents).
  Logical volume centos/root successfully resized.
[root@ambari-02 ~]# lsblk  #验证,查看逻辑卷
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0   500G  0 disk 
├─sda1            8:1    0     1G  0 part /boot
├─sda2            8:2    0   199G  0 part 
│ ├─centos-root 253:0    0 491.1G  0 lvm  /
│ └─centos-swap 253:1    0   7.9G  0 lvm  [SWAP]
└─sda3            8:3    0   300G  0 part 
  └─centos-root 253:0    0 491.1G  0 lvm  /
sr0              11:0    1  1024M  0 rom  
[root@ambari-02 ~]# 

最后,最关键的是文件系统扩容!!!

[root@ambari-02 ~]# xfs_growfs /dev/centos/root   #文件系统扩容
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=12525056 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=50100224, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=24463, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 50100224 to 128743424
[root@ambari-02 ~]# lsblk
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0   500G  0 disk 
├─sda1            8:1    0     1G  0 part /boot
├─sda2            8:2    0   199G  0 part 
│ ├─centos-root 253:0    0 491.1G  0 lvm  /
│ └─centos-swap 253:1    0   7.9G  0 lvm  [SWAP]
└─sda3            8:3    0   300G  0 part 
  └─centos-root 253:0    0 491.1G  0 lvm  /
sr0              11:0    1  1024M  0 rom  
[root@ambari-02 ~]# df -Th  #查看,验证文件系统已扩容
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs       492G   39G  453G   8% /
devtmpfs                devtmpfs   12G     0   12G   0% /dev
tmpfs                   tmpfs      12G     0   12G   0% /dev/shm
tmpfs                   tmpfs      12G   17M   12G   1% /run
tmpfs                   tmpfs      12G     0   12G   0% /sys/fs/cgroup
/dev/sda1               xfs      1014M  145M  870M  15% /boot
tmpfs                   tmpfs     2.4G     0  2.4G   0% /run/user/0
[root@ambari-02 ~]# 

 遇到问题:三节点集群,第三个节点扩容失败

[root@ambari-03 ~]# vgextend centos /dev/sda3
/etc/lvm/archive/.lvm_ambari-03_12302_2001839236: write error failed: No space left on device

标签:02,ambari,centos,虚拟机,partition,sda,table,root
From: https://www.cnblogs.com/santia-god/p/17009622.html

相关文章