How to resize an IMG file's partition info?

5,163

Solution 1

You could simply re-create the image "from scratch" with mkisofs.

$ mkisofs -o new_image_name /path/to/the/mounted/dvd

If you don't have the CD-ROM available anymore, loop-mount the iso image with:

$ sudo mount -o loop /media/disk/linux.iso /path/to/the/mounted/dvd

(And don't forget to unmount it.)

This will not copy boot information from the DVD. If you need that, a little more work is necessary to extract to boot information and pass it as an option to mkisofs.

Solution 2

ISO is short for iso9660, the filesystem type used on CDROMs. Filesystems do not know or care about partitions, and cdroms do not have partitions. Since you copied a partition, then it likely is not an iso9660 filesystem at all, so you have named the file incorrectly. Instead of an iso image, you have an image of whatever filesystem was in that partition. How to resize it depends on what the type of filesystem is. If it is an ext[234] filesystem, then you can resize it with resize2fs.

Share:
5,163

Related videos on Youtube

Joshua Robison
Author by

Joshua Robison

Updated on September 18, 2022

Comments

  • Joshua Robison
    Joshua Robison over 1 year

    I made an ISO this way: sudo partimage save /dev/sdc1 /media/56AE8240AE82191F/Backup/xfcefat.iso

    The resulting iso file is very small but when mounted I see that it has correctly preserved the partition information.

    The problem is my partition was 8gigs and only had like 100mb of data on it.

    I want to fix the partition information on the iso and tell it to think it is only a 500mb partition.

    How can I shrink it's partition information?

    If it was a usb drive I could do this with gparted and shrink it just fine. But this is an iso file raw copy clone of my disk.

    • boehj
      boehj almost 13 years
      Do you get the same result if you do cat /dev/sdc2 > /media/disk/linux.iso?
    • jlliagre
      jlliagre almost 13 years
      How did you create sdc2 content ?
    • jlliagre
      jlliagre almost 13 years
      You didn't create an ISO in the first place.
  • Joshua Robison
    Joshua Robison almost 13 years
    I rephrased the question. I don't think it was understandable. I need to resize the iso's partition information to make it think it is a smaller partition because it only has a small amount of data on it.
  • Joshua Robison
    Joshua Robison almost 13 years
    your answer will not work because I need to preserve the boot information.
  • Mat
    Mat almost 13 years
    you radically changed the question from a 8G ISO dumped with dd that only had 2G data, to a few hundred meg image... I'm not even sure I understand your new question
  • Joshua Robison
    Joshua Robison almost 13 years
    by resize the iso, i always meant make the partition info on it smaller.i just didnt know how to say it. im learning as i go.
  • Joshua Robison
    Joshua Robison almost 13 years
    i need to do this if i want to be able to quick clone my drive bootable on a smaller disk any time i want to. messing with boot loader info is not an option. what do big schools do who want linux on all their machines? they're not gonna install it on each individual one. their gonna clone one drive on all. and some computers drives are smaller. what to do then? i cant believe im the first one trying to do this? they're not gonna go back and install bootloaders on each individual one either.
  • Joshua Robison
    Joshua Robison almost 13 years
    one is fat32. one is ext3. when they are named .iso they mount by right clicking on them. iso or img, i will try out resize2fs
  • Joshua Robison
    Joshua Robison almost 13 years
    wait a second resize2fs does not resize img file's partition info at all. it only resizes real media like usb drives or HDs O_o that would be useless to me.
  • psusi
    psusi almost 13 years
    @Joshua Robison no, it reiszes filesystems. Once again, filesystems do not know or care about partitions. A partition is only a container that may or may not contain a filesystem.
  • Joshua Robison
    Joshua Robison almost 13 years
    no matter what you say, resize2fs is not going to resize my img files, filesystem smilesystem, so why did you post it as an answer to my question about how to resize an IMG FILE'S partition info?
  • psusi
    psusi almost 13 years
    @Joshua Robison, it most certainly will, IF it is an image of an ext[234] filesystem.
  • Joshua Robison
    Joshua Robison almost 13 years
    @psusi If you are correct then you should be able to post a command line example of how to resize an img file's partition information with resize2fs.
  • psusi
    psusi almost 13 years
    @Joshua Robison again, the image file does not have "partition information". To resize the filesystem in the image, you run resize2fs /path/to/file size where size is how big you want it to be.
  • Joshua Robison
    Joshua Robison almost 13 years
    @psusi, by "partition information" i am referring to how a mounted iso/img image of my partition willdisplay that it only has 100mb of files in it and 1gig of free space
  • Joshua Robison
    Joshua Robison almost 13 years
    @psusi if you dd if=/dev/sdd of=/media/diskname/file.iso the resulting iso will save all your partition table info, so you either have no idea what you are talking about or you are completely misunderstanding me.
  • psusi
    psusi almost 13 years
    @Joshua Robison again, that is not an iso. You have an image of a filesystem, so you use a filesystem resizer to resize it. I don't understand why this isn't sinking in.