rancher / k3os

Purpose-built OS for Kubernetes, fully managed by Kubernetes.
https://k3os.io
Apache License 2.0
3.5k stars 402 forks source link

Unable to Patch ISO to Enlarge Initial OS Partition #603

Open xanalogica opened 4 years ago

xanalogica commented 4 years ago

Version (k3OS / kernel)

$ k3os --version k3os version v0.11.1-dirty $ uname --kernel-release --kernel-version 5.4.0-48-generic #52 SMP Sat Sep 26 08:27:15 UTC 2020

Architecture

$ uname --machine x86_64

Describe the bug

I have been struggling with patching the k3os ISO to add airgap images. The current snag is that although I add images to the ISO, the k3os boot sequence first creates a 700MB root partition, copies the ISO into it, and then later resizes the root partition to 100% of the boot disk.

During the time the root partition is 700MB it's too small to receive the airgap images. I've tried to patch the install.sh script, have done so but the change is not used so I think there is another stashed copy of the original install.sh someplace.

To Reproduce

  1. Build the ISO image using Make
  2. Unpack the ISO under $ISO directory and apply patches $ sudo sed -i 's/700MB/900MB/' $ISO/k3os/system/k3os/current/k3os-install.sh $ sudo sed -i '3 a K3OS_DEBUG=true' $ISO/k3os/system/k3os/current/k3os-install.sh
  3. Repack the ISO
  4. Boot the ISO in LiveCD mode to a shell prompt, which works
  5. Examine the file for my patches and they ARE there: $ less /k3os/system/k3os/current/k3os-install.sh
  6. Run the install process manually $ K3OS_DEBUG=true k3os install
  7. The commands logged to the screen are the UNPATCHED ones, e.g. the parted mkpart is 700MB not 900MB
  8. And the untarring of shows the out-of-space error: ... k3os/data/var/lib/rancher/k3s/agent/images/k3s-airgap-images-amd64.tar k3os/system/kernel/ k3os/system/kernel/5.4.0-48-generic/initrd k3os/system/kernel/5.4.0-48-generic/kernel.squashfs tar: k3os/system/kernel/5.4.0-48-generic/kernel.squashfs: Wrote only 512 of 10240 byte

Expected behavior

I expected the root partition to be 900MB initially, to receive the untarred files and later to be resized to the full disk.

Actual behavior

Untar process fails due to out of space.

Additional context

  1. The VM is behind a firewall so is not getting anything from the GitHub.
  2. A "grep -r parted /k3os/*' of the filesystem while booted in the LiveCD shows only the one k3os-install.sh file with my patches found.
  3. Mounting the ISO into a temp directory while booted in the LiveCD and running "grep -r parted *" also only shows the one file k3os-install.sh with my patches. So no hidden file inside any binary I can find unless it is compressed/encrypted.

Where is "k3os install" getting its script command "parted mkpart ... 700MB"?

xanalogica commented 4 years ago

k3os-14025 [~]$ K3OS_DEBUG=true k3os install

Running k3OS configuration Choose operation

  1. Install to disk
  2. Configure server or agent Select Number [1]: 1 Installation target. Device will be formatted
  3. fd0
  4. sda Select Number []: 2 Config system with cloud-init file? [y/N]: y cloud-init file location (file path or http URL): /var/lib/rancher/config.yaml

Configuration

config_url: /var/lib/rancher/config.yaml device: /dev/sda

