How to Clone a USB Stick Including Partitions in Linux
This post will guide you how to close a USB stick including partitions using dd command in Linux operating systems.
Close USB Stick using dd Command
You can use dd command to copy a file, converting and formatting according to the operands. To close a USB stick in your Linux system, just do the following steps:
#1 insert your USB stick in your system.
#2 You can use some commands like fdisk -l
or lsblk
to identify the device names for your inserted USB stick or disk. see below:
$ fdisk -l
or
$ lsblk
Outputs:
devops@devops-ubuntu:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 140.7M 1 loop /snap/gnome-3-26-1604/92
loop1 7:1 0 14.8M 1 loop /snap/gnome-characters/317
loop2 7:2 0 3.7M 1 loop /snap/gnome-system-monitor/100
loop3 7:3 0 172.5M 1 loop /snap/skype/92
loop4 7:4 0 89M 1 loop /snap/core/7713
loop5 7:5 0 149.9M 1 loop /snap/gnome-3-28-1804/67
loop6 7:6 0 149.9M 1 loop /snap/gnome-3-28-1804/71
loop7 7:7 0 54.5M 1 loop /snap/core18/1192
loop8 7:8 0 140.7M 1 loop /snap/gnome-3-26-1604/90
loop9 7:9 0 956K 1 loop /snap/gnome-logs/73
loop10 7:10 0 956K 1 loop /snap/gnome-logs/81
loop11 7:11 0 132.1M 1 loop /snap/postman/81
loop12 7:12 0 3.7M 1 loop /snap/gnome-system-monitor/95
loop13 7:13 0 35.3M 1 loop /snap/gtk-common-themes/1198
loop14 7:14 0 172.6M 1 loop /snap/skype/96
loop15 7:15 0 88.7M 1 loop /snap/core/7396
loop16 7:16 0 4M 1 loop /snap/gnome-calculator/406
loop17 7:17 0 614.9M 1 loop /snap/intellij-idea-community/172
loop18 7:18 0 42.8M 1 loop /snap/gtk-common-themes/1313
loop19 7:19 0 54.4M 1 loop /snap/core18/1144
loop20 7:20 0 14.8M 1 loop /snap/gnome-characters/296
loop21 7:21 0 4.2M 1 loop /snap/gnome-calculator/501
loop22 7:22 0 615.6M 1 loop /snap/intellij-idea-community/177
loop23 7:23 0 181.1M 1 loop /snap/spotify/36
loop24 7:24 0 132.4M 1 loop /snap/postman/93
sda 8:0 0 50G 0 disk
└─sda1 8:1 0 50G 0 part /
sdb 8:16 0 149.1G 0 disk
├─sdb1 8:17 0 9.8G 0 part
├─sdb2 8:18 0 1K 0 part
├─sdb3 8:19 0 69.5G 0 part /media/devops/UUI
└─sdb5 8:21 0 69.8G 0 part /media/devops/C2F8758EF8758189
sr0 11:0 1 1024M 0 rom
From the above outputs, /dev/sdb
is my USB stick . If you only want to copy and clone /dev/sdb3 from your USB stick into your local disk, and you can type the following dd command:
$ sudo dd if=/dev/sdb3 of=/tmp/myusbstick.img bs=1M
Outputs:
devops@devops-ubuntu:~$ sudo dd if=/dev/sdb3 of=/tmp/myusbstick.img bs=1M
[sudo] password for devops:
6206+0 records in
6205+0 records out
6506414080 bytes (6.5 GB, 6.1 GiB) copied, 2030.91 s, 3.2 MB/s
If you want to get more help about dd command, and you can check man page by running the following command:
$ man dd
or
$ dd --help
Outputs:
devops@devops-ubuntu:/tmp$ dd --help
Usage: dd [OPERAND]...
or: dd OPTION
Copy a file, converting and formatting according to the operands.
bs=BYTES read and write up to BYTES bytes at a time (default: 512);
overrides ibs and obs
cbs=BYTES convert BYTES bytes at a time
conv=CONVS convert the file as per the comma separated symbol list
count=N copy only N input blocks
ibs=BYTES read up to BYTES bytes at a time (default: 512)
if=FILE read from FILE instead of stdin
iflag=FLAGS read as per the comma separated symbol list
obs=BYTES write BYTES bytes at a time (default: 512)
of=FILE write to FILE instead of stdout
oflag=FLAGS write as per the comma separated symbol list
seek=N skip N obs-sized blocks at start of output
skip=N skip N ibs-sized blocks at start of input
status=LEVEL The LEVEL of information to print to stderr;
'none' suppresses everything but error messages,
'noxfer' suppresses the final transfer statistics,
'progress' shows periodic transfer statistics
N and BYTES may be followed by the following multiplicative suffixes:
c =1, w =2, b =512, kB =1000, K =1024, MB =1000*1000, M =1024*1024, xM =M,
GB =1000*1000*1000, G =1024*1024*1024, and so on for T, P, E, Z, Y.
Each CONV symbol may be:
ascii from EBCDIC to ASCII
ebcdic from ASCII to EBCDIC
ibm from ASCII to alternate EBCDIC
block pad newline-terminated records with spaces to cbs-size
unblock replace trailing spaces in cbs-size records with newline
lcase change upper case to lower case
ucase change lower case to upper case
sparse try to seek rather than write the output for NUL input blocks
swab swap every pair of input bytes
sync pad every input block with NULs to ibs-size; when used
with block or unblock, pad with spaces rather than NULs
excl fail if the output file already exists
nocreat do not create the output file
notrunc do not truncate the output file
noerror continue after read errors
fdatasync physically write output file data before finishing
fsync likewise, but also write metadata
Each FLAG symbol may be:
append append mode (makes sense only for output; conv=notrunc suggested)
direct use direct I/O for data
directory fail unless a directory
dsync use synchronized I/O for data
sync likewise, but also for metadata
fullblock accumulate full blocks of input (iflag only)
nonblock use non-blocking I/O
noatime do not update access time
nocache Request to drop cache. See also oflag=sync
noctty do not assign controlling terminal from file
nofollow do not follow symlinks
count_bytes treat 'count=N' as a byte count (iflag only)
skip_bytes treat 'skip=N' as a byte count (iflag only)
seek_bytes treat 'seek=N' as a byte count (oflag only)
Sending a USR1 signal to a running 'dd' process makes it
print I/O statistics to standard error and then resume copying.
Options are:
--help display this help and exit
--version output version information and exit
GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
Full documentation at: <http://www.gnu.org/software/coreutils/dd>
or available locally via: info '(coreutils) dd invocation'
Conclusion
You should know that how to close a USB Stick or disk using dd command in your CentOS/RHEL/Ubuntu Linux.