Backing store on full partition (without the loop device)

Post there if you plan to contribute to this SystemCd
emiliano
Posts: 22
Joined: 22 Nov 2010, 19:14
Location: Italy

Backing store on full partition (without the loop device)

Postby emiliano » 16 Dec 2010, 01:40

Hello,
with this patch is possible to use an entire dedicated partition as a backing store, without the need to create the /path/to/mysysrcd.bs loopback filesystem (see here for details).
The rationale is that using a partition is (much) faster than using a loopback filesystem, and this could be useful, for example, when creating appliances based on SystemRescueCD.
Tha patch introduces a new syntax for the backstore kernel boot option: the noloop value is used to mount an entire parition as a backing store, and the backstore partition is referred by its UUID or LABEL:

backstore=noloop,UUID=<uuid>

backstore=noloop,LABEL=<label>

where <uuid> is the UUID in canonical form, and <label> is the label unquoted.
For example:

backstore=noloop,UUID=8f133fd5-7018-49ee-be9c-798b4c08ddd6

backstore=noloop,LABEL=mybs

NOTE: UUIDs and labels can be read with blkid and set with tune2fs.

Here follows the patch for the /init script in the initram.igz of SystemRescueCD-1.7.0-beta010.

Code: Select all

--- initram/init        2010-12-16 01:51:37.000000000 +0100
+++ init        2010-12-16 01:53:12.000000000 +0100
@@ -723,13 +723,9 @@
        fi
 }
 
-# find the device that contains a file with that path: ${SUBDIR}/${LOOPDAT}
-sysresccd_find_file() # $1=devtype, $2=filepath $3=mountdir, $4=mode
+sysresccd_find_devices() # $1=devtype
 {
-       devtype="$1"   # on which devices should we search that file
-       filepath="$2"  # path of the file we are looking for (eg: "/sysrcd.dat")
-       mountdir="$3"  # where to mount the device if we find it
-       mountmode="$4" # mount mode: either 'ro' or 'rw'
+       devtype="$1"
 
        case "${devtype}" in
        auto) # all devices
@@ -755,15 +751,29 @@
                if [ -b "${target}" ]
                then
                        searchdevices="${target}"
-               elif [ -b "/dev/disk/by-label/${uuid}" ]
+               elif [ -b "/dev/disk/by-label/${label}" ]
                then
-                       searchdevices="/dev/disk/by-label/${uuid}"
+                       searchdevices="/dev/disk/by-label/${label}"
                fi
                ;;
        *) # specific device name (eg: "/dev/sda1")
                searchdevices="${devtype}"
                ;;
        esac
+       
+       echo "${searchdevices}"
+       return 1
+}
+
+# find the device that contains a file with that path: ${SUBDIR}/${LOOPDAT}
+sysresccd_find_file() # $1=devtype, $2=filepath $3=mountdir, $4=mode
+{
+       devtype="$1"   # on which devices should we search that file
+       filepath="$2"  # path of the file we are looking for (eg: "/sysrcd.dat")
+       mountdir="$3"  # where to mount the device if we find it
+       mountmode="$4" # mount mode: either 'ro' or 'rw'
+
+       searchdevices="$(sysresccd_find_devices ${devtype})"
 
        SEARCHDEVICE='' # result returned
        mkdir -p ${mountdir}
@@ -995,28 +1005,57 @@
        if [ "${BACKSTORE_CMD}" != 'off' ]
        then
                BACKSTORE_DEVTYPE='rmdev' # by default search backstores only on removable devices
+               BACKSTORE_NOLOOP=''
                for curopt in $(echo ${BACKSTORE_CMD} | sed -e 's!,! !g')
                do
                        case "${curopt}" in
                                alldev)
                                        BACKSTORE_DEVTYPE='auto' # search for backstores on all types of devices
                                        ;;
+                               UUID\=*)
+                                       BACKSTORE_DEVTYPE=${curopt}
+                                       ;;
+                               LABEL\=*)
+                                       BACKSTORE_DEVTYPE=${curopt}
+                                       ;;
+                               noloop)
+                                       BACKSTORE_NOLOOP='1' # uses a device as backstore
+                                       ;;
                                *)
                                        BACKSTORE_DAT=${curopt} # search for backstores on that particular device
                                        ;;
                        esac
                done
 
-               good_msg "Searching for ${SUBDIR}/${BACKSTORE_DAT} on devices..."
-               if sysresccd_find_file ${BACKSTORE_DEVTYPE} ${SUBDIR}/${BACKSTORE_DAT} ${BACKSTORE_MNT} 'rw'
+               if [ -n "${BACKSTORE_NOLOOP}" ]
                then
-                       good_msg "Backing store ${SUBDIR}/${BACKSTORE_DAT} found on ${SEARCHDEVICE}"
-                       if ! mount ${BACKSTORE_MNT}/${SUBDIR}/${BACKSTORE_DAT} ${BACKSTORE_MEM}
+                       case "${BACKSTORE_DEVTYPE}" in
+                               UUID\=* | LABEL\=* )
+                                       good_msg "Mounting device ${BACKSTORE_DEVTYPE} as backing store"
+                                       BACKSTORE_DEV="$(sysresccd_find_devices ${BACKSTORE_DEVTYPE})"
+                                       if ! mount ${BACKSTORE_DEV} ${BACKSTORE_MEM}
+                                       then
+                                               sysresccd_panic "Cannot mount the backstore device ${BACKSTORE_DEV}"
+                                       fi
+                                       BACKSTORE_FOUND='1'
+                                       ;;
+                               rmdev | auto | * )
+                                       sysresccd_panic "UUID or LABEL needed to mount a block device as backing store"
+                                       ;;
+                       esac
+               else
+                       good_msg "Searching for ${SUBDIR}/${BACKSTORE_DAT} on devices..."
+                       if sysresccd_find_file ${BACKSTORE_DEVTYPE} ${SUBDIR}/${BACKSTORE_DAT} ${BACKSTORE_MNT} 'rw'
                        then
-                               sysresccd_panic "Cannot mount the loopback backstore file ${SUBDIR}/${BACKSTORE_DAT}"
+                               good_msg "Backing store ${SUBDIR}/${BACKSTORE_DAT} found on ${SEARCHDEVICE}"
+                               if ! mount ${BACKSTORE_MNT}/${SUBDIR}/${BACKSTORE_DAT} ${BACKSTORE_MEM}
+                               then
+                                       sysresccd_panic "Cannot mount the loopback backstore file ${SUBDIR}/${BACKSTORE_DAT}"
+                               fi
+                               BACKSTORE_FOUND='1'
                        fi
-                       BACKSTORE_FOUND='1'
                fi
+
        fi
 
        # 2. store modifications in a tmpfs filesystem if there is no backstore


The patch uses some of the original code of the sysresccd_find_file() which is now moved to a new function sysresccd_find_devices(). The backstore partition could be referred directly via the device name (/dev/sda4 for example) by I prefer using only UUIDs or labels because they are robust against renaming of the devices (this is the reason why the modern distributions uses them inside the fstab).

admin
Site Admin
Posts: 2715
Joined: 17 Jul 2003, 09:44

