How does dd differ from cp

Hi Neville,

I don’t quite understand. If I dd MX25.ISO to a USB stick won’t I just end up with the file MX25.ISO on the USB drive. How does that make it a live USB? Do you need some parameters with the dd command to make the ISO ready to boot?

Thanks,
Howard

Good question Howard,

A iso file is a file containing an image of a whole filesystem.
When you give dd an iso file as its input, it copies the CONTENT of the iso file to usb drive.
dd always copies content, whether its input be a partition or a file.

Unix utilities like cp copy files … they need a filesystem at the destination to receive the file. A file can only exist in a filesystem . Its content can exist anywhere, eg on a raw device like a usb or a magnetic tape. dd is old, it comes from the days of writing on raw devices that do not have a filesystem

An iso file was originally designed to boot from a CD… the CD drive supplied the boot loader.
When USB drives appeared, they added a bootloader to iso files and called them hybrid iso files.
Today most iso files are hybrid. If you encounter an old iso file that is not hybrid, it will boot from a CD but not from a USB drive. There is a program called isohybrid which you can use to make it hybrid.

Two things I hate about “dd” (and I’ve been using it for decades) :

  1. so easy to output to the wrong device - now that’s a user mistake for sure - but Balena Etcher asks a bunch of things before it does anything destructive - when you press enter on a dd command - only a second later - the damage is mostly done.
  2. There’s no progress indicator - not only that - but - you need to run sync after dd - because while it says its finished - it REALLY HAS NOT! I’ve run it with --progress in the past - and it finishes - but I run “sync” after that and that runs for minutes…

Not especially - so long as the ISO image is bootable (should have an /isolinux folder in the ISO filesystem).
e.g. write lmde-7-cinnamon-64bit.iso ISO to a USB flash drive at /dev/sdc :
dd if=lmde-7-cinnamon-64bit.iso of=/dev/sdc bs=4M

“bs=4M” is the blocksize… sometimes a higher number will seem to make it go faster - I dunno… that could be anecdotal…

Also - to know what your freshly inserted USB drive is - you can run either “sudo fdisk -l” or “sudo lsblk” - I find the output from the latter easier to follow…

Note : you ALWAYS use the device, not any of the partitions - when flashing an ISO onto other media - i.e.

╰─➤  lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda      8:0    0 465.8G  0 disk
├─sda1   8:1    0   512M  0 part /boot/firmware
└─sda2   8:2    0 465.3G  0 part /
sdb      8:16   0   5.5T  0 disk
└─sdb1   8:17   0   5.5T  0 part /mnt/BUNGER00
zram0  253:0    0   9.5G  0 disk [SWAP]

if I was going to write to the 2nd disk - it would be “/dev/sda” not “/dev/sdb1” - having said that - there maybe occasions when you want output dd to a specific partition - but - not when flashing a bootable ISO to a USB thumb drive…

The newer versions have progress

Modern GNU dd (Linux)

If you are using GNU Coreutils 8.24 or later, native progress tracking is built-in. [1]

bash

sudo dd if=/dev/source_device of=/dev/target_device status=progress

You can avoid having to sync by putting
conv=fsync
That forces dd to empty its buffers before returning the prompt.

Those options should be the default.

Quite honestly, I can not remember the last time I used the dd command. I use the Nemo file manager that comes with Mint to perform my file copies. In the drop down menu for an ISO file is an option called “Make bootable USB stick”.

Using this option making an USB boot drive from an ISO file is almost is fool proof.

Using that “Make bootable usb stick” button is probably a good thing to recommend for beginners.
I assume it asks for

  • name of iso file
  • device name of usb stick

So you can still make the same error as with dd and write on the wrong device.

Since the “Make boot-able USB stick” option is in the ISO file’s context menu, the only risk would be to choose the wrong destination drive, but I’d have to use the option to know what safeguards against that possibility are in place …

Ernie

I think it probable asks twice… I dont have Nemo.

People fly from dd, but you can make the same silly mistake with lots of utilities … eg) cp, rsync, rm… none of them ask.

Agree, the only solution is vigilance and double-checking your choices before committing any change/command …

Ernie

It would be very hard to mistake with Nemo. The drop down menu for making a bootable USB only comes up if you right click on an ISO file. Then the next screen comes up.

Looks like the only error you could make would be if you had 2 USB drives attached and selected the wrong one.

With laptop it’s better when you have an nvme SSD and sdX for USB.

What about USB driven external drives?
Can it tell those from flash drives?

I’ve found that depends on the use case and distribution…

