I need my EC2 instance to create EBS snapshots of its attached volumes. To ensure a consistent snapshot, I want to use fsfreeze; however, fsfreeze requires the mount point.

I can use AWS APIs to obtain the list of attached EBS volumes and their device names, but the device names are listed as /dev/sd[a-z][1-6] and Ubuntu (or Xen?) renames these to /dev/xvd[a-z][1-6]. The AWS documentation says "in most cases, the trailing letter remains the same." I know I can get the mount point from the device name with mount -l, but this obviously requires I have the correct device name (i.e. not /dev/sda1).

For a given set of EBS volume IDs (e.g. "vol-abc123"), how can I reliably determine their mount-point on the file system?

Edited to add a new thought: If the API gives me /dev/sda1 and neither that nor /dev/xvda1 exist, can I safely assume the first existing /dev/xvd[b-z]1 will be the same volume?

Background: I'm running Ubuntu 14.04 LTS Server; the Kernel log talks about loading Xen virtual drivers, so I assume that's what AWS is using for the HVM virtualisation. My current situation is trivial (one EBS volume, mounted at /), but I'd like the solution to work for more complex scenarios (multiple EBS volumes, including the presence of instance volumes—which won't need snapshots, but may be around while I'm taking snapshots).

  • 1
    Use filesystem labels. Then it doesn't matter what AWS calls 'em. – womble Oct 25 '15 at 3:48
  • @womble Ok, so how can I get a label (which is indeed being used to mount the volume) from the EBS volume ID (e.g. vol-abc123)? – Calrion Oct 25 '15 at 3:56
  • You label the filesystem the same as the EBS volume ID. – womble Oct 25 '15 at 3:59
  • @womble I'd rather leave the labels as they are, but that's a good fallback. Thanks. – Calrion Oct 25 '15 at 4:21

Since udev is doing all of that renaming at mount time, you can inspect the udev logs and see what the device is being renamed to. You may have to set the log level to info or debug first, as I think it defaults to err.

After setting the log level and rebooting, I see this when I attach a new EBS volume at /dev/sdf (according to AWS):

# cat /var/log/messages | grep udev | grep sdf
Oct 25 08:04:10 ip-10-128-240-37 udevd-work[571]: '/usr/sbin/ami-udev' (stdout) 'sdf'
Oct 25 08:04:10 ip-10-128-240-37 udevd-work[571]: LINK 'sdf' /etc/udev/rules.d/99-ami-udev.rules:1
Oct 25 08:04:10 ip-10-128-240-37 udevd-work[571]: creating link '/dev/sdf' to '/dev/xvdf'

Sure enough, the device is named /dev/xvdf and there is a symlink to it at /dev/sdf.

I'm testing on CentOS, so my udev logs are in /var/log/messages, but yours will probably be in /var/log/syslog.

I'm not sure how that output looks when the letter changes (a to e, etc). I've seen it happen, but I don't have an instance in front of me where that's the case.

You can also look in /etc/udev/rules.d and see what the renaming rules are for your AMI.

For your particular issue, I think the workflow would be to first call the AWS API to get a mapping of volume ID to AWS-specified device name, then inspect the udev logs to get the renamed device.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.