未加星标

Linux copy and clone USB stick including partitions command

字体大小 | |
[系统(linux) 所属分类 系统(linux) | 发布者 店小二04 | 时间 2018 | 作者 红领巾 ] 0人收藏点击收藏

I need to copy and clone existing data from a USB stick. How do I clone a bootable USB key/pen drive on linux? How do I clone a USB stick including partitions on Linux operating system?

You can easily clone USB flash drives on Linux. It is useful for backups and other purposes such as cloning USB for installation. You need to use the dd command. It will clone a bootable USB (or USB hard disk) for backup. This page shows how to copy and clone USB stick on Linux operating systems.

Linux copy and clone USB stick command

dd command used for copy a file, converting and formatting according to the operands. The procedure clone a USB stick including partitions is as follows on Linux:

Insert USB disk/stick or pen drive Open the terminal application Find out your USB disk/stick name using the lsblk command Run dd command as: dd if=/dev/usb/disk/sdX of=/path/to/backup.img bs=4M

Let us see all commands in details.

Copy and clone a USB stick including partitions on Linux

Naturally, the first step is to find out your USB stick name on Linux. Selecting the wrong device name can result in data loss.

Find USB disk name on Linux

Simply run the dmesg command after inserting the USB stick or key:

$ dmesg

Filter out info using thegrep command:

$ dmesg | grep -i usb $ dmesg | grep -i 'attached'

Sample outputs:

[ 5.793647] sd 0:0:0:0: Attached scsi generic sg0 type 0 [ 5.795335] sd 0:0:0:0: [sda] Attached SCSI disk [ 7.421446] sd 6:0:0:0: Attached scsi generic sg1 type 0 [ 7.438791] sd 6:0:0:0: [sdb] Attached SCSI removable disk [ 334.349540] sd 6:0:0:0: Attached scsi generic sg1 type 0 [ 334.365272] sd 6:0:0:0: [sdb] Attached SCSI removable disk

/dev/sdb is my usb stick. Additionally, one can run the following lsblk command lists information about all available or the specified block devices :

$ lsblk

OR use the fdisk command to list the Linux disk partition tables for the specified devices and its size:

$ sudo fdisk /dev/sdb
Linux copy and clone USB stick including partitions command
Use dd command to copy and clone a usb stick on Linux

The syntax is as follows:

dd if=/dev/sdX of=/path/to/file.img bs=SIZE

To clone a usb stick named /dev/sdb to ~/usb-opensuse-current.img, run:

$ sudo dd if=/dev/sdv ~/usb-opensuse-current.img bs=4M

You can show progress copy bar with status option for the dd command :

$ sudo dd if=/dev/sdv ~/usb-opensuse-current.img bs=4M status=progress
Linux copy and clone USB stick including partitions command

Verify new file with the ls command:

$ ls -i ~/*.img

You may want to change file permission too as the sudo command created the image with root:root. Use the chown command as follows:

$ sudo chown vivek:users ~/usb-opensuse-current.img $ ls -l ~/usb-opensuse-current.img

Optional: Copy file usb-opensuse-current.img to NAS server or external media

Be sure that you copy ~/usb-opensuse-current.img somewhere safe. I usually like to keep on a FreeNAS or Linux NAS server using the scp command:

$ scp ~/usb-opensuse-current.img user@IP:/path/to/safe/

OR

$ scp ~/usb-opensuse-current.img vivek@server1.cyberciti.biz:~/backups/x230/usb/

Conclusion

You just learned how to clone a USB stick including partitions on Linux operating system using the dd command. For more info see man pages by typing the following man command:

man dd man lsblk man dmesg man fdisk

本文系统(linux)相关术语:linux系统 鸟哥的linux私房菜 linux命令大全 linux操作系统

tags: USB,command,usb,stick,Linux,clone,img,dd,current,disk,opensuse
分页:12
转载请注明
本文标题:Linux copy and clone USB stick including partitions command
本站链接:https://www.codesec.net/view/586955.html


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 系统(linux) | 评论(0) | 阅读(96)