1

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?

3 Answers3

1

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
  • 747
  • 3
  • 9
  • Or avoiding cloning at all, (learn) `rsync`. – Tom Yan Aug 16 '21 at 16:49
  • 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 – anthony COPPET Aug 16 '21 at 16:54
  • @anthonyCOPPET You should not worry about skip and seek, but instead use `conv=sparse`. All of the zero space will be skipped. – Michael Hampton Aug 18 '21 at 00:44
  • 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 Aug 18 '21 at 12:17
  • Even with the sparse option .. or noerror. The write ended at 2.4 GB... – anthony COPPET Aug 18 '21 at 12:41
0

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

Gerrit
  • 1,552
  • 8
  • 8
0

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).

NStorm
  • 1,312
  • 7
  • 18
  • 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 : – anthony COPPET Aug 16 '21 at 16:35
  • 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. – Tero Kilkanen Aug 16 '21 at 18:14
  • @anthonyCOPPET I've missed an order in 2nd example. Corrected my answer. It should be 1.7*10^12. – NStorm Aug 16 '21 at 19:10
  • and for restoring ?? what is the perfect command. the new destination drive is smaller (2TO) – anthony COPPET Aug 16 '21 at 22:42
  • @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. – NStorm Aug 17 '21 at 04:51
  • 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. – NStorm Aug 17 '21 at 06:14
  • I understand ... Clonezilla is simple that's true.. But the case "shrinking output image" appears more complicated – anthony COPPET Aug 18 '21 at 14:20