0

At first, I had this USB flash drive with a Ubuntu 14.04 LTS bootable in it. But now, I want to remove/wipe it and create a new bootable of another OS. First, I tried directly:

sudo cat file.iso > /dev/sdb; sync

As suggested in this thread. It didn't worked, returned

bash: /dev/sdb: Permission denied

So, I thought that this was happening because of it already containing a bootable and decide to wipe it. So I just shreded it

sudo shred -v /dev/sdb

After it, It wasn't appearing on the nautilus vertical nav as I sticked it into PC. So I made a file system for it sudo mkfs.ext3 /dev/sdb (I don't know if it's the right type of fs to make it but I was just testing anyway, if it isn't, please warn me about this)

Now, I access it through nautilus and I see that it is indeed empty. I'm trying to make that command I was doing in the beginning sudo cat file.iso > /dev/sdb; sync but still having the same "permission denied" again.

So, two questions on that, did this mkfs was applied correctly or I shouldn't do that? And, how do I solve my problem of making my bootable iso finally? (I don't want to use unetbootin, couldn't install it and I read that it could be done using cat/sync) Thanks in advance.

  • 2
    Possible duplicate of When using sudo with redirection, I get 'permission denied' – steeldriver Apr 1 '16 at 2:52
  • 1
    cat doesn't copy file permissions! So, it won't be bootable! – blade19899 Apr 1 '16 at 6:56
  • May we just ask where did you get this command ? cat is for reading text files, not for writing data to disks – Sergiy Kolodyazhnyy Apr 1 '16 at 6:58
  • @blade19899 EXT4 permissions don't matter at all when you are writing a new filesystem (contained in the ISO image) to the USB stick. It's writing a new filesystem to the USB. The ISO contains a MBR boot sector which gets written to the USB regardless of the executable bit on the ISO according to the hard disk's filesystem. – Wyatt8740 Feb 2 '18 at 21:01
1

The command you try

sudo cat file.iso > /dev/sdb; sync

would, if it does what you expect, completly overwrite the usb drive. So there is no need / no sense to create a ext3 filesystem on it before.

Your mkfs.ext3 command in a sense is fine.

The actually cat command will not work because the sudo command runs as root but the redirection of the output does not. A simple way to get it working is

sudo dd if=file.iso of=/dev/sdb bs=16k; sync

As this doesn't use output redirection there is no problem with sudo.

This is mentioned as the "retro way" in the question you linked to.

2

I have noticed that the other answers all seem to be questioning why you're using cat in this context, and then go on to suggest you use dd.

There's no need. The original command you posted is basically right, it just won't work with sudo (because direction is done by the shell, not by cat, so you don't have permission to do it), so get yourself initially to a root shell.

sudo -i

When you drop to the root prompt, issue your first command.

cat file.iso > /dev/sdb; sync

It'll do exactly what you think, and write the ISO directly to the USB stick, and is probably the quicker and more sensible way to do this than using dd

Don't forget to type

exit

When you've finished with the root shell.

  • 3
    And is even more dangerous than dd because you forgot to tell the OP to get out of the root prompt ASAP. ;-) so sudo sh -c 'cat file.iso > /dev/sdb; sync' would be the 100% correct answer. – Fabby Sep 20 '17 at 20:14
  • I accept your edit graciously :) – CraigE Sep 21 '17 at 9:44
  • And I've just upvoted! :-) – Fabby Sep 22 '17 at 17:47
0

Powerful but dangerous commands

cat and dd can do the trick, to clone from an iso file to a mass storage device, for example a USB flash drive or a memory card.

When you write to a device like this, you will overwrite what was there before, including the partition table and file systems. These commands do what you tell them to do without any questions. So if you tell them to wipe your family pictures, they will do it. And it is a minor typing error away.

Since dd has been used traditionally for this purpose, it has deserved the nicknames 'Disk Destroyer' and 'Data Destroyer', but the same risks apply to cat, when used in this context.

Tools that identify the target device, and have a final checkpoint

For this reason it is better to use tools with help functions to identify the target device, and a final checkpoint, where you have an opportunity to check that you have selected the correct target device, the USB flash drive. This way you can avoid overwriting the internal drive with the operating system and various personal data files or an external drive with personal data files or backup.

  • Cloning tools that produce the same result as cat and dd for this purpose,

    • Startup Disk Creator in Ubuntu 16.04 LTS and newer versions
    • Disks alias gnome-disks
    • mkusb
  • Extracting tools that produce working USB boot drives, that are different (not cloned copies),

    • Rufus (only in Windows)
    • Unetbootin (in Linux, Windows and MacOS)

See this link and links from it for more details,

help.ubuntu.com/community/Installation/FromUSBStick

0

There is Etcher too to do this...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.