通过xenstore探索亚马逊EC2

已知xen的各dom之间通过xenstore共享配置信息。
so,先装上xenstore-utils
加载xenfs,并挂载到/proc/xen路径下。

root@ip-172-31-26-60:~# modprobe xenfs
root@ip-172-31-26-60:~# mount -t xenfs none /proc/xen/

然后就可以读取dom配置信息了。
由于权限问题。这里只能读自己的。

root@ip-172-31-26-60:~# xenstore-read domid
1505
root@ip-172-31-26-60:~# xenstore-ls /local/domain/1505
vm = "/vm/ec22d790-58e6-6c14-51f6-44eacf17feef"
device = ""
 vbd = ""
  2049 = ""
   virtual-device = "2049"
   device-type = "disk"
   protocol = "x86_64-abi"
   backend-id = "0"
   state = "4"
   backend = "/local/domain/0/backend/vbd/1505/2049"
   ring-ref = "8"
   event-channel = "9"
  2064 = ""
   virtual-device = "2064"
   device-type = "disk"
   protocol = "x86_64-abi"
   backend-id = "0"
   state = "4"
   backend = "/local/domain/0/backend/vbd/1505/2064"
   ring-ref = "9"
   event-channel = "10"
  2080 = ""
   virtual-device = "2080"
   device-type = "disk"
   protocol = "x86_64-abi"
   backend-id = "0"
   state = "4"
   backend = "/local/domain/0/backend/vbd/1505/2080"
   ring-ref = "10"
   event-channel = "11"
  2051 = ""
   virtual-device = "2051"
   device-type = "disk"
   protocol = "x86_64-abi"
   backend-id = "0"
   state = "4"
   backend = "/local/domain/0/backend/vbd/1505/2051"
   ring-ref = "11"
   event-channel = "12"
 vif = ""
  0 = ""
   mac = "0a:a7:3f:42:b3:e9"
   handle = "0"
   protocol = "x86_64-abi"
   backend-id = "0"
   state = "4"
   backend = "/local/domain/0/backend/vif/1505/0"
   tx-ring-ref = "12"
   rx-ring-ref = "768"
   event-channel = "13"
   request-rx-copy = "1"
   feature-rx-notify = "1"
   feature-sg = "1"
   feature-gso-tcpv4 = "1"
 console = ""
  0 = ""
   protocol = "x86_64-abi"
   state = "1"
   backend-id = "0"
   backend = "/local/domain/0/backend/console/1505/0"
control = ""
 platform-feature-multiprocessor-suspend = "1"
error = ""
memory = ""
 target = "1740800"
guest = ""
hvmpv = ""
data = ""
device-misc = ""
 vif = ""
  nextDeviceID = "1"
 console = ""
  nextDeviceID = "1"
console = ""
 ring-ref = "4595562"
 port = "2"
 limit = "1048576"
 type = "xenconsoled"
 tty = "/dev/pts/27"
name = "dom_1813114895"
domid = "1505"
cpu = ""
 0 = ""
  availability = "online"
store = ""
 ring-ref = "4595563"
 port = "1"
serial = ""
 0 = ""
  tty = "/dev/pts/27"

这里可以看到磁盘、网卡等设备。
再看几个磁盘

root@ip-172-31-26-60:~# xenstore-ls /local/domain/0/backend/vbd/1505/2049
domain = "dom_1813114895"
frontend = "/local/domain/1505/device/vbd/2049"
uuid = "b3547591-292e-f124-6ecf-d579a3dcfbf7"
bootable = "1"
dev = "sda1"
state = "4"
params = "/dev/xgnbd925"
mode = "w"
removable = "1"
online = "1"
frontend-id = "1505"
type = "phy"
max-ring-pages = "1"
physical-device = "fc:39d"
hotplug-status = "connected"
sectors = "16777216"
info = "0"
sector-size = "512"
root@ip-172-31-26-60:~# xenstore-ls /local/domain/0/backend/vbd/1505/2064
domain = "dom_1813114895"
frontend = "/local/domain/1505/device/vbd/2064"
uuid = "aa44ee16-71dd-0fdf-3963-01d9d0235de6"
bootable = "0"
dev = "sdb"
state = "4"
params = "/dev/mapper/cow-VolGroupDomU-instance_ephemeral_store_24"
mode = "w"
removable = "1"
online = "1"
frontend-id = "1505"
type = "phy"
max-ring-pages = "1"
physical-device = "fd:9c"
hotplug-status = "connected"
sectors = "312705024"
info = "0"
sector-size = "512"
root@ip-172-31-26-60:~# xenstore-ls /local/domain/0/backend/vbd/1505/2080
domain = "dom_1813114895"
frontend = "/local/domain/1505/device/vbd/2080"
uuid = "8b297bf6-fa19-513a-dad3-4782bab750f5"
bootable = "0"
dev = "sdc"
state = "4"
params = "/dev/xgnbd317"
mode = "w"
removable = "1"
online = "1"
frontend-id = "1505"
type = "phy"
max-ring-pages = "1"
physical-device = "fc:13d"
hotplug-status = "connected"
sectors = "4194304"
info = "0"
sector-size = "512"
root@ip-172-31-26-60:~# xenstore-ls /local/domain/0/backend/vbd/1505/2051
domain = "dom_1813114895"
frontend = "/local/domain/1505/device/vbd/2051"
uuid = "6eb3cab4-b007-dba0-3e5a-6204361fec4f"
bootable = "0"
dev = "sda3"
state = "4"
params = "/dev/VolGroupDomU/instance_swap_store_24"
mode = "w"
removable = "1"
online = "1"
frontend-id = "1505"
type = "phy"
max-ring-pages = "1"
physical-device = "fd:64"
hotplug-status = "connected"
sectors = "1835008"
info = "0"
sector-size = "512"

可以看到ebs磁盘sda1(xvda1,root)、sda3(xvda3,swap)、sdc是由amazon修改的gnbd变种xgnbd实现。
而sdb(instance store 0:ephemeral0)则由lvm实现。

测试过程中竟然出现了dns nameserver没有配置好的情况,看来ec2也不像传说中那般神奇啊。

============ 2013.12.18 补充 =============
官方镜像都是基于ebs的。
而社区镜像里还有一种root(sda1)为Instance store的镜像。

root@ip-172-31-30-64:~# xenstore-ls /local/domain/0/backend/vbd/1581/2049
domain = "dom_1821728485"
frontend = "/local/domain/1581/device/vbd/2049"
uuid = "4c382ca3-d5b1-39f0-67c5-60758cac32f5"
bootable = "1"
dev = "sda1"
state = "4"
params = "/mnt/instance_image_store_12/1751320884"
mode = "w"
removable = "1"
online = "1"
frontend-id = "1581"
type = "file"
max-ring-pages = "1"
node = "/dev/loop16"
physical-device = "7:10"
hotplug-status = "connected"
sectors = "20971520"
info = "0"
sector-size = "512"

可见这种镜像是通过loop实现的虚拟块设备,既然是loop则社区镜像是raw格式。
这种Instance store的系统镜像只有9.9G,其他空间则通过sda2(xvda2)挂载到/mnt的形式提供,和swap一起都是lvm的后端实现,但是不知这块空的数据盘为毛是cow,也不知这个_netdev是哪来的,fstab里没有的啊。

ubuntu@ip-172-31-29-253:/mnt$ mount
/dev/xvda1 on / type ext4 (rw)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
none on /sys/fs/fuse/connections type fusectl (rw)
none on /sys/kernel/debug type debugfs (rw)
none on /sys/kernel/security type securityfs (rw)
udev on /dev type devtmpfs (rw,mode=0755)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)
none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880)
none on /run/shm type tmpfs (rw,nosuid,nodev)
/dev/xvda2 on /mnt type ext3 (rw,_netdev)
ubuntu@ip-172-31-29-253:/mnt$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1      9.9G  775M  8.6G   9% /
udev            819M   12K  819M   1% /dev
tmpfs           331M  168K  331M   1% /run
none            5.0M     0  5.0M   0% /run/lock
none            827M     0  827M   0% /run/shm
/dev/xvda2      147G  188M  140G   1% /mnt
ubuntu@ip-172-31-29-253:/mnt$ cat /etc/fstab
LABEL=cloudimg-rootfs   /        ext4   defaults        0 0
/dev/xvda2      /mnt    auto    defaults,nobootwait,comment=cloudconfig 0      2
/dev/xvda3      none    swap    sw,comment=cloudconfig  0       0
ubuntu@ip-172-31-29-253:/mnt$
发表评论?

0 条评论。

发表评论


请输入正确的验证码