date
int64
1,220B
1,719B
question_description
stringlengths
28
29.9k
accepted_answer
stringlengths
12
26.4k
question_title
stringlengths
14
159
1,444,865,232,000
I have a disk image, it's a "whole" disk image, e.g., contains multiple partitions, and I want to clone just one of them (not the first one..) onto a partition on an external drive with multiple partitions on it (I'm also not cloning it onto the first partition of the disk...) FDisk'ing the image gives this: # fdisk -...
# losetup --find --show --partscan --read-only 2013-02-09-wheezy-raspbian.img /dev/loop7 # dd if=/dev/loop7p2 of=/dev/narnia bs=1M If --partscan doesn't work, you can also use one of: # partx -a /dev/loop7 # kpartx /dev/loop7 or similar partition mapping solutions. You should probably mount it first just to see if i...
How to use DD to clone a partition off a disk image?
1,444,865,232,000
I want to clone a hard disk using dd. Because I want to keep a process on the machine alive continuously, I would like to do this while the filesystem is still mounted. I understand this is not the "ideal" way to do this, but it also seems from Googling that it is possible. The clone is being used as a backup; in the ...
If you're lucky, the filesystem corruption will be detected as soon as you try to mount the copy. If you're unlucky, it won't be detected until later. It's also possible that you'll manage to get a consistent copy of the filesystem except for the files that were modified during the copy. But I wouldn't count on it. It...
Using dd to clone a disk while mounted - risks?
1,444,865,232,000
Consider a 100MB raw block device as a simple example. That is 204800 blocks of 512 bytes each for a total of 102760448 bytes. The challenge is to shift the first 98MB (200704 blocks) so there is a gap of 2MB (4096 blocks) in front of it. To do this in-place requires that nothing is written to a sector that has not be...
Without a buffer, you could go backwards, one block at a time. for i in $(seq 100 -1 0) do dd if=/dev/thing of=/dev/thing \ bs=1M skip=$i seek=$(($i+2)) count=1 done Please note that this example is dangerous due to lack of error checking. It's also slow due to the amount of dd calls. If you have memory to...
How can `dd` be used to right-shift data blocks?
1,444,865,232,000
I need to create a binary file that is filled only with 11111111. I only know how to create zero-filled binary with dd if=/dev/zero bs=18520 count=1 Could you please say to me what a command in pipeline should I use to fill the bin with 1? How can I use awk in this case?
Probably easiest to use tr to convert the zeroes from /dev/zero to whatever you want, and then cut to length using dd or head or such. This would write 18520 bytes with all bits ones, so value 0xff or 255, or 377 in octal as the input must be: < /dev/zero tr '\000' '\377' | head -c 18520 > test.bin (To convert from h...
How do I create binary file with certain value?
1,444,865,232,000
I found these Debian EeePC HowToInstallUsingStandardInstaller instructions at the Debian Wiki, stating that I can install an ISO to a USB using this: dd if=debian-*-netinst.iso of=/dev/sdX Do I need to delete the contents of the USB prior to running this so that nothing is left at the end of the USB? Does it matter ...
Writing to the device (/dev/sdX) instead of to a file system (/mount/point) deletes the file system on the device anyway so there's no need for mkfs before. There is also no need to erase data in the non-written area. It is not visible anyway. Linux file systems can without problems be smaller than the block device th...
How should I format a USB prior to writing an ISO to it?
1,444,865,232,000
I am tring to create random 1G test file via dd command. dd status=progress if=/dev/zero of=/tmp/testfile.zer bs=100M count=10 dd status=progress if=/dev/urandom of=/tmp/testfile1.ran bs=100M count=10 dd status=progress if=/dev/urandom of=/tmp/testfile2.ran bs=100M count=20 The output is: -rw-rw-r-- 1 dorinand dorin...
With larger blocksize, there is a risk of getting incomplete reads. This also happens a lot when reading from a pipe, rather than a block device. If you expect to receive a certain size (count*bs) you also have to supply iflag=fullblock. It might not be necessary for bs=1M or smaller, but it's still recommended either...
Different size of file from /dev/zero and /dev/urandom [duplicate]
1,444,865,232,000
I just tried to overwrite a fast ssd using dd. Using the ubuntu boot image I typed in: dd if=/dev/zero of=/dev/sda bs=100M error writing '/dev/sda': No space left on device blah blah 256 GB copied, 1195.81 s 214 MB/s Isn't that quite slow? And where is the bottleneck? What about the choice of block size?
Optimal blocksizes for dd are around 64k-256k, humans usually prefer 1M. A benchmark without real I/O: $ for bs in 512 4k 16k 64k 128k 256k 512k 1M 4M 16M 64M 128M 256M 512M > do > echo ---- $bs: ---- > dd bs=$bs if=/dev/zero of=/dev/null iflag=count_bytes count=10000M > done ---- 512: ---- 20480000+0 records...
Why is dd so slow with a bs of 100M [closed]
1,444,865,232,000
I will be backing up a large (750GB) disk to an external USB disk using dd. Should I be using redirection or piping? Which is more efficient? Or is there a difference? Also, what is the best block size? USB is likely to be the bottleneck here. dd if=/dev/sda bs=1M | gzip -c > /mnt/sdb1/backups/disk.img.gz gzip -dc /m...
You don't need to use dd or piping at all. </dev/sda gzip >/mnt/sdb1/backups/disk.img.gz </mnt/sdb1/backups/disk.img.gz gunzip >/dev/sda I once made a benchmark and found using dd slower than cat for a straight copy between different disks. I would expect the pipe to make any solution involving dd even slower in this...
gzip - redirection or piping?
1,444,865,232,000
Is there any difference between doing i.e. dd bs=4M if=archlinux.iso of=/dev/sdx status=progress oflag=sync or doing cp archlinux.iso /dev/sdx && sync, and reason to use one over the other? (aside from the pretty progress bar in dd)
One difference is efficiency, and thus speed. For example, you could get the bytes one by one and copy them to the device, with cat if it had the idealized implementation or in older systems, for example BSD4: cat archlinux.iso > /dev/sdx In these implementations cat will move each byte independently. That is a slow ...
Why use dd instead of cp to create bootable disk?
1,444,865,232,000
I have to test a hash function and I want to change only a single bit of a specific file. I tried with the dd command. That works, but I can only change a whole byte and not just a bit. sudo dd if=/dev/zero of=/file.bin bs=1 seek=10 count=1 conv=notrunc I also tried the sed command with a regex, but as I don't know ...
Since the file may contain nulls, text-oriented filters like sed are going to fail. But you can use a programming language that can handle nulls, like perl or python. Here's a solution for Python 3. It's a few lines longer than strictly necessary, for readability. #!/usr/bin/env python3 """Toggle the bit at the specif...
Change only one bit in a file
1,444,865,232,000
At the memory address, 0x7fffffffeb58 of a program lies a value, I want to find out the value of the address. Is there a way to get the value just by using commands? I've tried dd but to no avail.
To peek at memory addresses of a process, you can look at /proc/$pid/mem. See also /proc/$pid/maps for what's mapped in the process' address space. You'll want to seek() within that file to the location you want, which you should be able to do with dd: dd bs=1 skip="$((0x7fffffffeb58))" count=4 if="/proc/$pid/mem" | ...
How to get value of a memory address using command?
1,444,865,232,000
I am reading a 550MB file into /dev/null and I am getting dd: writing '/dev/null': No space left on device I was surprised. I thought /dev/null is a black hole where you can send as much as you want ( because its a virtual fs). Yes my disk is almost full when I get this error. What can I do other than deleting conten...
/dev/null is a special file, of type character device. The driver for that character device ignores whatever you try to write to the device and writes are always successful. If a write to /dev/null fails, it means that you've somehow managed to remove the proper /dev/null and replace it by a regular file. You might ha...
dd: writing '/dev/null': No space left on device
1,444,865,232,000
How can I create a bootable USB stick from an iso image? I thought dd should do the work, but so far I were unsuccesful. This is what I've tried: umount /dev/sdx deleted every partition on sdx with Gparted dd if=/path/to/iso/some_file.iso of=/dev/sdx bs=1024K The file is a bootable BIOS update utility, but since my ...
Using gparted remove the existing partitions from your usb, and fix the msdos partition table (by going to the device menu and selecting "create partition Table"). Then, create a new partition fat32 by right clicking on the unallocated space and selecting new, making a primary FAT32 partition. Next step create your bo...
Terminal: create bootable USB from iso
1,444,865,232,000
I need to save data from a failing hard drive. Sounds like ddrescue or myrescue (or maybe clonezilla?) will be my best friends here, but I'm just wondering what will likely be faster: using dd/ddrescue/myrescue/clonezilla to simply clone the failing drive to a new drive of identical capacity using rsync/tar/cp to mov...
No question, rsync will be faster. dd will have to read and write the whole 1.5TB and it will hit every bad block, triggering multiple read retries which will further slow an already long process. rsync will only have to read blocks that matter, and since it is unlikely that every bad block occurs in existing files ...
What's faster, dd 1.5TB or rsync 500GB?
1,444,865,232,000
From reading this, it seems that when copying data to a different hard drive, cat automatically uses the optimum block size (or very near it). I wonder how it determines the optimum block size, and whether the method cat uses can be applied to dd somehow.
The main loop of GNU cat, in the simplest case is (function simple_cat from cat.c): while (true) { /* Read a block of input. */ n_read = safe_read (input_desc, buf, bufsize); /* ... */ } Then the question becomes "how is bufsize set?" The answer is it's using io_blksize (insize = io_b...
How does cat 'know' the optimum block size to use?
1,579,611,829,000
I want to write a CGI, which must read a specified number of bytes from STDIN. My idea is to do it this way: dd bs=$CONTENT_LENGTH count=1 But I was wondering, if the block size is limited by anything else but the RAM. $ dd bs=1000000000000 dd: memory exhausted by input buffer of size 1000000000000 bytes (931 GiB) T...
The POSIX specifications for dd don’t specify a maximum explicitly, but there are some limits: the datatype used to store the value given can be expected to be size_t, since that’s the type of the number of bytes to read given to the read function; read is also specified to have a limit of SSIZE_MAX; under Linux, rea...
What is the maximum value for the bs argument of dd?
1,579,611,829,000
Suddenly something was messed up with my partitions, or just one partition. I have a default Ubuntu installation, on a Kingston SSD, with the root file system encrypted with LUKS, (using AES I think). Now I'm trying to mount the partition from a live cd, but without luck. I am so afraid of doing some additional harm ...
Yes it does, even the blocks that would not (officially) contain data and also all information regarding partitions, UUIDs, etc.. E.g. recovery of data (i.e. after deleting files) from the dd-copied drive would be possible. You may want to read this regarding the noerror and sync options. Block size (bs=) doesn't affe...
Does dd copy everything, including all metadata and all "empty" blocks
1,579,611,829,000
I run dd to create bootable Ubuntu but it won't make it bootable. Instead it returns instantly without creating anything as I see. When I point partition, sda1 it writes data to it but the usb won't boot the system. Also sudo fdisk -l does not list the usb but lsblk does. How to make bootable usb with dd? [I] ➜ uname...
You've got a file as /dev/sda not a device, so when you write to /dev/sda you're overwriting the file. With your NVMe disk this explains why writing speed is so high. Remove the file /dev/sda, unplug and replug the USB stick. Check that /dev/sda is now a block device (first character from ls -l is b) rather than a fil...
`dd` does not create bootable Ubuntu iso
1,579,611,829,000
I have an empty file (only zeroes are in it) of size 9,0KB and I need to write another file (with size 1,1KB) to it, but the first file must not lose its size or the rest of its contents. So if the whole file is 00000000000000... now, I need to write second file in it and leave the zeroes as they are. I have tried to ...
To overwrite the start of the destination file without truncating it, give the notrunc conversion directive: $ dd if=out/one.img of=out/go.img conv=notrunc If you wanted the source file's data appended to the destination, you can do that with the seek directive: $ dd if=out/one.img of=out/go.img bs=1k seek=9 This te...
How to write file into another
1,579,611,829,000
I'm on a Linux busybox 1.27 only system so no output=progress available, no busybox's own implementation of pv which is pipe_progress nor pv itself. I have two questions. The first is based on https://www.linux.com/training-tutorials/show-progress-when-using-dd/. It says that by sending the USR1 signal to dd it "pause...
dd if=/dev/zero of=/dev/null bs=1048576 count=1024 Note that dd can mangle data, at least when using the bs parameter. And its performance advantage is small at best if you hand-pick an optimal block size for your particular system configuration: cat or cp can do better, and at most is only slightly slower. So don't...
Check dd's progress without USR1?
1,579,611,829,000
I'm trying to approximate the computer's write speed using dd: dd if=/dev/urandom of=/dev/null bs=1K count=10000 which gives the following output 10000+0 records in 10000+0 records out 10240000 bytes (10 MB) copied, 0.746313 s, 13.7 MB/s How can I get the '13.7 MB/s' into a bash variable? I've tried piping the outpu...
The problem is your designated output from dd goes to STDERR and not STDOUT so you have to redirect STDERR as well and not only STDOUT. For bash and zsh you can use |& instead of | which will also redirect STDERR to STDIN of the second command, e.g: dd if=/dev/urandom of=/dev/null bs=1K count=10000 |& awk '/copied/ {p...
Sending the output from 'dd' to awk/sed/grep
1,579,611,829,000
I am executing this command to test a connection from a remove server: ssh -l user $IP "dd if=/dev/zero count=3500 bs=1M status=progress" > /dev/null This shows progress reports of the form 3145728000 bytes (3,1 GB, 2,9 GiB) copied, 276,047 s, 11,4 MB/s so apparently, dd reads at 11mb per second. The network bandwid...
SSH can be operated as a compressed protocol, and judging by your results, it is enabled as such by default in your distribution or configuration (or you are using ssh -C). As such, your stream of zeroes compresses nicely into something much more compact -- from your readings, with a compression ratio of about 300: th...
How can dd over ssh report read speeds exceeding the network bandwidth?
1,579,611,829,000
I'm wondering if there is some way to prevent certain certain devices from becoming the output file of the dd command and the target of the fdisk command. I'm currently using the two operations to set up a write a bootloader, kernel, and root filesystem on an SD card, which appears as /dev/sdd. I'm always a little anx...
You might try writing a udev rule to give the supplemental HDD(s) sufficiently unique names. Another idea: Whenever you can phrase a security requirement as "It's not who's doing it, it's how they're doing it" you're talking about type enforcement, and in most Linux distros TE is done at the MAC level. Most of my MAC ...
Protecting Devices from dd and fdisk Commands
1,579,611,829,000
I have a couple of large disks with backup/archive material on them. They're ext4. Regarding the ones of those that will be stored for a couple of years without reading the whole disc again I've been thinking of a way to refresh the disks magnetic state. Shelf life of drives seems to be a matter of debate everywhere I...
Generally you can't really refresh the whole disk without reading/writing all of it. fsck is unlikely to provide what you need - it works with the file system not the underlying device hence it mostly just scans file system meta data (inodes and other file system structures). badblocks -n might be an option to dd if=X...
How do I refresh the magnetic state on a disks with backups?
1,579,611,829,000
I have a USB flash drive usb 3, the reading speed is much more than the writing speed. Let's say that 99% of the flash memory is already full with zeros, and I would like to fill it with zeros until 100%, by overwriting all the memory flash with zeros dd if=/dev/zero of=/dev/FLASH. This process is going to be long, ...
Security reasons aside, let's do it. We can (ab)use GNU ddrescue. To detect sectors of zeros --generate-mode is useful. When ddrescue is invoked with the --generate-mode option it operates in "generate mode", which is different from the default "rescue mode". That is, if you use the --generate-mode option, ddrescue d...
How to fill a device with zeros, without overwriting the bytes that are already zeros?
1,579,611,829,000
I need to create an image of a partition of a usb drive: dd if=/dev/sdb1 of=sdb1.img Is there a way to do it without sudo/su? Maybe by changing permissions on the usb drive? What would be the security implications?
Is there a way to do it without sudo/su? Maybe by changing permissions on the usb drive? If your /dev/sdb1 has permissions like: $ ls -l /dev/sdb1 brw-rw---- 1 root disk 8, 17 Apr 25 17:07 /dev/sdb1 Then an option would be to add your user to the disk group: # usermod --append --groups disk username After that, th...
dd without sudo to image a partition
1,579,611,829,000
I have taken a complete image of a hard drive using: dd if=/dev/sda of=/home/user/harddriveimg bs=4M It would seem to me, that I should be able to re-size the partitions within it after suitably mounting it. As I am less than familiar with the command line parted, I tried: gparted /home/user/harddriveimg While this ...
You need to associate a loopback device with the file: sudo losetup /dev/loop0 /home/user/harddriveimg Then run gparted on that.
How to re-size partitions in a complete hard drive image?
1,579,611,829,000
I remembered reading one question how would you back up the MBR of a disk. Two of the choices are dd if=/dev/sda of=/dev/sdb bs=512 count=1 dd if=/dev/sda of=/dev/sdb bs=440 count=1 and the correct answer is dd if=/dev/sda of=/dev/sdb bs=440 count=1 I am confused. Is the MBR size 440B or 512B ?
The MBR IS 512 bytes. So the first example is how you would back it up. The partition table is at the end, in the area after 440 bytes in - so, if you wanted to back it up WITHOUT the partition table, then you could use the second example (why you'd want that, I don't know).
MBR size is 440 bytes or 512 bytes
1,579,611,829,000
I'm learning to use dd by experimentally playing with its arguments. I would like to create a 10-byte file. I thought the following would work: dd if=/dev/zero of=./foo count=1 bs=1 obs=9 seek=1 ...because of these comments from the man page: obs=BYTES write BYTES bytes at a time (default: 512) seek=...
Your command dd if=/dev/zero of=./foo count=1 bs=1 obs=9 seek=1 creates a two-byte file rather than a 10-byte file because of poorly-defined interaction between bs and obs. (Call this a program bug if you like, but it's probably better defined as a documentation bug.) You are supposed to use either bs or ibs and obs. ...
dd with obs and seek makes file of unexpected size
1,579,611,829,000
Given this file $ cat hello.txt hello doge world I would like to remove a range of bytes to end up with this $ cat hello.txt heorld I would like to do this with dd if possible. The reason is because I am already using dd to overwrite bytes in this manner printf '\x5E' | dd conv=notrunc of=hello.txt bs=1 seek=$((0xE)...
It is a matter of specifying blocksize, count, and skip: $ cat hello.txt hello doge world $ { dd bs=1 count=2 ; dd skip=3 bs=1 count=1 ; dd skip=6 bs=1 ; } <hello.txt 2>/dev/null he orld The above uses three invocations of dd. The first gets the first two characters he. The second skips to the end of hello and copi...
dd remove range of bytes
1,579,611,829,000
I just tried burning both a Debian CD and a Debian DVD from their .iso files and I've got a weird behavior: the checksum of the CD is correct but the one of the DVD ain't. Here's what working: downloaded the two .iso files verified the checksum of the two .iso files burn the CD debian-7.1.0-amd64-CD-1.iso to a CD ve...
In addition to Gilles answer, If you still have the ISO image, you could use cmp instead of checksums. It would tell you at which byte the difference happens. It would also make the check faster as if there is an error early on, it would tell you right away, whereas the checksum always has to read the entire media. $ ...
How to take sha-1, sha-256 or MD5 of CDs / DVDs?
1,579,611,829,000
Possible Duplicate: dd: How do I know if it's still working? I'm using dd to clone a disk to an image file, and compress it on the fly: dd if=/dev/sda | gzip > /mnt/image_file How can I check how much data dd already processed? Looking at the output file size is of course useless, due to it being compressed.
Most dd implementations print status information upon recieving SIGUSR1. pkill -USR1 -x dd is probably what you want.
How to check progress when cloning a disk using `dd`? [duplicate]
1,579,611,829,000
I'm currently writing a small script to backup bulks of floppy disks and format them afterward for later use. I use dd to copy the disk's image and cp to copy all the files on the disk. Here are the commands I use to do so: # Copying disk image dd if="/dev/fd0" of="/path/to/backup/folder" &>/dev/null && sync # Copyin...
I'd do: ok=true if dd ...; then sync else ok=false fi cp ... || ok=false if "$ok"; then mformat... fi
Check command success in bash
1,579,611,829,000
I try to run simple test case on linux operating system with dd command . I create a simple disk image with this command : dd if=/dev/urandom of=disk.img bs=1M count=100 This is First Test : Now I run this commands : dd if=disk.img of=output_1 bs=1k count=4 dd if=disk.img of=output_2 bs=4k count=1 md...
The skip parameter is in (input) blocks, not in bytes, as written in the man page: skip=N skip N ibs-sized blocks at start of input In the first case the skipped part is: 1500 * 1KiB = 1536000 bytes The second case: 1500 * 4KiB = 6144000 bytes As long as the involved values divide exactly you can adjust. For the...
Linux dd problem on difference result for same blocks
1,579,611,829,000
At work we use sparse files as part of out Oracle VM environment for the guest disk images. After some questions from a colleague (which have since been answered) I am left with more questions about sparse files, and perhaps more widely about inode structure - reading the man pages of stat(2) and statfs(2) (on FreeBS...
Some quick answers: first, you didn't create a sparse file. Try these extra commands dd if=/tmp/BIL of=/tmp/sparse seek=1000 ls -ls /tmp/sparse You will see the size is 512003 bytes, but only takes 8 blocks. The null bytes have to occupy a whole block, and be on a block boundary for them to be possibly sparse in the ...
Understanding sparse files, dd, seek, inode block structure
1,579,611,829,000
Trying lots of different Linux distributions on all kinds of hardware, I find myself typing commands like this quite often: sudo dd if=xubuntu-13.10-desktop-amd64.iso of=/dev/sdc bs=10240 Needless to say, sooner or later I will mistype the destination and wipe a harddrive instead of the intended USB drive. I would li...
I think you can use UDEV to do what you want. Creating a rules file such as/etc/udev/rules.d/99-thumbdrives.rules you'd simply add a rule that will allow either a Unix group or user access to arbitrary USB thumb drives. KERNEL=="sd*", SUBSYSTEM=="block", ENV{DEVTYPE}=="disk", OWNER="<user>", GROUP="<group>", MODE="066...
Writing raw images safely to USB sticks
1,579,611,829,000
I tried to copy /dev/Storage/Storage (an LV under LVM) to an image file using a dd | pv | dd pipeline. dd reported an error, and I want to know whether dd finished copying my disk or stopped due to the error. I'm not sure since it gave me two different outputs: one with an error at the top and one without. I'd take a ...
You are using the default 512 bytes dd block size. You would significantly improve performance by using a larger block size, say 128k or even 1m. There are two outputs because you are running two dd commands, the first one is the device reader and it shows an I/O error. You are likely using LVM given the device name ...
Interpreting dd Input/Output error
1,579,611,829,000
There are many articles on the web that describe a command-line to make an ISO image from a DVD-Video disc like this: dd if=/dev/sr0 of=mydvd.iso conv=noerror,sync,notrunc I'd like to uderstand why notrunc is necessary. From my knowledge, and from the man page for the command, notrunc prevents the output file from be...
It is not needed if you want to copy a whole DVD to a file which shall afterwards contain only the payload of that DVD. Actually notrunc is a risk for privacy and can cause media overflow if you overwrite an old file that is larger than the DVD payload. In this case the surplus blocks of the old file will stay append...
why do people use "notrunc" when making an ISO from a DVD?
1,579,611,829,000
I use dd a lot. I live in a contant fear of making a mistake one day, for example writing on sda (computer disk) instead of sdb (USB disk) and then erasing everything I have on my computer. I know dd is supposed to be a power user tool but still, it doesn't make sense to me that you can basically screw your whole comp...
It's reasonable to ask why the dd command doesn't first check whether its target contains a mounted filesystem, and then prompt for confirmation or require a special flag. One simple answer is that it would break any scripts that expect to be able to use dd in this way, and that aren't designed to handle interactive ...
Why is dd not protected against writing on the active disk ?
1,579,611,829,000
Over a year back, I contributed to a tutorial on how to install NixOS on Linode. It seems like most tutorials that deal with putting iso files on installation media always use dd, which is why "is dd still relevant these days?" doesn't answer my question. This tutorial also originally used dd and I slightly modified i...
Using dd is not safer or faster or less reliable. In fact, here, it introduces two additional risks of failure. Neither risk is likely to be a problem in practice if people follow those instructions manually, but they would be significant bugs if the instructions were in an automated script. Bug: race condition Observ...
tee iso contents into dd or directly to /dev/sda?
1,579,611,829,000
my command: gunzip -c serial2udp.image.gz | sudo dd of=/dev/mmcblk0 conv=fsync,notrunc status=progress bs=4M my output: 15930949632 bytes (16 GB, 15 GiB) copied, 1049 s, 15.2 MB/s 0+331128 records in 0+331128 records out 15931539456 bytes (16 GB, 15 GiB) copied, 1995.2 s, 8.0 MB/s the card: SanDisk Ultra 32GB M...
I figure there is a cache somewhere that is holding up the final 5MB but I thought fsync should make sure that doesn't happen conv=fsync means to write back any caches by calling fsync - after dd has written all the data. Hanging at the end is exactly what it will do. When the output file is slower than the input f...
Why does a gunzip to dd pipeline slow down at the end?
1,579,611,829,000
I'm curious to know the difference between these two commands in Linux: $ cat ./boot.bin ./kernel.bin /dev/zero | dd bs=512 count=2880 of=devos.img and $ cat ./boot.bin ./kernel.bin > devos.img
dd copies exactly count blocks of bs bytes, or 2880*512 bytes in total in this case(but see below). That will truncate or pad the concatenation of the two files to a fixed size (since /dev/zero gives as many zero bytes as required). 1440 kB is looks like the size of a 3.5" HD floppy disk, so perhaps someone wanted to ...
What's the difference in these commands - cat piped to dd and just cat? [duplicate]
1,579,611,829,000
I wish to clone a large disk (a 500GB SSD, for what it's worth), and I am leaning toward using cat, as suggested by Gilles here. But what gave me pause is that I do not really know what cat does upon read errors. I know how dd behaves in these cases, i.e. the command dd if=/dev/sda of=/dev/sdb bs=64K conv=noerror,sync...
cat stops if it encounters a read or write error. If you’re concerned there might be unreadable sectors on your source drive, you should look at tools such as ddrescue.
Errors on cloning disk with cat
1,579,611,829,000
Can I just dd an Ubuntu 11.04 mini.iso to an usb flashdrive an boot from it? or what am I missing?
You should be able to dd if=linux.iso of=/dev/sdx, where x is the letter for your USB device. Don't use /dev/sdx1, just /dev/sdx. It has worked for me (not with Ubuntu, though). Beware that this will destroy any data previously on the flashdrive.
How can I make a bootable usb flashdrive?
1,579,611,829,000
I have two non-networked servers, each with 1.2TB of storage in a RAID5 config on an LSI MegaRaid 9240-8i controller. I have been trying without success to get Symantec Ghost to image one machine to the other due to driver issues, and so I was wondering if it wouldn't be easier to boot from a Linux LiveCD, plug in an...
Sounds like the device is remote. Assuming linux... ssh remote_host 'dd if=/dev/sdb1' | cp --sparse=always /proc/self/fd/0 new-sparse-file If local... dd if=/dev/sdb1 | cp --sparse=always /proc/self/fd/0 new-sparse-file This gives you an image that is mountable. However, if you pulled it across the network then yo...
Is creating a sparse image using dd appropriate for backup/restore from a RAID?
1,579,611,829,000
I just backed up the microSD card from my Raspberry Pi on my PC running a Linux distro using this command: dd if=/dev/sdx of=file.bin bs=16M The microSD card is only 3/4 full so I suppose there's a few gigs of null bytes at the end of the tremendous file. I am very sure I don't need that. How can I strip those null b...
To create a backup copy of a disk while saving space, use gzip: gzip </dev/sda >/path/to/sda.gz When you want to restore the disk from backup, use: gunzip -c /path/to/sda.gz >/dev/sda This will likely save much more space than merely stripping trailing NUL bytes. Removing trailing NUL bytes If you really want to re...
Remove null bytes from the end of a large file
1,579,611,829,000
I would like to create a ISO file for testing optical drives with the method mentioned here. I want to create an ISO file filled with random data, so I can burn it to a CD, read it back and compare with the original ISO. I think the command bellow will do what I want. dd if=/dev/urandom of=cd-rom_test.iso bs=2048 coun...
Since you're writing to a file with dd, the block size will not change the resulting output. Block size only matters when writing to devices. You're reading from a device that won't ever return short reads, so you don't need to use sync to pad blocks. In any event, dd does not have read or write access to the error c...
Create a Random ISO Image Using dd
1,579,611,829,000
I have an iso image (it's a windows installation disk), but I do not want to burn dvd. I want to create a bootable usb flash drive instead. And I want to use linux tools to accomplish this task. I have found several recipes, they suggest using dd tool as follows: dd if=/path/to/my.iso of=/dev/sdx (f.e. here https://w...
Cloning and extraction I have an iso image (it's a windows installation disk), but I do not want to burn dvd. I want to create a bootable usb flash drive instead. And I want to use linux tools to accomplish this task. I have found several recipes, they suggest using dd tool as follows: dd if=/path/to/my.iso of=/d...
General question about `dd`, iso images and linux devices
1,579,611,829,000
I am having some issues with system-wide latency/lagging when doing large disk imaging operations on an Ubuntu 18.04 system. Here's the system specs: Processor: Intel Core i7 (never near capacity on any core) Memory: 12GB (never near capacity) System disk: SSD (never near capacity) External disks: USB 3.0 5400 and 720...
How can I remedy it? When you write a disk image, use dd with oflag=direct. The O_DIRECT writes will avoid writing the data through the page cache. Note oflag=direct will require a larger block size, in order to get good performance. Here is an example: dd if=/dev/usbdisk1 of=/dev/usbdisk2 oflag=direct bs=32M sta...
System lags when doing large R/W operations on external disks
1,579,611,829,000
I've been using dd in Linux to overwrite an external USB hard drive. When I use the default block size of 512 bytes, with this command: # dd if=/dev/zero of=/dev/sdb throughout the whole operation, the hard drive (/dev/sdb) is being read from and written to alternately, approximately 1GB at a time. I.e. read 1GB...wr...
If you specify a block size (512 bytes) of less than the block size of the disk (often 4096 bytes, but nowadays maybe more), the block will be partially written, so that the contents of the rest of the block must be preserved before writing. This is because disk blocks cannot be written to with only 512 bytes, but you...
Why is dd reading from and writing to the same disk?
1,579,611,829,000
I want to create an image of some directory tree that is writable directly to a USB drive, just like the images of many Linux distributions. For example, with openSUSE you can download an ISO image that is writable directly the USB using dd. root@computer# dd if=openSUSE.iso of=/dev/sdb I tried to create images using...
You can use kpartx for this. Here is a way to create a complete disk image. # create empty image dd if=/dev/zero of=myvm.img bs=1G count=0 seek=100 # partition the image file with fdisk/gdisk or any other tool gdisk myvm.img # make the partitions in the image file available as individual devices kpartx -a myvm.img ...
How do I create a USB image with a partition table?
1,579,611,829,000
I've backed up a partition using sudo dd bs=8M if=/dev/sda2 | gzip > /someFolderOnSDB/sda2.img.gz. The image is stored on a separate disk sdb. When restoring it using gunzip -k /mnt/bkp/sda2.img.gz | sudo dd of=/dev/sda2, I noticed that the image is being unzipped into the folder someFolderOnSDB where the gz file is, ...
You can do this by instructing gunzip to write the decompressed data to its standard output: gunzip -c /mnt/bkp/sda2.img.gz | sudo dd of=/dev/sda2
How to uncompress a gzipped partition image and dd it directly to the destination partition without writing to current partition?
1,410,974,521,000
Background Info: Copying some .bin files to an SD card (to be read by an embedded device, no filesystem) Commissioning the card requires some segments to be wiped (i.e. zero'd), and others to have binary files copied to them Calling dd from a python script using subprocess module (as the dd operations involved are tr...
Solution: dd if='input_file.bin' \ of='/dev/sd{X}' \ bs={desired write block size} \ seek={start offset in bytes} \ count={write size in bytes} \ oflag=seek_bytes \ iflag=count_bytes From the man page: count_bytes treat 'count=N' as a byte count (iflag on...
dd, seek with one block size, write with another block size
1,410,974,521,000
I have an iso file (foo.iso) that I burnt to a dvd with the command : growisofs -dvd-compat -Z /dev/cdrom=foo.iso I then tried the command dd if=/dev/cdrom of=foo2.iso However, foo2.iso is larger by a few kB. What explains this difference? How can I retrieve the original file from a cd? EDIT: Simply removing the ext...
What dd reads when you run dd if=/dev/cdrom of=foo2.iso is not a file (there is no such thing on a physical CD), but a number of 4KB sectors. If the length of the image file you wrote is not an exact multiple of 4KB = 4096, there will be some padding at the end. You can safely ignore it.
Size difference between an iso file burnt to a cd and the file retrieved with dd
1,410,974,521,000
I'm trying to copy data off a rather damaged CD using the following command: dd if=/dev/sr1 of=IDT.img conv=sync,noerror status=progress However, the 'of' device got disconnected and the dd stopped (output below). ... dd: error reading '/dev/sr1': Input/output error 1074889+17746 records in 1092635+0 records out 55942...
You have encountered read errors, so the options conv=sync,noerror have almost certainly altered the stream of data, unfortunately making your output file worthless or at the very least an inaccurate copy. Each time there is a bad read (short read) on the input, the conv=sync option pads out the block with NUL bytes. ...
resuming dd with read errors, skip/seek numbers
1,410,974,521,000
I found a very nice tutorial on how to create virtual hard disks, and I am considering using these for my work in order to store reliably and portably large datasets with associated processing results. Basically, the tutorial consist in doing this: dd if=/dev/zero of=MyDrive.vhd bs=1M count=500 mkfs -t ext3 MyDrive.vh...
There is better alternative than dd to extend a file. The dd command requires several parameters to run properly (to not corrupt your data). I use truncate instead. Despite of its name it can extend the size of a file as well: truncate - shrink or extend the size of a file to the specified size -s, --size=SIZE set or...
Resizing a virtual hard drive
1,410,974,521,000
I am trying to fill a file with a sequence of random 0 and 1s with a user-defined number of lines and number of characters per line. the first step is to get a random stream of 0 and 1s: cat /dev/urandom | tr -dc 01 then I tried to fill a file with this stream (and end the process of filling by ctrl+c) cat /dev/uran...
How about fold? It's part of coreutils... $ tr -dc 01 < /dev/urandom | fold -w 30 | head -n 5 001010000111110001100101101101 000101110011011100100101111000 111010101011100101010110111001 111011000000000101111110110100 110011010111001110011010100011 Or if that's not available, some flavour of awk: $ tr -dc 01 < /dev/u...
How to fill a file with a stream from /dev/urandom with a specified number of lines ?
1,410,974,521,000
I have two drives in a mirror (linux sw raid/mdadm); one drive somehow left the mirror in the past and its content is now several days old. At this moment, I'm using degraded mirror (with one drive missing) and considering: clone uptodate drive to the second one with dd add second drive and resync, but I don't know h...
The right thing to do is something like mdadm --add /dev/md0 /dev/sdb1. Use the correct array in place of md0 and the correct partition in place of sdb1. The key thing is the array is running. Its completely unambiguous which data to copy: the data that is currently running. If you have bitmaps enabled, the resync wil...
How does mdraid resync work?
1,410,974,521,000
Does anyone know an alternative for 'dd', which won't truncate the file, without using: conv=notrunc. Adding conv=notrunc isn't supported via busybox/toybox due to limited amount of space. For instance, I'd like the equivalent of dd bs=4 count=3 skip=2 seek=3 if=file.in of=file.out conv=notrunc But that would work wh...
Use the standard <> sh redirection operator which opens the file in read+write mode without truncation. cat < file.in 1<> file.out To copy the content of file.in at the start of file.out. If you need to seek in the input or output file, and assuming your dd still supports these directives: dd bs=4 count=3 skip=2 seek...
alternative to 'dd' which doesn't truncate the file
1,410,974,521,000
If I: dd if=/dev/cdrom of=cdrom.iso then I will always get the exact same, bit-by-bitly same image that is the same as the original CDROM? Or are there any methods that prevents copying all the bits from the CDROM? Asking for archiving old games on old CDROMS
No, dd can be not sufficient. As examples: If you have a multi-track cd-rom with data and audio track mixed, using dd you will copy only the first data session. Many old video-games cd (on Play-Station 1) use as copy-protection some fake session on the cd. You have to replicate them to obtain a working cd. I success...
If I dd a CDROM, then I always get the exact copy of the CDROM?
1,410,974,521,000
I have a 32GB SD Card that contains an Armbian installation for some pi gadget. I want to clone the content into a 16GB card. Using GParted, I shrank the partitions to be less than 16GB and here is the state of the SD Card as shown in fdisk. There are 2 partitions, one is the Armbian and the other one is an small FAT3...
You could use the largest end sector for count: dd bs=512 count=26509312 if=/dev/sdk of=devsdk.img Or with a different blocksize: dd bs=1M count=$((26509312*512)) iflag=count_bytes if=/dev/sdk of=devsdk.img It is strange that the Armbian leaved 8129 sectors free, and calls it unpartitioned space, what is in that ar...
Using dd to create an image up to an specific sector
1,410,974,521,000
I have a text file with two (2) only possible characters (and maybe new lines \n). Example: ABBBAAAABBBBBABBABBBABBB (Size 24 bytes) How can I convert this to a binary file, meaning a bit representation, with each one of the two possible values being assigned to 0 or 1? Resulting binary file (0=A, 1=B): 0111000011111...
Another perl: perl -pe 'BEGIN { binmode \*STDOUT } chomp; tr/AB/\0\1/; $_ = pack "B*", $_' Proof: $ echo ABBBAAAABBBBBABBABBBABBB | \ perl -pe 'BEGIN { binmode \*STDOUT } chomp; tr/AB/\0\1/; $_ = pack "B*", $_' | \ od -tx1 0000000 70 fb 77 0000003 The above reads input one line at a time. It's up to you to ...
How can I convert two-valued text data to binary (bit-representation)
1,410,974,521,000
I have an old 64MB CF card which I use in my laptop(kernel 2.6.38) with CardBus adapter. If I write a 64MB image to this CF card, then the write speed is more than 200MB/s: T42 ~ # fdisk -lu Disk /dev/sda: 40.0 GB, 40007761920 bytes 255 heads, 63 sectors/track, 4864 cylinders, total 78140160 sectors Units = sectors o...
Block device writes are buffered by the kernel. This is clearly visible when a filesystem is mounted (when you unmount, the buffers have to be flushed, leading to a sometimes very long delay before the umount returns). This delay is seemingly getting worse as the available RAM is getting larger and larger. You may be ...
dd writes to CF with delay
1,410,974,521,000
I have a 660297728 byte HDD image with MD5 hash f5a9d398e974617108d26c1654fe7bcb: root@T42# ls -l image -rw-rw-r-- 1 noc noc 660297728 Sep 29 19:00 image root@T42# md5sum image f5a9d398e974617108d26c1654fe7bcb image Now if I dd this image file to /dev/sdb disk and check the MD5 hash of the disk, then it is different...
Is /dev/sdb exactly 660297728 bytes large? (blockdev --getsize64 /dev/sdb). If not, the checksum would naturally be different. Use cmp image /dev/sdb to find out where the differences are in detail. If it says EOF on image, it's identical.
HDD image file checksum does not match with device checksum
1,410,974,521,000
I have a ~1GB image that I'm writing to a 8GB SD card via the dd tool. I'd like to verify that it was written without corruption by reading it back and comparing its hash with original one. Obviously, when I read it back via dd the size of resulting image matches size of my SD card, therefore checking hashes are usele...
Determine the size of the image, for example with \ls -l my.img (not ls -lh, that would give you an approximate size; \ls protects against an alias like ls='ls -h') or with stat -c %s my.img. If you want to check the copy against the original just this once, then just compare the files. Using hashes is useless for a o...
How one can re-read image with dd so it will match one you just wrote?
1,410,974,521,000
I was messing around with my new hard drive, which only contains some personal files, and to check its write speed, I typed: sudo dd if=/dev/zero of=/dev/sda, /dev/sda/ being the new 2 TB connected to my Raspberry Pi. Hopefully, I cancelled the command and only 11 MB have been written. Now disk content can't show up, ...
You will first need to reconstruct the partition table the way it was. This will not affect the contents of any partition, just the system's idea of where each partition begins and ends. It sounds like you might have already done this because you seem to have a partition that exists that is "unknown", but exactly the ...
Partially overwrote /dev/sda, can I recover anything?
1,410,974,521,000
I am looking at an image file which was created using dd with an SD card with Raspbian (with Qt 5.7 on it that I compiled a while ago) as input. When invoking sudo parted raspbian_jessie_qt5.7_all_modules.img unit s print I get Error: Can't have a partition outside the disk! I checked the partitions using fdisk usin...
Your image has 16267263 sectors, but the start and end sectors count from 0, so your partition extends one sector beyond the end of the image. Since the image appears to work fine you can probably fix it by appending 512 bytes to it.
"Error: Can't have a partition outside the disk!" even though number of sectors is fine
1,410,974,521,000
Requirement I want to write a file at various offsets into the partition. Partition /dev/part2 is mounted at /mypart I tried the commands below: dd if=/dev/urandom of=/mypart/aaa bs=1024 seek=0 count=15000 dd if=/dev/urandom of=/mypart/aaa bs=1024 seek=15000 count=15000 dd if=/dev/urandom of=/mypart/aaa bs=1024 se...
You can't "write a file" at an "offset into the partition" using dd this way -- you are just writing data into a file named "aaa" within the mounted file system on that partition. "seek=" will indeed cause dd to lseek to the given position before beginning its writes -- that means that it will simply create a file cal...
How to write a file at various offsets to a filesystem partition with dd command
1,410,974,521,000
Assume I want to create a large encrypted drive stored in a file using cryptsetup, the first step is to create a random file, assume this should be of size 3T: dd if=/dev/urandom of=$FILE bs=1G count=3000 the above process can take really long time. I was wondering if the following short-cut makes any sense (from a s...
/dev/urandom is way too slow for this amount of data. If pseudorandom is good enough: shred -v -n 1 /kill/me If encrypted random is good enough: cryptsetup open --type=plain /kill/me cryptkillme shred -v -n 1 /dev/mapper/cryptkillme cryptsetup close cryptkillme Encryption is slow too but still order of magnitude fas...
Creating a large file with random content: short-cut by copying?
1,410,974,521,000
I always thought that when doing: dd if=/dev/sdx of=/dev/sdy the report which is displayed once the command finishes, such as: 79304319+0 records in 79304319+0 records out 40603811328 bytes (41 GB) copied, 459.645 s, 88.3 MB/s contains the speed which corresponds to the slowest one between: The read speed from the ...
In general dd displays the time it took for the entire transfer and the speed is "amount of data divided by time it took". Basically it's the same you should get with time dd ..., no magic there. 40603811328 bytes (41 GB) copied, 459.645 s, 88.3 MB/s 40603811328 / 459.645 / 1000 / 1000 = 88.3373 Maybe you cancelled t...
What is actually the speed reported by dd?
1,410,974,521,000
I have HDD with my data (partial backup of most important data available on other HDD), currently it's formatted as Ext4 over LVM over LUKS. I want to remove LUKS layer, but reformatting and data restore from backup is too long/no fun. Is there any possibility/chance to overwrite LUKS partition with it's content witho...
You're going to have to copy all the data around anyway. You should definitely have a backup at this point. Unless your backup device is significantly slower than your active disk, restoring from backup is as fast as it can go. A LUKS volume starts with a header (up to 2MB). If you lose the header, the data in the vol...
Can I overwrite LUKS partition with it's decrypted content?
1,410,974,521,000
I am running Ubuntu 18.04.1 in a Virtual Machine (VMWare) on a Windows host. I am trying to zero out an entire SD card using dd. This is part of the process I use to release embedded Linux to the software group (SD card images compress much better when the empty FS data is all 0). The command I am using is: sudo dd ...
As said in the comments, the sdcard was with badblocks. The solution I proposed was to run: badblocks -t 0x0000 -sw /dev/sdc CAUTION: this is data destructive like dd if=/dev/zero. And the user received something like: 7234624 done, 39:10 elapsed. (0/0/2417408 errors) Showing the sdcard was damaged. The sdcard was...
dd doesn't overwrite the disk
1,410,974,521,000
I was trying to create bootable USB of Ubuntu 17.04. First, I erased everything from the pen drive and then started to copy using sudo dd if=path_to_ubuntu_image of=/dev/rdisk2 but it is taking around 5 hrs to complete the process. I read previous answers about speeding up it using rdisk instead of disk but I was init...
The default block size is only 512 bytes, which significantly cripples the transfer rate. You should use a block size that is a much, much larger. OSX Daily has step by step instructions, they suggest 1 MB, but you might want to try even larger. sudo dd if=/path/image.iso of=/dev/r(IDENTIFIER) bs=1m
How to speed up dd on macOS High Sierra?
1,410,974,521,000
I have a copy of the Slackware 64 bit dvd installation iso. I've burned this image to a dvd and used it to properly install the distro. I wanted to try also having this image available on a usb flash drive. I divided a 32 GB drive into two partitions: 1, about 22 GB for data; and 2, about 10 GB for messing around with...
It's not Slackware expierence based answer, but it seems that problem is, that iso isn't supposed to be dd'd into flash drive. Probably bootloader is not supposed to load from other source than CD. Instead you should copy the iso to usb and have bootloader that can handle iso. SysLinux bootloader MEMDISK tool is suppo...
Why can't I simply dd an installation iso to a bootable partition on an USB flash drive?
1,410,974,521,000
The final purpose is to build the image of a partition sector by sector. I want the sector size to be 4096. As a first step I am trying to create an empty image of 32MiB with 4096bytes sectors rather than 512bytes. For this I am trying: dd if=/dev/zero of=empty4k.img bs=4096 count=8192 Then I do fdisk -l empty4k.img...
The bs given to dd just tells how large the buffer should be during creating the file. In the end, the file consists of nothing but zero-bytes, there is no information about alignment. You have to use the specific parameter to fdisk, which is -b, as per the man-page of fdisk(8): -b, --sector-size sectorsize ...
create empty img with dd so that it its sectors are of 4096bytes rather than 512
1,410,974,521,000
I'm able to auto detect RAM in GB as below and round off to the nearest integer: printf "%.f\n" $(grep MemTotal /proc/meminfo | awk '$3=="kB"{$2=$2/1024^2;$3="GB";} 1' | awk '{print $2}') Output: 4 I multiply by 2 to determine the required swap as 8GB ans=`expr $(printf "%.f\n" $(grep MemTotal /proc/meminfo | awk '$...
The reason why your dd command didn't work is because you set dd's block size to 8 GB. i.e. you told it to read and write 8 GiB at a time, which would require a RAM buffer of 8 GB. As Marcus said, 8 GiB is more RAM than you have, so a buffer of that size isn't going to work. And ~ 8 billion megabytes (8 GiB x 1M = 8...
Auto detect RAM and create double the swap memory
1,410,974,521,000
Note: While I agree that this question basically is a duplicate of the above question, I feel @alienth's answer (below) is more concise, so I suggest you take a look at it before going to the other question. I periodically backup/image/clone my entire ubuntu system drive to another drive with: dd if=/dev/sda of=/medi...
You'll need to determine where in the disk image your partition starts. To do so, run the following: sudo parted /media/disk1/backup.iso unit s print The output will look like the following: Model: (file) Disk /tmp/file: 200000s Sector size (logical/physical): 512B/512B Partition Table: msdos Number Start End ...
Can I mount a partition from a full drive image? [duplicate]
1,410,974,521,000
I have generated an image file with dd. The image contains two partitions. I created a loop virtual disk: losetup -P /dev/loop0 $image_file. I mounted the two loop created partitions (loop0p1, loop0p2) to two mounting points. My problem is the loop disk is too small for the files I want to add. I looked into the optio...
You cannot do that: the way the loopback device in the Linux kernel works it uses the image file size to operate on it and it won't write beyond it. The only way to achieve what you want is to umount the image, increase its size/repartition it, run resize2fs or whatever FS you're using to resize partitions and then mo...
How to increase the size of a loop virtual disk?
1,410,974,521,000
I have a filesystem handled by ZFS and it's about 8 GB. I tried to zero out the filesystem by running: dd if=/dev/zero of=/EMPTY bs=1M | true rm -f /EMPTY And normally on an ext4 filesystem, it completes in a few seconds. But this time it just kept going. I was able to launch a second terminal and see what the size o...
You're running into ZFS's compression. If you're trying to wipe out the filesystem, then you can't do it that way in ZFS. If you're trying to wipe out the underlying disk, the best thing to do would be to use "zpool destroy" on the zfs pool, then use dd on the physical device itself. ("dd if=/dev/zero of=/dev/...."). ...
Why is dd running forever on a 8 GB drive
1,410,974,521,000
I made regular complete backups of my hard disk (with all partitions) using dd tool as backup.img file. I have several such files. Now that my old hard disk died, how can I use backup.img file to write on a new hard disk so that I have all the partitions and file intact as in the image. Also is it possible to extract ...
Restore You can restore the image back to your replacement HDD with something along the lines of: # dd if=backup.img of=/dev/sd? You will end up with a clone of your original disk including all partitions and data. The downside to this is that the partitions won't be resized by dd so your replacement disk must be ide...
Use backup file from dd to restore hard disk and also extract files
1,410,974,521,000
I'd like to understand the interaction between fstrim and a file system driver (such as ext4). More precisely I'd like to understand whether dd interfere with this. I've queried elsewhere about how the file system informs an SSD when a block is not used. This is important because it can help with wear levelling. Th...
Will fstrim recover from this or is it incremental, only discarding after a file is deleted? It will recover from this, it discards all unused blocks. It doesn’t care about when the blocks became unused. Is it now recommended that users call fstrim or similar after using dd to copy a disk? Doing so will only add o...
How does fstrim interact with dd
1,576,861,160,000
I had a gpt-partitioned drive, with unpartitioned space at the end, I used dd to clone it to another smaller drive. Unfortunately Linux won't see the partitions on the cloned drive. My understanding is that GPT has two copies of the partition table, the primary copy at the start just after the MBR table, and the secon...
gdisk was able to fix the drive. It displayed some warnings, but was able to correctly read the primary copy of the GPT, adjust the location of the secondary GPT, and write the partition table back to the disk. I also tried fdisk and gparted, but neither of them was able to correctly handle the drive. fdisk only saw t...
repair gpt after cloning to smaller drive
1,576,861,160,000
I use dd extensively as a means of software configuration control. The images are typically deployed on flash disk to update devices. I find I am often making small incremental updates to the image files and having to then re-copy the entire image over to the block device. This is fairly time consuming as images are t...
The following is a fast hack for a small C program able to compare two files (file1, file2) blockwise and, if the blocks are different, copies the corresponding block from file1 to file2. Works for files and block devices as well. Do with it what you want, but at your own risk! /* Small program to blockwise compare tw...
Update block device with image while writing only the Delta, is it possible?
1,576,861,160,000
When I run the following command: dd if=/dev/sda of=output bs=512 count=1 In the middle of the output, I see this text: GRUB ^@Geom^@Hard Disk^@Read^@ Error^M What does it mean?
Those are just strings that GRUB has in its bootloader. This doesn't mean that you have a hard disk read error, just that GRUB has some text in its bootloader that will be displayed if you do.
Error(?) in output of the dd command
1,576,861,160,000
Let's say I accidentally ran sudo dd if=/dev/sda of=/dev/sda instead of sudo dd if=/dev/sda of=/dev/sdb And I didn't want to wait for the 500gb operation to complete to find out if I broke my system. Does anyone know what the outcome would be so I can either wait in peace for it to complete or just interrupt it and st...
In isolation, dd if=/dev/sdx of=/dev/sdx would write the same data that is already there. No harm done(*). However, if the device is in active use e.g. by a filesystem, there may be a possible race condition: dd reads data (A), filesystem writes data (B), dd writes data (A), causing (B) to be lost / corrupted. So it c...
What would happen if dd receives same input file as output file
1,576,861,160,000
Just looking to overwrite a small portion of a device with zeros or random bits. More precisely I would like to overwrite the first 1% of all the sectors or few MiB. Is there an easy way to do that ?
Although /dev/urandom is extremely slow and as such not suitable for overwriting large amounts of data (entire disk), it might do for small regions. Example overwriting 8MiB: dd bs=1M count=8 iflag=fullblock if=/dev/urandom of=/dev/destroyme Alternatively you can use shred: shred -v -n 1 -s 8M /dev/destroyme You can...
How to overwrite beginning of a device with random bits or zeros?
1,576,861,160,000
Using the fdisk -l command I got the following answer: Device Boot Start End Blocks Id System /dev/sda1 * 2048 28266495 14132224 27 Hidden NTFS WinRE /dev/sda2 28268544 28473343 102400 7 HPFS/NTFS/exFAT /dev/sda3 28473344 132552703 52039680 7 ...
first of all, here's how: First do almost as you did before, but no subtraction - and add one to the count. dd count=132552704 </dev/sda >img Next print the partition table at a sed process which can screen out the ones which you're removing. sed will write a delete command to a second fdisk which has opened your...
How can I copy three partitions of my disk with a specific beginning and ending using dd?
1,576,861,160,000
The goal in my case is not to securely erase data, but simply to force sector reallocation by the drives firmware. I have a drive that has had a few file corruptions. It seems to be due to getting very hot at some point in the past, the max reported temperature is 99C ! I've recovered as much data from it as I can wit...
If your goal is to really "zero" the drive, then I bet the fastest you can get is to issue a low-level secure erase command using hdparm (see here for step-by-step instructions). Note two things: As hdparm manpage vividly states, the operation is "DANGEROUS". On the other hand, it may also repair bad blocks.
What is the fastest way to write all sectors on a drive?
1,576,861,160,000
I'm trying to see the contents in raw bytes of a dummy partition /dev/sda3, which I've made to be 100MiB through gparted. I want to test writing and reading on that partition. Is there a tool that can be used for manual inspection ?
The same tools that you can use for other files (generally) can also be used on block devices. This means that you can use, for example, xxd or hexdump to inspect the filesystem: $ sudo xxd /dev/sda2 | head -10 00000000: eb58 9053 5953 4c49 4e55 5800 0200 0000 .X.SYSLINUX..... 00000010: 0000 0000 0000 0000 3f00 ff00 ...
How to inspect the raw contents of a partition?
1,576,861,160,000
I have a device from about twenty years ago that uses an IDE hard drive as storage. I would like to keep using it, but it has a USB 1 interface that is extremely slow. I can take out the hard drive and connect it to a USB 2.0 cable that is much faster, however getting access to the FAT32 data is not so straightforward...
Through a bit of trial and error and being pointed in the right direction by @MarcusMüller, the following command successfully mounted the drive in a read-write configuration. The performance seems a bit lacking, but it is still much better than the original USB 1 configuration. nbdkit eval get_size='blockdev --getsiz...
Mounting a drive from an embedded device with bytes swapped
1,576,861,160,000
I want to create a disk image of my solid-state drive using the dd (disk dump) command. There are multiple partitions on the SSD. Is it possible to make a complete image of the drive including all partitions? This is an example of how it works with an HDD: dd if=/dev/sda of=/mnt/sdb/disk.img conv=sync,noerror bs=64K ...
If you want do make image of the entire disk, use /dev/nvme0n1, this is the NVMe drive block device (it's actually a "namespace", you can in theory have multiple namespaces on an NVMe drive, it's like a "partition on a hardware level", but most "consumer" NVMes come with only one namespace). /dev/nvme0 is controller, ...
How to create an ISO disk image of an NVMe SSD?
1,576,861,160,000
I have an embedded device with this SD card: [root@(none) ~]# busybox fdisk -l Disk /dev/mmcblk0: 3965 MB, 3965190144 bytes 4 heads, 16 sectors/track, 121008 cylinders Units = cylinders of 64 * 512 = 32768 bytes Device Boot Start End Blocks Id System /dev/mmcblk0p1 305 84...
I am guessing here, as I have no Kobo Glo (I wish my Bookeen HD was reprogrammable). You seem to have a 2Gb SD memory internally ( 60352 cylinders of 32K each) The dd does skip 2048 blocks of 512 (1048576), which is less than the 305 cylinder offset (9994240). In fact have to write more than 8Mb to reach the /dev/mmcb...
What does this dd command do exactly?
1,576,861,160,000
I have a running Linux system, and I'd like to have a full backup of it using dd, which, in my limited knowledge is the only tool every system has. The distro doesn't matter mainly because I should apply this approach to several different servers with different flavours installed, and I cannot install new software on...
Not so much a solution as a few nuggets of advice which may be helpful to consider if using tar/cpio/rsync etc. First, it might be a good idea to backup from a bind mount of your source filesystem (mount --bind source mntdir). This will have a similar effect as the --one-file-system options to rsync and tar and -xdev ...
How to backup a running system?
1,576,861,160,000
sudo mdadm --build /dev/md0 --level=linear --raid-devices=3 /dev/loop0 /dev/sda1 /dev/sda2 After running the above command, /dev/md0 is smaller than /dev/loop0 + /dev/sda1 + /dev/sda2. Why is that happening, and how can I make it the correct size? /dev/sda1 is a very small partition needed by the /dev/sda2 Windows 7 ...
Normally, Linux mdadm RAID devices are always a little smaller than the size of the component devices (or their sum in the case of RAID 0), because MD devices store metadata. In this case you have used --build, which invokes a manual assembly mode that does not use metadata. Nevertheless, a linear array might be small...
RAID mdadm virtual disk too small
1,576,861,160,000
Some preamble: I'm taking bitwise copy of disk devices (via dd command) from twin hosts (i.e. with the same virtualized hardware layout and software packages, but with different history of usage). To optimize image size I trailed all empty space on partitions with zeroes (e.g. from /dev/zero). I'm also aware of reser...
You can purge the journal by either un-mounting, or remounting read-only (arguably a good idea when cloning). With ext4 you can also turn off the journal altogether (tune2fs -O ^has_journal), the .journal magic immutable file will be removed automatically. The journal data will still be on the underlying disk of cours...
How to clean journals in ext3/ext4 filesystem? [closed]
1,576,861,160,000
This question has bothered me for a while. I have a remote machine with CentOS, which can only be accessed via ssh. I need to clone everything this system has and replicate it in my local with virtualbox. Here is what did: Clone the system by following steps/commands (dd) mentioned in this article. The command looks ...
You may be missing a boot loader. You'll probably want to go with dd if=/dev/sda instead of /dev/sda1. Maybe you'll want to use some stop argument to prevent from dumping further than your bootloader and first partition. Update: Reading your df output, I'm guessing your source instance is something like a Xen Paravir...
How to clone remote Linux system and make an image file with it locally?
1,576,861,160,000
I need to delete the first 2 bytes of a 6MB file. However, this is an embedded Linux with only 32 Mbytes RAM and less than 1 MB free flash memory. I tried using dd, as: 1 - # dd bs=1 skip=2 count=1022 if=input of=ouput_1 2 - # dd bs=1024 skip=1 if=input of=ouput_2 3 - # rm -rf input 4 - # (dd if=ouput_1 ; dd if=ouput_...
I think this should work: $ # Create test file $ echo "Hello, World" > h.data $ $ # Move contents up by 2 bytes $ # Note if= and of= are the same for in-place editing $ dd bs=2 if=h.data skip=1 seek=0 conv=notrunc of=h.data 5+1 records in 5+1 records out 11 bytes (11 B) copied, 0.000598796 s, 18.4 kB/s $ $ # N...
How to delete part of a binary file without copying
1,576,861,160,000
I found a few examples that claimed this but I could not manage to get dd to convert a file with a given block size to double that block size. dd if=disk256bytesectors.img of=disk512bytesectors.img cbs=256 ibs=512 obs=512 conv=sync My disk img is 10 megabytes in size I was expecting a new image of 20 megabytes, but n...
You might be able to use socat which uses a Unix domain socket when you specify exec: for a command. This can be made of type datagram (type=2) to ensure the input to dd is only 256 bytes. For example, for 2 bytes per datagram (-b2) padded to 4 (bs=4): $ echo abcdefx | socat -u -b2 - exec:'dd bs=4 conv=sync',type=2 ...
dd need to enlarge/pad each input block to double size
1,576,861,160,000
What is the count default in dd command if not specified ? dd if=/dev/mem bs=1k skip=768 instead of full form like dd if=/dev/mem bs=1k skip=768 count=50 I did not find an answer with Google.
The default is unlimited - keep going until you run out of space.
dd count default
1,576,861,160,000
I'm working on Raspberry Pi OS on a Pi3B. I'm working with a script that does a few things for partitioning and there are times I want to wipe the drive, so I use (as root): dd if=/dev/zero of=/dev/mmblk0 status=progress bs=1M And I always get this - even with different microSD cards and different sizes: 300941312 by...
On my Pi the SD cards are named /dev/mmcblkN (for values of N from 0). You typed /dev/mmblk0, which suggests you are filling the root filesystem instead of writing to the primary storage device. You can verify this by looking at the file type (consider the first character of each line; - is a file, b is a block device...
dd - No space left on device with microSD cards