[英]Attach a EBS volume with boto
I was trying to add several EBS to an EC2 instance, I use something like that: 我试图将多个EBS添加到EC2实例中,我使用类似的方法:
block_map = BlockDeviceMapping()
xvdf = EBSBlockDeviceType()
xvdf.delete_on_termination = True
xvdf.size = opts.ebs_vol_size
block_map['/dev/xvdf'] = xvdf
req = conn.request_spot_instances(key_name=opts.key_pair,
price=opts.price,
image_id=ami,
security_groups=[instance_group],
instance_type=opts.instance_type,
block_device_map=block_map,
count=count
)
EBS are created as I could see them within the EC2 instance in the AWS console. 正如我在AWS控制台的EC2实例中看到的那样,创建了EBS。 Beside that, I'm 100% sure they are created as I can list them with the lsblk command once I log into the EC2 instance.
除此之外,我100%肯定会创建它们,因为一旦登录EC2实例,便可以使用lsblk命令列出它们。 I also added a couple of entries to my /etc/fstab so that the EBS volumes at mounted at creation time.
我还在/ etc / fstab中添加了几个条目,以便在创建时挂载EBS卷。
However, they are not mounted. 但是,它们未安装。 If I run the command
mount -a
the following error shows up: mount: wrong fs type, bad option, bad superblock on /dev/xvdf, missing codepage or helper program, or other error In some cases useful info is found in syslog - try dmesg | 如果我运行命令
mount -a
,则会显示以下错误:mount:错误的fs类型,错误的选项,/ dev / xvdf上的超级块错误,缺少代码页或帮助程序,或其他错误在某些情况下,可以在syslog中找到有用的信息-尝试dmesg | tail or so 尾巴左右
So, it seems EBS volumes are created but not formatted with EBSBlockDeviceType. 因此,似乎EBS卷已创建,但未使用EBSBlockDeviceType进行格式化。 After I formatted, I can run
mount -a
again and they are already mounted. 格式化之后,我可以再次运行
mount -a
,并且它们已经挂载。
My question is, if is possible to create and format a volume within the EBSBlockDeviceType() constructor, so that I can mount it. 我的问题是,是否可以在EBSBlockDeviceType()构造函数中创建和格式化卷,以便我可以挂载它。
Another option I think I might have is attach an already formatted EBS snapshot usign the snapshot_id field in the boto.ec2.blockdevicemapping.BlockDeviceType class. 我想我可能拥有的另一个选择是在boto.ec2.blockdevicemapping.BlockDeviceType类中的snapshot_id字段中附加一个已格式化的EBS快照。
Thank you! 谢谢!
mount
command fails for a newly allocated volume because there is no file system on it. 对于新分配的卷,
mount
命令失败,因为该卷上没有文件系统。 BlockDeviceType (or EBSBlockDeviceType) does not have an option to chose a file system for the underlying EBS volume. BlockDeviceType(或EBSBlockDeviceType)没有选择用于基础EBS卷的文件系统的选项。 Once the volume is allocated, user can create a file system of choice.
一旦分配了卷,用户就可以创建一个选择的文件系统。
However, for a volume created from a formatted EBS snapshot (created from a volume having file system), there is no need to create file system again. 但是,对于从格式化的EBS快照创建的卷(从具有文件系统的卷创建),则无需再次创建文件系统。 You can use
file -s <device name>
to find out if the device already has a file system. 您可以使用
file -s <device name>
来确定设备是否已经具有文件系统。
More details at: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-using-volumes.html 有关更多详细信息,请访问: http : //docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-using-volumes.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.