cloudymax/pxeless

BUG: extra files not copied to live system during install when using `-x`

finnje opened this issue · 4 comments

I'm trying to figure out how to take the additional files I've added to the iso and have them copied to the hard-drive of the machine being built.

I originally used -x to add a directory to the iso..but I didn't see that directory in the / dir of the newly installed machine. Next I tried adding a cp -R /root/my_additional_stuff /root/ to see if that would copy over my additional directory but that didn't seem to work either.

What would be the preferred method to accomplish getting some custom files copied from the iso to the new machine?

Thanks for the report! I can recreate the issue as described and am looking for a fix. I'll update as soon as I have something 👍

So I've tested this a bunch of different ways over the past week and I'm not able to get the option working. This feature was added by a community member a while back and I haven't been using it so that's how I missed this issue.

There seem to be a few ways this can be resolved though either through chrooting the iso's squashfs, or possibly by haviing ubuquity copy the files from /cdrom during install.

I'm reading through a few articles for inspiration while I look for a way to make this functional:

I'll keep updating as things progress.

Cheers!

Okay, I've managed to figure out a way to make this functional after reviewing the articles above.

TLDR; it requires putting the extra files into the actual squashfs, not just at the root of the ISO.

Once the following is merged you will have all the files from your extras folder in the /media directory of the installed system.

# Add extra files from a folder into the build dir
insert_extra_files(){
        if [ ${LEGACY_IMAGE} -eq 1 ]; then
		SQUASH_FS="filesystem.squashfs"
	else
		SQUASH_FS="ubuntu-server-minimal.squashfs"
	fi

	rm -rf "${SQUASH_FS}"

        log "Adding additional files to the iso image..."

        log "Step 1. Copy squashfs to safe location..."
        cp "${BUILD_DIR}/casper/${SQUASH_FS}" .

        log "Step 2. Expand filesystem..."
        unsquashfs "${SQUASH_FS}"

        log "Step 3. Copy extra files to /media..."
        cp -R "${EXTRA_FILES_FOLDER}/." "squashfs-root/media/"

        log "Step 4. Rebuilding squashfs.."
        mksquashfs squashfs-root/ "${SQUASH_FS}" -comp xz -b 1M -noappend

        log "Step 5. Copy squashfs copied back to {BUILD_DIR}/casper/${SQUASH_FS}"
        cp "${SQUASH_FS}" "${BUILD_DIR}/casper/${SQUASH_FS}"

	log "➕➕ Step 6. Cleaning up directories..."
	rm -rf "${SQUASH_FS}"
	rm -rf squashfs-root
}

I've tested it on focal and jammy, but didn't have time to fix the Dockerfile just yet. I'll try to get this pushed out tomorrow though.

Cheers!

This is resolved now in v0.0.5 and it's usage is documented int he new quick-start section of the README:

# Quickstart

1. Clone the rpos

    ```bash
    git clone https://github.com/cloudymax/pxeless.git
    ```

2. Change directory to the root of the repo

    ```bash
    cd pxeless
    ```

3. Run in a Docker container

    - Basic Usage:
      ```bash
      docker run --rm --volume "$(pwd):/data" --user $(id -u):$(id -g) deserializeme/pxeless \
      -a -u user-data.basic -n jammy
      ```
          
    - Adding extra files to the ISO via the `-x` or `--extra-files` flag requires root access in order to chroot the squashfs. The contents of the `extras` directory will be copied to the `/media` dir of the image's filesystem. The extra-files are mounted as `/data/<directory>` when running in a docker conatiner because we mount `$(pwd)` as `/data/`
      ```bash
      docker run --privileged --rm --volume "$(pwd):/data" pxe -a -u user-data.basic -n jammy -x /data/extras
      ```


4. Writing your ISO to a USB drive

    - On MacOS I reccommend using [Etcher](https://www.balena.io/etcher/) 
    
    - On Linux use `dd`.
    
          ```bash
          # /dev/sdb is assumed for the sake of the example
  
          export IMAGE_FILE="ubuntu-autoinstall.iso"

          sudo fdisk -l |grep "Disk /dev/"

          export DISK_NAME="/dev/sdb"

          sudo umount "$DISK_NAME"

          sudo dd bs=4M if=$IMAGE_FILE of="$DISK_NAME" status=progress oflag=sync
          ```


4. Boot your ISO file on a physical machine for VM and log-in. If you used my `user-data.basic` file the user is `vmadmin`, and the password is `password`. You can create your own credentials by running `mkpasswd --method=SHA-512 --rounds=4096` as documented on [THIS](https://cloudinit.readthedocs.io/en/0.7.8/topics/examples.html) page at line 49.