centos调整在AWS上的Linux实例的root EBS卷大小

来源:www.howtoing.com 更新时间:2023-05-25 21:55

我创建了一个新的CentOS Linux实例。我实例的创建后,但是当系统上线时只显示盘8GB是可用的过程中选择了根卷的50GB。我试着用resize2fs中调整大小根磁盘,我得到以下信息
root@howtoing.com [~]# resize2fs /dev/xvda1 

The filesystem is already 16775167 blocks long.  Nothing to do!
所以,我按照下面的实例创建过程中选择的步骤,并能够成功地调整空间的大小

第1步:进行备份

我们强烈建议把你的实例的完整备份(AMI)做任何更改。同时创建根磁盘的快照。

第2步:检查当前分区

现在使用以下命令检查磁盘分区。你可以看到,/dev/xvda是53GB的大小,但
root@howtoing.com [~]# df -h 

Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1       8G  3.7G   4.2G  45% /
tmpfs           1.8G     0  1.8G   0% /dev/shm
/usr/tmpDSK     485M  111M  349M  25% /tmp
root@howtoing.com [~]# fdisk -l

Disk /dev/xvda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 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: 0x00098461

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           1        1045     8387584   83  Linux

第3步:增大空间的大小

现在使用以下命令设置磁盘分区重新启动。执行如下命令。
root@tecadmin[~]# fdisk /dev/xvda 

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').
现在,使用u选项改变显示单元扇区。
Command (m for help): u 
Changing display/entry units to sectors
现在打印分区表来检查磁盘详细信息
Command (m for help): p 

Disk /dev/xvda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders, total 104857600 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 identifier: 0x00098461

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *        2048    16777215     8387584   83  Linux
现在,使用以下命令删除第一个分区。
Command (m for help): d
Selected partition 1
现在,创建一个使用下面的命令一个新的分区。对于第一个扇区输入2048(如上面的命令的输出显示)和最后一秒只需按Enter键选择所有分区。
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First sector (63-104857599, default 63): 2048 
Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599): [PRESS ENTER]
Using default value 104857599
再次打印分区表。你会看到新的分区已经占据了所有的磁盘空间。
Command (m for help): p 

Disk /dev/xvda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders, total 104857600 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 identifier: 0x00098461

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1            2048   104857599    52427776   83  Linux
现在设置分区 1 启动标志。
Command (m for help): a 
Partition number (1-4): 1
永久写入磁盘分区,然后退出。
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@howtoing.com [~]# reboot
让我们用resize2fs中命令调整文件系统。记住,你的文件系统调整不格式化。
root@howtoing.com [~]# resize2fs /dev/xvda1 

resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/xvda1 is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 4
Performing an on-line resize of /dev/xvda1 to 13106944 (4k) blocks.
The filesystem on /dev/xvda1 is now 13106944 blocks long.

第4步:验证升级磁盘

此时,您的根卷已成功调整。只是验证磁盘已正确地调整大小
root@howtoing.com[~]# df -h 

Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1       50G  6.7G   40G  15% /
tmpfs           1.8G     0  1.8G   0% /dev/shm
/usr/tmpDSK     485M  111M  349M  25% /tmp