0

I have a test.iso file not bootable, it is just an image with some files and folders. I write my usb stick with this test.iso file by using ''dd' command.

dd if=/root/test/test.iso of=/dev/sdd bs=4096

Finally I have my desired files onto my usb Stick but I want to add manually other two files but I can't because it is in readonly mode. How could I do this procedure to be possible to write files later? Is it there any parameter for 'dd' to avoid readonly mode or should I create iso file with other parameters?

This is the output of file /root/test/test.iso:

test.iso: ISO 9660 CD-ROM filesystem data 'My-Image'
1
  • the result of command is: test.iso: # ISO 9660 CD-ROM filesystem data 'My-Image' By the way, the future is with USB stick and I will love to deliver my .iso to be burned to usb then possible some files adjustment. I can remake .iso file but this is not a solution.
    – antonio1
    Commented Oct 6, 2023 at 11:59

2 Answers 2

4

Explanation

Your test.iso contains an ISO 9660 filesystem. After dd-ing, your USB drive contains a copy of the filesystem. ISO 9660 is intended for read-only media like CDs and it's by design read-only.

Your Linux can mount ISO 9660 from USB as if it was mounting a CD. There is even a way to mount from a regular file (i.e. you can mount the filesystem from test.iso, we will get to this). ISO 9660 is read-only regardless of where it is mounted from.

In some cases we can write to a USB stick after dd-ing an "iso" to it. This will happen if the "iso" contains a filesystem of another type, or a partition table and such filesystem(s). People tend to call any copy of a block device "iso", even if it contains something else than ISO 9660. They write their "isos" to USBs and there is no problem, so they (and you, I guess, until now) think any "iso" can be mounted for writing. Your file contains ISO 9660 though, it's a real iso, therefore read-only.

And what you did with dd was just reading from test.iso and writing to /dev/sdd. There is no magic in dd. You could do the same with cat or cp (more examples and some insight in this answer: Cloning an SSD with pv command). There are few options in dd that convert data (so the output is not identical to the input), but they surely cannot convert one filesystem type to another.


Solution

To create a modified ISO filesystem you need to work with genisoimage. You don't want this, because a new ISO filesystem would still be read-only.

What you want to do is to create an empty filesystem on your USB. It should be of a type that is designed to be mounted for reading and writing: ext4, ext3, Btrfs, NTFS, FAT32, … Note filesystems have limitations. For Linux only, you should be good with ext4. To use the filesystem also with Windows, NTFS is a good idea. You should know what type of filesystem you want.

In case you no longer have /root/test/test.iso, copy the files from the USB to another location because we are going to wipe the current content of the USB stick.

I assume /dev/sdd is still your USB. Note this can change after reboot or after removing and inserting the USB, so you should not make this assumption automatically. Adjust all commands to your current situation and make sure you're working with the right device (lsblk may be handy).

Unmount the USB (umount /dev/sdd) before you proceed.

A standard procedure to create a filesystem on /dev/sdd is like this:

  1. Use wipefs -a /dev/sdd to start from scratch.
  2. Create a partition table with one big partition (rather than a superfloppy) with fdisk /dev/sdd or gdisk /dev/sdd, or a similar tool.
  3. Create a filesystem within the new partition (/dev/sdd1) with mkfs.<type> (e.g. mkfs.ntfs).

There are tools (often with GUI) that can do this all, e.g. gparted or whatever disk management tool your distro uses.

Then you mount your USB somewhere, like you did when it contained the ISO 9660, but this time you will mount your new empty filesystem capable of being written to. You should also mount the ISO 9660 filesystem from test.iso at another mountpoint (i.e. at some existing empty directory):

mount /root/test/test.iso /another/mountpoint

Finally you copy from /another/mountpoint to your mounted USB. After that you umount /another/mountpoint.

Or, if you no longer have /root/test/test.iso, copy the files you have saved from the USB before wiping it. One way or another the files from test.iso are now on your USB, inside a filesystem that you can write to.

2
  • Thank you for so large and detailed explanation but this is just copy of files to USB. I need to deliver my files via iso image which should be capable of writing after burned. So, is it possible to use mkisofs command to create a special iso image with ext4 file system to write later after burned to usb?
    – antonio1
    Commented Oct 11, 2023 at 6:42
  • @antonio1 Real ISO 9660 cannot be written to after "burning". You can create an image of another filesystem though (e.g. the one you can create by following my answer). You can name the image something.iso, but it won't magically become an iso. Commented Oct 11, 2023 at 6:45
2

It's a matter of the type of the filesystem and the metadata (size) in it.

If test.iso is actually e.g. an ext4 image and it is not full as per its filesystem size yet, you can mount /dev/sdd somewhere and write extra files to the chosen mountpoint (e.g. /mnt).

If the filesystem size is not as large as the size of the drive, you can extend it with the corresponding utility (e.g. resize2fs for ext4) to get even more space.

(For partitioned image, you may want to check out losetup -P.)

If the filesystem type doesn't allow such operation, then you'll probably need to rebuild the image and write the whole new one to the drive. (To state the obvious, if you don't like this, then you should really just format the drive with a filesystem that allows such operation and copy the files in the image over.)

8
  • mounting and copy then remake iso is not a solution. Sometimes when .iso is delivered, and the .iso is large enough as 6Gb it is needed just to edit a file in usb after the .iso was burnt with 'dd' to keep iso label.
    – antonio1
    Commented Oct 6, 2023 at 12:04
  • 1
    @antonio1 as I said, if you need "edit", don't burn, just format
    – Tom Yan
    Commented Oct 6, 2023 at 12:11
  • this is a stupid limit of iso file type and it is not normal in our days technology. The magic command used by me to create iso "mkisofs" should have a different format or some new parameter for files system in such way to not be just readonly after burned.
    – antonio1
    Commented Oct 11, 2023 at 6:46
  • @antonio1 Do not use the "stupidly limited" filesystems then. Even an image of a "smarter" filesystem is not necessarily right for what you want to do because any filesystem has its size; and such images often contain a partition table. And then there are problems like "dd-ing made my USB drive smaller! HLEP!!!". Commented Oct 11, 2023 at 7:00
  • do not take my opinion as fight discuss just try to take it as a problem which should have a solution this is why I called stupidly limit. When iso standard was created USB didn't exist but now we use USB more than CD/DVD so iso standard could be improved to technology evolution. dd-ing is not a problem anymore, I understood that dd is doing its part well, but iso standard could be extended to multiple use. Do you have another solution for 6 Gb iso image to be burned to USB using dd and then to edit a file on USB?
    – antonio1
    Commented Oct 11, 2023 at 7:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .