diff --git a/.dockerignore b/.dockerignore index e7f7a4a..0ac6c79 100644 --- a/.dockerignore +++ b/.dockerignore @@ -3,3 +3,4 @@ work/ deploy/ apt-cacher-ng/ .git/objects/* +build/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index d1a1b84..07302bd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,7 +18,9 @@ RUN apt install -y --no-install-recommends \ kpartx \ lbzip2 \ sudo \ - e2fsprogs + e2fsprogs \ + dosfstools \ + qemu-utils RUN python3 -m pip install ansible diff --git a/ansible/roles/base/templates/etc/netplan/netcfg.yaml b/ansible/roles/base/templates/etc/netplan/netcfg.yaml index ccc85bd..56360b8 100644 --- a/ansible/roles/base/templates/etc/netplan/netcfg.yaml +++ b/ansible/roles/base/templates/etc/netplan/netcfg.yaml @@ -4,3 +4,4 @@ network: ethernets: eth0: dhcp4: true + dhcp6: true diff --git a/ansible/roles/grub/tasks/main.yaml b/ansible/roles/grub/tasks/main.yaml index 17caed9..7024e36 100644 --- a/ansible/roles/grub/tasks/main.yaml +++ b/ansible/roles/grub/tasks/main.yaml @@ -6,7 +6,13 @@ - name: Install GRUB Bootloader apt: - name: grub2 + name: grub-efi-amd64 + +- name: Install GRUB System + shell: | + set -e + grub-install --target=x86_64-efi + GRUB_DISABLE_OS_PROBER=true update-grub - name: Install Linux firmware apt: diff --git a/ansible/tasks/mount.yaml b/ansible/tasks/mount.yaml index 630b0ca..573a04d 100644 --- a/ansible/tasks/mount.yaml +++ b/ansible/tasks/mount.yaml @@ -1,8 +1,8 @@ --- - name: Mount pseudo filesystems connection: local - shell: mount -o bind '{{ item }}' '{{ lookup('env', 'ANSIBLE_ROOTFS_DIR') }}{{ item }}' - with_items: - - /proc - - /dev - - /dev/pts \ No newline at end of file + shell: | + mount -o bind,ro /dev {{ lookup('env', 'ANSIBLE_ROOTFS_DIR') }}/dev + mount -o bind,ro /dev/pts {{ lookup('env', 'ANSIBLE_ROOTFS_DIR') }}/dev/pts + mount -t proc none {{ lookup('env', 'ANSIBLE_ROOTFS_DIR') }}/proc + mount -t sysfs none {{ lookup('env', 'ANSIBLE_ROOTFS_DIR') }}/sys \ No newline at end of file diff --git a/ansible/tasks/umount.yaml b/ansible/tasks/umount.yaml index c1f8557..4d0933b 100644 --- a/ansible/tasks/umount.yaml +++ b/ansible/tasks/umount.yaml @@ -5,4 +5,5 @@ with_items: - /proc - /dev/pts - - /dev \ No newline at end of file + - /dev + - /sys \ No newline at end of file diff --git a/build_grub.sh b/build_grub.sh index 7b48c1c..1bcadfb 100755 --- a/build_grub.sh +++ b/build_grub.sh @@ -4,15 +4,89 @@ set -e INPUT_DIR="$1" IMAGE_NAME="$(basename $INPUT_DIR)" +GRUB_IMG="$TARGET$BUILD/export.img" GRUB_DIR="$TARGET$BUILD/grub" +LOOP_DEV="/dev/loop5" -printf "Copying base rootfs... " -rm -fr $GRUB_DIR +printf "Creating image file... " +if [ "$(lsblk | grep $(basename $LOOP_DEV))" ]; then + losetup -d $LOOP_DEV +fi +rm -fr $GRUB_IMG +printf "(OK)\n" + +echo "Allocating image file..." +if [ -f $GRUB_IMG ]; then + rm -fr $GRUB_IMG +fi +qemu-img create $GRUB_IMG 10G +parted -s -a optimal -- $GRUB_IMG \ + mklabel gpt \ + mkpart primary fat32 1MiB 270MiB \ + mkpart primary ext4 1GiB -0 \ + name 1 uefi \ + name 2 root \ + set 1 esp on +losetup --partscan $LOOP_DEV $GRUB_IMG +partprobe $LOOP_DEV +echo "Allocating image file... (OK)" + +printf "Find partitions UUID... " +ROOT_UUID=$(blkid | grep "^$LOOP_DEV" | grep ' PARTLABEL="root" ' | grep -o ' PARTUUID="[^"]\+"' | sed -e 's/^ //' ) +EFI_UUID=$(blkid | grep "^$LOOP_DEV" | grep ' PARTLABEL="uefi" ' | grep -o ' PARTUUID="[^"]\+"' | sed -e 's/^ //' ) +printf "(OK)\n" + +echo "Formatting image file..." +mkfs -t vfat -F 32 -n EFI ${LOOP_DEV}p1 +mkfs -t ext4 -L root ${LOOP_DEV}p2 +echo "Formatting image file... (OK)" + +printf "Mounting root filesystem... " +if [ -d "$GRUB_DIR" ]; then + umount -q $GRUB_DIR || true + rm -fr $GRUB_DIR +fi +mkdir -p $GRUB_DIR +mount $ROOT_UUID $GRUB_DIR +printf "(OK)\n" + +printf "Copying filesystem to image... " cp -rp $INPUT_DIR/. $GRUB_DIR/ printf "(OK)\n" +printf "Mounting efi filesystem... " +if [ -d "$GRUB_DIR/boot/efi" ]; then + umount -q $GRUB_DIR/boot/efi || true + rm -fr $GRUB_DIR/boot/efi +fi +mkdir -p $GRUB_DIR/boot/efi +mount $EFI_UUID $GRUB_DIR/boot/efi +printf "(OK)\n" + echo "Run GRUB installation tasks..." pushd $TARGET/ansible > /dev/null export ANSIBLE_ROOTFS_DIR=$GRUB_DIR ansible-playbook -v 03_grub.yaml -echo "Run GRUB installation tasks... (OK)" \ No newline at end of file +echo "Run GRUB installation tasks... (OK)" + +printf "Installing fstab... " +echo "$ROOT_UUID / ext4 errors=remount-ro 0 1" > $GRUB_DIR/etc/fstab +echo "$EFI_UUID /boot/efi vfat defaults 0 1" >> $GRUB_DIR/etc/fstab +printf "(OK)\n" + +printf "Umounting everything... " +umount -q $GRUB_DIR/boot/efi +umount -q $GRUB_DIR +printf "(OK)\n" + +echo "Checking filesystem..." +fsck -y ${LOOP_DEV}p2 +echo "Checking filesystem... (OK)" + +echo "Detaching loop device..." +losetup -d $LOOP_DEV +echo "Detaching loop device... (OK)" + +printf "Moving export image file... " +mv $GRUB_IMG "${EXPORT_DIR}/${PISDR_IMG_NAME}-${IMAGE_NAME}-amd64.img" > /dev/null +printf "(OK)\n" \ No newline at end of file