'psavemark' - make it work with 'pmedia' and 'pdev1' - done

Under development: PCMCIA, wireless, etc.
Post Reply
Message
Author
gyro
Posts: 1798
Joined: Tue 28 Oct 2008, 21:35
Location: Brisbane, Australia

'psavemark' - make it work with 'pmedia' and 'pdev1' - done

#1 Post by gyro »

The easiest way to limit the searching done by the 'init' script is to specify both "pmedia" and "pdev1" boot parameters. This will limit the search to just the "pdev1" partition.
Unfortunately, if a "psavemark" boot param, or SAVEMARK file, is being used to specify a save partition, this is ignored.
"psavemark" does not work when "pmedia" and "pdev1" are both specified.

With the following patch to the 'init' script in 'initrd.gz' in place, specifying "pmedia", "pdev1" and "psavemark" will result in both the "pdev1" partition and the "psavemark" partition, being searched.

Edit: Prompted by the following discussion, I've finally settled on the following patch:

Code: Select all

--- init.orig   2016-01-14 23:08:12.755102000 +1000
+++ init   2016-02-04 14:25:29.926602336 +1000
@@ -340,7 +340,14 @@
    ;;
    *)
     #note: a mistake if have PDEV1 on usb booting, as it can change.
-    [ "$PDEV1" ] && LESSPARTS0="`echo "$LESSPARTS0" | grep "${PDEV1}|"`" #kernel boot param.
+    if [ "$PDEV1" ];then #kernel boot param
+     if [ "$PSAVEMARK" ];then #kernel boot param
+      BOOTDRV="`echo -n "$PDEV1" | grep -o -f /tmp/ALLDRVS0`" #ex: sda1 becomes sda
+      LESSPARTS0="`echo "$LESSPARTS0" | grep -E "${PDEV1}|${BOOTDRV}${PSAVEMARK}"`"
+     else
+      LESSPARTS0="`echo "$LESSPARTS0" | grep "${PDEV1}|"`"
+     fi
+    fi
    ;;
   esac
  fi
Original patch, left here so the discussion makes sense:

Code: Select all

--- init.orig	2016-01-14 23:08:12.755102000 +1000
+++ init	2016-02-04 14:25:29.926602336 +1000
@@ -340,7 +340,18 @@
    ;;
    *)
     #note: a mistake if have PDEV1 on usb booting, as it can change.
-    [ "$PDEV1" ] && LESSPARTS0="`echo "$LESSPARTS0" | grep "${PDEV1}|"`" #kernel boot param.
+    if [ "$PDEV1" ];then #kernel boot param
+     if [ "$PSAVEMARK" ];then #kernel boot param
+      BOOTDRV="`echo -n "$PDEV1" | grep -o -f /tmp/ALLDRVS0`" #ex: sda1 becomes sda
+      SAVEPART="${BOOTDRV}${PSAVEMARK}"
+     fi
+     #ensure SAVEPART is included
+     if [ "$SAVEPART" ];then
+      LESSPARTS0="`echo "$LESSPARTS0" | grep -E "${PDEV1}|${SAVEPART}"`"
+     else
+      LESSPARTS0="`echo "$LESSPARTS0" | grep "${PDEV1}|"`"
+     fi
+    fi
    ;;
   esac
  fi
Note: To see what partitions were searched in the last boot, view the file '/initrd/tmp/puppy-file-search.log'.
gyro
Last edited by gyro on Fri 05 Feb 2016, 03:30, edited 5 times in total.

User avatar
mavrothal
Posts: 3096
Joined: Mon 24 Aug 2009, 18:23

Re: 'psavemark' - make work with 'pmedia' and 'pdev1'

#2 Post by mavrothal »

Not that makes a lot of difference but what about one less condition?

Code: Select all

