4

Is there a way to extract the contents of an ISO image file to a folder in one step?

I have been doing this and want to do less typing, and not to have to do the mount -o loop as well as the need to be root to do the mount command to access the ISO image contents:

cp rhel-server-7.6-x86_64-dvd.iso /home/ron/
mkdir /home/ron/temp
mount -o loop /root/rhel-server-7.6-x86_64-dvd.iso /home/ron/temp
mkdir /home/ron/rhel7.6dvd
mv /home/ron/temp/* /home/ron/rhel7.6dvd
rmdir /home/ron/temp
Peter Mortensen
  • 1,029
  • 1
  • 8
  • 10
ron
  • 5,749
  • 7
  • 48
  • 84
  • 2
    Why not put your commands into a script and run that? – Panki Jan 12 '22 at 15:37
  • it would still require root to do the mount command, which i don't feel I should need to just access the contents of an iso file. I really like the `7z x my.iso` not sure it can get any better than that. – ron Jan 12 '22 at 16:32
  • Slightly related: *[Can I download and write a disk image to partition without saving as a file?](https://unix.stackexchange.com/questions/685233/)* – Peter Mortensen Feb 02 '22 at 16:35

3 Answers3

8

There's multiple programs that can just treat an ISO-9660 file as an archive. 7z is a popular one: 7z x yourfile.iso works.

If this is a modern Linux with a user session manager running, udisksctl loop-setup -f yourfile.iso is a way to get your file into a loop device, and consequently automounted.

Also:

mv /home/ron/temp/* /home/ron/rhel7.6dvd

that line must be throwing a lot of errors: a mounted ISO image is read-only, so you can't move things away from it. cp instead.

Marcus Müller
  • 21,602
  • 2
  • 39
  • 54
  • 3
    **note:** for anyone doing the `7z x my.iso` it explodes the contents into the current folder, which can be problematic. So make an empty subfolder first and then execute `7z` from within that empty subfolder. No different than doing a `tar -xf` for example. – ron Jan 12 '22 at 16:34
5

osirrox -indev rhel-server-7.6-x86_64-dvd.iso -extract / /home/ron/rhel7.6dvd

osirrox is a special invocation of the xorriso tool.

https://www.gnu.org/software/xorriso/

virullius
  • 1,036
  • 2
  • 10
  • 19
  • 1
    this works. but gonna mark the `7z x my.iso` one as correct since it was the least amount of typing. I was able to `yum install xorriso` on RHEL 7.9 with having the EPEL repository available. Thanks for the suggestion, always nice to find a new linux tool. – ron Jan 12 '22 at 16:24
  • seconding that, even have xorriso installed, but for the love of it couldn't remember how to find it ^^". Have a very well-deserved upvote. – Marcus Müller Jan 12 '22 at 17:09
0

Users running FreeBSD can:

mkdir /home/ron/rhel7.6dvd
tar xpf rhel-server-7.6-x86_64-dvd.iso -C /home/ron/rhel7.6dvd

Other BSDs might support this as well, but I'm not sure.

Jim L.
  • 7,188
  • 1
  • 13
  • 25