Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
finnje opened this issue Feb 13, 2023 · 4 comments · Fixed by #28
Closed

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

finnje opened this issue Feb 13, 2023 · 4 comments · Fixed by #28
Assignees
Labels
bug Something isn't working enhancement New feature or request

Comments

@finnje
Copy link

finnje commented Feb 13, 2023

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?

@cloudymax
Copy link
Owner

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 👍

@cloudymax cloudymax self-assigned this Feb 17, 2023
@cloudymax cloudymax added the bug Something isn't working label Feb 17, 2023
@cloudymax
Copy link
Owner

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!

@cloudymax cloudymax changed the title Question regarding additional directories and files BUG: extra files not copied to live system during install Feb 26, 2023
@cloudymax cloudymax added the enhancement New feature or request label Feb 26, 2023
@cloudymax
Copy link
Owner

cloudymax commented Feb 26, 2023

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!

@cloudymax cloudymax changed the title BUG: extra files not copied to live system during install BUG: extra files not copied to live system during install when using -x Feb 27, 2023
@cloudymax cloudymax linked a pull request Feb 27, 2023 that will close this issue
@cloudymax
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants