Hot answers tagged

58

dd was useful in the old days when people used tapes (when block sizes mattered) and when simpler tools such as cat might not be binary-safe. Nowadays, dd if=/dev/sdb of=/dev/sdc is a just complicated, error-prone, slow way of writing cat /dev/sdb >/dev/sdc. While dd still useful for some relatively rare tasks, it is a lot less useful than the number of ...


20

Just for completeness the call for ddrescue. The --sparse or -S flag allows the destination to be written sparsely: $ ddrescue -S -b8M /dev/sda1 /mount/external/backup/sda1.raw Or with long option: $ ddrescue --sparse --block-size 8M /dev/sda1 /mount/external/backup/sda1.raw Or if you prefer MiBs: $ ddrescue -S -b8Mi /dev/sda1 /mount/external/backup/...


13

Use: tune2fs -U random /dev/sdb1 if it's an ext filesystem, or xfs_admin -U generate /dev/sdb1 if it's an xfs filesystem. The reason the second partition has the same UUID is because dd just copies data from one file to another (dd if=/dev/sda1 of=/dev/sdb1 = cat /dev/sda1 > /dev/sdb1); dd doesn't know what a partition is, or how to generate a UUID, ...


13

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.


12

When is dd suitable for copying data? (or, when are read() and write() partial) points out an important caveat when using count: dd can copy partial blocks, so when given count it will stop after the given number of blocks, even if some of the blocks were incomplete. You may therefore end up with fewer than bs * count bytes copied, unless you specify iflag=...


11

Besides of ext2 /ext3 / ex4 and xfs, you can also change UUID of the following filesystem or block device. Swap swaplabel -U $NEW_UUID Software RAID (md raid) For MD RAID, you must stop the RAID first, then update the UUID when re-assembling. So if your RAID is mounted to /, you need update UUID in offline mode -- use a live CD to do it. mdadm --stop $...


9

QEMU comes with the qemu-img program to convert between image formats. qemu-img convert -f qcow2 -O raw my-qcow2.img /dev/sdb


7

FSArchiver (http://www.fsarchiver.org/Main_Page) may do what you're looking for. Disk images include only data, not free space, and can be restored to disks of differing sizes.


7

dd uses a very small blocksize by default (512 bytes). That results in a lot of overhead (one read() and write() syscall for every 512 bytes). It goes a lot faster when you use a larger blocksize. Optimal speeds start at bs=64k or so. Most people use a still larger bs=1M so it becomes human readable (when dd says it copied 1234 blocks, you know it's 1234 ...


7

The physical drive should not start smoking, at least, but chances are very good that your filesystem will not work anymore (I mean, the target filesystem; if you just copied and did not touch anything in the source, the source itself should be fine). Data inside a partition is not necessarily allocated in increasing order. Some of it may be at the end of ...


7

If you're just looking to copy an SD card exactly from one to another then you can do so with dd on the command line. You should NOT do this from your raspberry pi from it's own OS. This is because the OS may write to the SD card while copying and corrupt the copy. To copy an sd card, plug both into your two readers (it doesn't matter whether or not they ...


6

For XFS, use: xfs_admin -U <uuid> <device> Use xfs_admin -u <device> to view a UUID (note lower case option to view, versus upper case option to set). Another post on U&L pointed out the blkid command for viewing all or some of the UUIDs on the system.


5

Here are some dd tricks I've come up with over the years.. Cut-and-Paste on unfriendly tty or non-interactive mode bash If you're in a situation where EOF/^D/^F is not detected you can use dd to transfer text files to a host. Since it will stop reading after a specified amount of bytes automatically. I used this as recently as last year during a security ...


5

Getting statistics about ongoing dd process You can use the kill command with the appropriate signal to make dd output statistics to standard error. From the GNU dd man page: Sending a USR1 signal to a running 'dd' process makes it print I/O statistics to standard error and then resume copying. $ dd if=/dev/zero of=/dev/null& pid=$! $ kill -...


5

Changing the block size is a good way to change how much gets buffered or is read/written at a time. Doesn't really relate to whether it's a real block device or an infinite/virtual one. It's about how much you want stored in memory before dd goes to write it out. bs= sets both ibs= (how much data is read in at a time) and obs= (how much data is written ...


5

There's a bit of a cargo cult around dd. Originally, there were two bugs in cp that caused problems: It would misdetect files as sparse when reported with a block size other than 512 (Linux used a block size of 1024), and it did not clear empty blocks from the destination when copying from a sparse file to a block device. You can find some references to ...


5

If you clone a partition of type ext4, the target partition will be completely overwritten with a direct and complete copy of the source partition. As such it will end up as being of type ext4. That's what cloning means. On the other hand if you copy all the files from a filesystem of type ext4 to a filesystem of type xfs, that's not a clone but you will ...


4

You can redirect some output content. It's particularly useful, if you need to write with sudo: echo some_content | sudo dd status=none of=output.txt Besides sudo it's equivalent to: echo some_content > output.txt or to this: echo some_content | sudo tee output.txt > /dev/null


4

You can use dd to copy the data from one device to another. dd if=/my/source/device of=/my/dest/device bs=4096 dd will do a byte-per-byte copy of the source, of course you will not be able to do this on a running filesystem, this will most likely cause corrupt data. If you are using a fileystem or some other utility like LVM with snapshot ability you can ...


4

You cannot and must not copy files in /proc, or /sys. Generally speaking, you need to arrange to copy only the disk-backed files. The files under /proc and /sys are generated by the kernel on the fly when you read them. Their contents provides information about the running system. For example, /proc/1234 is a directory where you can read information about ...


4

You can use the lower level dmsetup command to direct the kernel device mapper to create a snapshot. If you are otherwise using LVM aside from the Windows partition, then create a logical volume to use as the backing store of the snapshot. lvcreate -n store -L 10g vg echo 0 `blockdev --getsz /dev/sda1` snapshot-origin /dev/sda1 | dmsetup create origin echo ...


4

To answer the second part of your question. How to mount a FS stored in two files (a and b) Two options I can think of: Using device-mapper and loop devices: losetup /dev/loop1 a losetup /dev/loop2 b s() { blockdev --getsize "$1"; } dmsetup create merge << EOF 0 $(s /dev/loop1) linear /dev/loop1 0 $(s /dev/loop1) $(s /dev/loop2) linear /dev/loop2 0 ...


4

Your server settings, like any system-wide program settings, are to be found under /etc. The exact location depends on the distribution, but /etc/apache or /etc/apache2 are good bets. Both Ubuntu and Mint use /etc/apache2. If you have the same plug-ins installed and versions of Apache that aren't too far apart, you can simply copy the whole /etc/apache2 ...


4

dd if=/dev/zero of=RISCPC.IMG.new bs=1 count=512 dd if=RISCPC.IMG of=RISCPC.IMG.new bs=512 seek=1 dd if=/dev/zero bs=1 count=512 >> RISCPC.IMG.new mv RISCPC.IMG{.new,} If you can use cat, you might consider this: cat > RISCPC.IMG.new \ <(dd if=/dev/zero bs=512 count=1) \ RISCPC.IMG \ <(dd if=/dev/zero bs=512 count=1) mv RISCPC....


4

Yes, just use for restore image from Clonezilla: cat sda5.ext3-ptcl-img.gz.a* | gunzip -c | partclone.restore -d -s - -o /dev/sda5


4

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 might work with ext4 as long as you don'...


3

You can do this if you have disks with the same type of partition tables: i.e. with the same type addressing mode in BIOS (CHS/LBA/LBA32/GPT). If you are not sure about it I can recommend you divide the new disk into partitions with the same size as on the old disk and copy (via dd) only partitions, not whole disk. Then you can use the last part of the disk ...


3

Yes, it is possible. It is not very hard but it requires a good comprehension of boot sequence. The "copy" sequence is something like: partition you usb stick and mkfs the partitions. copy the files from source partitions to usb-stick partitions (e.g. using rsync). modify the /etc/fstab to match your new partitions. install a new boot-loader on usb-stick. ...


3

Sounds like you have to build your own repository. Put your RPMs in your desired version into that repository. Then activate these repositories on both machines (as installation source) and install the packages.


3

What you're looking for is a way to clone a filesystem, a disk or partition. See in particular How can I use DD to migrate data from an old drive to a new drive? Clone OS to a smaller drive Clone whole partition or hard drive to a sparse file Cloning a bootable USB stick to a different-size stick Cloning the whole disk or partition with cat or cp is the ...


Only top voted, non community-wiki answers of a minimum length are eligible