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

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}"


# Format partition
mkfs.ext4 ${loopback_dev}

# Mount partition
mkdir -p ${image_mount_point}
mount ${loopback_dev} ${image_mount_point}

# add_on_exit "umount ${image_mount_point}"