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

Recognizing SWAP partitions (incorrectly) and loop inputs



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.

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 then also made two changes to the knoppix-autoconfig script.

  One was to add an 'anyswap' cheat code which causes reversion to
  the old method of just checking the signature (in case anybody
  needs that).

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
or:
	while dondition ; do
	  stuff
	done < somefile

One uses normal pipes. the other just does a regular redirect.

BOTH changes are in the autoconfig.diff file... Otherwise the only
addition there was to add the line:
    checkbootparam "anyswap" &&  export ANYSWAP='yes' || export ANYSWAP=""


the one construct:

	cat /proc/sys/dev/cdrom/info 2>/dev/null  |
	while read drive name cdroms; do
		....
	done
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?

--
Stephen Samuel +1(604)876-0426             samnospam@bcgreen.com
		   http://www.bcgreen.com/
   Powerful committed communication. Transformation touching
     the jewel within each person and bringing it to light.
--- fstype	2004/09/27 22:26:59	1.1
+++ fstype	2004/09/27 22:37:48
@@ -28,7 +28,16 @@
   *[Jj][Ff][Ss]*)              echo "jfs";;
   *[Ee][Xx][Tt]3*)             echo "ext3";;
   *[Ee][Xx][Tt]2*)             echo "ext2";;
-  *[Ss][Ww][Aa][Pp]*)          echo "swap";;
+  *[Ss][Ww][Aa][Pp]*)          
+	  basedsk=${1%[0-9]} basedsk=${basedsk%[0-9]} 
+	  if [  "yes" = "$ANYSWAP"  ]  || [ ! -b "$basedsk" ] ||
+	     fdisk -l $basedsk  | grep "^$1 "|grep -iqs linux ;then
+		echo swap 
+	  else
+		echo auto 
+		echo 1>&2 "ignoring swap signature  on $1 use 'anyswap' to enable"  
+	  fi
+  ;;
   *[Nn][Tt][Ff][Ss]*)          echo "ntfs";;
   *[Ff][Aa][Tt]*)              echo "vfat";;
   *)                           echo "auto";;
--- knoppix-autoconfig	2004/09/27 22:28:58	1.1
+++ knoppix-autoconfig	2004/09/27 22:43:39
@@ -732,6 +732,7 @@
 fi
 
 # Add cdrom drives that have NOT been found by hwsetup (Kernel 2.6 bug?)
+cat /proc/sys/dev/cdrom/info 2>/dev/null | 
 while read drive name cdroms; do
 case "$drive$name" in drivename:) 
 for cd in $cdroms; do
@@ -744,9 +745,7 @@
 done
 ;;
 esac
-done <<EOT
-$(cat /proc/sys/dev/cdrom/info 2>/dev/null)
-EOT
+done 
 
 update_progress 60
 
@@ -912,6 +911,7 @@
 
 # Collect partitions from /proc/partitions
 partitions=""
+awk 'BEGIN{old="__start"}{if($0==old){exit}else{old=$0;if($4&&$4!="name"){print $0}}}' /proc/partitions |
 while read major minor blocks partition relax; do
 partition="${partition##*/}"
 [ -z "$partition" -o ! -e "/dev/$partition" ] && continue
@@ -920,9 +920,7 @@
 sd?) ;;                                               # SCSI Harddisk, entire disk
 [hs]d*) partitions="$partitions /dev/$partition";;    # IDE or SCSI disk partition
 esac
-done <<EOT
-$(awk 'BEGIN{old="__start"}{if($0==old){exit}else{old=$0;if($4&&$4!="name"){print $0}}}' /proc/partitions)
-EOT
+done 
 
 # Enable DMA for all IDE drives now if not disabled (and if not already done by linuxrc).
 # This is already done by linuxrc now.
@@ -946,6 +944,7 @@
 if checkbootparam "nofstab"; then
 echo " ${BLUE}Skipping /etc/fstab creation as requested on boot commandline.${NORMAL}"
 else
+checkbootparam "anyswap" && export ANYSWAP='yes' || export ANYSWAP=""
 echo -n "${BLUE}Scanning for Harddisk partitions and creating ${YELLOW}/etc/fstab${BLUE}... "
 rebuildfstab -r -u knoppix -g knoppix >/dev/null 2>&1
 if [ -e /var/run/rebuildfstab.pid ]; then
@@ -990,9 +989,7 @@
    fi
    ;;
   esac
- done <<EOT
-$(cat /etc/fstab)
-EOT
+ done < /etc/fstab
 fi
 update_progress 90
 
@@ -1165,9 +1162,7 @@
 break
 ;;
 esac
-done <<EOT
-$(cat /proc/mounts)
-EOT
+done < /proc/mounts
 fi
 fi
 

Reply to: