3

I am trying to copy a partition from an entire disk image.

This command is working: dd if=image.iso of=test bs=512 skip=1161215 count=32768

In order to increase the speed, I'd like to set a bigger bs.

dd if=image.iso of=test bs=1M skip=1161215 count=32768

skip and count's unit is bs, is it possible to set a separate unit ?

I could then make this command:

dd if=image.iso of=test bs=4M skip=1161215*512 bytes count=32768*512 bytes

4 Answers 4

7

Specify Different Units

Yes, it is possible to specifiy different units for bs and skip and count. However, there are only two choices for the skip and count units. skip and count must match the bs value or be specified in bytes. To set the units to bytes you must add an additional operand of iflag=skip_bytes for skip and iflag=count_bytes for count or iflag=skip_bytes,count_bytes for both.

In your case, this command should accomplish your goal:

dd if=image.iso of=test iflag=skip_bytes,count_bytes bs=4M \
  skip=$((1161215*512)) count=$((32768*512))

It appears you want to extract exactly 16M. Set bs=4M count=4 and use only skip_bytes:

dd if=input.file of=output.file iflag=skip_bytes bs=4M \
  skip=$((1161215*512)) count=4

Example for testing:

An input file with the contents:

aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz

With count_bytes (extract exactly count bytes):

$ dd if=input.file of=output.file iflag=skip_bytes,count_bytes bs=8 skip=5 count=20

yields 20 characters:

cddeeffgghhiijjkkllm

Without count_bytes (count is multiplied by bs):

dd if=input.file of=output.file iflag=skip_bytes bs=8 skip=5 count=3

yields 24 characters:

cddeeffgghhiijjkkllmmnno

Your version of dd may not include iflag, skip_bytes, or count_bytes. These examples were tested on Debian 9 using dd (coreutils) 8.26.

Update: skip_bytes and count_bytes are supported from coreutils v8.16(March 2012), so nearly all distributions will support it by default

0
3

It is possible by combining dd commands.

dd if=image.iso bs=4M | { dd bs=1161215 count=1 of=/dev/null; dd bs=${16*512} count=${32768/16} of=partition.dump; }

We can just use the count size as a dividable without remainder instead of both, offset and size.

Or use the end sectors.

2
  • Interesting approach, very nice idea. But I don't really understand the calculation ${32768/8192} you made. Did you also test the performance of this? I suspect it could be lower with your pipe and the different block sizes.
    – Byte Commander
    Jul 16, 2016 at 9:42
  • Yes, I made a mistake, divided by 16 since 32768 is the number of 512B's sectors. Lack of time, I didn't try yet, I found this solution unexpectedly. After thinking, you may be right, maybe the first instance of dd which redirects to /dev/null, will take times. But we could imagine another configuration with pipe to remove this processing time.
    – None
    Jul 17, 2016 at 1:12
1

What you want to achieve seems impossible to me.

From man dd:

   bs=BYTES
          read and write up to BYTES bytes at a time

   ibs=BYTES
          read up to BYTES bytes at a time (default: 512)

   obs=BYTES
          write BYTES bytes at a time (default: 512)


   count=N
          copy only N input blocks

   skip=N skip N ibs-sized blocks at start of input

While bs (or ibs and obs) has an argument BYTES which determines the block size i.e. the amount of bytes that gets processed at once, the count and seek parameters have an argument N which determines the number of blocks to process/skip.

So as dd can always only copy or skip whole blocks of data (block size determined by bs/ibs&obs), you must set the block size to a value by which the skip offset and the count size are dividable without remainder.

2
  • With your assumption, the quantity of Bytes copied is different for both dd if=image.iso of=test bs=1M skip=1161215 count=32768 and dd if=image.iso of=test bs=512 skip=1161215 count=32768. It means it's correlated.
    – None
    Jul 15, 2016 at 8:25
  • @Alexis_FR_JP Sorry, I was obviously wrong before. I researched it again and corrected my mistake. Unfortunately this means you can not do what you wanted to achieve.
    – Byte Commander
    Jul 15, 2016 at 10:20
1

is it possible to set a separate unit?

AFAIK, with dd only, no.

but you can use losetup to achieve your goal, like this:

dd if=$(losetup --sector-size 512 --offset $((1161215*512)) --sizelimit $((32768*512)) --find --show image.iso) of=test bs=4M

or, more concisely, like this:

dd if=$(losetup -b 512 -o $((1161215*512)) --sizelimit $((32768*512)) -f --show image.iso) of=test bs=4M

Even more...

In order to increase the speed, I'd like to set a bigger bs

if you just want to 'forget about' "blocksize optimization", and it's available for you, simply use pv, like this:

pv $(losetup -b 512 -o $((1161215*512)) --sizelimit $((32768*512)) -f --show image.iso) > test
1
  • I forgot why I needed that, let me try later and approve your answer if it's correct.
    – None
    May 31, 2019 at 14:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .