Amazon EC2 调整根设备大小
Amazon EC2 resize root device
我有一个 amazonw ec2 实例,想将根设备从 100G 扩展到 500G。创建一个新的 500G 卷并重新附加到实例后。
我可以通过命令 $lsblk 看到音量在那里。但是,在我调整磁盘大小之后。我无法执行错误“文件系统已经有 26212055 个块长。无事可做!
name@ip-172-1-1-3:~$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 3.9G 8.0K 3.9G 1% /dev
tmpfs 799M 840K 798M 1% /run
/dev/xvda1 99G 92G 3.1G 97% /
name@ip-172-1-1-3:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE
MOUNTPOINT
xvda 202:0 0 500G 0 disk
└─xvda1 202:1 0 100G 0 part /
name@ip-172-1-1-3:~$sudo resize2fs /dev/xvda1
resize2fs 1.42.9 (4-Feb-2014)
The filesystem is already 26212055 blocks long. Nothing to do!
具体操作如下:
df -h
#打印启动分区的名称
lsblk
#显示所有块设备的信息
您将从该输出中看到您的根分区的磁盘名称。例如,您可能会看到类似这样的内容:
xvde 202:64 0 32G 0 disk
└─xvde1 202:65 0 8G 0 part /
我们的目标是让 xvde1
使用 xvde
中全部可用的 space。
以下是调整分区大小的方法:
fdisk /dev/xvda
(磁盘名称,不是你的分区)
这将进入 fdisk
实用程序。
u
#将显示改为扇区
p
#打印信息
d
#删除分区
n
#新建分区
p
#主分区
1
#分区号
2048
#第一扇区
- 按 Enter 接受默认值
p
#打印信息
a
#切换 bootable 标志
1
#Select 分区 1
w
#将table写入磁盘并退出
现在,重启您的实例:
reboot
返回后做:
resize2fs /dev/xvde1
(你分区的名字,不是块设备)
最后验证新的磁盘大小:
df -h
在我按照@error2007s 第 12 步 "a" a #Toggle the bootable flag 停止并重新启动之后。我无法调出实例。
Disk /dev/xvda: 536.9 GB, 536870912000 bytes
255 heads, 63 sectors/track, 65270 cylinders, total 1048576000 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: 0x00000000
Device Boot Start End Blocks Id System
/dev/xvda1 2048 1048575999 524286976 83 Linux
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.
name@ip-172-1-1-3:~$ reboot
reboot: Need to be root
name@ip-172-1-1-3:~$ sudo reboot
Broadcast message from name@ip-172-1-1-3
(/dev/pts/1) at 10:18 ...
The system is going down for reboot NOW!
$ ssh -i "a.pem" name@ec2-172.1.1.3.compute-1.amazonaws.com -p 22
ssh: connect to host ec2-172.1.1.3.compute-1.amazonaws.com port 22: Operation timed out
您需要扩展可用 space:
$ lsblk
xvda 202:0 0 500G 0 disk
└─xvda1 202:1 0 100G 0 part /
$ growpart /dev/xvda 1
$ resize2fs /dev/xvda1
我有一个 amazonw ec2 实例,想将根设备从 100G 扩展到 500G。创建一个新的 500G 卷并重新附加到实例后。 我可以通过命令 $lsblk 看到音量在那里。但是,在我调整磁盘大小之后。我无法执行错误“文件系统已经有 26212055 个块长。无事可做!
name@ip-172-1-1-3:~$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 3.9G 8.0K 3.9G 1% /dev
tmpfs 799M 840K 798M 1% /run
/dev/xvda1 99G 92G 3.1G 97% /
name@ip-172-1-1-3:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE
MOUNTPOINT
xvda 202:0 0 500G 0 disk
└─xvda1 202:1 0 100G 0 part /
name@ip-172-1-1-3:~$sudo resize2fs /dev/xvda1
resize2fs 1.42.9 (4-Feb-2014)
The filesystem is already 26212055 blocks long. Nothing to do!
具体操作如下:
df -h
#打印启动分区的名称
lsblk
#显示所有块设备的信息
您将从该输出中看到您的根分区的磁盘名称。例如,您可能会看到类似这样的内容:
xvde 202:64 0 32G 0 disk
└─xvde1 202:65 0 8G 0 part /
我们的目标是让 xvde1
使用 xvde
中全部可用的 space。
以下是调整分区大小的方法:
fdisk /dev/xvda
(磁盘名称,不是你的分区)
这将进入 fdisk
实用程序。
u
#将显示改为扇区p
#打印信息d
#删除分区n
#新建分区p
#主分区1
#分区号2048
#第一扇区- 按 Enter 接受默认值
p
#打印信息a
#切换 bootable 标志1
#Select 分区 1w
#将table写入磁盘并退出
现在,重启您的实例:
reboot
返回后做:
resize2fs /dev/xvde1
(你分区的名字,不是块设备)
最后验证新的磁盘大小:
df -h
在我按照@error2007s 第 12 步 "a" a #Toggle the bootable flag 停止并重新启动之后。我无法调出实例。
Disk /dev/xvda: 536.9 GB, 536870912000 bytes
255 heads, 63 sectors/track, 65270 cylinders, total 1048576000 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: 0x00000000
Device Boot Start End Blocks Id System
/dev/xvda1 2048 1048575999 524286976 83 Linux
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.
name@ip-172-1-1-3:~$ reboot
reboot: Need to be root
name@ip-172-1-1-3:~$ sudo reboot
Broadcast message from name@ip-172-1-1-3
(/dev/pts/1) at 10:18 ...
The system is going down for reboot NOW!
$ ssh -i "a.pem" name@ec2-172.1.1.3.compute-1.amazonaws.com -p 22
ssh: connect to host ec2-172.1.1.3.compute-1.amazonaws.com port 22: Operation timed out
您需要扩展可用 space:
$ lsblk
xvda 202:0 0 500G 0 disk
└─xvda1 202:1 0 100G 0 part /
$ growpart /dev/xvda 1
$ resize2fs /dev/xvda1