[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [debian-knoppix] Recognizing SWAP partitions (incorrectly) and loop inputs



Hello Stephen,

On Mon, Sep 27, 2004 at 03:52:34PM -0700, Stephen Samuel (leave the email alone) wrote:
> I ran into a situation this weekend where I had a disk which
> had ONCE been formatted as a Linux SWAP partition and then later
> as a BSD filesystem... IT turns out that the bsd newfs program
> does NOT stomp on the Linux swap magic string, meaning that when
> knoppix booted, it used the new BSD filesystem as a swap partition.
> Since the machine in question is low on memory, the swap was
> quickly ued, and the filesystem trashed.

That's bad, but I would rather say it's a definitive bug of the bsd newfs
program not to clear a swap signature when creating a file system header!

Linux does not require a swap partition to be of type 82, it can well swap on
any partition or even file / NFS volume that has a valid swap signature. So,
the behaviour you observed was, sorry for your BSD filesystem, IMHO technically
correct: Knoppix just reused a valid swap space on your harddisk.

> I suggest that the best thing to do for this is to check partitions
> which exhibit a SWAP signature to verify that they're also LINUX
> type partitions... I modified fstype to do this.  (see attached diffs).

I will probably add your patches, even that it means that swap partitions other
than type 82 will no longer be detected and used correctly. Most people,
however, DO use type 82 for swap partitions. Thanks.

> The other is that I changed the way that input is fed to while
> loops.
> 
> The construct
> 	while condition ; do
> 	   stuff
> 	done << EOF
> $( prog )
> EOF
> 
> seems ineffecient, and obtuse... I'd rather do either:
> 
> 	prog |
> 	while condition ; do
> 	  stuff
> 	done

But this forks another subshell (efficiency?), plus, all the variables that are
set within the while loop (which is running in the forked subshell) will be
"forgotten" at the end of that loop. Won't work in many cases. :-(

Simple wxample:

i=0
cat /etc/passwd | i=`wc -l`
echo $i

does not give the results that you probably did expect.

> or:
> 	while dondition ; do
> 	  stuff
> 	done < somefile

The "here" document <<EOF has the advantage of automatic creation and deletion
of the temporary file you created implicitly by $(). That's one reason why I
use it very often in my scripts.

> could be seitched to:
> 	[ -r /proc/sys/dev/cdrom/info ] &&
> 	while read drive name cdroms; do
> 		...
> 	done < /proc/sys/dev/cdrom/info
> 
> but I'm not sure if the proc file is capable of creating an error
> even if the -r test fails.... Is that a real worry?

Caution: Somtimes constructs like

while read variable; do ...; done < /proc/something

just read one or NO line at all, because the shell seems to check the size of
the file to be read incorrectly. I have also observed differences in the result
of $(cat /proc/...) and $(</proc/...) occasionally. I'm not sure if this is a
kernel or bash bug, but it seems that cat is more safe in these cases than
using redirects.

Regards
-Klaus Knopper


Reply to: