mirror of
https://git.launchpad.net/livecd-rootfs
synced 2025-07-03 21:11:30 +00:00
ubuntu-cpc: move vmdk creation code into common funtion to support Vagrant Box builds
This commit is contained in:
parent
dc9da068dc
commit
e931fbeaa5
@ -59,3 +59,66 @@ umount_partition() {
|
|||||||
umount "$mountpoint/dev"
|
umount "$mountpoint/dev"
|
||||||
umount "$mountpoint"
|
umount "$mountpoint"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
modify_vmdk_header() {
|
||||||
|
# Modify the VMDK headers so that both VirtualBox _and_ VMware can
|
||||||
|
# read the vmdk and import them. The vodoo here is _not_ documented
|
||||||
|
# anywhere....so this will have to do.
|
||||||
|
|
||||||
|
vmdk_name="${1}"
|
||||||
|
descriptor=$(mktemp)
|
||||||
|
newdescriptor=$(mktemp)
|
||||||
|
|
||||||
|
# Extract the vmdk header for manipulation
|
||||||
|
dd if="${vmdk_name}" of="${descriptor}" bs=1 skip=512 count=1024
|
||||||
|
|
||||||
|
# The sed lines below is where the magic is. Specifically:
|
||||||
|
# ddb.toolsVersion: sets the open-vm-tools so that VMware shows
|
||||||
|
# the tooling as current
|
||||||
|
# ddb.virtualHWVersion: set the version to 7, which covers most
|
||||||
|
# current versions of VMware
|
||||||
|
# createType: make sure its set to stream Optimized
|
||||||
|
# remove the vmdk-stream-converter comment and replace with
|
||||||
|
# # Disk DescriptorFile. This is needed for Virtualbox
|
||||||
|
# remove the comments from vmdk-stream-converter which causes
|
||||||
|
# VirtualBox and others to fail VMDK validation
|
||||||
|
|
||||||
|
sed -e 's|ddb.comment.*|ddb.toolsVersion = "2147483647"|' \
|
||||||
|
-e 's|ddb.virtualHWVersion.*|ddb.virtualHWVersion = "7"|' \
|
||||||
|
-e 's|createType.*|createType="streamOptimized"|' \
|
||||||
|
-e 's|# Description file.*|# Disk DescriptorFile|' \
|
||||||
|
-e '/# Believe.*/d' \
|
||||||
|
-e '/# Indicates no parent/d' \
|
||||||
|
"${descriptor}" > "${new_descriptor}"
|
||||||
|
|
||||||
|
# The header is cannot be bigger than 1024
|
||||||
|
expr $(stat --format=%s ${new_descriptor}) \< 1024 || {
|
||||||
|
echo "descriptor is too large, VMDK will be invalid!"; exit 1; }
|
||||||
|
|
||||||
|
# Overwrite the vmdk header with our new, modified one
|
||||||
|
dd conv=notrunc,nocreat \
|
||||||
|
if="${new_descriptor}" of="${vmdk_name}" \
|
||||||
|
bs=1 seek=512 count=1024
|
||||||
|
|
||||||
|
rm ${descriptor} ${new_descriptor}
|
||||||
|
}
|
||||||
|
|
||||||
|
create_vmdk() {
|
||||||
|
src="$1"
|
||||||
|
destination="$2"
|
||||||
|
size="${3:-102400}"
|
||||||
|
|
||||||
|
apt-get install -qqy qemu-utils vmdk-stream-converter
|
||||||
|
streamconverter="/usr/share/pyshared/VMDKstream.py"
|
||||||
|
scratch_d=$(mktemp -d)
|
||||||
|
|
||||||
|
cp ${src} ${scratch_d}/resize.img
|
||||||
|
qemu-img resize ${scratch_d}/resize.img ${size}M
|
||||||
|
python ${streamconverter} ${scratch_d}/resize.img "${destination}"
|
||||||
|
modify_vmdk_header "${destination}"
|
||||||
|
qemu-img info "${destination}"
|
||||||
|
|
||||||
|
rm -rf ${scratch_d}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,66 +18,10 @@ case ${architecture} in
|
|||||||
exit 0;;
|
exit 0;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
apt-get install -qqy qemu-utils vmdk-stream-converter
|
. /build/config/functions
|
||||||
|
|
||||||
streamconverter="/usr/share/pyshared/VMDKstream.py"
|
create_vmdk binary/boot/disk.ext4 livecd.ubuntu-cpc.disk1.vmdk
|
||||||
|
|
||||||
# Lets be safe about this
|
|
||||||
scratch_d=$(mktemp -d)
|
|
||||||
trap "rm -rf ${scratch_d}" EXIT
|
|
||||||
|
|
||||||
modify_vmdk_header() {
|
|
||||||
# Modify the VMDK headers so that both VirtualBox _and_ VMware can
|
|
||||||
# read the vmdk and import them. The vodoo here is _not_ documented
|
|
||||||
# anywhere....so this will have to do.
|
|
||||||
|
|
||||||
vmdk_name="${1}"
|
|
||||||
|
|
||||||
# Extract the vmdk header for manipulation
|
|
||||||
dd if="${vmdk_name}" of=descriptor.txt bs=1 skip=512 count=1024
|
|
||||||
|
|
||||||
# The sed lines below is where the magic is. Specifically:
|
|
||||||
# ddb.toolsVersion: sets the open-vm-tools so that VMware shows
|
|
||||||
# the tooling as current
|
|
||||||
# ddb.virtualHWVersion: set the version to 7, which covers most
|
|
||||||
# current versions of VMware
|
|
||||||
# createType: make sure its set to stream Optimized
|
|
||||||
# remove the vmdk-stream-converter comment and replace with
|
|
||||||
# # Disk DescriptorFile. This is needed for Virtualbox
|
|
||||||
# remove the comments from vmdk-stream-converter which causes
|
|
||||||
# VirtualBox and others to fail VMDK validation
|
|
||||||
|
|
||||||
sed -e 's|ddb.comment.*|ddb.toolsVersion = "2147483647"|' \
|
|
||||||
-e 's|ddb.virtualHWVersion.*|ddb.virtualHWVersion = "7"|' \
|
|
||||||
-e 's|createType.*|createType="streamOptimized"|' \
|
|
||||||
-e 's|# Description file.*|# Disk DescriptorFile|' \
|
|
||||||
-e '/# Believe.*/d' \
|
|
||||||
-e '/# Indicates no parent/d' \
|
|
||||||
descriptor.txt > new_descriptor.txt
|
|
||||||
|
|
||||||
# The header is cannot be bigger than 1024
|
|
||||||
expr $(stat --format=%s new_descriptor.txt) \< 1024 || {
|
|
||||||
echo "descriptor is too large, VMDK will be invalid!"; exit 1; }
|
|
||||||
|
|
||||||
# Overwrite the vmdk header with our new, modified one
|
|
||||||
dd conv=notrunc,nocreat \
|
|
||||||
if=new_descriptor.txt of="${vmdk_name}" \
|
|
||||||
bs=1 seek=512 count=1024
|
|
||||||
}
|
|
||||||
|
|
||||||
convert_image() {
|
|
||||||
src="$1"
|
|
||||||
destination="$2"
|
|
||||||
|
|
||||||
cp ${src} ${scratch_d}/resize.img
|
|
||||||
qemu-img resize ${scratch_d}/resize.img 10G
|
|
||||||
python ${streamconverter} ${scratch_d}/resize.img "${destination}"
|
|
||||||
modify_vmdk_header "${destination}"
|
|
||||||
qemu-img info "${destination}"
|
|
||||||
}
|
|
||||||
|
|
||||||
convert_image binary/boot/disk.ext4 livecd.ubuntu-cpc.disk1.vmdk
|
|
||||||
|
|
||||||
if [ -e binary/boot/disk-uefi.ext4 ]; then
|
if [ -e binary/boot/disk-uefi.ext4 ]; then
|
||||||
convert_image binary/boot/disk-uefi.ext4 livecd.ubuntu-cpc.uefi.vmdk
|
create_vmdk binary/boot/disk-uefi.ext4 livecd.ubuntu-cpc.uefi.vmdk
|
||||||
fi
|
fi
|
||||||
|
@ -28,6 +28,8 @@ if [ ! -e ${base_vmdk} ]; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
. /build/config/functions
|
||||||
|
|
||||||
# Virtualbox is needed for making a small VMDK
|
# Virtualbox is needed for making a small VMDK
|
||||||
apt-get -qqy install genisoimage qemu-utils
|
apt-get -qqy install genisoimage qemu-utils
|
||||||
|
|
||||||
@ -83,12 +85,13 @@ genisoimage \
|
|||||||
-output ${seed_d}/seed.iso \
|
-output ${seed_d}/seed.iso \
|
||||||
-volid cidata \
|
-volid cidata \
|
||||||
-joliet -rock \
|
-joliet -rock \
|
||||||
|
-input-charset utf-8 \
|
||||||
${seed_d}/user-data \
|
${seed_d}/user-data \
|
||||||
${seed_d}/meta-data \
|
${seed_d}/meta-data \
|
||||||
${seed_d}/bloat_file
|
${seed_d}/bloat_file
|
||||||
|
|
||||||
# Make a VMDK out of the seed file.
|
# Make a VMDK out of the seed file.
|
||||||
qemu-img convert -O vmdk ${seed_d}/seed.iso ${cdrom_vmdk_f}
|
create_vmdk ${seed_d}/seed.iso ${cdrom_vmdk_f}
|
||||||
|
|
||||||
### END Create ConfigDrive
|
### END Create ConfigDrive
|
||||||
##########################
|
##########################
|
||||||
|
Loading…
x
Reference in New Issue
Block a user