How to create a bootable USB Drive without any software and automate this process?

Hi geeks welcome to another tutorial and in this, I will drive you through some steps to automate the process of creating a bootable USB drive and that too without a need of any other software. All you need is a notepad to write down your batch script.

If you are familiar with changing Operating System (OS) of a system, only hard part is to create a bootable USB drive. Mostly after this process we just need to click next again and again to install most of the operating system (especially windows). But in case of linux you need to have some understanding on its directory structure to install them.

Bootable USBs are used for operating system installation, so your system will know to boot into the installer, and the installer will essentially unpack a large compressed file containing the actual operating system’s resources.

In general, booting is the process of making a pen-drive into a bootable medium and this can be done generally in these two ways :

  • You can go to cmd (command prompt) and write commands to boot the pen-drive manually.
  • You can use some third party software for booting.

Today we will discuss the third option. I was bored of doing the same thing again and again manually to boot pen-drives, some of my friends suggested me to use some software. But it makes no sense to use a third party software even when this task can be done with a small code, so I decided to automate the same process which I used to boot the pen-drive manually and I came up with this simple code.

You don’t need any compilers or IDKs to run this program, this is done in batch script and you just need a text editor (Notepad).

Okay let’s start with a simple two-step process to create a bootable USB drive:

  1. Open the notepad in your system and start writing the below code.
    
    @echo off
    (echo diskpart /s “%appdata%\cmd.txt” )>”%appdata%\boot.bat”
    (echo list disk
    echo select disk 1
    echo clean
    echo create partition primary
    echo format fs ntfs Label=”SummA” quick
    echo active)>”%appdata%\cmd.txt”
    call “%appdata%\boot.bat”
    pause
    del /F /Q /S “%appdata%\cmd.txt”
    del /F /Q /S “%appdata%\boot.bat”
    
    
  2. And now save it by pressing ctrl+S and select .bat as file extension.

Are you going to just copy past the above code? Just type the whole code by yourself, trust me you will get some ideas while typing it.


And now GEEK section :

Anyone can search online for this kind of code and just copy past it. But we are coding geeks, we understand what we do right!!. I’ll be doing a series of articles on how to start programming with batch script from scratch soon. But for now I’ll just tell you what this code is doing.

  • First it creates 2 files. First file is created with .bat extension which opens the Diskpart and a text file that contains the commands needed to boot a pen-drive is created.
  • Both of them are created in a temporary location.
  • Then the created .bat file is called, now this file opens the Diskpart with administrator privilege and starts reading the text file (second file).
  • The Boot.bat file reads the text file line by line and sends them as commands to the diskpart to boot the pen-drive.
  • Once when the process is done, both files are deleted, this is kind of self-destruction after completing the task.

NOTE : Please make sure that you have plugged in only one pen-drive which need to be booted while running this program, make sure that you backup your data from pendrive before running this program and also be sure that your pendrive is the disk 1, If not change disk “1” to the number it shows you in Diskpart’s list disk command.

To Do that go to your command prompt (open run and type cmd) and enter “diskpart”, a new cmd with admin privilage prompts there type “list disk” to list all the available disks of the system check which one is your pendrive by comparing the disk size and check the disk number and change it in the code (line no. 4).

This is my first post on Codingeek please share your feedback and suggestion, I’ll be more than happy to hear them. Happy coding !! 🙂

Recommended -

Subscribe
Notify of
guest
7 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Naveen
Naveen
7 years ago

Its been very useful om prakash…. Thanks… Keep doing..

om prakash
om prakash
7 years ago
Reply to  Naveen

Thank you dude 🙂 will be posting more cool stuffs stay tuned!

santosh
santosh
7 years ago

Pretty cool stuff om….way to go…….

om prakash
om prakash
7 years ago
Reply to  santosh

Thank you buddy !!

Kit Krishna
Kit Krishna
7 years ago

Superb bro this is great..

om prakash
om prakash
7 years ago
Reply to  Kit Krishna

Thank you bro, let us know if you face any issues while trying this !! happy coding 🙂

eddy
eddy
2 years ago

Thanks! very useful! instead of ntfs can we put fat32 in place of that to be compatible with uefi?

7
0
Would love your thoughts, please comment.x
()
x
Index