Score:1

Can't make good size image with the command DD

ng flag

Need to make an image disk of my DD. This a is a 4to hard drive with 2 partitions (total used :1,7 TO). How to get an 1,7 TO correct image with the dd command ?

Disque status with fdisk

Used :

dd if=/dev/sdq count=2399842303 of=/tmp/imagedisk.img bs=4096 status=progress

But this is not working.. The task will continue over 2,3,4 TO .

Please can somebody give me the correct command?

Score:1
in flag

First of all, please be noted that if you are making a disk image (or even a partition image), you can't just clone how much is used on filesystem level (i.e. Used as shown in df).

Besides, even if by "used" you are referring to the size of the partition(s), if you are not making a full disk image, you should probably make image(s) of the partition(s) instead (and optionally back up the partition table / MBR to a separate file, especially with the case of GPT -- there's sgdisk).

If you really can't afford to actually make disk/partition image(s) because of shortage of spare storage, you can consider:

  • make "filesystem clone", with tool like partclone or upstream / official approach for certain types of filesystem, such as btrfs send.
  • dd with conv=sparse, which could avoid blocks (in the sizebs=, I think) that are completely zero from taking up as much space (See this for more details.)
  • shrink the filesystem(s) as much as you can so that you can then resize the partition(s) before cloning. Some types of filesystems do not support shrinking though.

I'm not actually experienced with conv=sparse btw. Also how well it works could depend on a few things, such as the type of the filesystem that the images are written to / stored, and/or whether the source drive is an SSD that is at least partially RZAT ("read zero after trim"), etc.

Finally, just to talk about dd, there's iflag=count_bytes, which would allow you to use count= to determine how many bytes (instead of blocks in the size of (i)bs=) to clone.

bs=4k is often good enough / the best to use, not because that might be the physical block size of the hard drive, but because it is the typical page size. Although size like 128k or 512k could work even better when reading from certain flash memory storage devices.

Tom Yan avatar
in flag
Or avoiding cloning at all, (learn) `rsync`.
anthony COPPET avatar
ng flag
THank you thank so so much... ... working on that for so long. Now it's clear. Count as you mentioned give me 180 mb img ... But I made this : dd if=/dev/sdq of=FinalBatocera.img bs=4k count=439453125 status=progress. And its seems to work (i'm waiting). Now what about the most important : restauring. The output disk is smaller (2TB instead of 4T source). I've read a lot about the skeep and seek options as I did for the count command... Thank you
Michael Hampton avatar
cz flag
@anthonyCOPPET You should not worry about skip and seek, but instead use `conv=sparse`. All of the zero space will be skipped.
anthony COPPET avatar
ng flag
ok I've checked the image. The size is good :1660156248 bytes. BUT When I m using /dev/loop got "mount: /mnt/loop: wrong fs type, bad option, bad superblock on /dev/loop0, missing codepage or helper program, or other error." However Its working when using Imagemounter on mac. The fdisk returns : FinalBatocera.img1 1 4294967295 4294967295 2T ee GPT. Tried to make (before reading your comment about sparse option) dd if=/Image.img of /dev/sdr (new disk 2TB). It's stopped to 2GB ....
anthony COPPET avatar
ng flag
Even with the sparse option .. or noerror. The write ended at 2.4 GB...
Score:0
np flag

dd if=/dev/sdq of=/tmp/imagedisk.img bs=1MB count=1700000

bs=1MB sets a block size of 1 Megabyte (1000000 bytes), while count=1700000 multiplies it, resulting in Terabyte scale.

If you really want to stick with 4Kb blocks, you have to do the math: 1.700.000.000.000/4096 = 415039062,5 ~ 415039063 resulting in:

dd if=/dev/sdq of=/tmp/imagedisk.img bs=4k count=415039062 (4k = 4096).

anthony COPPET avatar
ng flag
THank you so much... Working about this for 4 days... test after test. Now it's clear. Count as you mentioned give me 180 mb img ... But I made this :
us flag
Notice that this command takes 17 TB from the start of the disk. If the data you want is not within the first 17 TB, you'll have a useless image.
np flag
@anthonyCOPPET I've missed an order in 2nd example. Corrected my answer. It should be 1.7*10^12.
anthony COPPET avatar
ng flag
and for restoring ?? what is the perfect command. the new destination drive is smaller (2TO)
np flag
@anthonyCOPPET You shouldn't really use dd for backups. There are much better software for this that can handle things at filesystem/file level. Like rsync and/or partclone.
np flag
You can also try CloneZilla. It includes & automates tools like partclone & automatic MBR/GPT backups. Usually works very well if you need to save your disk to image and restore it later to a larger/smaller driver (it can resize known filesystems too). Only thing it can't handle yet - thin LVM volumes. If you don't have them, you should be good with it.
anthony COPPET avatar
ng flag
I understand ... Clonezilla is simple that's true.. But the case "shrinking output image" appears more complicated
Score:0
cn flag

bs=512 should do the trick. The logical sectors displayed in the start end columns are 512 bytes sectors

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.