5

How to create a bootable Ubuntu USB flash drive from terminal?

Why do guys here use umount first? I assume USB flash drive should be formatted first, so does umount format the disk, or just detach mounted device so it can be safely removed if another process isn't using it?

muru
  • 197,895
  • 55
  • 485
  • 740
mk1024
  • 669

2 Answers2

10

umount un-mounts file systems.

This is needed here because it would be bad if you overwrote the partition while it is still mounted and possibly accessed by any application. You'd get errors.

See man umount for more information about the command.

Byte Commander
  • 107,489
  • Yes, but why did they in linked post unmounted plugged device, made new folder with the same name they deleted, and used dd after all? Were eventually existed data from that device lost? Was it shortcut for formatting? - that is what confuses me. – mk1024 Mar 25 '18 at 13:13
  • I'm curious if writing to an unmounted device also bypasses write cache – ravery Mar 25 '18 at 13:13
  • 3
    @MilosKalicanin they didn't delete or make any new folder. /dev/sd? is the name of the device. no formating is necessary, dd is a copy program, similar to "burning a CD". the formating, file structure etc is copied from the image file used as input. – ravery Mar 25 '18 at 13:17
7

Please correct me if I do not use the most appropriate terms here.

Within Linux/Ubuntu all devices are represented as files under the directory /dev. In the first answer of the linked question umount is used to detach certain device from the file-system in use, thus you can manipulate the entire device as pure file (/dev/sd?) without limitations. Then the command dd is used to copy the content of the input file image.iso file as content of the output file /dev/sd?.

Here I found a better explanation provided by Colin Ian King:

If you write data to the 'raw' block device while a filesystem on this device is still mounted then the kernel will have problems when updating the trashed file system. For example, the kernel will periodically flush dirty data back to the mounted device, or may do file lookups. If the underlying block device has been fundamentally changed then the kernel will find issues this can lead too kernel OOPs messages or even halt on BUG_ON() checks. So always unmount the filesystem before changing the underlying data on the block device.

pa4080
  • 29,831
  • "They detached certain device using umount in order to manipulate the entire device without limitations." - That's exactly how I understood. – mk1024 Mar 25 '18 at 13:41