Background
Have you ever needed to change the Volume ID on a pre-existing ISO file? I thought for sure there had to be a command-line tool that would allow for this. But after googling for over an hour I could only find 2 methods to do this.
- The first was simply firing up a GUI, such as ISO Master and changing the Volume ID.
- The second method involved remastering the ISO by copying the files out to a directory, and then essentially recreating a new .iso file.
Neither of these were exactly what I was looking for so I asked the question on serverfault.com. My question: Is there a way to change a .iso files volume id from the command line?. Thankfully someone answered and provided a pretty painless way to manipulate the Volume ID of a .iso file.
NOTE: The Volume ID I’m talking about is this string within a given .iso file, as seen in the example below, or more typically when you mount a CD/DVD in Windows Explorer or Nautilus as the CD/DVD’s label.
1 2 | % isoinfo -d -i /usr/share/virtualbox/VBoxGuestAdditions.iso | grep "Volume id" Volume id: VBOXADDITIONS_4.1.8_75467 |
Solution
According to kupson, the person that answered my question, the Volume ID is stored at offset 0x8028 as a 32 byte ASCII string within the .iso file. With this information it’s pretty straightforward to put together a Perl script to manipulate the .iso file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #!/usr/bin/perl # SCRIPT: chkisovol.pl # DESCRIPTION: Change a given .iso file's Volume ID to something else # references # - http://perldoc.perl.org/functions/open.html # - http://serverfault.com/questions/361474/is-there-a-way-to-change-a-iso-files-volume-id-from-the-command-line use strict; use warnings; # usage die "Use: $0 <iso_file> <new volume id>\n" unless @ARGV == 2; # open file for read/write updates (+<) doesn't clobber file 1st open my $file, "+<", $ARGV[0] or die "Cannot open: $!"; seek $file, 0x8028,0; # write new Volume ID all uppercased (uc). The -32.32s takes care of left # aligning the output, and forcing it into a 32 byte long string printf $file "%-32.32s", uc($ARGV[1]); |
Now for a test.
1 2 3 4 5 6 7 8 9 10 | # Before % isoinfo -d -i ~/netware.iso |grep "Volume id" Volume id: VMWTOOLS # Change the Volume ID % ./chgisovol.pl ~/netware.iso SOMENEWVOL # After isoinfo -d -i ~/netware.iso |grep "Volume id" Volume id: SOMENEWVOL |
Again, thanks to kupson for providing the technique on how to accomplish this.
References
links
- Is there a way to change a .iso files volume id from the command line? – serverfault.com
- How can I change the volume label on DVD ISO’s? – ubuntuforums.org
NOTE: For further details regarding my one-liner blog posts, check out my one-liner style guide primer.