记一次阿里云CentOS6磁盘扩容

阿里云数据盘盘扩容

环境

系统:CentOS6.10

磁盘:20G高效云盘

内核:2.6

数据盘状态:已挂载及格式化并分区

操作步骤

控制台-实例-需要扩容的ECS-需要扩容的数据盘

  1. 创建快照——对需要扩容磁盘进行备份

在这里插入图片描述
2. 点击磁盘扩容

image

根据需求选在扩容磁盘大小此处由20G扩容至30G

  1. 进入控制台重启服务(centos6需要重启才能生效),使磁盘扩容生效
  [root@iZuf633xawg78i3i3n8o2yZ ~]# fdisk -l
  
  Disk /dev/vda: 21.5 GB, 21474836480 bytes
  255 heads, 63 sectors/track, 2610 cylinders
  Units = cylinders of 16065 * 512 = 8225280 bytes
  Sector size (logical/physical): 512 bytes / 512 bytes
  I/O size (minimum/optimal): 512 bytes / 512 bytes
  Disk identifier: 0x0003a613
  
     Device Boot      Start         End      Blocks   Id  System
  /dev/vda1   *           1        2611    20970496   83  Linux
  
  Disk /dev/vdb: 32.2 GB, 32212254720 bytes
  16 heads, 63 sectors/track, 62415 cylinders
  Units = cylinders of 1008 * 512 = 516096 bytes
  Sector size (logical/physical): 512 bytes / 512 bytes
  I/O size (minimum/optimal): 512 bytes / 512 bytes
  Disk identifier: 0xcd52d77f
  
     Device Boot      Start         End      Blocks   Id  System
  /dev/vdb1               1       52012    26214016+  83  Linux
  
  1. 运行blkid确认文件系统的类型。本示例中, /dev/vdb1的文件系统类型为 ext4 。
[root@iZuf633xawg78i3i3n8o2yZ ~]# blkid /dev/vdb1
/dev/vdb1: UUID="c96986e3-bbdf-42cd-a4ca-0b4421329ae5" TYPE="ext4" 
  1. 运行以下命令确认文件系统的状态

    • ext系列文件系统:e2fsck -n <dst_dev_part_path>

    • xfs文件系统:xfs_repair -n <dst_dev_part_path>

      本示例中,文件系统状态为clean。如果状态不是clean,请排查并修复。

   [root@iZuf633xawg78i3i3n8o2yZ ~]# e2fsck -n /dev/vdb1 
   e2fsck 1.41.12 (17-May-2010)
   /dev/vdb1: clean, 16/1638400 files, 146854/6553504 blocks
   ```

   

6. 此处内核为2.6,需要先取消已挂载的磁盘(根据内核版本选择具体步骤,详见阿里云文档)

 ```bash
 umount /dev/vdb1

7.使用fdisk命令删除旧分区。

[root@iZuf633xawg78i3i3n8o2yZ ~]# fdisk /dev/vdb

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): d
Selected partition 1

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

8.使用fdisk命令新建分区。

[root@iZuf633xawg78i3i3n8o2yZ ~]# fdisk /dev/vdb

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): d
Selected partition 1

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@iZuf633xawg78i3i3n8o2yZ ~]# fdisk /dev/vdb

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-62415, default 1):    
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-62415, default 62415): 
Using default value 62415

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

警告

  • 新分区的起始位置,必须和旧分区的起始位置相同。
  • 新分区的结束位置,必须大于旧分区的结束位置,否则会导致扩容失败。
  1. 运行lsblk /dev/vdb确保分区表已经增加。
  [root@iZuf633xawg78i3i3n8o2yZ ~]# lsblk /dev/vdb
  NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
  vdb    252:16   0  30G  0 disk 
  └─vdb1 252:17   0  30G  0 part 
  1. 运行e2fsck -n /dev/vdb1再次检查文件系统,确认扩容分区后的文件系统状态为clean
      [root@iZuf633xawg78i3i3n8o2yZ ~]# e2fsck -n /dev/vdb1
      e2fsck 1.41.12 (17-May-2010)
      /dev/vdb1: clean, 16/1638400 files, 146854/6553504 blocks
  1. 通知内核更新分区表

    partx -a /dev/vdb1 /dev/vdb
    
  2. 扩容文件系统

    resize2fs /dev/vdb1
    

    注:可能会提示先运行e2fsck -f /dev/vdb1

  3. 挂载扩容后的分区

    mount /dev/vdb1 /data
    
  4. 使用df命令查看磁盘挂载情况

    [root@iZuf633xawg78i3i3n8o2yZ ~]# df -h
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/vda1        20G  1.3G   18G   7% /
    tmpfs           498M     0  498M   0% /dev/shm
    /dev/vdb1        30G   44M   28G   1% /data
    

扩容成功

猜你喜欢

转载自blog.csdn.net/CN_SHzhaoyujie/article/details/89884306