Skip to content

Instantly share code, notes, and snippets.

@eevmanu
Created October 8, 2018 17:45
Show Gist options
  • Save eevmanu/7787950e6b6016fd4eaf8edf3ae40a9e to your computer and use it in GitHub Desktop.
Save eevmanu/7787950e6b6016fd4eaf8edf3ae40a9e to your computer and use it in GitHub Desktop.
Instructions to write iso file in USB with only commands
  1. Insert USB

  2. Unmount it

# Check where is mounted
$ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda           8:0    1  15,7G  0 disk
└─sda1        8:1    1  15,7G  0 part /media/eevmanu/test1
# Here is mounted in /dev/sda1

$ sudo umount /dev/sda1

$ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda           8:0    1  15,7G  0 disk
└─sda1        8:1    1  15,7G  0 part
  1. Check partitions on USB
$ sudo fdisk -l /dev/sda
Disk /dev/sda: 15,7 GiB, 16811065344 bytes, 32834112 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x1fee81cd

Device     Boot Start      End  Sectors  Size Id Type
/dev/sda1        2048 32834111 32832064 15,7G 83 Linux
  1. Remove partitions
$ sudo fdisk /dev/sda
m (help)
d (delete partition, repeat until delete all partitions)
o (new empty DOS partition table)
w (write)

$ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda           8:0    1  15,7G  0 disk

$ sudo fdisk -l /dev/sda
Disk /dev/sda: 15,7 GiB, 16811065344 bytes, 32834112 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x7c6c8ed6
  1. Write iso in USB
$ sudo dd status=progress if=/path/to/file.iso of=/dev/sda bs=4M conv=fdatasync && sync

$ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda           8:0    1  15,7G  0 disk
├─sda1        8:1    1   1,8G  0 part
└─sda2        8:2    1   2,3M  0 part

$ sudo fdisk -l /dev/sda
Disk /dev/sda: 15,7 GiB, 16811065344 bytes, 32834112 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x663eb4c4

Device     Boot   Start     End Sectors  Size Id Type
/dev/sda1  *          0 3815135 3815136  1,8G  0 Empty
/dev/sda2       3737268 3741939    4672  2,3M ef EFI (FAT-12/16/32)
  1. Mount USB just to verify
$ sudo mkdir /media/eevmanu/test

$ sudo mount /dev/sda1 /media/eevmanu/test
mount: /dev/sda1 is write-protected, mounting read-only

$ ls -la /media/eevmanu/test
  1. Umount USB
$ sudo umount /dev/sda1
  1. Eject USB
sudo eject /dev/sda
@eevmanu
Copy link
Author

eevmanu commented Oct 8, 2018

  • If you want to mount USB with FAT partition
$ sudo mount -t vfat /dev/sda1 /media/eevmanu/test
  • If you want to remove all data in USB
$ sudo dd status=progress if=/dev/zero of=/dev/sda bs=4k && sync
  • If you want to format a FAT partition in USB
$ sudo mkfs.vfat -v -F 32 -n 'test1' /dev/sda1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment