[Merge] ~davidkrauser/livecd-rootfs/+git/livecd-rootfs:hyperv-gallery-images into livecd-rootfs:ubuntu/master

Francis Ginther francis.ginther at canonical.com
Wed May 8 02:13:26 UTC 2019


Initial review

Diff comments:

> diff --git a/live-build/auto/config b/live-build/auto/config
> index 46246eb..4db3b5f 100755
> --- a/live-build/auto/config
> +++ b/live-build/auto/config
> @@ -453,6 +453,7 @@ if [ "$PREINSTALLED" = "true" ]; then
>  		*)
>  			add_package live oem-config-gtk ubiquity-frontend-gtk
>  			add_package live ubiquity-slideshow-ubuntu
> +			add_package live language-pack-en-base

The "ubuntu" project falls through to this catch-all case which feels like an accident, plus this is changing the behavior for other projects. I'd rather see a the project specifically called out and the `language-pack-en-base` added there. Also, does the preinstalled image need ubiquity and oem-config?
`

>  			;;
>  	esac
>  fi
> diff --git a/live-build/functions b/live-build/functions
> index 7908900..5c1648d 100644
> --- a/live-build/functions
> +++ b/live-build/functions
> @@ -326,9 +326,10 @@ replace_grub_root_with_label() {
>  divert_grub() {
>  	CHROOT_ROOT="$1"
>  
> -	# Don't divert all of grub-probe here; just the scripts we don't want
> -	# running. Otherwise, you may be missing part-uuids for the search
> -	# command, for example. ~cyphermox
> +	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

I don't think we want to make this change. It will impact more then the desktop-preinstalled image.

>  
>  	chroot "$CHROOT_ROOT" dpkg-divert --local \
>  		--divert /etc/grub.d/30_os-prober.dpkg-divert \
> @@ -347,6 +348,10 @@ divert_grub() {
>  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
> +

I don't think we want to make this change. It will impact more then the desktop-preinstalled image.

>  	chroot "$CHROOT_ROOT" dpkg-divert --remove --local \
>  		--divert /etc/grub.d/30_os-prober.dpkg-divert \
>  		--rename /etc/grub.d/30_os-prober
> diff --git a/live-build/ubuntu/hooks/033-disk-image-uefi.binary b/live-build/ubuntu/hooks/033-disk-image-uefi.binary
> new file mode 100644
> index 0000000..3aad890
> --- /dev/null
> +++ b/live-build/ubuntu/hooks/033-disk-image-uefi.binary
> @@ -0,0 +1,186 @@
> +#!/bin/bash -eux
> +
> +case $ARCH in
> +    amd64)
> +        ;;
> +    *)
> +        echo "We don't create EFI images for $ARCH."
> +        exit 0
> +        ;;
> +esac
> +
> +IMAGE_STR="# Ubuntu Desktop"
> +FS_LABEL="desktop-rootfs"
> +IMAGE_SIZE=11806965760
> +
> +. config/binary
> +
> +. config/functions
> +
> +create_partitions() {
> +    disk_image="$1"
> +    sgdisk "${disk_image}" --zap-all
> +    case $ARCH in
> +        arm64|armhf)
> +            sgdisk "${disk_image}" \
> +                --new=15:0:204800 \
> +                --typecode=15:ef00 \
> +                --new=1:
> +            ;;
> +        amd64)
> +            sgdisk "${disk_image}" \
> +                --new=14::+4M \
> +                --new=15::+106M \
> +                --new=1::
> +            sgdisk "${disk_image}" \
> +                -t 14:ef02 \
> +                -t 15:ef00
> +            ;;
> +    esac
> +    sgdisk "${disk_image}" \
> +        --print
> +}
> +
> +create_and_mount_uefi_partition() {
> +    uefi_dev="/dev/mapper${loop_device///dev/}p15"
> +    mountpoint="$1"
> +    mkfs.vfat -F 32 -n UEFI "${uefi_dev}"
> +
> +    mkdir -p "${mountpoint}"/boot/efi
> +    mount "${uefi_dev}" "$mountpoint"/boot/efi
> +    #efipartuuid=$(blkid -s PARTUUID -o value "$uefi_dev")
> +
> +    cat << EOF >> "mountpoint/etc/fstab"
> +LABEL=UEFI	/boot/efi	vfat	defaults	0 0
> +EOF
> +}
> +
> +install_grub() {
> +    mkdir mountpoint
> +    mount_partition "${rootfs_dev_mapper}" mountpoint
> +
> +    create_and_mount_uefi_partition mountpoint
> +
> +    echo "(hd0) ${loop_device}" > mountpoint/tmp/device.map
> +    mkdir -p mountpoint/etc/default/grub.d
> +    efi_boot_dir="/boot/efi/EFI/BOOT"
> +    chroot mountpoint mkdir -p "${efi_boot_dir}"
> +
> +    if [ "${SUBPROJECT:-}" = minimized ] && [ -n "$partuuid" ]; then
> +        echo "partuuid found for root device; omitting initrd"
> +        echo "GRUB_FORCE_PARTUUID=$partuuid" >> mountpoint/etc/default/grub.d/40-force-partuuid.cfg
> +    fi

I don't think minimized makes sense for a desktop build and we're not building/testing it. I would recommended removing it.

> +
> +    chroot mountpoint apt-get -y update
> +
> +    # UEFI GRUB modules are meant to be used equally by Secure Boot and
> +    # non-Secure Boot systems. If you need an extra module not already
> +    # provided or run into "Secure Boot policy forbids loading X" problems,
> +    # please file a bug against grub2 to include the affected module.
> +    case $ARCH in
> +        arm64)
> +            chroot mountpoint apt-get -qqy install --no-install-recommends grub-efi-arm64 grub-efi-arm64-bin
> +            efi_target=arm64-efi
> +            ;;
> +        armhf)
> +            chroot mountpoint apt-get -qqy install --no-install-recommends grub-efi-arm grub-efi-arm-bin
> +            efi_target=arm-efi
> +            ;;
> +        amd64)
> +            chroot mountpoint apt-get install -qqy grub-efi-amd64-signed grub-efi-amd64 shim-signed
> +            efi_target=x86_64-efi
> +            ;;
> +    esac
> +
> +    chroot mountpoint grub-install "${loop_device}" \
> +        --boot-directory=/boot \
> +        --efi-directory=/boot/efi \
> +        --target=${efi_target} \
> +        --removable \
> +        --uefi-secure-boot \
> +        --no-nvram
> +
> +    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 "1i${IMAGE_STR}" mountpoint/boot/efi/EFI/BOOT/grub.cfg
> +        # For some reason the grub disk is looking for /boot/grub/grub.cfg on
> +        # part 15....
> +        chroot mountpoint mkdir -p /boot/efi/boot/grub
> +        chroot mountpoint cp /boot/efi/EFI/BOOT/grub.cfg /boot/efi/boot/grub
> +    fi
> +
> +    if [ "$ARCH" = "amd64" ]; then
> +        # Install the BIOS/GPT bits. Since GPT boots from the ESP partition,
> +        # it means that we just run this simple command and we're done
> +        chroot mountpoint grub-install --target=i386-pc "${loop_device}"
> +    fi
> +
> +    divert_grub mountpoint
> +
> +    chroot mountpoint rm /usr/sbin/grub-probe
> +    chroot mountpoint dpkg-divert --remove --local \
> +	--rename /usr/sbin/grub-probe
> +
> +    # update grub.cfg again, make sure this image has fs-uuid.
> +    chroot mountpoint update-grub
> +
> +    chroot mountpoint dpkg-divert --local \
> +    	--rename /usr/sbin/grub-probe
> +    chroot mountpoint touch /usr/sbin/grub-probe
> +    chroot mountpoint chmod +x /usr/sbin/grub-probe
> +	    
> +    replace_grub_root_with_label mountpoint
> +
> +    undivert_grub mountpoint
> +
> +    chroot mountpoint apt-get -y clean
> +
> +    rm mountpoint/tmp/device.map
> +    umount mountpoint/boot/efi
> +    umount_partition mountpoint
> +    rmdir mountpoint
> +}
> +
> +disk_image=binary/boot/disk-uefi.ext4
> +
> +create_empty_disk_image "${disk_image}"
> +create_partitions "${disk_image}"
> +mount_image "${disk_image}" 1
> +
> +partuuid=$(blkid -s PARTUUID -o value "$rootfs_dev_mapper")
> +
> +# Copy the chroot in to the disk
> +make_ext4_partition "${rootfs_dev_mapper}"
> +mkdir mountpoint
> +mount "${rootfs_dev_mapper}" mountpoint
> +cp -a chroot/* mountpoint/
> +setup_mountpoint mountpoint
> +
> +# Disable UUID so we find root by label
> +sed -i "s|#GRUB_DISABLE_LINUX_UUID|GRUB_DISABLE_LINUX_UUID|" mountpoint/etc/default/grub
> +
> +# Add a swap file
> +dd if=/dev/zero of=mountpoint/swapfile bs=1024 count=1048576
> +chmod 0600 mountpoint/swapfile
> +mkswap mountpoint/swapfile
> +
> +# Edit fstab in the mounted disk
> +cat > "mountpoint/etc/fstab" << EOF
> +# <file system> <mount point>   <type>  <options>       <dump>  <pass>
> +LABEL=${fs_label}  /       ext4    errors=remount-ro   0   1
> +/swapfile	none	swap	sw	0	0
> +EOF
> +
> +# Don't run gnome-initial-setup from gdm
> +sed -i "s|#WaylandEnable=false|#WaylandEnable=false\nInitialSetupEnable=false|" mountpoint/etc/gdm3/custom.conf
> +
> +chroot mountpoint /usr/sbin/useradd -d /home/oem -m -N -u 29999 oem
> +chroot mountpoint /usr/sbin/oem-config-prepare --quiet
> +touch mountpoint/var/lib/oem-config/run
> +umount_partition mountpoint
> +rmdir mountpoint
> +
> +install_grub
> +
> +clean_loops
> +trap - EXIT
> diff --git a/live-build/ubuntu/hooks/040-hyperv-desktop-images.binary b/live-build/ubuntu/hooks/040-hyperv-desktop-images.binary
> new file mode 100644
> index 0000000..c8ebc2a
> --- /dev/null
> +++ b/live-build/ubuntu/hooks/040-hyperv-desktop-images.binary
> @@ -0,0 +1,109 @@
> +#!/bin/bash -eux
> +
> +echo "Creating Hyper-V image with Desktop..."
> +
> +case "${ARCH}" in
> +    amd64)
> +        ;;
> +    *)
> +        echo "Hyper-V only supports amd64";
> +        exit 0
> +        ;;
> +esac
> +
> +IMAGE_STR="# Ubuntu Desktop"
> +FS_LABEL="desktop-rootfs"
> +IMAGE_SIZE=11806965760
> +
> +. config/functions
> +
> +export DEBIAN_FRONTEND=noninteractive
> +
> +create_derivative uefi hyperv
> +scratch_d=$(mktemp -d)
> +mount_disk_image "${derivative_img}" "${scratch_d}"
> +
> +cleanup_hyperv() {
> +    umount_disk_image ${scratch_d}
> +    rm -rf ${scratch_d}
> +}
> +trap cleanup_hyperv EXIT
> +
> +# Perform customisations
> +
> +chroot "${scratch_d}" apt-get update -y
> +chroot "${scratch_d}" apt-get -y install xrdp linux-tools-virtual linux-cloud-tools-virtual
> +
> +cat > ${scratch_d}/etc/modules-load.d/hyperv.conf << EOF
> +hv_sock
> +EOF
> +
> +# Customise xrdp
> +
> +# use vsock transport.
> +sed -i_orig -e 's/use_vsock=false/use_vsock=true/g' "${scratch_d}/etc/xrdp/xrdp.ini"
> +# use rdp security.
> +sed -i_orig -e 's/security_layer=negotiate/security_layer=rdp/g' "${scratch_d}/etc/xrdp/xrdp.ini"
> +# remove encryption validation.
> +sed -i_orig -e 's/crypt_level=high/crypt_level=none/g' "${scratch_d}/etc/xrdp/xrdp.ini"
> +# disable bitmap compression since its local its much faster
> +sed -i_orig -e 's/bitmap_compression=true/bitmap_compression=false/g' "${scratch_d}/etc/xrdp/xrdp.ini"
> +
> +# Add script to setup the ubuntu session properly
> +cat > "${scratch_d}/etc/xrdp/startubuntu.sh" << EOF
> +#!/bin/sh
> +export GNOME_SHELL_SESSION_MODE=ubuntu
> +export XDG_CURRENT_DESKTOP=ubuntu:GNOME
> +exec /etc/xrdp/startwm.sh
> +EOF
> +chmod a+x "${scratch_d}/etc/xrdp/startubuntu.sh"
> +
> +# use the script to setup the ubuntu session
> +sed -i_orig -e 's/startwm/startubuntu/g' "${scratch_d}/etc/xrdp/sesman.ini"
> +
> +# rename the redirected drives to 'shared-drives'
> +sed -i -e 's/FuseMountName=thinclient_drives/FuseMountName=shared-drives/g' "${scratch_d}/etc/xrdp/sesman.ini"
> +
> +# Changed the allowed_users
> +sed -i_orig -e 's/allowed_users=console/allowed_users=anybody/g' "${scratch_d}/etc/X11/Xwrapper.config"
> +
> +# Blacklist the vmw module
> +cat > "${scratch_d}/etc/modprobe.d/blacklist_vmw_vsock_vmci_transport.conf" << EOF
> +blacklist vmw_vsock_vmci_transport
> +EOF
> +
> +# Configure the policy xrdp session
> +cat > ${scratch_d}/etc/polkit-1/localauthority/50-local.d/45-allow-colord.pkla << EOF
> +[Allow Colord all Users]
> +Identity=unix-user:*
> +Action=org.freedesktop.color-manager.create-device;org.freedesktop.color-manager.create-profile;org.freedesktop.color-manager.delete-device;org.freedesktop.color-manager.delete-profile;org.freedesktop.color-manager.modify-device;org.freedesktop.color-manager.modify-profile
> +ResultAny=no
> +ResultInactive=no
> +ResultActive=yes
> +EOF
> +
> +sed -i -e 's|After=|ConditionPathExists=!/var/lib/oem-config/run\nAfter=|g' "${scratch_d}/lib/systemd/system/xrdp.service"
> +
> +# End xrdp customisation
> +
> +chroot "${scratch_d}" apt-get clean
> +echo "FJG: before"
> +ls -la "${scratch_d}"/usr/sbin/update-initramfs
> +cat "${scratch_d}"/usr/sbin/update-initramfs
> +echo "FJG: after"
> +#rm -f "${scratch_d}"/usr/sbin/update-initramfs
> +#chroot "${scratch_d}" dpkg-divert --quiet --remove --rename /usr/sbin/update-initramfs
> +ls -la "${scratch_d}"/usr/sbin/update-initramfs
> +#cat "${scratch_d}"/usr/sbin/update-initramfs
> +echo "FJG: done"

This entire block starting with `echo "FJG: before"` can be removed.

> +
> +# End customisations
> +
> +cleanup_hyperv
> +trap - EXIT
> +
> +raw_img=binary/boot/disk-hyperv-uefi.ext4
> +vhd_img=livecd.ubuntu-desktop-hyperv.vhdx
> +
> +qemu-img convert -O vhdx "$raw_img" "$vhd_img"
> +xz -T4 -1 "$vhd_img"

We should be zipping the vhdx instead of xz, but this can be done post build.

> diff --git a/live-build/ubuntu/hooks/functions b/live-build/ubuntu/hooks/functions
> new file mode 100644
> index 0000000..ed45e03
> --- /dev/null
> +++ b/live-build/ubuntu/hooks/functions
> @@ -0,0 +1,31 @@
> +#!/bin/sh -eux
> +# vi: ts=4 expandtab syntax=sh
> +#
> +# Add common functions here
> +#
> +grow_fs() {
> +    # Grow a file system to fill its partition
> +    local fs=${1}
> +
> +    e2fsck -f -y -E discard "${fs}"
> +    resize2fs "${fs}"
> +    zerofree "${fs}"
> +}
> +
> +grow_image() {
> +    # Grow the image to a specified size and expand the root FS (located
> +    # in partition 1) to fill the space
> +    # NOTE: The image specified should not be mounted when calling grow_image
> +    local img=${1}
> +    local size=${2}
> +
> +    apt-get install -qqy qemu-utils
> +    qemu-img resize -f raw "${img}" "${size}"
> +    growpart "${img}" 1
> +
> +    # This requires sourcing of functions from livecd-rootfs
> +    mount_image "${img}" 1
> +    grow_fs "${rootfs_dev_mapper}"
> +    clean_loops
> +    trap - EXIT
> +}

I don't see grow_fs or grow_image being used outside this file. This can be removed I think.

> diff --git a/live-build/ubuntu/includes.chroot/etc/hosts b/live-build/ubuntu/includes.chroot/etc/hosts
> new file mode 100644
> index 0000000..8168434
> --- /dev/null
> +++ b/live-build/ubuntu/includes.chroot/etc/hosts
> @@ -0,0 +1,9 @@
> +127.0.0.1	localhost.localdomain	localhost
> +::1		localhost6.localdomain6	localhost6
> +
> +# The following lines are desirable for IPv6 capable hosts
> +::1     localhost ip6-localhost ip6-loopback
> +fe00::0 ip6-localnet
> +ff02::1 ip6-allnodes
> +ff02::2 ip6-allrouters
> +ff02::3 ip6-allhosts

I don't see where this is used either.



-- 
https://code.launchpad.net/~davidkrauser/livecd-rootfs/+git/livecd-rootfs/+merge/366849
Your team Ubuntu Core Development Team is subscribed to branch livecd-rootfs:ubuntu/master.



More information about the Ubuntu-reviews mailing list