Sometimes an SD Card will appear as /dev/mmcblk0 (that could be wrong) or /dev/sda, /dev/sdb et cetera… I prefer it when the device indicates what type of storage :
/dev/sda
/dev/nvme
/dev/mmcblk

Here’s my Pi3 (I can jump to it via from the internet vi my home wifi router and Pi4 over SSH) :

╭─x@telesto ~
╰─➤  lsblk
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
mmcblk0     179:0    0 59.5G  0 disk
├─mmcblk0p1 179:1    0 42.9M  0 part /boot
└─mmcblk0p2 179:2    0 59.4G  0 part /

My main Pi (4) system that I keep on 24x7 (that I use as a jumphost) doesn’t have an SD Card - it boots off a USB 3 SSD, and has a 6 TB USB hard drive mounted (for backups) :

╭─x@frambo /mnt/BARGEARSE/BNZ/LINUXISO/LinuxMint
╰─➤  lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda      8:0    0 465.8G  0 disk
├─sda1   8:1    0   512M  0 part /boot/firmware
└─sda2   8:2    0 465.3G  0 part /
sdb      8:16   0   5.5T  0 disk
└─sdb1   8:17   0   5.5T  0 part /mnt/BUNGER00
zram0  253:0    0   9.5G  0 disk [SWAP]

The reason I like things like Balena Etcher is that it actually presents the Vendor string - e.g. “Sandisk 250 GB” as a target - so it’s more human friendly - it does also offer the option of e.g. “KINGSTON SNVS1000GB NVMe” - i.e. the main system disk … So it’s easier to NOT make an unforgiving mistake - yeah - you still choose the internal system desk - “Kingston SNVS1000GB” - but - even after that - it presents you with an “Are you sure?” and then it prompts you for your password to run it with sudo…

So if you do manage to screw up and write to the wrong device - the system did EVERYTHING it could to prevent that in several steps - however “sudo dd if=file.iso of=/dev/sda” is instant and unforving - you might have intended to do the second disk “sudo dd if=file.iso /dev/sdb” - but you got one character wrong - and your system is hosed - so new users should probably not be using dd…

Here’s my Lenovo ThinkPad with Ubuntu 24.04 (I hadn’t realised I’d left it powered up while away) :

╭─x@fenrixii ~
╰─➤  lsblk --output NAME,VENDOR,MODEL |grep -v loop
NAME                        VENDOR MODEL
nvme0n1                            KINGSTON SNVS1000GB
├─nvme0n1p1
├─nvme0n1p2
└─nvme0n1p3
  └─dm_crypt-0
    └─ubuntu--vg-ubuntu--lv

The single dd command you run with sudo - is expedient - but fraught with risk.

And earlier - you (@nevj) mentioned --progress and --conv=fsync - I’ve found they aren’t 100% reliable - I have used both those - and - I’ve seen a “dd” finish (too quickly to be 100% complete) and run “sync” anyway before removing the drive - and it’s taken minutes - so there’s still some background writing going on…

So I’ll keep using balena etcher because it presents a confirmation before writing, and, it has a reliable progress indicator…

And I usually use the RaspberryPi Imager tool for writing an O/S to a device (SD Card or USB drive) - it’s very useful - similar to Balena Etcher but even more sophisticated - you can select boot options (to TTY or DE), WiFi network, user name, and SSH key - which it will do when writing the image - and I’ve used it to do both Raspbian (Debian) and Ubuntu and it works… This versus using “dd” to write an IMG file to SD-Card, ejecting it, re-inserting it and mounting it, find the “/boot/” folder (probably on /dev/sdb1) and editing a few files here and there, and then creating a file to enable sshd (touch /media/x/SD-Card/boot/ssh) and maybe editing the WiFi parameters file - Pi imager does all that for you at “the time of writing”…

30 years ago - I mostly used DD to get a tar file from a raw “tar” floppy disk, or magnetic tape… not always necessary with a tape (and slow) - but e.g. vendor ships something on a floppy - insert the floppy into a Windows PC - and shows “unformatted”… Insert it in a UNIX or Linux system - and “tar tvf /dev/fd0” (if your floppy is “fd0” - it’s been so long I don’t remember the floppy device name format) to get a content list - or - easier still “dd if=/dev/fd0 of=/home/dan/floppy-image.tar” - then I could put that tar file on a network shared drive…

I can’t remember if Balena Etcher has a Windows version (most Windows users use Rufus - and Windows doesn’t even have “dd” naturally enough), but it does have a MacOS version, and RaspberryPi Imager (from the RPi foundation) is available on Linux desktop, MacOs and Windows…

No, it can not.
I attached a USB drive and a USB attached HDD and the boot maker will let me select either one for output. The window does show the device selected.