The image that needs to be uploaded to OpenStack needs to be an ext4 filesystem image. Here are the steps to create a ext4 filesystem image from the raw image i.e server.img

 
sudo losetup -f  server.img
 
sudo losetup -a

You should see an output like this:

 
/dev/loop0: [0801]:16908388 ($filepath)

Observe the name of the loop device ( /dev/loop0 in our setup) when $filepath is the path to the mounted .raw file.

Now we need to find out the starting sector of the partition. Run:

 
sudo fdisk -cul /dev/loop0

You should see an output like this:

 
Disk /dev/loop0: 5368 MB, 5368709120 bytes
 
149 heads, 8 sectors/track, 8796 cylinders, total 10485760 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: 0x00072bd4
Device              Boot  Start      End               Blocks        Id     System
/dev/loop0p1  *       2048     10483711    5240832   83    Linux

Make a note of the starting sector of the /dev/loop0p1 partition i.e the partition whose ID is 83. This number should be multiplied by 512 to obtain the correct value. In this case: 2048 x 512 = 1048576

Unmount the loop0 device:

 
sudo losetup -d /dev/loop0

Now mount only the partition(/dev/loop0p1) of server.img which we had previously noted down, by adding the -o parameter with value previously calculated value

 
sudo losetup -f -o 1048576 server.img
 
sudo losetup -a

You'll see a message like this:

 
/dev/loop0: [0801]:16908388 ($filepath) offset 1048576

Make a note of the mount point of our device(/dev/loop0 in our setup) when $filepath is the path to the mounted .raw file.

Copy the entire partition to a new .raw file

 
sudo dd if=/dev/loop0 of=serverfinal.img

Now we have our ext4 filesystem image i.e serverfinal.img

Unmount the loop0 device

 
sudo losetup -d /dev/loop0

loading table of contents...