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

invalid argument error when trying to extract ISO to directory #47

Open
smahm006 opened this issue Nov 4, 2023 · 3 comments
Open

invalid argument error when trying to extract ISO to directory #47

smahm006 opened this issue Nov 4, 2023 · 3 comments

Comments

@smahm006
Copy link

smahm006 commented Nov 4, 2023

I am trying to extract a ubuntu iso image (from https://releases.ubuntu.com/22.04/) to a temporary folder. Below is the code I am using

func ExtractISO() error {
	temp, err := os.MkdirTemp("temp", "ubuntu-")
	if err != nil {
		return fmt.Errorf("creating temp dir: %s", err)
	}
	iso_file, err := os.Open("ubuntu-22.04.3-live-server-amd64.iso")
	if err != nil {
		return fmt.Errorf("opening iso file: %s", err)
	}
	defer iso_file.Close()
	if err = util.ExtractImageToDirectory(iso_file, temp); err != nil {
		return fmt.Errorf("extracting image: %s", err)
	}
	return nil
}

I am getting hit with an error extracting image: open temp/ubuntu-4020240902/boot/grub/i386-pc/zstd.mod: invalid argument

I am not sure what the reason is, maybe the - in i386-pc?

EDIT: I just realized this might also be a permissions issue

@FNDenisovna
Copy link

i have analogous problem :(

boot/grub/i386-efi/xnu.mod: invalid argument

@smahm006
Copy link
Author

I just ended up using os.Exec to call xorriso

func extractISOToDirectory(filename string, source string, destination string) error {
	xorriso_args := fmt.Sprintf("-osirrox on -indev %s/%s -extract / %s", source, filename, destination)
	cmd := exec.Command("xorriso", strings.Split(xorriso_args, " ")...)
	err := cmd.Run()
	if err != nil {
		return fmt.Errorf("xorriso error: %s", err)
	}
	err = filepath.Walk(destination, func(path string, info os.FileInfo, err error) error {
		if err != nil {
			return err
		}
		return os.Chmod(path, os.FileMode(0755))
	})
	if err != nil {
		return fmt.Errorf("setting directory permissions: %s", err)
	}
	return nil
}

@FNDenisovna
Copy link

thank you! i was just thinking this way :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants