Amazon EBS Enables Live Volume Modifications with Elastic Volumes


Elastic Volumes:
亚马逊EBS新特性:卷的属性的在线修改-包括卷的类型和大小
目前该功能只支持卷的扩展,不支持卷的缩小。
该功能针对的目标卷有两种:root系统卷和数据卷。

无论是root系统卷和数据卷,如果没有创建分区的话,通过特性扩展完EBS卷后,在线扩展文件系统即可。

根据官方文档解释如下:
如果使用了分区,在扩展了EBS卷后,需要unmount EBS卷,然后进行分区的扩展,最后进行文件系统的扩展。 这对于数据卷来说比较容易。
对于root系统卷,需要停机后,把数据卷attach到其他实例上去,进行EBS卷分区的扩展。
详细内容见:
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/storage_expand_partition.html

请在进行扩展之前做好EBS卷的备份(snapshot),防止数据丢失。

以下为在ubuntu14.04操作系统测试结果:
结论是我们可以在线通过Elastic Volumes进行EBS卷的扩展。
针对root卷和数据卷存在分区的情况,我们也可以在线进行分区的扩展。

root卷分区的在线扩展:
1.查看root卷的大小为30G
root@ip:/data01# fdisk   -l

Disk /dev/xvda: 32.2 GB, 32212254720 bytes
255 heads, 63 sectors/track, 3916 cylinders, total 62914560 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   *       16065    62910539    31447237+  83  Linux

2.通过过Elastic Volumes特性进行在线扩展后,root卷大大小变为45G
root@ip:/data01# fdisk   -l

Disk /dev/xvda: 48.3 GB, 48318382080 bytes
255 heads, 63 sectors/track, 5874 cylinders, total 94371840 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   *       16065    62910539    31447237+  83  Linux

此时用于root卷存在分区xvda1 ,所以我们需要扩展分区,然后才能扩张文件系统。

3.扩展root卷的分区:
  a.在扩展root分区的时候需要记住分区的起始扇区(此分区为:16065)
  b.通过fdisk进行分区的扩展:
  root@ip:~# fdisk /dev/xvda

Command (m for help): p

Disk /dev/xvda: 48.3 GB, 48318382080 bytes
255 heads, 63 sectors/track, 5874 cylinders, total 94371840 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   *       16065    62910539    31447237+  83  Linux

Command (m for help): d
Selected partition 1

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
   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): p

Disk /dev/xvda: 48.3 GB, 48318382080 bytes
255 heads, 63 sectors/track, 5874 cylinders, total 94371840 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

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): 16065
Invalid partition type `1'

Command (m for help): p

Disk /dev/xvda: 48.3 GB, 48318382080 bytes
255 heads, 63 sectors/track, 5874 cylinders, total 94371840 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

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
Using default value 1
First sector (2048-94371839, default 2048): 16065
Last sector, +sectors or +size{K,M,G} (16065-94371839, default 94371839):
Using default value 94371839

Command (m for help): p

Disk /dev/xvda: 48.3 GB, 48318382080 bytes
255 heads, 63 sectors/track, 5874 cylinders, total 94371840 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           16065    94371839    47177887+  83  Linux

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
   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): 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分区需要设置启动标志:
root@ip:~# fdisk /dev/xvda

Command (m for help): p

Disk /dev/xvda: 48.3 GB, 48318382080 bytes
96 heads, 45 sectors/track, 21845 cylinders, total 94371840 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           16065    94371839    47177887+  83  Linux

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
   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): a
Partition number (1-4): 1

Command (m for help): p

Disk /dev/xvda: 48.3 GB, 48318382080 bytes
96 heads, 45 sectors/track, 21845 cylinders, total 94371840 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   *       16065    94371839    47177887+  83  Linux

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.

4.root分区扩展后,
运行 partprobe -s  命令  refresh 分区表

5.最后我们可以扩展文件系统
root@ip:~# partprobe -s
/dev/mapper/vg01-data01: loop partitions 1
/dev/xvda: msdos partitions 1
/dev/xvdf: msdos partitions 1
root@ip:~# df -h
Filesystem               Size  Used Avail Use% Mounted on
udev                     7.9G   12K  7.9G   1% /dev
tmpfs                    1.6G  380K  1.6G   1% /run
/dev/xvda1                30G  2.2G   26G   8% /
none                     4.0K     0  4.0K   0% /sys/fs/cgroup
none                     5.0M     0  5.0M   0% /run/lock
none                     7.9G     0  7.9G   0% /run/shm
none                     100M     0  100M   0% /run/user
/dev/mapper/vg01-data01   97G   13K   93G   1% /data01
root@ip:~# resize2fs /dev/xvda1
resize2fs 1.42.9 (4-Feb-2014)
Filesystem at /dev/xvda1 is mounted on /; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 3
The filesystem on /dev/xvda1 is now 11794471 blocks long.

root@ip:~# df -h
Filesystem               Size  Used Avail Use% Mounted on
udev                     7.9G   12K  7.9G   1% /dev
tmpfs                    1.6G  380K  1.6G   1% /run
/dev/xvda1                45G  2.2G   41G   6% /
none                     4.0K     0  4.0K   0% /sys/fs/cgroup
none                     5.0M     0  5.0M   0% /run/lock
none                     7.9G     0  7.9G   0% /run/shm
none                     100M     0  100M   0% /run/user
/dev/mapper/vg01-data01   97G   13K   93G   1% /data01

root分区xvda1 由30G变为45G , 进过实例重启测试可正常启动,root卷和root分区在线扩展成功。



关于数据卷的扩展,由于使用了lvm,所以在数据卷和分区扩展(同上步骤)完成后;需要进行pv(pvresize)的扩展以及lv(lvextend -l +100%free )的扩展,最后扩展文件系统(resize2fs)即可。
数据卷的扩展也是在线扩展,不需要umount操作。




以上对于ubuntu 生效, 对于cenos:

操作如下, 需要重启


[root@ip-172-30-0 ~]# fdisk   -l  -u

Disk /dev/xvda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 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: 0x00057cbb

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *        2048    16777215     8387584   83  Linux
[root@ip-172-30-0- ~]# fdisk -u   /dev/xvda

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c').

Command (m for help): p

Disk /dev/xvda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 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: 0x00057cbb

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *        2048    16777215     8387584   83  Linux

Command (m for help): d
Selected partition 1

Command (m for help): p

Disk /dev/xvda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 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: 0x00057cbb

    Device Boot      Start         End      Blocks   Id  System

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

Command (m for help): p

Disk /dev/xvda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 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: 0x00057cbb

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1            2048    41943039    20970496   83  Linux

Command (m for help): a
Partition number (1-4): 1

Command (m for help): p

Disk /dev/xvda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 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: 0x00057cbb

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *        2048    41943039    20970496   83  Linux

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.


对于centos  partprobe(8) or kpartx(8) 都试过 不能在线fresh分区表, 需要重启才可以。

重启后 ,分区表也更新了, 文件系统也会自动扩展。


对于centos可以实现在线添加新的分区:

How to use a new partition in RHEL6 without reboot?

https://access.redhat.com/solutions/57542


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值