In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to use the dd command in the Linux system without damaging your disk. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Make a complete copy of the drive and partition
After careful study, you will find that you can use dd to do a variety of tasks, but its most important function is to deal with disk partitions. Of course, you can use the tar command or the scp command to copy the entire filesystem files from one computer and paste them as is on another computer that has just installed the Linux operating system. However, because those file system archives are not complete image files, the operation of the computer operating system is required as a basis in the process of copying files.
On the other hand, any digital information can be mirrored byte by byte using dd. But whenever and wherever you want to operate on partitions, I'll tell you that early Unix administrators made a joke like this: "dd means disk destroyer" (LCTT translation: dd originally means disk copy disk dump). When using the dd command, if you type even one letter, you may immediately erase all important data from the entire disk drive. Therefore, it is important to pay attention to the spelling format of the command.
Remember: stop and think carefully before pressing enter to execute the dd command.
Basic operation of dd command
Now that you have been properly reminded, we will start with simple things. Suppose you want to create an accurate image of the entire disk data codenamed / dev/sda, and you have inserted an empty disk drive (ideally with the same capacity as the disk drive codenamed / dev/sda). The syntax is simple: if= defines the source drive, and of= defines the file or location where you want to save the data:
# dd if=/dev/sda of=/dev/sdb
The next example is to create an .img image file for the / dev/sda drive, and then save the file to your user account home directory:
# dd if=/dev/sda of=/home/username/sdadisk.img
The above command creates an image file for the entire drive, or you can operate on a single partition on the drive. The following example operates on a single partition of the drive and uses a bs parameter to set the number of bytes for a single copy (4096 in this case). Setting the value of the bs parameter may affect the overall speed of the dd command, and the ideal setting of this parameter depends on your hardware configuration and other considerations.
# dd if=/dev/sda2 of=/home/username/partition2.img bs=4096
Data recovery is very simple: the task can be effectively accomplished by reversing the if and of parameters. In this example, if= uses the image you want to restore, and of= uses the target drive you want to write to the image:
# dd if=sdadisk.img of=/dev/sdb
You can also create and copy tasks at the same time in one command. In the following example, use SSH to create a compressed image file from a remote drive and save the file to your local computer:
# ssh username@54.98.132.10 "dd if=/dev/sda | gzip-1 -" | dd of=backup.gz
You should always test your archives to make sure they work properly. If it is the boot drive you created, paste it into your computer and see if it starts as expected. If it is the data of a normal partition, mount the partition to make sure the files exist and can be accessed properly.
Use dd to erase disk data
Many years ago, a friend of mine who was in charge of the security of the government's overseas embassies once told me that when he was in office, the government would provide every embassy with an official version of the hammer. Why? Once the embassy facility may be occupied by unfriendly personnel, this hammer will be used to destroy all the hard drives.
Why would you do that? Why not just delete the data? You're kidding, right? Everyone knows that deleting files that contain sensitive information from the storage device does not actually remove the data. Unless a hammer is used to completely destroy these storage media, as long as there is enough time and motivation, almost everything can be retrieved from almost any digital storage medium.
However, you can use the dd command to make it very difficult for the bad guys to get your old data. This command takes some time to write millions of zeros in each sector of the / dev/sda1 partition (LCTT translation refers to 0x0 bytes, meaning NUL, not the number 0):
# dd if=/dev/zero of=/dev/sda1
There's a better way. By using / dev/urandom as the source file, you can write random characters on disk:
# dd if=/dev/urandom of=/dev/sda1 monitors dd operations
Since archiving of disks or disk partitions can take a long time, you may need to add a progress viewer to the command. Install the pipe viewer (the installation command is sudo apt install pv on Ubuntu systems), and then combine the pv command with the dd command. With pv, the final command looks like this:
# dd if=/dev/urandom | pv | dd of=/dev/sda1 4pm 14MB 0:00:05 [98kB/s] [] this is the end of the article on "how to use the dd command in a Linux system without damaging your disk". I hope the above content can be helpful to you, so that you can learn more knowledge, if you think the article is good. Please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.