[Discuss] Knoppix to the rescue

Patrick NixNoob-sneaking at sneakEmail.com
Sat Oct 27 21:45:52 PDT 2007


On Tue, 23 Oct 2007 13:56:04 -0700
"pw" wrote:

> John Blomfield wrote:
> > In case I every want to try using dd to backup a Window's partition, 
> > what is the syntax, i.e. the options on the command line "dd 
> > .............."???
> > 
> > Thanks
> > John Blomfield
> 
> 
> You need to know what device the windows partitions are first.
> 
> ie:
> 
> /dev/hda1
> /dev/sda1
> ....???
> 
> The command to make a file image of the partition would be:
> 
> dd if=/dev/<whats_your_partition>  of=/somedirectory/somefile.bin
> 
> 
> To recover the partition just do the reverse using the binary file
> as the 'if' <input file> and the device as 'of' <output file>.
> 
> As is sometimes the case, my memory may be a bit hazey, so use
> the 'dd' man page as a guide.
> 
> ie:
> 
> man dd

Thanks, the manual helped, but this was the most clear and
concise.  :-)

As noted, dd seems to copy the *entire* partition, including free
space, so here's a little dd helper; something to fill the blank
blocks with nothing but 0xFF bytes -- as apposed to the garbage
data left over from previously deleted files -- so the free space
will compress better.

May be *very* time-consuming, depending how much free space
you've got, but here it is;



#!/bin/bash

if [ ! -b "$1" ] || [ ! -d "$2" ]
then
	echo "Usage: `basename $0` DEVICE DIR [FILE]

  where DEVICE is the device you want to fill,
        DIR is a directory on that (mounted) device,"
  and   FILE is the resulting backup file.
"
	exit 1
fi

tmp1="$(env TMPDIR="$2" mktemp)"
tmp2="$(env TMPDIR="$2" mktemp)"
#
#  Kludgy, but the most reliable way I could think of to create
#  temp-files inside a specified directory, *instead_of* in /tmp

echo -n $'\xFF' > "$tmp1"
#  File needs at least 1 byte to start with.

while :
do
	cat "$tmp1" >> "$tmp2" && \
	cat "$tmp2" >> "$tmp1" || \
	break
	#
	#  Keep appending/juggling data between the two files,
	#  doubling size until you run out of free space [or
	#  hit some other error, but running out of space seems
	#  likely enough].
done

sync
sleep 11
umount "$1"
mount "$1"
rm -f "$tmp1" "$tmp2"
umount "$1"
#
#  Please excuse all the mount/umount stuff.  I just want to
#  make sure everything that's supposed to get written to disk
#  actually gets written to disk, before the files are deleted.

if [ -d "$(dirname "$3")" ]
then
	if [ "$(echo "$3" | grep '\.gz$')" = "" ]
	then
		dd if="$1" | gzip > "$3.gz"
	else
		dd if="$1" | gzip > "$3"
	fi
	#
	#  If `of=/path/to/output_file' is omitted,
	#  dd pours its noise out onto standard output.
	#  Handy, for piping said noise through gzip.
fi

#  End.



This resulted in a 1 GB FAT16 partition that compressed down to a
39.0 MB file [built-in memory from an MP3 player, containing
config options, some system stuff I think [because it became
crash-prone after reformatting with gparted, but seems to work
okay now, after restoring from said backup], plus a few stock MP3s
that came with the device [not recommended, unless you're into
Chinese pop music]].

I tried it again just now, and the result was more like 226.2 MB.
Of course, now it's got more MP3s on it, and a little less blank
space.

> 
> 
> Peter

Patrick.

-- 
QOTD:
	"What do you mean, you had the dog fixed?   Just what
made you think he was broken!"


More information about the Discuss mailing list