Solved preparing a usb-stick (with file-system / partitions) on command line - to get it ready for data transfer

Solved issue

dhubs

Member
Joined
Nov 5, 2024
Messages
73
Reaction score
28
Credits
1,027
dear community, :)


this is due to the lack of knowledge and experience with the command line. I am currently pulling my hair - since a simple datatransfer from the notebook to a usb-stick does not work at propperly.

That said: therefore i need to know how to format a storage drive from the terminal.

to be frank: a very helpful thing would be to dive into all that steps - and the options for commands and to get a base knowledge that i (hopefully) am able to use to extrapolate future uses. As said above - i eagerly would like to know how to format in the different file systems such as NTFS, FAT32, EXT4 and oters more.

Background: well i have had some bad experiences since i tried to copy files from hard drive to USB flash drive in tty4 terminal?

imagine - this failed so badly: it was a truely nightmare:

i did a try with this command
Code:
sudo rsync -av --progress /home/ubuntu/Dokumente/ /media/ubuntu/sdb/

this gave back the following:

Code:
              0 100%    0,00kB/s    0:00:00 (xfr#51203, to-chk=5/59613)
Dokumente/new_literatur/theo/petra_/mirjam_0406.jpg
              0 100%    0,00kB/s    0:00:00 (xfr#51204, to-chk=4/59613)
Dokumente/new_literatur/theo/petra_/mirjam_0407.jpg
              0 100%    0,00kB/s    0:00:00 (xfr#51205, to-chk=3/59613)
Dokumente/new_literatur/theo/petra_/mirjam_0408.jpg
              0 100%    0,00kB/s    0:00:00 (xfr#51206, to-chk=2/59613)
Dokumente/new_literatur/theo/petra_/mirjam_0409.jpg
              0 100%    0,00kB/s    0:00:00 (xfr#51207, to-chk=1/59613)
Dokumente/new_literatur/theo/petra_/mirjam_0410.jpg
              0 100%    0,00kB/s    0:00:00 (xfr#51208, to-chk=0/59613)

and subsequently this :
Code:
sent 4.694.015.209 bytes  received 1.024.752 bytes  46.256.551,34 bytes/sec
total size is 4.688.989.106  speedup is 1,00

but well nothing could be found on the usb-stick: i could not find and data on the usb-stick either with

Code:
a. lsblk or
b. sudo fdisk -l

okay - so i concluded to digg deeper here: as said above: a very helpful thing would be to dive into all that steps - and the options for commands and to get a base knowledge that i (hopefully) am able to use to extrapolate future uses. As said above - i eagerly would like to know how to format in the different file systems such as NTFS, FAT32, EXT4:

What if my USB stick (mounted as /media/ubuntu/sdb/) isn’t actually set up with a proper partition and filesystem, or it might be mounted read-only, which would cause errors with the rsync command...


Well - i have to say that i went through the motions but didn’t actually copy the data.

Well - i think that i have to try to figure out ....i need to break it down step by step to get that stick ready for real: i think that its worth to firstly check the drive Setup. So i think that the first step is to check what my USB stick looks like at the low level:

Code:
lsblk

then i think its time for something like sdb and its partitions (e.g., sdb1, sdb2, etc.). Sometimes i only see sdb with no partitions under it, that confirms i need to partition it.

Code:
NAME         MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sdb            8:0    1 15.2G  0 disk
└─sdb1

Or we can check with:

Code:
sudo fdisk -l


afterwards i need to have a closer look for our USB stick there (it might say /dev/sdb).

Step "partition" the Drive (i guess its needed to go forward


If our lsblk or fdisk -l shows sdb without any partitions like sdb1, i think its time to create one:
i can do that with the following step: i ll have to open the Partition Tool:

Code:
sudo fdisk /dev/sdb

with the following
Inside fdisk:

Code:
    Press p → to print the current partition table (it might be empty).
    Press n → to create a new partition.
    Choose primary partition (default is fine).
    Accept all defaults for start/end sectors.
    Press w → to write the changes and exit.

Now i think i should see /dev/sdb1 when i run lsblk.

3.step Create a Filesystem
Assuming i ll have to see /dev/sdb1, format it with a filesystem (like ext4 or vfat but i do not need any Windows compatibility):

For ext4:

Code:
sudo mkfs.ext4 /dev/sdb1

Or for vfat (FAT32) (better if we need compatibility with other systems):

Code:
sudo mkfs.vfat /dev/sdb1


4. Mount the New Partition

Now i think that i have to mount our freshly created filesystem:

Code:
sudo mkdir -p /media/ubuntu/sdb
sudo mount /dev/sdb1 /media/ubuntu/sdb/

and subsequently i ll have to check the contents to see if it’s empty:

Code:
ls -al /media/ubuntu/sdb/

now i am able to conttinue with tne next - thank god with the last step....:)
5. Copy the Files

Now i guess that i have done all the necessary steps to get the usb-stick ready - so subsequently our rsync command should actually work:

Code:
sudo rsync -av --progress /home/ubuntu/Dokumente/ /media/ubuntu/sdb/


dear friends - can you confirm that - are these steps the right ones - so that i hopefully get it done - and am able to copy the data to the usb-stick propperly


love to hear from you
 
Last edited:


You're using sdb when, it looks like, you should be using sdb1.

Try this:

sudo rsync -av --progress /home/ubuntu/Dokumente/ /media/ubuntu/sdb1
 
good evening dear KGill

many thanks for your reply.

You're using sdb when, it looks like, you should be using sdb1.

Try this:

sudo rsync -av --progress /home/ubuntu/Dokumente/ /media/ubuntu/sdb1

Awesome - this worked perfectly

thank you so much!

greetings


update:

if we have with

lsblk
something like so..:

Code:
sda               8:0    0 119,2G  0 disk 
├─sda1            8:1    0     1G  0 part /boot/efi
├─sda2            8:2    0     2G  0 part /boot
└─sda3            8:3    0 116,2G  0 part 
  └─ubuntu--vg-ubuntu--lv
                253:0    0 116,2G  0 lvm  /var/snap/firefox/common/host-hunspell
                                          /
sdb               8:16   1  28,9G  0 disk 
└─sdb1            8:17   1  28,9G  0 part /media/ubuntu/71BE-0530
sr0              11:0    1  1024M  0 rom

my command could be so

Code:
sudo dd bs=4M if=/Videos/eos2.iso of=/dev/sdb1 status=progress oflag=sync

which leads to

Code:
                                                    /
sdb                         8:16   1  28,9G  0 disk 
└─sdb1                      8:17   1  28,9G  0 part /media/ubuntu/EOS_202502
sr0                        11:0    1  1024M  0 rom  
ubuntu@T420s:~$

regarding the sdb and the sdb1

but i guess that if i use sdb it will overwrite the device; ie. the input & all data (inc. metadata) will be written to the new device; so if the source [ISO] was bootable; the sdb device will also be bootable. If we write to a partition (sdb1) then we 'll have a copy there; but any metadata won't exist & even if source was bootable (metadata is hidden inside partition); the copy on sdb1 will NOT be bootable unless we create/have boot code that will perform those functions. conclusio: Both are correct (just different!); it'll depend what we trying to achieve as to which will suit our needs
.
:)
 
Last edited:
Awesome - this worked perfectly

Yeah, I figured it would. You can edit your first post to mark this as solved, though I suppose I can do that for you.

To elaborate, the sdb refers to the disk. The sdb1 refers to the partition on the disk. If you have a second partition, it would be sdb2. This is enumarted up through the alphabet, with sdb, sdc, sde, sdf...

I do not know how that works after you run out of letters.

Also, it depends on how the drive is mounted. You can mount it all sorts of ways. I suspect you're mounting it automatically, which is absolutely fine. If you're mounting other drives, those may assume same name, meaning that sdb1 can refer to another drive entirely under certain circumstances.
 
Hello dear KGIII

many thanks -
To elaborate, the sdb refers to the disk. The sdb1 refers to the partition on the disk. If you have a second partition, it would be sdb2. This is enumarted up through the alphabet, with sdb, sdc, sde, sdf...

awesome : and yes: you have helped me so many times. This is just great.

I am pretty sure that this thread will help others too.

And i am so glad that we have a sub-forum for command-line-questions. This is outstanding1

note; i have marked the thread as "solved"


have a great day :)
greetings
 
@KGIII :-

To elaborate, the sdb refers to the disk. The sdb1 refers to the partition on the disk. If you have a second partition, it would be sdb2. This is enumarted up through the alphabet, with sdb, sdc, sde, sdf...

I do not know how that works after you run out of letters.
You might find this useful in answering that question, David. It's one I've often wondered about myself, but never taken the time to research it.

Now I have....



Mike. ;)
 
@KGIII :-


You might find this useful in answering that question, David. It's one I've often wondered about myself, but never taken the time to research it.

Now I have....



Mike. ;)
Thanks for that link. I've wondered about that, too, though I'm guessing it doesn't come up all that often IRL. :)
 
It's one I've often wondered about myself, but never taken the time to research it.

Oddly, that's exactly how I figured they'd deal with it but I had never taken the time to look it up.

I thought about opening my folder with Linux images and mounting them to see what happened. I had some free time but not that much free time - and not that much motivation.

many thanks

Happy to help. It just happens that I had spare time yesterday, so I was pretty 'productive'.

In this case, I only really skimmed your post and the problem sort of jumped out at me. So, I went back to read your post to make sure. As you're relatively new to Linux, I can see why you'd overlook that and be confused. We were all new users at one point or another.
 


Staff online


Top