Your disk will be formatted and k3OS will be installed with the above configuration. Continue? [y/N]: y

  • '[' 0 -gt 0 ']'
  • '[' -e /etc/environment ']'
  • source /etc/environment ++ K3S_KUBECONFIG_MODE=0644 ++ INSTALL_K3S_SKIP_DOWNLOAD=true
  • '[' -e /etc/os-release ']'
  • source /etc/os-release ++ NAME=k3OS ++ VERSION='k3OS v0.11.1-dirty' ++ ID=k3os ++ ID_LIKE=alpine ++ PRETTY_NAME='k3OS v0.11.1-dirty' ++ VERSION_ID=v0.11.1-dirty ++ HOME_URL=https://k3os.io/ ++ SUPPORT_URL=https://k3os.io/ ++ BUG_REPORT_URL=https://github.com/rancher/k3os/issues ++ ISO_URL=https://github.com/rancher/k3os/releases/download/v0.11.1-dirty/k3os-amd64.iso
  • '[' -z '' ']'
  • K3OS_INSTALL_ISO_URL=https://github.com/rancher/k3os/releases/download/v0.11.1-dirty/k3os-amd64.iso
  • '[' -z /dev/sda ']'
  • validate_progs
  • for i in $PROGS ++ which dd
  • '[' '!' -x /usr/bin/dd ']'
  • for i in $PROGS ++ which curl
  • '[' '!' -x /usr/bin/curl ']'
  • for i in $PROGS ++ which mkfs.ext4
  • '[' '!' -x /usr/sbin/mkfs.ext4 ']'
  • for i in $PROGS ++ which mkfs.vfat
  • '[' '!' -x /usr/sbin/mkfs.vfat ']'
  • for i in $PROGS ++ which fatlabel
  • '[' '!' -x /usr/sbin/fatlabel ']'
  • for i in $PROGS ++ which parted
  • '[' '!' -x /usr/sbin/parted ']'
  • for i in $PROGS ++ which partprobe
  • '[' '!' -x /usr/sbin/partprobe ']'
  • for i in $PROGS ++ which grub-install
  • '[' '!' -x /usr/sbin/grub-install ']'
  • '[' -n '' ']'
  • validate_device
  • DEVICE=/dev/sda
  • '[' '!' -b /dev/sda ']'
  • trap cleanup exit
  • get_iso ++ blkid -L K3OS
  • ISO_DEVICE=/dev/sr0
  • '[' -z /dev/sr0 ']'
  • '[' -z /dev/sr0 ']'
  • '[' -z /dev/sr0 ']'
  • setup_style
  • '[' '' = true ']'
  • '[' -e /sys/firmware/efi ']'
  • PARTTABLE=msdos
  • BOOTFLAG=boot
  • do_format
  • '[' '' = true ']'
  • dd if=/dev/zero of=/dev/sda bs=1M count=1 1+0 records in 1+0 records out 1048576 bytes (1.0 MB, 1.0 MiB) copied, 0.0331593 s, 31.6 MB/s
  • parted -s /dev/sda mklabel msdos
  • '[' msdos = gpt ']'
  • BOOT_NUM=
  • STATE_NUM=1
  • parted -s /dev/sda mkpart primary ext4 0% 700MB
  • parted -s /dev/sda set 1 boot on
  • partprobe /dev/sda
  • sleep 2
  • PREFIX=/dev/sda
  • '[' '!' -e /dev/sda1 ']'
  • '[' '!' -e /dev/sda1 ']'
  • '[' -n '' ']'
  • STATE=/dev/sda1
  • mkfs.ext4 -F -L K3OS_STATE /dev/sda1 mke2fs 1.45.5 (07-Jan-2020) /dev/sda1 contains a ext4 file system labelled 'K3OS_STATE' last mounted on /run/k3os/target on Tue Oct 27 09:57:18 2020 Discarding device blocks: done
    Creating filesystem with 170752 4k blocks and 42720 inodes Filesystem UUID: d619c452-0dea-4b10-bada-50f86e5239a9 Superblock backups stored on blocks: 32768, 98304, 163840

Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done Writing superblocks and filesystem accounting information: done

  • '[' -n '' ']'
  • do_mount
  • TARGET=/run/k3os/target
  • mkdir -p /run/k3os/target
  • mount /dev/sda1 /run/k3os/target
  • mkdir -p /run/k3os/target/boot
  • '[' -n '' ']'
  • mkdir -p /run/k3os/iso
  • mount -o ro /dev/sr0 /run/k3os/iso
  • do_copy
  • tar xvf - -C /run/k3os/target
  • tar cf - -C /run/k3os/iso k3os k3os/ k3os/data/ k3os/data/var/ k3os/data/var/lib/ k3os/data/var/lib/rancher/ k3os/data/var/lib/rancher/k3s/ k3os/data/var/lib/rancher/k3s/agent/ k3os/data/var/lib/rancher/k3s/agent/images/ k3os/data/var/lib/rancher/k3s/agent/images/k3s-airgap-images-v1.18.9.tar k3os/system/ k3os/system/config.yaml k3os/system/k3os/ k3os/system/k3os/current k3os/system/k3os/v0.11.1-dirty/ k3os/system/k3os/v0.11.1-dirty/k3os-install.sh k3os/system/k3os/v0.11.1-dirty/k3os k3os/system/k3s/ k3os/system/k3s/current k3os/system/k3s/v1.18.9+k3s1/ k3os/system/k3s/v1.18.9+k3s1/k3s-install.sh k3os/system/k3s/v1.18.9+k3s1/k3s k3os/system/kernel/ k3os/system/kernel/5.4.0-48-generic/ k3os/system/kernel/5.4.0-48-generic/initrd k3os/system/kernel/5.4.0-48-generic/kernel.squashfs tar: k3os/system/kernel/5.4.0-48-generic/kernel.squashfs: Wrote only 5632 of 10240 bytes k3os/system/kernel/current tar: Exiting with failure status due to previous errors
  • cleanup
  • EXIT=2
  • cleanup2
  • return 2 ERRO[0033] exit status 2
    k3os-14025 [~]$
F-Malmsjo commented 3 years ago

Did you find any solution to this? I'm having the same issue with a remastered ISO containing air-gapped-images tar-file.