In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article is about how to use the dd command in Linux. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Dd
After actual measurement, the fastest way to back up two disks directly under Linux is to use
Do not exceed 5000k that can be increased under dd if=/dev/sda of=/dev/sdb bs=30000k% IDE environment under 30m SATA environment.
The hard disk mirror backup of 40g is completed in 25 minutes and starts smoothly.
1 disk free space cleared # dd if=/dev/zero of=/tmp/delete.me bs=8M; rm delete.me2 make image # dd if=/dev/sdb conv=sync,noerror bs=64K | gzip-c > ~ / mybackup.img.gz3 save partition format # fdisk-l / dev/sdb > ~ / sdb_fdisk.info4 restore method # gunzip-c ~ / mybackup.img.gz | dd of=/dev/sdb conv=sync,noerror bs=64K
Use the linux command dd to create files of a certain size.
Linux create file command: dd command
Copies the specified input file to the specified output file, and the format can be converted during the copy process. Syntax:
CODE: [Copy to clipboard] dd (option)
QUOTE:
If = enter the file (or device name).
Of = output file (or device name).
Ibs = bytes reads bytes bytes at a time, that is, the number of bytes read into the buffer.
Skip = blocks skips the ibs*blocks block at the beginning of the read-in buffer.
Obs = bytes writes bytes bytes at a time, that is, the number of bytes written to the buffer.
Bs = bytes also sets the number of bytes in the read / write buffer (equal to setting obs and obs).
Cbs = bytes converts bytes bytes at once.
Count = blocks copies only the input blocks blocks.
Conv = ASCII converts EBCDIC codes to ASCII codes.
Conv = ebcdic converts ASCII codes to EBCDIC codes.
Conv = ibm converts ASCII codes to alternate EBCDIC codes.
Conv = blick converts variable bits to fixed characters.
Conv = ublock converts the fixtures into motions.
Conv = ucase changes letters from lowercase to uppercase.
Conv = lcase changes letters from uppercase to lowercase.
Conv = notrunc does not truncate the output file.
Conv = swab swaps each pair of input bytes.
Conv = noerror does not stop processing when there is an error.
Conv = sync adjusts the size of each input record to the size of ibs (filled with ibs).
Fdformat command
Low-level formatted floppy disk.
Example:
Create an empty file of 100m
Dd if=/dev/zero of=hello.txt bs=100M count=1
The above is the use of the linux create file command: dd.
two。 Case analysis
2.1. Data backup and recovery
2.1.1 full disk data backup and recovery
Backup
Back up the local / dev/hdx entire disk to / dev/hdy: dd if=/dev/hdx of=/dev/hdy
Back up the full / dev/hdx data to the image file in the specified path: dd if=/dev/hdx of=/path/to/image
Back up / dev/hdx the whole data, compress it with gzip tool and save it to the specified path: dd if=/dev/hdx | gzip
> / path/to/image.gz
Restore
Restore backup files to the specified disk: dd if=/path/to/image of=/dev/hdx
Restore the compressed backup files to the specified disk: gzip-dc / path/to/image.gz | dd of=/dev/hdx
2.1.2. Remote backup with netcat
Execute this command on the source host to back up / dev/hda:dd if=/dev/hda bs=16065b | netcat
< targethost-IP >1234 execute this command on the destination host to receive data and write / dev/hdc:netcat-l-p 1234 | dd of=/dev/hdc
Bs=16065b
The following two instructions are changes in the destination host instructions that use bzip2 gzip to compress the data and save the backup file in the
Front directory:
Netcat-l-p 1234 | bzip2 > partition.img
Netcat-l-p 1234 | gzip > partition.img
2.1.3. Backup MBR
Backup:
Backup the MBR information of the 512Byte size at the beginning of the disk to the specified file: dd if=/dev/hdx of=/path/to/image
Count=1 bs=512
Restore:
Write the backup MBR information to the beginning of the disk: dd if=/path/to/image of=/dev/hdx
2.1.4. Backup floppy disk
Back up the floppy drive data to the disk.img file in the current directory: dd if=/dev/fd0 of=disk.img count=1 bs=1440k
2.1.5. Copy memory data to hard disk
Copy the data in memory to the mem.bin file in the root directory: dd if=/dev/mem of=/root/mem.bin
Bs=1024
2.1.6. Copy an iso image from a CD
Copy the CD data to the root folder and save it as a cd.iso file: dd if=/dev/cdrom of=/root/cd.iso
2.2. Increase Swap partition file size
Create a file large enough (256m in this case): dd if=/dev/zero of=/swapfile bs=1024 count=262144
Change this file to a swap file: mkswap / swapfile
Enable the swap file: swapon / swapfile
To load the swap file automatically every time you boot, you need to add a line to the / etc/fstab file: / swapfile swap
Swap defaults 0 0
2.3. Destroy disk data
Fill the hard drive with random data: dd if=/dev/urandom of=/dev/hda1
It can be used to destroy data in some necessary situations. After performing this operation, / dev/hda1 will not be able to mount, create and copy operations
Unable to execute.
2.4 disk Management
2.4.1. Get the most appropriate block size
By comparing the command execution time shown in the dd instruction output, you can determine the best block size size for the system:
Dd if=/dev/zero bs=1024 count=1000000 of=/root/1Gb.filedd if=/dev/zero bs=2048 count=500000 of=/root/1Gb.file
Dd if=/dev/zero bs=4096 count=250000 of=/root/1Gb.file
Dd if=/dev/zero bs=8192 count=125000 of=/root/1Gb.file
2.4.2 Test the read and write speed of the hard disk
The read / write speed of the test hard disk can be calculated from the execution time of the two command outputs:
Dd if=/root/1Gb.file bs=64k | dd of=/dev/null
Hdd if=/dev/zero of=/root/1Gb.file bs=1024 count=1000000
2.4.3. Repair hard disk
When the hard drive is not in use for a long time (such as a year or two), magnetic flux point will be generated on the disk. When the head reads
Difficulties can be encountered in these areas and may result in an Imax O error. When this situation affects the first sector of the hard disk, it may result in
The hard drive is scrapped. The following command has the potential to bring this data back to life. And the process is safe and efficient.
Dd if=/dev/sda of=/dev/sda
Thank you for reading! This is the end of the article on "how to use dd commands in Linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can 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.