#!/bin/bash # just a script to help with some disk rescue that involves cd writing # this will output a series of command lines for taking a snapshot of # a drive or partition, in CD-sized chunks, using dd # # edit these to suit # disk info in MB, where 1MB = 1024*1024 bytes = 1048576 bytes # get diskend by: # 'fdisk -lu' which will show sectors of 512 bytes # 'echo "scale=1;([end sector] - [start sector])/2048" | bc # the 2048 comes from: (512 bytes per sector) / (1024 * 1024) bytes per Mb # round the result up to the nearest integer for $diskend diskend=24380 # $chunk is the size of the CD, in Mb chunk=660 # which disk disk=/dev/hda12 # get a name for dd's output, tail of $disk above, # to be combined with the count later fname=${disk##*/} # blocksize, in bytes, used in dd # 1MB (1024 * 1024) is chosen here block=1048576 # bytes in a sector sector=512 # sectors per block secb=$((${block} / ${sector})) numchunks=$(($(echo "${diskend} / ${chunk}" | bc ) + 1)) # counters skip=0 cnt=0 while [ ${cnt} -lt ${numchunks} ] do start=$((${cnt} * ${chunk})) end=$((${start} + ${chunk})) if [ ${end} -gt ${diskend} ] then chunk=$((chunk - (${end} - ${diskend}))) end=$((${diskend})) fi fpre=$((${cnt}+1)) if [ ${fpre} -lt 100 ] then fpre=0${fpre} fi if [ ${fpre} -lt 10 ] then fpre=0${fpre} fi secst=$((${start} * ${secb})) secen=$((${end} * ${secb})) echo "dd if=${disk} of=${fpre}${fname} bs=${block} skip=${skip} count=${chunk}" echo " (start=${start}MB, ${secst}s, end=${end}MB, ${secen}s)" skip=$((${skip} + ${chunk})) cnt=$((${cnt} + 1)) done echo "chunks=${numchunks}"