mirror of
https://git.launchpad.net/livecd-rootfs
synced 2025-06-01 21:21:42 +00:00
Merge lp:~rcj/livecd-rootfs/xenial-proposed
This commit is contained in:
commit
b925874fe0
8
debian/changelog
vendored
8
debian/changelog
vendored
@ -1,3 +1,11 @@
|
|||||||
|
livecd-rootfs (2.408.32) xenial; urgency=medium
|
||||||
|
|
||||||
|
* snaps: Fixes for snap pre-seeding (LP: #1775710)
|
||||||
|
* Backport: Refactor functions out of ubuntu-cpc and ubuntu-server hooks.
|
||||||
|
* Add dependency on distro-info for snap preseeding
|
||||||
|
|
||||||
|
-- Robert C Jennings <robert.jennings@canonical.com> Thu, 07 Jun 2018 14:12:26 -0700
|
||||||
|
|
||||||
livecd-rootfs (2.408.31) xenial; urgency=medium
|
livecd-rootfs (2.408.31) xenial; urgency=medium
|
||||||
|
|
||||||
* Backport snap preseeding functions from bionic. (LP: #1771177)
|
* Backport snap preseeding functions from bionic. (LP: #1771177)
|
||||||
|
1
debian/control
vendored
1
debian/control
vendored
@ -12,6 +12,7 @@ Depends: ${misc:Depends},
|
|||||||
android-tools-fsutils [armhf],
|
android-tools-fsutils [armhf],
|
||||||
apt-utils,
|
apt-utils,
|
||||||
debootstrap,
|
debootstrap,
|
||||||
|
distro-info,
|
||||||
dosfstools,
|
dosfstools,
|
||||||
e2fsprogs,
|
e2fsprogs,
|
||||||
gdisk,
|
gdisk,
|
||||||
|
@ -33,9 +33,11 @@ if [ -z "$MIRROR" ]; then
|
|||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mkdir -p config/package-lists
|
mkdir -p config
|
||||||
cp -af /usr/share/livecd-rootfs/live-build/functions config/functions
|
cp -af /usr/share/livecd-rootfs/live-build/functions config/functions
|
||||||
|
|
||||||
|
mkdir -p config/package-lists
|
||||||
|
|
||||||
add_task ()
|
add_task ()
|
||||||
{
|
{
|
||||||
local pass="$1"
|
local pass="$1"
|
||||||
|
@ -2,6 +2,323 @@
|
|||||||
|
|
||||||
#imagesize=${IMAGE_SIZE:-$((2252*1024**2))} # 2.2G (the current size we ship)
|
#imagesize=${IMAGE_SIZE:-$((2252*1024**2))} # 2.2G (the current size we ship)
|
||||||
imagesize=${IMAGE_SIZE:-2361393152} # 2.2G (the current size we ship)
|
imagesize=${IMAGE_SIZE:-2361393152} # 2.2G (the current size we ship)
|
||||||
|
fs_label="${FS_LABEL:-rootfs}"
|
||||||
|
|
||||||
|
rootfs_dev_mapper=
|
||||||
|
loop_device=
|
||||||
|
loop_raw=
|
||||||
|
backing_img=
|
||||||
|
|
||||||
|
clean_loops() {
|
||||||
|
local kpartx_ret
|
||||||
|
local kpartx_stdout
|
||||||
|
|
||||||
|
if [ -n "${backing_img}" ]; then
|
||||||
|
# sync before removing loop to avoid "Device or resource busy" errors
|
||||||
|
sync
|
||||||
|
kpartx_ret=""
|
||||||
|
kpartx_stdout=$(kpartx -v -d "${backing_img}") || kpartx_ret=$?
|
||||||
|
echo "$kpartx_stdout"
|
||||||
|
if [ -n "$kpartx_ret" ]; then
|
||||||
|
if echo "$kpartx_stdout" | grep -q "loop deleted"; then
|
||||||
|
echo "Suppressing kpartx returning error (#860894)"
|
||||||
|
else
|
||||||
|
exit $kpartx_ret
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
unset backing_img
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "${rootfs_dev_mapper}" ]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
unset loop_device
|
||||||
|
unset loop_raw
|
||||||
|
unset rootfs_dev_mapper
|
||||||
|
}
|
||||||
|
|
||||||
|
create_empty_disk_image() {
|
||||||
|
# Prepare an empty disk image
|
||||||
|
dd if=/dev/zero of="$1" bs=1 count=0 seek="${imagesize}"
|
||||||
|
}
|
||||||
|
|
||||||
|
make_ext4_partition() {
|
||||||
|
device="$1"
|
||||||
|
label=${fs_label:+-L "${fs_label}"}
|
||||||
|
mkfs.ext4 -F -b 4096 -i 8192 -m 0 ${label} -E resize=536870912 "$device"
|
||||||
|
}
|
||||||
|
|
||||||
|
mount_image() {
|
||||||
|
trap clean_loops EXIT
|
||||||
|
backing_img="$1"
|
||||||
|
local rootpart="$2"
|
||||||
|
kpartx_mapping="$(kpartx -s -v -a ${backing_img})"
|
||||||
|
|
||||||
|
# Find the loop device
|
||||||
|
loop_p1="$(echo -e ${kpartx_mapping} | head -n1 | awk '{print$3}')"
|
||||||
|
loop_device="/dev/${loop_p1%p[0-9]*}"
|
||||||
|
if [ ! -b ${loop_device} ]; then
|
||||||
|
echo "unable to find loop device for ${backing_img}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Find the rootfs location
|
||||||
|
rootfs_dev_mapper="/dev/mapper/${loop_p1%%[0-9]}${rootpart}"
|
||||||
|
if [ ! -b "${rootfs_dev_mapper}" ]; then
|
||||||
|
echo "${rootfs_dev_mapper} is not a block device";
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Add some information to the debug logs
|
||||||
|
echo "Mounted disk image ${backing_img} to ${rootfs_dev_mapper}"
|
||||||
|
blkid ${rootfs_dev_mapper}
|
||||||
|
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
setup_mountpoint() {
|
||||||
|
local mountpoint="$1"
|
||||||
|
|
||||||
|
mount --rbind --make-rslave /dev "$mountpoint/dev"
|
||||||
|
mount proc-live -t proc "$mountpoint/proc"
|
||||||
|
mount sysfs-live -t sysfs "$mountpoint/sys"
|
||||||
|
mount -t tmpfs none "$mountpoint/tmp"
|
||||||
|
mount -t tmpfs none "$mountpoint/var/lib/apt"
|
||||||
|
mount -t tmpfs none "$mountpoint/var/cache/apt"
|
||||||
|
mv "$mountpoint/etc/resolv.conf" resolv.conf.tmp
|
||||||
|
cp /etc/resolv.conf "$mountpoint/etc/resolv.conf"
|
||||||
|
chroot "$mountpoint" apt-get update
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
teardown_mountpoint() {
|
||||||
|
# Reverse the operations from setup_mountpoint
|
||||||
|
local mountpoint="$1"
|
||||||
|
|
||||||
|
# ensure we have exactly one trailing slash, and escape all slashes for awk
|
||||||
|
mountpoint_match=$(echo "$mountpoint" | sed -e's,/$,,; s,/,\\/,g;')'\/'
|
||||||
|
# sort -r ensures that deeper mountpoints are unmounted first
|
||||||
|
for submount in $(awk </proc/self/mounts "\$2 ~ /$mountpoint_match/ \
|
||||||
|
{ print \$2 }" | LC_ALL=C sort -r); do
|
||||||
|
umount $submount
|
||||||
|
done
|
||||||
|
mv resolv.conf.tmp "$mountpoint/etc/resolv.conf"
|
||||||
|
}
|
||||||
|
|
||||||
|
mount_partition() {
|
||||||
|
partition="$1"
|
||||||
|
mountpoint="$2"
|
||||||
|
|
||||||
|
mount "$partition" "$mountpoint"
|
||||||
|
setup_mountpoint "$mountpoint"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
mount_disk_image() {
|
||||||
|
local disk_image=${1}
|
||||||
|
local mountpoint=${2}
|
||||||
|
mount_image ${disk_image} 1
|
||||||
|
mount_partition "${rootfs_dev_mapper}" $mountpoint
|
||||||
|
|
||||||
|
local uefi_dev="/dev/mapper${loop_device///dev/}p15"
|
||||||
|
if [ -b ${uefi_dev} -a -e $mountpoint/boot/efi ]; then
|
||||||
|
mount "${uefi_dev}" $mountpoint/boot/efi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# This is needed to allow for certain operations
|
||||||
|
# such as updating grub and installing software
|
||||||
|
cat > $mountpoint/usr/sbin/policy-rc.d << EOF
|
||||||
|
#!/bin/sh
|
||||||
|
# ${IMAGE_STR}
|
||||||
|
echo "All runlevel operations denied by policy" >&2
|
||||||
|
exit 101
|
||||||
|
EOF
|
||||||
|
chmod 0755 $mountpoint/usr/sbin/policy-rc.d
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
umount_partition() {
|
||||||
|
local mountpoint=${1}
|
||||||
|
teardown_mountpoint $mountpoint
|
||||||
|
umount -R $mountpoint
|
||||||
|
udevadm settle
|
||||||
|
|
||||||
|
if [ -n "${rootfs_dev_mapper}" -a -b "${rootfs_dev_mapper}" ]; then
|
||||||
|
# buildd's don't have /etc/mtab symlinked
|
||||||
|
# /etc/mtab is needed in order zerofree space for ext4 filesystems
|
||||||
|
[ -e /etc/mtab ] || ln -s /proc/mounts /etc/mtab
|
||||||
|
|
||||||
|
# both of these are likely overkill, but it does result in slightly
|
||||||
|
# smaller ext4 filesystem
|
||||||
|
e2fsck -y -E discard ${rootfs_dev_mapper}
|
||||||
|
zerofree ${rootfs_dev_mapper}
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
umount_disk_image() {
|
||||||
|
mountpoint="$1"
|
||||||
|
|
||||||
|
local uefi_dev="/dev/mapper${loop_device///dev/}p15"
|
||||||
|
if [ -e "$mountpoint/boot/efi" -a -b "$uefi_dev" ]; then
|
||||||
|
umount --detach-loop "$mountpoint/boot/efi"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -e $mountpoint/usr/sbin/policy-rc.d ]; then
|
||||||
|
rm $mountpoint/usr/sbin/policy-rc.d
|
||||||
|
fi
|
||||||
|
umount_partition $mountpoint
|
||||||
|
clean_loops
|
||||||
|
}
|
||||||
|
|
||||||
|
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. This is undocumented vodoo
|
||||||
|
# that has been learned by the Cloud Image team.
|
||||||
|
|
||||||
|
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|# Description file.*|# Disk DescriptorFile|' \
|
||||||
|
-e '/# Believe this is random*/d' \
|
||||||
|
-e '/# Indicates no parent/d' \
|
||||||
|
-e '/# The Disk Data Base/d' \
|
||||||
|
-e 's|ddb.comment.*|ddb.toolsVersion = "2147483647"|' \
|
||||||
|
"${descriptor}" > "${newdescriptor}"
|
||||||
|
|
||||||
|
# The header is cannot be bigger than 1024
|
||||||
|
expr $(stat --format=%s ${newdescriptor}) \< 1024 > /dev/null 2>&1 || {
|
||||||
|
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="${newdescriptor}" of="${vmdk_name}" \
|
||||||
|
bs=1 seek=512 count=1024
|
||||||
|
|
||||||
|
rm ${descriptor} ${newdescriptor}
|
||||||
|
}
|
||||||
|
|
||||||
|
create_vmdk() {
|
||||||
|
# There is no real good way to create a _compressed_ VMDK using open source
|
||||||
|
# tooling that works across multiple VMDK-capable platforms. This functions
|
||||||
|
# uses vmdk-stream-converter and then calls modify_vmdk_header to produce a
|
||||||
|
# compatible VMDK.
|
||||||
|
|
||||||
|
src="$1"
|
||||||
|
destination="$2"
|
||||||
|
size="${3:-10240}"
|
||||||
|
|
||||||
|
streamconverter="/usr/share/pyshared/VMDKstream.py"
|
||||||
|
scratch_d=$(mktemp -d)
|
||||||
|
cp ${src} ${scratch_d}/resize.img
|
||||||
|
|
||||||
|
truncate --size=${size}M ${scratch_d}/resize.img
|
||||||
|
python ${streamconverter} ${scratch_d}/resize.img ${destination}
|
||||||
|
modify_vmdk_header ${destination}
|
||||||
|
|
||||||
|
qemu-img info ${destination}
|
||||||
|
rm -rf ${scratch_d}
|
||||||
|
}
|
||||||
|
|
||||||
|
create_derivative() {
|
||||||
|
# arg1 is the disk type
|
||||||
|
# arg2 is the new name
|
||||||
|
unset derivative_img
|
||||||
|
case ${1} in
|
||||||
|
uefi) disk_image="binary/boot/disk-uefi.ext4";
|
||||||
|
dname="${disk_image//-uefi/-$2-uefi}";;
|
||||||
|
*) disk_image="binary/boot/disk.ext4";
|
||||||
|
dname="${disk_image//.ext4/-$2.ext4}";;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ ! -e ${disk_image} ]; then
|
||||||
|
echo "Did not find ${disk_image}!"; exit 1;
|
||||||
|
fi
|
||||||
|
|
||||||
|
cp ${disk_image} ${dname}
|
||||||
|
export derivative_img=${dname}
|
||||||
|
}
|
||||||
|
|
||||||
|
convert_to_qcow2() {
|
||||||
|
|
||||||
|
src="$1"
|
||||||
|
destination="$2"
|
||||||
|
qemu-img convert -c -O qcow2 -o compat=0.10 "$src" "$destination"
|
||||||
|
qemu-img info "$destination"
|
||||||
|
}
|
||||||
|
|
||||||
|
replace_grub_root_with_label() {
|
||||||
|
# When update-grub is run, it will detect the disks in the build system.
|
||||||
|
# Instead, we want grub to use the right labelled disk
|
||||||
|
CHROOT_ROOT="$1"
|
||||||
|
|
||||||
|
# If boot by partuuid has been requested, don't override.
|
||||||
|
if [ -f $CHROOT_ROOT/etc/default/grub.d/40-force-partuuid.cfg ] && \
|
||||||
|
grep -q ^GRUB_FORCE_PARTUUID= $CHROOT_ROOT/etc/default/grub.d/40-force-partuuid.cfg
|
||||||
|
then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
sed -i -e "s,root=[^ ]*,root=LABEL=${fs_label}," \
|
||||||
|
"$CHROOT_ROOT/boot/grub/grub.cfg"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# When running update-grub in a chroot on a build host, we don't want it to
|
||||||
|
# probe for disks or probe for other installed OSes. Extract common
|
||||||
|
# diversion wrappers, so this isn't reinvented differently for each image.
|
||||||
|
divert_grub() {
|
||||||
|
CHROOT_ROOT="$1"
|
||||||
|
|
||||||
|
chroot "$CHROOT_ROOT" dpkg-divert --local \
|
||||||
|
--rename /usr/sbin/grub-probe
|
||||||
|
chroot "$CHROOT_ROOT" touch /usr/sbin/grub-probe
|
||||||
|
chroot "$CHROOT_ROOT" chmod +x /usr/sbin/grub-probe
|
||||||
|
|
||||||
|
chroot "$CHROOT_ROOT" dpkg-divert --local \
|
||||||
|
--divert /etc/grub.d/30_os-prober.dpkg-divert \
|
||||||
|
--rename /etc/grub.d/30_os-prober
|
||||||
|
|
||||||
|
# Divert systemd-detect-virt; /etc/kernel/postinst.d/zz-update-grub
|
||||||
|
# no-ops if we are in a container, and the launchpad farm runs builds
|
||||||
|
# in lxd. We therefore pretend that we're never in a container (by
|
||||||
|
# exiting 1).
|
||||||
|
chroot "$CHROOT_ROOT" dpkg-divert --local \
|
||||||
|
--rename /usr/bin/systemd-detect-virt
|
||||||
|
echo "exit 1" > "$CHROOT_ROOT"/usr/bin/systemd-detect-virt
|
||||||
|
chmod +x "$CHROOT_ROOT"/usr/bin/systemd-detect-virt
|
||||||
|
}
|
||||||
|
|
||||||
|
undivert_grub() {
|
||||||
|
CHROOT_ROOT="$1"
|
||||||
|
|
||||||
|
chroot "$CHROOT_ROOT" rm /usr/sbin/grub-probe
|
||||||
|
chroot "$CHROOT_ROOT" dpkg-divert --remove --local \
|
||||||
|
--rename /usr/sbin/grub-probe
|
||||||
|
|
||||||
|
chroot "$CHROOT_ROOT" dpkg-divert --remove --local \
|
||||||
|
--divert /etc/grub.d/30_os-prober.dpkg-divert \
|
||||||
|
--rename /etc/grub.d/30_os-prober
|
||||||
|
|
||||||
|
rm "$CHROOT_ROOT"/usr/bin/systemd-detect-virt
|
||||||
|
chroot "$CHROOT_ROOT" dpkg-divert --remove --local \
|
||||||
|
--rename /usr/bin/systemd-detect-virt
|
||||||
|
}
|
||||||
|
|
||||||
release_ver() {
|
release_ver() {
|
||||||
# Return the release version number
|
# Return the release version number
|
||||||
|
@ -1,320 +0,0 @@
|
|||||||
# vi: ts=4 expandtab syntax=sh
|
|
||||||
|
|
||||||
CLOUD_IMG_STR="# CLOUD_IMG: This file was created/modified by the Cloud Image build process"
|
|
||||||
IMAGE_SIZE=$((2252*1024**2)) # 2.2G (the current size we ship)
|
|
||||||
|
|
||||||
rootfs_dev_mapper=
|
|
||||||
loop_device=
|
|
||||||
loop_raw=
|
|
||||||
backing_img=
|
|
||||||
|
|
||||||
clean_loops() {
|
|
||||||
local kpartx_ret
|
|
||||||
local kpartx_stdout
|
|
||||||
|
|
||||||
if [ -n "${backing_img}" ]; then
|
|
||||||
# sync before removing loop to avoid "Device or resource busy" errors
|
|
||||||
sync
|
|
||||||
kpartx_ret=""
|
|
||||||
kpartx_stdout=$(kpartx -v -d "${backing_img}") || kpartx_ret=$?
|
|
||||||
echo "$kpartx_stdout"
|
|
||||||
if [ -n "$kpartx_ret" ]; then
|
|
||||||
if echo "$kpartx_stdout" | grep -q "loop deleted"; then
|
|
||||||
echo "Suppressing kpartx returning error (#860894)"
|
|
||||||
else
|
|
||||||
exit $kpartx_ret
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
unset backing_img
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "${rootfs_dev_mapper}" ]; then
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
unset loop_device
|
|
||||||
unset loop_raw
|
|
||||||
unset rootfs_dev_mapper
|
|
||||||
}
|
|
||||||
|
|
||||||
create_empty_disk_image() {
|
|
||||||
# Prepare an empty disk image
|
|
||||||
dd if=/dev/zero of="$1" bs=1 count=0 seek="${IMAGE_SIZE}"
|
|
||||||
}
|
|
||||||
|
|
||||||
make_ext4_partition() {
|
|
||||||
device="$1"
|
|
||||||
|
|
||||||
mkfs.ext4 -F -b 4096 -i 8192 -m 0 -L cloudimg-rootfs -E resize=536870912 "$device"
|
|
||||||
}
|
|
||||||
|
|
||||||
mount_image() {
|
|
||||||
trap clean_loops EXIT
|
|
||||||
backing_img="$1"
|
|
||||||
local rootpart="$2"
|
|
||||||
kpartx_mapping="$(kpartx -s -v -a ${backing_img})"
|
|
||||||
|
|
||||||
# Find the loop device
|
|
||||||
loop_p1="$(echo -e ${kpartx_mapping} | head -n1 | awk '{print$3}')"
|
|
||||||
loop_device="/dev/loop$(echo ${loop_p1} | cut -b5)"
|
|
||||||
if [ ! -b ${loop_device} ]; then
|
|
||||||
echo "unable to find loop device for ${backing_img}"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Find the rootfs location
|
|
||||||
rootfs_dev_mapper="/dev/mapper/${loop_p1%%[0-9]}${rootpart}"
|
|
||||||
if [ ! -b "${rootfs_dev_mapper}" ]; then
|
|
||||||
echo "${rootfs_dev_mapper} is not a block device";
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Add some information to the debug logs
|
|
||||||
echo "Mounted disk image ${backing_img} to ${rootfs_dev_mapper}"
|
|
||||||
blkid ${rootfs_dev_mapper}
|
|
||||||
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
setup_mountpoint() {
|
|
||||||
local mountpoint="$1"
|
|
||||||
|
|
||||||
mount --rbind --make-rslave /dev "$mountpoint/dev"
|
|
||||||
mount proc-live -t proc "$mountpoint/proc"
|
|
||||||
mount sysfs-live -t sysfs "$mountpoint/sys"
|
|
||||||
mount -t tmpfs none "$mountpoint/tmp"
|
|
||||||
mount -t tmpfs none "$mountpoint/var/lib/apt"
|
|
||||||
mount -t tmpfs none "$mountpoint/var/cache/apt"
|
|
||||||
mv "$mountpoint/etc/resolv.conf" resolv.conf.tmp
|
|
||||||
cp /etc/resolv.conf "$mountpoint/etc/resolv.conf"
|
|
||||||
chroot "$mountpoint" apt-get update
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
teardown_mountpoint() {
|
|
||||||
# Reverse the operations from setup_mountpoint
|
|
||||||
local mountpoint="$1"
|
|
||||||
|
|
||||||
# ensure we have exactly one trailing slash, and escape all slashes for awk
|
|
||||||
mountpoint_match=$(echo "$mountpoint" | sed -e's,/$,,; s,/,\\/,g;')'\/'
|
|
||||||
# sort -r ensures that deeper mountpoints are unmounted first
|
|
||||||
for submount in $(awk </proc/self/mounts "\$2 ~ /$mountpoint_match/ \
|
|
||||||
{ print \$2 }" | LC_ALL=C sort -r); do
|
|
||||||
umount $submount
|
|
||||||
done
|
|
||||||
mv resolv.conf.tmp "$mountpoint/etc/resolv.conf"
|
|
||||||
}
|
|
||||||
|
|
||||||
mount_partition() {
|
|
||||||
partition="$1"
|
|
||||||
mountpoint="$2"
|
|
||||||
|
|
||||||
mount "$partition" "$mountpoint"
|
|
||||||
setup_mountpoint "$mountpoint"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
mount_disk_image() {
|
|
||||||
local disk_image=${1}
|
|
||||||
local mountpoint=${2}
|
|
||||||
mount_image ${disk_image} 1
|
|
||||||
mount_partition "${rootfs_dev_mapper}" $mountpoint
|
|
||||||
|
|
||||||
local uefi_dev="/dev/mapper${loop_device///dev/}p15"
|
|
||||||
if [ -b ${uefi_dev} -a -e $mountpoint/boot/efi ]; then
|
|
||||||
mount "${uefi_dev}" $mountpoint/boot/efi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# This is needed to allow for certain operations
|
|
||||||
# such as updating grub and installing software
|
|
||||||
cat > $mountpoint/usr/sbin/policy-rc.d << EOF
|
|
||||||
#!/bin/sh
|
|
||||||
# ${CLOUD_IMG_STR}
|
|
||||||
echo "All runlevel operations denied by policy" >&2
|
|
||||||
exit 101
|
|
||||||
EOF
|
|
||||||
chmod 0755 $mountpoint/usr/sbin/policy-rc.d
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
umount_partition() {
|
|
||||||
local mountpoint=${1}
|
|
||||||
teardown_mountpoint $mountpoint
|
|
||||||
umount -R $mountpoint
|
|
||||||
udevadm settle
|
|
||||||
|
|
||||||
if [ -n "${rootfs_dev_mapper}" -a -b "${rootfs_dev_mapper}" ]; then
|
|
||||||
# buildd's don't have /etc/mtab symlinked
|
|
||||||
# /etc/mtab is needed in order zerofree space for ext4 filesystems
|
|
||||||
[ -e /etc/mtab ] || ln -s /proc/mounts /etc/mtab
|
|
||||||
|
|
||||||
# both of these are likely overkill, but it does result in slightly
|
|
||||||
# smaller ext4 filesystem
|
|
||||||
e2fsck -y -E discard ${rootfs_dev_mapper}
|
|
||||||
zerofree ${rootfs_dev_mapper}
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
umount_disk_image() {
|
|
||||||
mountpoint="$1"
|
|
||||||
|
|
||||||
local uefi_dev="/dev/mapper${loop_device///dev/}p15"
|
|
||||||
if [ -e "$mountpoint/boot/efi" -a -b "$uefi_dev" ]; then
|
|
||||||
umount --detach-loop "$mountpoint/boot/efi"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -e $mountpoint/usr/sbin/policy-rc.d ]; then
|
|
||||||
rm $mountpoint/usr/sbin/policy-rc.d
|
|
||||||
fi
|
|
||||||
umount_partition $mountpoint
|
|
||||||
clean_loops
|
|
||||||
}
|
|
||||||
|
|
||||||
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. This is undocumented vodoo
|
|
||||||
# that has been learned by the Cloud Image team.
|
|
||||||
|
|
||||||
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|# Description file.*|# Disk DescriptorFile|' \
|
|
||||||
-e '/# Believe this is random*/d' \
|
|
||||||
-e '/# Indicates no parent/d' \
|
|
||||||
-e '/# The Disk Data Base/d' \
|
|
||||||
-e 's|ddb.comment.*|ddb.toolsVersion = "2147483647"|' \
|
|
||||||
"${descriptor}" > "${newdescriptor}"
|
|
||||||
|
|
||||||
# The header is cannot be bigger than 1024
|
|
||||||
expr $(stat --format=%s ${newdescriptor}) \< 1024 > /dev/null 2>&1 || {
|
|
||||||
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="${newdescriptor}" of="${vmdk_name}" \
|
|
||||||
bs=1 seek=512 count=1024
|
|
||||||
|
|
||||||
rm ${descriptor} ${newdescriptor}
|
|
||||||
}
|
|
||||||
|
|
||||||
create_vmdk() {
|
|
||||||
# There is no real good way to create a _compressed_ VMDK using open source
|
|
||||||
# tooling that works across multiple VMDK-capable platforms. This functions
|
|
||||||
# uses vmdk-stream-converter and then calls modify_vmdk_header to produce a
|
|
||||||
# compatible VMDK.
|
|
||||||
|
|
||||||
src="$1"
|
|
||||||
destination="$2"
|
|
||||||
size="${3:-10240}"
|
|
||||||
|
|
||||||
streamconverter="/usr/share/pyshared/VMDKstream.py"
|
|
||||||
scratch_d=$(mktemp -d)
|
|
||||||
cp ${src} ${scratch_d}/resize.img
|
|
||||||
|
|
||||||
truncate --size=${size}M ${scratch_d}/resize.img
|
|
||||||
python ${streamconverter} ${scratch_d}/resize.img ${destination}
|
|
||||||
modify_vmdk_header ${destination}
|
|
||||||
|
|
||||||
qemu-img info ${destination}
|
|
||||||
rm -rf ${scratch_d}
|
|
||||||
}
|
|
||||||
|
|
||||||
create_derivative() {
|
|
||||||
# arg1 is the disk type
|
|
||||||
# arg2 is the new name
|
|
||||||
unset derivative_img
|
|
||||||
case ${1} in
|
|
||||||
uefi) disk_image="binary/boot/disk-uefi.ext4";
|
|
||||||
dname="${disk_image//-uefi/-$2-uefi}";;
|
|
||||||
*) disk_image="binary/boot/disk.ext4";
|
|
||||||
dname="${disk_image//.ext4/-$2.ext4}";;
|
|
||||||
esac
|
|
||||||
|
|
||||||
if [ ! -e ${disk_image} ]; then
|
|
||||||
echo "Did not find ${disk_image}!"; exit 1;
|
|
||||||
fi
|
|
||||||
|
|
||||||
cp ${disk_image} ${dname}
|
|
||||||
export derivative_img=${dname}
|
|
||||||
}
|
|
||||||
|
|
||||||
convert_to_qcow2() {
|
|
||||||
|
|
||||||
src="$1"
|
|
||||||
destination="$2"
|
|
||||||
qemu-img convert -c -O qcow2 -o compat=0.10 "$src" "$destination"
|
|
||||||
qemu-img info "$destination"
|
|
||||||
}
|
|
||||||
|
|
||||||
replace_grub_root_with_label() {
|
|
||||||
# When update-grub is run, it will detect the disks in the build system.
|
|
||||||
# Instead, we want grub to use the cloudimg-rootfs labelled disk
|
|
||||||
CHROOT_ROOT="$1"
|
|
||||||
|
|
||||||
# If boot by partuuid has been requested, don't override.
|
|
||||||
if [ -f $CHROOT_ROOT/etc/default/grub.d/40-force-partuuid.cfg ] && \
|
|
||||||
grep -q ^GRUB_FORCE_PARTUUID= $CHROOT_ROOT/etc/default/grub.d/40-force-partuuid.cfg
|
|
||||||
then
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
sed -i -e "s,root=[^ ]*,root=LABEL=cloudimg-rootfs," \
|
|
||||||
"$CHROOT_ROOT/boot/grub/grub.cfg"
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# When running update-grub in a chroot on a build host, we don't want it to
|
|
||||||
# probe for disks or probe for other installed OSes. Extract common
|
|
||||||
# diversion wrappers, so this isn't reinvented differently for each image.
|
|
||||||
divert_grub() {
|
|
||||||
CHROOT_ROOT="$1"
|
|
||||||
|
|
||||||
chroot "$CHROOT_ROOT" dpkg-divert --local \
|
|
||||||
--rename /usr/sbin/grub-probe
|
|
||||||
chroot "$CHROOT_ROOT" touch /usr/sbin/grub-probe
|
|
||||||
chroot "$CHROOT_ROOT" chmod +x /usr/sbin/grub-probe
|
|
||||||
|
|
||||||
chroot "$CHROOT_ROOT" dpkg-divert --local \
|
|
||||||
--divert /etc/grub.d/30_os-prober.dpkg-divert \
|
|
||||||
--rename /etc/grub.d/30_os-prober
|
|
||||||
|
|
||||||
# Divert systemd-detect-virt; /etc/kernel/postinst.d/zz-update-grub
|
|
||||||
# no-ops if we are in a container, and the launchpad farm runs builds
|
|
||||||
# in lxd. We therefore pretend that we're never in a container (by
|
|
||||||
# exiting 1).
|
|
||||||
chroot "$CHROOT_ROOT" dpkg-divert --local \
|
|
||||||
--rename /usr/bin/systemd-detect-virt
|
|
||||||
echo "exit 1" > "$CHROOT_ROOT"/usr/bin/systemd-detect-virt
|
|
||||||
chmod +x "$CHROOT_ROOT"/usr/bin/systemd-detect-virt
|
|
||||||
}
|
|
||||||
|
|
||||||
undivert_grub() {
|
|
||||||
CHROOT_ROOT="$1"
|
|
||||||
|
|
||||||
chroot "$CHROOT_ROOT" rm /usr/sbin/grub-probe
|
|
||||||
chroot "$CHROOT_ROOT" dpkg-divert --remove --local \
|
|
||||||
--rename /usr/sbin/grub-probe
|
|
||||||
|
|
||||||
chroot "$CHROOT_ROOT" dpkg-divert --remove --local \
|
|
||||||
--divert /etc/grub.d/30_os-prober.dpkg-divert \
|
|
||||||
--rename /etc/grub.d/30_os-prober
|
|
||||||
|
|
||||||
rm "$CHROOT_ROOT"/usr/bin/systemd-detect-virt
|
|
||||||
chroot "$CHROOT_ROOT" dpkg-divert --remove --local \
|
|
||||||
--rename /usr/bin/systemd-detect-virt
|
|
||||||
}
|
|
@ -1,9 +1,12 @@
|
|||||||
#!/bin/bash -ex
|
#!/bin/bash -ex
|
||||||
|
|
||||||
. config/functions
|
IMAGE_STR="# CLOUD_IMG: This file was created/modified by the Cloud Image build process"
|
||||||
|
FS_LABEL="cloudimg-rootfs"
|
||||||
|
|
||||||
. config/binary
|
. config/binary
|
||||||
|
|
||||||
|
. config/functions
|
||||||
|
|
||||||
BOOTPART_START=
|
BOOTPART_START=
|
||||||
BOOTPART_END=
|
BOOTPART_END=
|
||||||
BOOT_MOUNTPOINT=
|
BOOT_MOUNTPOINT=
|
||||||
|
@ -9,6 +9,11 @@ case $ARCH in
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
IMAGE_STR="# CLOUD_IMG: This file was created/modified by the Cloud Image build process"
|
||||||
|
FS_LABEL="cloudimg-rootfs"
|
||||||
|
|
||||||
|
. config/binary
|
||||||
|
|
||||||
. config/functions
|
. config/functions
|
||||||
|
|
||||||
create_partitions() {
|
create_partitions() {
|
||||||
@ -88,7 +93,7 @@ install_grub() {
|
|||||||
esac
|
esac
|
||||||
|
|
||||||
cat << EOF >> mountpoint/etc/default/grub.d/50-cloudimg-settings.cfg
|
cat << EOF >> mountpoint/etc/default/grub.d/50-cloudimg-settings.cfg
|
||||||
${CLOUD_IMG_STR}
|
${IMAGE_STR}
|
||||||
# For Cloud Image compatability
|
# For Cloud Image compatability
|
||||||
GRUB_PRELOAD_MODULES="${GRUB_PRELOAD_MODULES:-$grub_modules}"
|
GRUB_PRELOAD_MODULES="${GRUB_PRELOAD_MODULES:-$grub_modules}"
|
||||||
EOF
|
EOF
|
||||||
@ -104,7 +109,7 @@ EOF
|
|||||||
|
|
||||||
if [ -f mountpoint/boot/efi/EFI/BOOT/grub.cfg ]; then
|
if [ -f mountpoint/boot/efi/EFI/BOOT/grub.cfg ]; then
|
||||||
sed -i "s| root| root hd0,gpt1|" mountpoint/boot/efi/EFI/BOOT/grub.cfg
|
sed -i "s| root| root hd0,gpt1|" mountpoint/boot/efi/EFI/BOOT/grub.cfg
|
||||||
sed -i "1i${CLOUD_IMG_STR}" mountpoint/boot/efi/EFI/BOOT/grub.cfg
|
sed -i "1i${IMAGE_STR}" mountpoint/boot/efi/EFI/BOOT/grub.cfg
|
||||||
# For some reason the grub disk is looking for /boot/grub/grub.cfg on
|
# For some reason the grub disk is looking for /boot/grub/grub.cfg on
|
||||||
# part 15....
|
# part 15....
|
||||||
chroot mountpoint mkdir -p /boot/efi/boot/grub
|
chroot mountpoint mkdir -p /boot/efi/boot/grub
|
||||||
|
@ -7,6 +7,11 @@ case $ARCH in
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
IMAGE_STR="# CLOUD_IMG: This file was created/modified by the Cloud Image build process"
|
||||||
|
FS_LABEL="cloudimg-rootfs"
|
||||||
|
|
||||||
|
. config/binary
|
||||||
|
|
||||||
. config/functions
|
. config/functions
|
||||||
|
|
||||||
create_partitions() {
|
create_partitions() {
|
||||||
@ -32,7 +37,7 @@ install_grub() {
|
|||||||
# set the kernel commandline to use hvc0
|
# set the kernel commandline to use hvc0
|
||||||
mkdir -p mountpoint/etc/default/grub.d
|
mkdir -p mountpoint/etc/default/grub.d
|
||||||
cat << EOF > mountpoint/etc/default/grub.d/50-cloudimg-settings.cfg
|
cat << EOF > mountpoint/etc/default/grub.d/50-cloudimg-settings.cfg
|
||||||
${CLOUD_IMG_STR}
|
${IMAGE_STR}
|
||||||
|
|
||||||
# Set the recordfail timeout
|
# Set the recordfail timeout
|
||||||
GRUB_RECORDFAIL_TIMEOUT=0
|
GRUB_RECORDFAIL_TIMEOUT=0
|
||||||
|
@ -44,6 +44,8 @@ case $ARCH in
|
|||||||
exit 0;;
|
exit 0;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
IMAGE_STR="# CLOUD_IMG: This file was created/modified by the Cloud Image build process"
|
||||||
|
|
||||||
. config/functions
|
. config/functions
|
||||||
|
|
||||||
# Lets be safe about this
|
# Lets be safe about this
|
||||||
|
@ -47,7 +47,7 @@ respawn
|
|||||||
script
|
script
|
||||||
exec /sbin/getty -L CONDEV 115200 vt102
|
exec /sbin/getty -L CONDEV 115200 vt102
|
||||||
end script
|
end script
|
||||||
${CLOUD_IMG_STR}
|
${IMAGE_STR}
|
||||||
EOF
|
EOF
|
||||||
sed -i "s/CONDEV/${condev}/g" "$idir/${condev}.conf"
|
sed -i "s/CONDEV/${condev}/g" "$idir/${condev}.conf"
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,10 @@ if [ ! -d ${my_dir}/extra ]; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
export IMAGE_STR="# CLOUD_IMG: This file was created/modified by the Cloud Image build process"
|
||||||
|
export CLOUD_IMG_STR="$IMAGE_STR"
|
||||||
|
export FS_LABEL="cloudimg-rootfs"
|
||||||
|
|
||||||
# Export the common functions to the extras
|
# Export the common functions to the extras
|
||||||
. config/functions
|
. config/functions
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user