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'

2 Answers2

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

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.)

Tom Yan
  • 10,996