Skip to content

Instantly share code, notes, and snippets.

@tatumroaquin
Last active February 28, 2024 13:02
Show Gist options
  • Save tatumroaquin/6c66efc3d66330f23e119a0e45bbec0a to your computer and use it in GitHub Desktop.
Save tatumroaquin/6c66efc3d66330f23e119a0e45bbec0a to your computer and use it in GitHub Desktop.
bootable USB guide using command line

How to make a bootable USB

Requirements

  1. Any USB drive, preferably SanDisk (Cruzer Edge/Switch)
  2. Computer running Linux / Windows 10

Linux

  1. Insert the USB to your linux file system
  2. Execute umount /dev/sdX if it is auto-mounted.
  3. Use the dd utility to copy your image to the use device.
dd if=file.iso of=/dev/sdX bs=1M status=progress && sync
  1. Proceed by booting to your USB device and doing your intended task.

Windows 10

  • Many third party software exist for the purpose of making bootable USB drives.
  • This guide uses Windows native methods of crafting a bootable USB.

Powershell Method

1. Press Meta/Win+R and type powershell

2. Ctrl+Shift+Enter execute powershell in administrator mode.

3. Delete all the files in the USB.

Get-Disk | Where BusType -eq 'USB'
Clear-Disk -Number 1 -RemoveData

4. Partition the USB drive.

New-Partition -DiskNumber 1 -UseMaximumSize -AssignDriveLetter

5. Format USB drive to NTFS or FAT32

Get-Volume
Format-Volume -DriveLetter F -FileSystem [NTFS/FAT32]

Use NTFS for BIOS boot and FAT32 for UEFI boot

6. Mount and read the ISO file using the CD drive.

Mount-DiskImage -ImagePath "C:\path\to\iso"
Get-CimInstance Win32_LogicalDisk | ?{ $_.DriveType -eq 5} | select DeviceID

7. Clone the contents of the ISO to your USB drive.

xcopy G:\*.* F:\ /e /f /h
exit

In this example G: is the CD drive, and F: is the destination USB


Diskpart Method

1. Select and clean the USB partitions

list disk
select disk <number>
clean

2. Creating the primary partition:

In UEFI boot:
create partition primary
list partition
select partition 1
In BIOS boot:
list disk
select disk <number>
clean
convert mbr

create partition primary
list partition
select partition 1
active

3. Format the USB to NTFS or FAT32.

format fs=[ntfs/fat32] quick

4. Assign a drive letter to the USB drive.

assign [letter=F]
exit

5. Mounting the ISO file.

Mount the ISO file using the context menu.
right-click file.iso
select "Mount"

OR

Mount the ISO file using the CLI interface.
  • Choose one of the following:
start path/to/iso
explorer path/to/iso
  • Either one of these commands will execute the iso file in Windows 10 to emulate a double-click.
  • If the default behaviour is edited, the second command may be used to mount the ISO to G:

6. Optional: Create a USB bootsector partition (for BIOS ONLY)

G:
cd BOOT
bootsect.exe /nt60 F:

7. Clone the ISO files to the USB drive.

xcopy G:\*.* F:\ /e /f /h
exit

8. Copy the ISO name/label to the drive label.

label f:ARCH_YYYYMM
@psadi
Copy link

psadi commented Mar 5, 2022

Thanks for the detailed gist, i found it useful

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