Re: Backing store on full partition (without the loop device

Postby admin » 16 Dec 2010, 19:53

Sorry I cannot get the patch to work. Could you please put the new version of the file on an HTTP / FTP server ?
Or in http://pastebin.com/ if you don't have one. Thanks

emiliano
Posts: 22
Joined: 22 Nov 2010, 19:14
Location: Italy

Re: Backing store on full partition (without the loop device

Postby emiliano » 17 Dec 2010, 00:05

Hello admin,
many thanks, I did not know pastebin.com, very handy!
I posted the diff and also the full patched init, in case of problems.

emiliano
Posts: 22
Joined: 22 Nov 2010, 19:14
Location: Italy

Re: Backing store on full partition (without the loop device

Postby emiliano » 14 Mar 2011, 11:20

Hello Admin,
the patch works with 2.1.0-beta005. I'm posting again the patch; any chance for inclusion?
It really speeds up operation when running SystemRescueCD with backing store in a virtual machine.

Many thanks,

Emiliano.

Code: Select all

diff --git a/initramfs/init b/initramfs/init
index 779bd62..dc49222 100755
--- a/initramfs/init
+++ b/initramfs/init
@@ -723,13 +723,9 @@ sysresccd_stage1_nfs()
    fi
 }
 
-# find the device that contains a file with that path: ${SUBDIR}/${LOOPDAT}
-sysresccd_find_file() # $1=devtype, $2=filepath $3=mountdir, $4=mode
+sysresccd_find_devices() # $1=devtype
 {
-   devtype="$1"   # on which devices should we search that file
-   filepath="$2"  # path of the file we are looking for (eg: "/sysrcd.dat")
-   mountdir="$3"  # where to mount the device if we find it
-   mountmode="$4" # mount mode: either 'ro' or 'rw'
+   devtype="$1"
 
    case "${devtype}" in
    auto) # all devices
@@ -755,15 +751,29 @@ sysresccd_find_file() # $1=devtype, $2=filepath $3=mountdir, $4=mode
       if [ -b "${target}" ]
       then
          searchdevices="${target}"
-      elif [ -b "/dev/disk/by-label/${uuid}" ]
+      elif [ -b "/dev/disk/by-label/${label}" ]
       then
-         searchdevices="/dev/disk/by-label/${uuid}"
+         searchdevices="/dev/disk/by-label/${label}"
       fi
       ;;
    *) # specific device name (eg: "/dev/sda1")
       searchdevices="${devtype}"
       ;;
    esac
+   
+   echo "${searchdevices}"
+   return 1
+}
+
+# find the device that contains a file with that path: ${SUBDIR}/${LOOPDAT}
+sysresccd_find_file() # $1=devtype, $2=filepath $3=mountdir, $4=mode
+{
+   devtype="$1"   # on which devices should we search that file
+   filepath="$2"  # path of the file we are looking for (eg: "/sysrcd.dat")
+   mountdir="$3"  # where to mount the device if we find it
+   mountmode="$4" # mount mode: either 'ro' or 'rw'
+
+   searchdevices="$(sysresccd_find_devices ${devtype})"
 
    SEARCHDEVICE='' # result returned
    mkdir -p ${mountdir}
@@ -995,28 +1005,57 @@ sysresccd_stage3_normal() # "backstore" + "aufs" + "mount --move"
    if [ "${BACKSTORE_CMD}" != 'off' ]
    then
       BACKSTORE_DEVTYPE='rmdev' # by default search backstores only on removable devices
+      BACKSTORE_NOLOOP=''
       for curopt in $(echo ${BACKSTORE_CMD} | sed -e 's!,! !g')
       do
          case "${curopt}" in
             alldev)
                BACKSTORE_DEVTYPE='auto' # search for backstores on all types of devices
                ;;
+            UUID\=*)
+               BACKSTORE_DEVTYPE=${curopt}
+               ;;
+            LABEL\=*)
+               BACKSTORE_DEVTYPE=${curopt}
+               ;;
+            noloop)
+               BACKSTORE_NOLOOP='1' # uses a device as backstore
+               ;;
             *)
                BACKSTORE_DAT=${curopt} # search for backstores on that particular device
                ;;
          esac
       done
 
-      good_msg "Searching for ${SUBDIR}/${BACKSTORE_DAT} on devices..."
-      if sysresccd_find_file ${BACKSTORE_DEVTYPE} ${SUBDIR}/${BACKSTORE_DAT} ${BACKSTORE_MNT} 'rw'
+      if [ -n "${BACKSTORE_NOLOOP}" ]
       then
