allomov
5/25/2015 - 2:25 PM

Reproduce an error with disk creating and mounting

Reproduce an error with disk creating and mounting


export work=/mnt/stemcells/openstack/kvm/ubuntu/work/work/
export stemcell_image_name=test01.raw  # RANDOM NAME HERE
export disk_image=${work}/${stemcell_image_name}
export image_create_disk_size=1225

# ppc64le guest images have a PReP partition 
# this and other code changes for ppc64le with input from Paulo Flabiano Smorigo @ IBM
part_offset=2048s
part_size=9MiB

dd if=/dev/null of=${disk_image} bs=1M seek=${image_create_disk_size} 2> /dev/null
parted --script ${disk_image} mklabel msdos

parted --script ${disk_image} mkpart primary $part_offset $part_size
parted --script ${disk_image} set 1 boot on
parted --script ${disk_image} set 1 prep on
parted --script ${disk_image} mkpart primary ext4 $part_size 100%

# unmap the loop device in case it's already mapped
kpartx -dv ${disk_image}

# Map partition in image to loopback
device=$(losetup --show --find ${disk_image})
add_on_exit "losetup --verbose --detach ${device}"

device_partition=$(kpartx -av ${device} | grep "^add" | grep "p2 " | grep -v "p1" | cut -d" " -f3)

# add_on_exit "kpartx -dv ${device}"

loopback_dev="/dev/mapper/${device_partition}"

# Format partition
mkfs.ext4 ${loopback_dev}

# Mount partition
image_mount_point=${work}/mnt
mkdir -p ${image_mount_point}
mount ${loopback_dev} ${image_mount_point}

# add_on_exit "umount ${image_mount_point}"