Previously I posted how to download amazon ec2 ami to local drive. And to use it, I posted there that we can copy it (actually “dd”) to a virtual disk in vmware in order to make use of it. That takes a lot of time (15 hours for a 10 GB disk image). Fortunately, if we don’t need to boot it, and only want to retrieve the content in the disk image, we don’t need to do that. The simplest way is to directly mount it in Linux.
To mount a disk image, we use
mount -o loop,ro,offset=XX image.img /path/to/the/mount/directory
(I didn’t use -t here because the ami is in ext4 and can be recognized directly on my ubuntu)
To determine the offset, we can use “parted” tool. So we type:
$parted image.img
GNU Parted 2.3
Using /home/zation/amazonec2/vm1/image
Welcome to GNU Parted! Type ‘help’ to view a list of commands.
(parted) unit
Unit? [compact]? B
(parted) print
Model: (file)
Disk /home/zation/amazonec2/vm1/image: 10737418240B
Sector size (logical/physical): 512B/512B
Partition Table: loop
Number Start End Size File system Flags
1 0B 10737418239B 10737418240B ext4
(parted) quit
We see that there is only one partition, starting from 0B. So we put the offset=0
If there are multiple partitions, we can mount each partition separately by inputting the start value to the offset.