-         good_msg "Backing store ${SUBDIR}/${BACKSTORE_DAT} found on ${SEARCHDEVICE}"
-         if ! mount ${BACKSTORE_MNT}/${SUBDIR}/${BACKSTORE_DAT} ${BACKSTORE_MEM}
+         case "${BACKSTORE_DEVTYPE}" in
+            UUID\=* | LABEL\=* )
+               good_msg "Mounting device ${BACKSTORE_DEVTYPE} as backing store"
+               BACKSTORE_DEV="$(sysresccd_find_devices ${BACKSTORE_DEVTYPE})"
+               if ! mount ${BACKSTORE_DEV} ${BACKSTORE_MEM}
+               then
+                  sysresccd_panic "Cannot mount the backstore device ${BACKSTORE_DEV}"
+               fi
+               BACKSTORE_FOUND='1'
+               ;;
+            rmdev | auto | * )
+               sysresccd_panic "UUID or LABEL needed to mount a block device as backing store"
+               ;;
+         esac
+      else
+         good_msg "Searching for ${SUBDIR}/${BACKSTORE_DAT} on devices..."
+         if sysresccd_find_file ${BACKSTORE_DEVTYPE} ${SUBDIR}/${BACKSTORE_DAT} ${BACKSTORE_MNT} 'rw'
          then
-            sysresccd_panic "Cannot mount the loopback backstore file ${SUBDIR}/${BACKSTORE_DAT}"
+            good_msg "Backing store ${SUBDIR}/${BACKSTORE_DAT} found on ${SEARCHDEVICE}"
+            if ! mount ${BACKSTORE_MNT}/${SUBDIR}/${BACKSTORE_DAT} ${BACKSTORE_MEM}
+            then
+               sysresccd_panic "Cannot mount the loopback backstore file ${SUBDIR}/${BACKSTORE_DAT}"
+            fi
+            BACKSTORE_FOUND='1'
          fi
-         BACKSTORE_FOUND='1'
       fi
+
    fi
 
    # 2. store modifications in a tmpfs filesystem if there is no backstore

admin
Site Admin
Posts: 2715
Joined: 17 Jul 2003, 09:44

Re: Backing store on full partition (without the loop device

Postby admin » 14 Mar 2011, 19:37

Could you please post the latest patched version in pastebin ?
Is that based on an up to date version ?

emiliano
Posts: 22
Joined: 22 Nov 2010, 19:14
Location: Italy

Re: Backing store on full partition (without the loop device

Postby emiliano » 14 Mar 2011, 23:00

Hello Admin,

this is the patch and this is the init with the patch applied.
The patch is based on the latest beta: 2.1.0-beta005.

Many thanks,
Emiliano

admin
Site Admin
Posts: 2715
Joined: 17 Jul 2003, 09:44

Re: Backing store on full partition (without the loop device

Postby admin » 15 Mar 2011, 23:06

Thanks, it's in SystemRescueCd-2.1.0-beta006

emiliano
Posts: 22
Joined: 22 Nov 2010, 19:14
Location: Italy

Re: Backing store on full partition (without the loop device

Postby emiliano » 16 Mar 2011, 15:15

many many thanks!

Emiliano

emiliano
Posts: 22
Joined: 22 Nov 2010, 19:14
Location: Italy

Re: Backing store on full partition (without the loop device

Postby emiliano » 18 Mar 2011, 17:36

hello Admin,

when I posted the patched init on Pastebin, the tabulation style was inadvertently changed from tabs to 4 spaces, that is:
1 tab --> 4 spaces.
I'm sorry! Could you please restore the tabs when releasing the next beta version?

Many thanks and kind regards.

Emiliano


Return to “Contributions”

Who is online

Users browsing this forum: No registered users and 3 guests