Fórum Ubuntu Linux - PT
Suporte Técnico => Sistema => Tópico iniciado por: pentestbox em 29 de Novembro de 2016, 11:21
-
Ola pessoal, vou fazer uma pergunta que parece ser simples, gostaria de saber pra que serve o parâmetro bs no comando dd, estava pesquisando a respeito e me disseram que esse comando agiliza a cópia bit a bit de um dado passo no if para o of, isso procede?
a final qual o proposito real desse parâmetro.
obrigado.
-
Em linhas gerais é isso mesmo que você disse.
Na relação de opções mais comuns vem dito assim:
bs=BYTES
read and write up to BYTES bytes at a time
Na documentação consta:
‘bs=bytes’
Set both input and output block sizes to bytes. This makes dd read and write bytes per block, overriding any ‘ibs’ and ‘obs’ settings. In addition, if no data-transforming conv option is specified, input is copied to the output as soon as it’s read, even if it is smaller than the block size.
Geralmente uso mesmo 1M, mas é mais por comodidade de padronização do que verificação real de qual valor de block size seria mais adequado.
Entretanto, querendo, isso pode ser testado conforme o específico hardware.
Claro que se tiver mesmo uma imensidão de dados a serem copiados, pode até compensar testar, porém nesses casos possivelmente será melhor usar um software especialista como o Clonezilla.
-
Por exemplo, nesse máquina usada aqui no momento, usando um live-iso do Ubuntu 16.10 padrão (=Unity) montado diretado em HDD, portanto, kernel 4.8, o resultado é esse:
./dd_obs_test.sh
NOTE: Kernel cache will not be cleared between tests without sudo. This will likely cause inaccurate results.
block size : transfer rate
512 : 261 MB/s
1024 : 516 MB/s
2048 : 887 MB/s
4096 : 1.0 GB/s
8192 : 1.4 GB/s
16384 : 1.5 GB/s
32768 : 1.8 GB/s
65536 : 2.2 GB/s
131072 : 2.4 GB/s
262144 : 2.5 GB/s
524288 : 2.4 GB/s
1048576 : 2.3 GB/s
2097152 : 1.7 GB/s
4194304 : 1.4 GB/s
8388608 : 1.4 GB/s
16777216 : 1.4 GB/s
33554432 : 1.3 GB/s
67108864 : 1.3 GB/s
O teste foi feito com o script postado adiante.
fonte:
dd: How to calculate optimal blocksize?
http://stackoverflow.com/questions/6161823/dd-how-to-calculate-optimal-blocksize
-
#!/bin/bash
# Since we're dealing with dd, abort if any errors occur
set -e
TEST_FILE=${1:-dd_obs_testfile}
TEST_FILE_EXISTS=0
if [ -e "$TEST_FILE" ]; then TEST_FILE_EXISTS=1; fi
TEST_FILE_SIZE=134217728
if [ $EUID -ne 0 ]; then
echo "NOTE: Kernel cache will not be cleared between tests without sudo. This will likely cause inaccurate results." 1>&2
fi
# Header
PRINTF_FORMAT="%8s : %s\n"
printf "$PRINTF_FORMAT" 'block size' 'transfer rate'
# Block sizes of 512b 1K 2K 4K 8K 16K 32K 64K 128K 256K 512K 1M 2M 4M 8M 16M 32M 64M
for BLOCK_SIZE in 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864
do
# Calculate number of segments required to copy
COUNT=$(($TEST_FILE_SIZE / $BLOCK_SIZE))
if [ $COUNT -le 0 ]; then
echo "Block size of $BLOCK_SIZE estimated to require $COUNT blocks, aborting further tests."
break
fi
# Clear kernel cache to ensure more accurate test
[ $EUID -eq 0 ] && [ -e /proc/sys/vm/drop_caches ] && echo 3 > /proc/sys/vm/drop_caches
# Create a test file with the specified block size
DD_RESULT=$(dd if=/dev/zero of=$TEST_FILE bs=$BLOCK_SIZE count=$COUNT conv=fsync 2>&1 1>/dev/null)
# Extract the transfer rate from dd's STDERR output
TRANSFER_RATE=$(echo $DD_RESULT | \grep --only-matching -E '[0-9.]+ ([MGk]?B|bytes)/s(ec)?')
# Clean up the test file if we created one
if [ $TEST_FILE_EXISTS -ne 0 ]; then rm $TEST_FILE; fi
# Output the result
printf "$PRINTF_FORMAT" "$BLOCK_SIZE" "$TRANSFER_RATE"
done
-
Entendi, vlw mesmo pela ajuda, uma duvida então se eu quiser que seja transferido de 1 em 1MB é so fazer bs=1M ?, se quiser então fazer de Giga em Gigabytes é so fazer bs=1G? no caso levando em consideração um bom hardware.