叫我大侠
人可以失败,但不可以被击败
扩展系统盘 - 增加系统磁盘大小

系统盘太小时需要扩展系统磁盘,我这里以Azure为例,系统盘默认8G,需要扩展增加磁盘容量。分为两个步骤:

1. 停止实例,调整磁盘大小(实例运行时无法调整,Azure 停止实例注意保存数据)

2. 重新启动实例,扩展磁盘分区大小

第一步不用多说,自己在平台操作即可,我们详细说说第二步:

1. 查看系统盘 

[root@azure]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        2.0G     0  2.0G   0% /dev
tmpfs           2.0G     0  2.0G   0% /dev/shm
tmpfs           2.0G   17M  2.0G   1% /run
tmpfs           2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/sda3       8.0G  2.1G  6.0G  26% /
/dev/sda1      1014M  229M  786M  23% /boot
/dev/sdb1       7.9G  2.1G  5.4G  28% /mnt/resource
tmpfs           394M     0  394M   0% /run/user/1001
系统盘为:/dev/sda3       8.0G  2.1G  6.0G  26% /

2.重新设置分区(数据不会掉的)

[root@azure]# fdisk /dev/sda

Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

输入 p  查看磁盘分区信息

Command (m for help): p
Disk /dev/sda: 128 GiB, 137438953472 bytes, 268435456 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x53b62a86

Device     Boot   Start       End   Sectors  Size Id Type
/dev/sda1  *       2048   2099199   2097152    1G 83 Linux
/dev/sda2       2099200   4196351   2097152    1G 82 Linux swap / Solaris
/dev/sda3  *    4196352 268435455 264239104  126G 8e Linux LVM

输入 d  清理分区信息,默认就是系统盘默认分区号3(不同的自己输入系统盘分区号)

Command (m for help): d
Partition number (1-3, default 3): 

Partition 3 has been deleted.

输入 n 新建分区信息:

Command (m for help): n
Partition type
   p   primary (2 primary, 0 extended, 2 free)
   e   extended (container for logical partitions)

输入 p  选择 primary类型(然后一直回车):

Select (default p): p
Partition number (3,4, default 3): 
First sector (4196352-268435455, default 4196352): 
Last sector, +sectors or +size{K,M,G,T,P} (4196352-268435455, default 268435455): 

Created a new partition 3 of type 'Linux' and of size 126 GiB.
Partition #3 contains a xfs signature.

Do you want to remove the signature? [Y]es/[N]o: N

输入 t  修改系统盘为 Linux LVM,我们操作的是默认系统盘分区 3 , Hex code 输入 8e 

Command (m for help): t
Partition number (1-3, default 3):     
Hex code (type L to list all codes): 8e

输入 p  查看新分区信息:

Command (m for help): p
Disk /dev/sda: 128 GiB, 137438953472 bytes, 268435456 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x53b62a86

Device     Boot   Start       End   Sectors  Size Id Type
/dev/sda1  *       2048   2099199   2097152    1G 83 Linux
/dev/sda2       2099200   4196351   2097152    1G 82 Linux swap / Solaris
/dev/sda3       4196352 268435455 264239104  126G 8e Linux LVM

输入 a  激活分区:

Command (m for help): a
Partition number (1-3, default 3): 

The bootable flag on partition 3 is enabled now.

输入 wr  保存设置:

Command (m for help): wr
The partition table has been altered.
Syncing disks.

输入 init6  重启机器:

[root@azure]# init 6

----喝水----wait----------wait----------- wait ----------重启完成

3.修改根文件系统的大小为正确值

输入 df 检查容量(容量没变依然8G):

[root@azure]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        2.0G     0  2.0G   0% /dev
tmpfs           2.0G     0  2.0G   0% /dev/shm
tmpfs           2.0G   17M  2.0G   1% /run
tmpfs           2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/sda3       8.0G  2.1G  6.0G  26% /
/dev/sda1      1014M  229M  786M  23% /boot
/dev/sdb1       7.9G  2.1G  5.4G  28% /mnt/resource
tmpfs           394M     0  394M   0% /run/user/1001

输入 resize2fs  /dev/sda3 修改根文件系统的大小(容量没变依然8G):

[root@azure]# resize2fs  /dev/sda3
resize2fs 1.45.6 (20-Mar-2020)
resize2fs: Bad magic number in super-block while trying to open /dev/sda3
Couldn't find valid filesystem superblock.

意料到会报错,因为是xfs系统centos不再支持使用resize2fs修改;因此

输入  xfs_growfs /dev/sda3  即可修改系统盘大小为正确的了

[root@azure]#  xfs_growfs /dev/sda3 
meta-data=/dev/sda3              isize=512    agcount=4, agsize=524224 blks
         =                       sectsz=4096  attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=2096896, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=4096  sunit=1 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 2096896 to 33029888


再次输入 df 检查容量(成功  鼓掌、喝酒 庆祝):

[root@azure]# df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs        2.0G     0  2.0G   0% /dev
tmpfs           2.0G     0  2.0G   0% /dev/shm
tmpfs           2.0G   17M  2.0G   1% /run
tmpfs           2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/sda3       126G  2.9G  124G   3% /
/dev/sda1      1014M  229M  786M  23% /boot
/dev/sdb1       7.9G  2.1G  5.4G  28% /mnt/resource
tmpfs           394M     0  394M   0% /run/user/1001



参考:

https://docs.azure.cn/zh-cn/articles/azure-operations-guide/virtual-machines/linux/aog-virtual-machines-qa-linux-root-file-system-extension

https://www.115115.xyz/everything/azure%E6%89%A9%E5%B1%95centos7-8%E7%B3%BB%E7%BB%9F%E7%9B%98%E5%A4%A7%E5%B0%8F/

https://docs.microsoft.com/zh-cn/azure/virtual-machines/linux/expand-disks

<< 上一篇 MySQL开启慢查询日志-调优、监控必备 centos7 yum安装 php7.3教程 下一篇 >>
文章标签
随意 | Created At 2014 By William Clinton | 蜀ICP备14002619号-4 |