create a bootable USB stick using Linux, using the commandline methods only!

dhubs

Member
Joined
Nov 5, 2024
Messages
33
Reaction score
6
Credits
470
good day dear friends - hello dear linux-user at linux.org


first of all - i am glad to be part of this great forum. This is a aweosome place for idea-sharing for the exchange of knoweldge of experience and - this is helpful for all of us. Thank you so much for your engagement. :)


as i am not sooo familiar i have a little question here:

how to create a bootable USB stick using Linux, using the commandline methods only!

what are the best methods, ways and commands to do this !?

how to create a bootable USB-stick!?

look forward to hear from you


regards dhubs :)
 
Last edited:


how to create a bootable USB-stick!?

:)
There are several means to create a bootable usb from an .iso file on linux.

To end up with a successful bootable usb, one needs to be clear about a few things, some of which are: having a valid verified .iso file, knowing the device name of the usb to which the .iso file is to be copied, and having the software on the linux machine to accomplish the writing to the usb.

The verification of the .iso file can be done using the procedures that the various distros provide and describe. They usually use checksums. Here's an example from linux mint:

To find the name of the usb one can plug it in and run the command:
Code:
lsblk

For example:
Code:
$ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda           8:0    1  14.3G  0 disk
└─sda1        8:1    1  14.3G  0 part
sr0          11:0    1  1024M  0 rom
nvme0n1     259:0    0 465.8G  0 disk
├─nvme0n1p1 259:1    0   476M  0 part /boot/efi
├─nvme0n1p2 259:2    0  14.9G  0 part [SWAP]
└─nvme0n1p3 259:3    0 450.4G  0 part /
It's clear here that sda is the usb device because it's the roughly the correct size, and all the other outputs are the other disks on the machine. The usb is 16 gigabytes, but the lsblk measures in gibibytes, so the 14.3 is a smaller figure. If this is checked on the dmesg output, after the usb has been plugged in, one finds the line showing this:
Code:
[ 6389.508992] sd 9:0:0:0: [sda] 30031872 512-byte logical blocks: (15.4 GB/14.3 GiB)
The actual small differences from the 16 GB to 15.4GB are for other reasons the reader can research.

There a few commands to write the .iso file to the usb. In the following examples the .iso file is called: image.iso, and the usb device is: /dev/sda
Code:
dd if=image.iso of=/dev/sda bs=4M

cat image.iso > /dev/sda

cp image.iso /dev/sda
There are options that can be added to the dd command above like "status=progress", and more so that the command will show some progress on screen in the terminal. See the man page for dd.

The user needs in each case above to wait until the command prompt returns signalling that the writing to the usb has completed. Sometimes one can press the <enter> key to check whether a prompt has become available again if the time of writing seems inordinately long.

There are other commands using pv, genisoimage, xorriso-dd-target, which one can check in the their manpages and online.

EDIT: @wizardfromoz in post #5 below makes the important point that the usb device needs to be unmounted when any of the above commands to write to it are executed.

If the operating system automatically mounts a usb device when it is plugged in, the user must unmount it. If it is automatically mounted, it's often mounted at the mount point:
/media/<user>/
but could be elsewhere.

Whether or not the usb is mounted can be checked with the command:
Code:
 mount
If the device's name, for example /dev/sda, appears in the output of the mount command, (e.g. it could be /dev/sda1), then the device is mounted and it needs sudo or root privileges to unmount it. If the name in the mount output is /dev/sda1 it can be unmounted with:
Code:
# umount /dev/sda1
or it can unmounted from the mount point:
Code:
# umount /media/<user>
where <user> is the name that appears in the filesystem.
It should also be noted that one can only unmount a device when that device is not in use, so the user should not be located in the directory where it is mounted, when unmounting it.

Thanks @wizardfromoz for that important detail. Alas, usbs are not automatically mounted here, so this detail was carelessly omitted originally.
 
Last edited:
good day dear osprey

many thanks for your quick reply with that much of helpful infos and data. Awesome

There are several means to create a bootable usb from an .iso file on linux.

thank you! you are encouraging me!

To end up with a successful bootable usb, one needs to be clear about a few things, some of which are: having a valid verified .iso file, knowing the device name of the usb to which the .iso file is to be copied, and having the software on the linux machine to accomplish the writing to the usb.

well this is great - and doing it on command line is somewhat nice - because here i guess we have full controll over the whole process.

The verification of the .iso file can be done using the procedures that the various distros provide and describe. They usually use checksums. Here's an example from linux mint:

To find the name of the usb one can plug it in and run the command:
Code:
lsblk

thank you - using lsblk is here pretty helpful - i guess. thank you for showing up your example of the lsblk output.


For example:
Code:
$ lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda           8:0    1  14.3G  0 disk
└─sda1        8:1    1  14.3G  0 part
sr0          11:0    1  1024M  0 rom
nvme0n1     259:0    0 465.8G  0 disk
├─nvme0n1p1 259:1    0   476M  0 part /boot/efi
├─nvme0n1p2 259:2    0  14.9G  0 part [SWAP]
└─nvme0n1p3 259:3    0 450.4G  0 part /
It's clear here that sda is the usb device because it's the roughly the correct size, and all the other outputs are the other disks on the machine.

very good: this helps alot! - its cristal clear!

The usb is 16 gigabytes, but the lsblk measures in gibibytes, so the 14.3 is a smaller figure. If this is checked on the dmesg output, after the usb has been plugged in, one finds the line showing this:
Code:
[ 6389.508992] sd 9:0:0:0: [sda] 30031872 512-byte logical blocks: (15.4 GB/14.3 GiB)
The actual small differences from the 16 GB to 15.4GB are for other reasons the reader can research.

There a few commands to write the .iso file to the usb. In the following examples the .iso file is called: image.iso, and the usb device is: /dev/sda
Code:
dd if=image.iso of=/dev/sda bs=4M

cat image.iso > /dev/sda

cp image.iso /dev/sda
There are options that can be added to the dd command above like "status=progress", and more so that the command will show some progress on screen in the terminal. See the man page for dd.

The user needs in each case above to wait until the command prompt returns signalling that the writing to the usb has completed. Sometimes one can press the <enter> key to check whether a prompt has become available again if the time of writing seems inordinately long.

There are other commands using pv, genisoimage, xorriso-dd-target, which one can check in the their manpages and online.

many thanks dear osprey - you have helped me alot.
and i am pretty sure - not alone me.
this is helpful for many others too

have a great day:):)
 
You can use /usr/bin/journalctl -xe right after plugging in your USB flash drive to see what device name it uses and what partitions are recognized on it.

I use /usr/bin/dd to write an ISO image to a flash drive. Always double check your command line arguments so you don't write something to somewhere else by mistake. dd will not forgive.

Signed,

Matthew Campbell
 
Just a mention, elaborating a little on the

dd

command, referred to in #2 and #4

If, as happens with many, your computer is set up so that when you insert a USB stick (should be formatted to FAT32 or similar) it mounts and perhaps opens your file manager to show you the content -

You must first unmount the USB stick before commencing the dd operation.

So, if your stick is /dev/sda and it has one partition /dev/sda1, you should first

Code:
sudo umount /dev/sda1

followed by

Code:
sudo dd if=image.iso of=/dev/sda bs=4M

If you do not unmount first, dd will proceed through the operation and appear to have succeeded, but there will be nothing on the stick.

That occurrence is not described under

man dd

Cheers

Wizard
 

Members online


Top