Oopse... [was: Re: [Discuss] Knoppix to the rescue]

Patrick NixNoob-sneaking at sneakEmail.com
Sun Oct 28 02:26:21 PDT 2007


On Sat, 27 Oct 2007 21:45:52 -0700
I wrote:

Umm, sorry about the extra double-quote in that `Usage' blurb.
Was just one line at first, but I wanted it more... usable.

And the remount doesn't work for generic /dev/sd* partitions if
they're not in fstab.



Uh, yeah,

Patrick.

[...]
> 
> 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
rm -f "$tmp1" "$tmp2"
umount "$1"
#
#  Well, I hope everything that's supposed to get written to
#  disk, actually *does* get written to disk, before the files
#  are deleted.

sleep 11
#  And a moment to cool off.

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.
else
	echo "Invalid path."
fi

#  End.

-- 
Why is it that all of the instruments seeking intelligent life in
the universe are pointed away from Earth?


More information about the Discuss mailing list