--- init.orig	2016-01-14 23:08:12.755102000 +1000
+++ init	2016-02-04 14:25:29.926602336 +1000
@@ -340,7 +340,13 @@
    ;;
    *)
     #note: a mistake if have PDEV1 on usb booting, as it can change.
-    [ "$PDEV1" ] && LESSPARTS0="`echo "$LESSPARTS0" | grep "${PDEV1}|"`" #kernel boot param.
+    if [ "$PDEV1" ];then #kernel boot param
+     if [ "$PSAVEMARK" ];then #kernel boot param
+      BOOTDRV="`echo -n "$PDEV1" | grep -o -f /tmp/ALLDRVS0`" #ex: sda1 becomes sda
+      xSAVEPART="|${BOOTDRV}${PSAVEMARK}" #distinct from other PSAVEPART calls
+     fi
+     LESSPARTS0="`echo "$LESSPARTS0" | grep -E "${PDEV1}${xSAVEPART}"`"
+    fi
    ;;
   esac
  fi
== [url=http://www.catb.org/esr/faqs/smart-questions.html]Here is how to solve your[/url] [url=https://www.chiark.greenend.org.uk/~sgtatham/bugs.html]Linux problems fast[/url] ==

gyro
Posts: 1798
Joined: Tue 28 Oct 2008, 21:35
Location: Brisbane, Australia

Re: 'psavemark' - make work with 'pmedia' and 'pdev1'

#3 Post by gyro »

mavrothal wrote:Not that makes a lot of difference but what about one less condition?
That removes 1 condition and adds 1 variable.
But it doesn't set SAVEPART. Doing so helps when the SAVEPART partition comes before the PDEV1 partition. e.g. isoBooter.
(If I remember correctly.)

gyro

User avatar
mavrothal
Posts: 3096
Joined: Mon 24 Aug 2009, 18:23

Re: 'psavemark' - make work with 'pmedia' and 'pdev1'

#4 Post by mavrothal »

gyro wrote:
mavrothal wrote:Not that makes a lot of difference but what about one less condition?
That removes 1 condition and adds 1 variable.
But it doesn't set SAVEPART. Doing so helps when the SAVEPART partition comes before the PDEV1 partition. e.g. isoBooter.
(If I remember correctly.)

gyro
Actually I'm not sure that the new variable is needed (never tested it), is more to be "safe". But looking at init, I do not think that using PSAVEMARK instead will be a problem since we do wan to use it even when PDEV1 is set.
== [url=http://www.catb.org/esr/faqs/smart-questions.html]Here is how to solve your[/url] [url=https://www.chiark.greenend.org.uk/~sgtatham/bugs.html]Linux problems fast[/url] ==

gyro
Posts: 1798
Joined: Tue 28 Oct 2008, 21:35
Location: Brisbane, Australia

Re: 'psavemark' - make work with 'pmedia' and 'pdev1'

#5 Post by gyro »

mavrothal wrote:Actually I'm not sure that the new variable is needed (never tested it), is more to be "safe". But looking at init, I do not think that using PSAVEMARK instead will be a problem since we do wan to use it even when PDEV1 is set.
I don't like the idea of leaving either PSAVEMARK or SAVEPART with a '|' in it.
There are many situations where this code is executed twice, once for ata drives and again for usb drives.
So, something like?

Code: Select all

--- init.orig   2016-01-14 23:08:12.755102000 +1000
+++ init   2016-02-04 14:25:29.926602336 +1000
@@ -340,7 +340,15 @@
    ;;
    *)
     #note: a mistake if have PDEV1 on usb booting, as it can change.
-    [ "$PDEV1" ] && LESSPARTS0="`echo "$LESSPARTS0" | grep "${PDEV1}|"`" #kernel boot param.
+    if [ "$PDEV1" ];then #kernel boot param
+     LESSSEP=""
+     if [ "$PSAVEMARK" ];then #kernel boot param
+      BOOTDRV="`echo -n "$PDEV1" | grep -o -f /tmp/ALLDRVS0`" #ex: sda1 becomes sda
+      SAVEPART="${BOOTDRV}${PSAVEMARK}"
+      LESSSEP="|"
+     fi
+     LESSPARTS0="`echo "$LESSPARTS0" | grep -E "${PDEV1}${LESSSEP}${SAVEPART}"`"
+    fi
    ;;
   esac
  fi
gyro

gyro
Posts: 1798
Joined: Tue 28 Oct 2008, 21:35
Location: Brisbane, Australia

#6 Post by gyro »

My previous code has a problem. If PSAVEMARK is not set but a SAVEMARK file is present, so SAVEPART is set by the ata search, then the grep of LESSPARTS0 for usb drives is rubbish.
So?

Code: Select all

--- init.orig   2016-01-14 23:08:12.755102000 +1000
+++ init   2016-02-04 14:25:29.926602336 +1000
@@ -340,7 +340,15 @@
    ;;
    *)
     #note: a mistake if have PDEV1 on usb booting, as it can change.
-    [ "$PDEV1" ] && LESSPARTS0="`echo "$LESSPARTS0" | grep "${PDEV1}|"`" #kernel boot param.
+    if [ "$PDEV1" ];then #kernel boot param
+     LESSSAVEPART=""
+     if [ "$PSAVEMARK" ];then #kernel boot param
+      BOOTDRV="`echo -n "$PDEV1" | grep -o -f /tmp/ALLDRVS0`" #ex: sda1 becomes sda
+      SAVEPART="${BOOTDRV}${PSAVEMARK}"
+      LESSSAVEPART="|${SAVEPART}"
+     fi
+     LESSPARTS0="`echo "$LESSPARTS0" | grep -E "${PDEV1}${LESSSAVEPART}"`"
+    fi
    ;;
   esac
  fi
gyro

gyro
Posts: 1798
Joined: Tue 28 Oct 2008, 21:35
Location: Brisbane, Australia

Tested code

#7 Post by gyro »

Well, it's not necessary to set SAVEPART.
The following patch works on ata drives with the savepart following pdev1. e.g 'pdev1=sdb2 psavemark=4'.
It also works on usb drives with the savepart before pdev1, e.g. 'pdev1=sdc4 psavepart=2' (isoBooter).

Code: Select all

--- init.orig   2016-01-14 23:08:12.755102000 +1000
+++ init   2016-02-04 14:25:29.926602336 +1000
@@ -340,7 +340,14 @@
    ;;
    *)
     #note: a mistake if have PDEV1 on usb booting, as it can change.
-    [ "$PDEV1" ] && LESSPARTS0="`echo "$LESSPARTS0" | grep "${PDEV1}|"`" #kernel boot param.
+    if [ "$PDEV1" ];then #kernel boot param
+     LESSSAVEPART=""
+     if [ "$PSAVEMARK" ];then #kernel boot param
+      BOOTDRV="`echo -n "$PDEV1" | grep -o -f /tmp/ALLDRVS0`" #ex: sda1 becomes sda
+      LESSSAVEPART="|${BOOTDRV}${PSAVEMARK}"
+     fi
+     LESSPARTS0="`echo "$LESSPARTS0" | grep -E "${PDEV1}${LESSSAVEPART}"`"
+    fi
    ;;
   esac
  fi
gyro

gyro
Posts: 1798
Joined: Tue 28 Oct 2008, 21:35
Location: Brisbane, Australia

Final version

#8 Post by gyro »

Please see the first post for the final version of this patch.

Tested on ata and usb drives.

gyro

User avatar
mavrothal
Posts: 3096
Joined: Mon 24 Aug 2009, 18:23

#9 Post by mavrothal »

Looks good.
== [url=http://www.catb.org/esr/faqs/smart-questions.html]Here is how to solve your[/url] [url=https://www.chiark.greenend.org.uk/~sgtatham/bugs.html]Linux problems fast[/url] ==

Post Reply