[arch-releng] [PATCH 5/6] Implement mount hook function in archiso hook.
Next version of mkinitcpio > 0.6.2 implements mount hook functionality. So can avoid skipping normal flow of main init script, and removing common end code with it. Signed-off-by: Gerardo Exequiel Pozzi <vmlinuz386@yahoo.com.ar> --- archiso/hooks/archiso | 34 +++++++++++++--------------------- archiso/install/archiso | 1 - 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/archiso/hooks/archiso b/archiso/hooks/archiso index 434fd39..7b4d756 100644 --- a/archiso/hooks/archiso +++ b/archiso/hooks/archiso @@ -2,15 +2,15 @@ _mnt_bind() { msg "::: Binding ${1} to ${2}" - mkdir -p /real_root${2} - /bin/mount -o bind ${1} /real_root${2} + mkdir -p $newroot${2} + /bin/mount -o bind ${1} $newroot${2} } # args: /path/to/image_file _mnt_squashfs() { /sbin/modprobe -q loop > /dev/null 2>&1 - + img="${1}" base_img="${img##*/}"; mnt="${2}" @@ -34,7 +34,7 @@ _mnt_squashfs() fi /bin/mount -r -t squashfs "/dev/loop${LOOP_NUM}" "/tmpfs/mnt/loop${LOOP_NUM}" if [ "${mnt}" = "/" ]; then - /bin/mount -t aufs -o remount,append:/tmpfs/mnt/loop${LOOP_NUM}=ro none "/real_root" + /bin/mount -t aufs -o remount,append:/tmpfs/mnt/loop${LOOP_NUM}=ro none "$newroot" else _mnt_bind "/tmpfs/mnt/loop${LOOP_NUM}" "${mnt}" fi @@ -61,6 +61,13 @@ run_hook () archisodevice="/dev/archiso" fi + # set mount handler for archiso + mount_handler="archiso_mount_handler" +} + +archiso_mount_handler() { + newroot="$1" + msg -n ":: Mounting tmpfs, size=${tmpfs_size}..." mount -t tmpfs -o "size=${tmpfs_size}" tmpfs /tmpfs msg "done." @@ -70,7 +77,7 @@ run_hook () echo "ERROR: boot device didn't show up after 30 seconds..." echo " Falling back to interactive prompt" echo " You can try to fix the problem manually, log out when you are finished" - PS1="ramfs$ " /bin/sh -i + launch_interactive_shell done FSTYPE=$(blkid -o value -s TYPE ${archisodevice} 2> /dev/null) @@ -91,7 +98,7 @@ run_hook () fi msg ":: Mounting root (aufs) filesystem" - /bin/mount -t aufs -o dirs=/tmpfs=rw none /real_root + /bin/mount -t aufs -o dirs=/tmpfs=rw none $newroot if [ $? -ne 0 ]; then echo "ERROR: while mounting root (aufs) filesystem." exit 1 @@ -124,21 +131,6 @@ run_hook () fi fi - if [ "${break}" = "y" ]; then - echo ":: Break requested, type 'exit' to resume operation" - PS1="ramfs$ " /bin/sh -i - fi - - #Special handling if udev is running - udevpid=$(/bin/pidof udevd) - if [ -n "${udevpid}" ]; then - /bin/kill -9 ${udevpid} > /dev/null 2>&1 - /bin/sleep 0.01 - fi - msg ":: Passing control to Arch Linux Initscripts...Please Wait" - /bin/umount /sys - /bin/umount /proc - exec /sbin/switch_root -c /dev/console /real_root /sbin/init ${CMDLINE} } # vim:ft=sh:ts=4:sw=4:et: diff --git a/archiso/install/archiso b/archiso/install/archiso index 77fddc3..5978f33 100644 --- a/archiso/install/archiso +++ b/archiso/install/archiso @@ -9,7 +9,6 @@ install () BINARIES="" FILES="" - add_dir /real_root add_dir /tmpfs add_dir /bootmnt SCRIPT="archiso" -- 1.6.6.1
* make /dev/loop0 at archiso install hook, to take advantage of automatic module loading. There is no need for wait cycle. * Mount squashfs images directly with mount instead of first using losetup, then mounting. These images are now mounted at /tmpfs/mnt/name-of-the-image instead of /tmpfs/mnt/loopN (count variable removed) * Use "/newroot" passed as argument to mount hook. * Drop to a recovery shell in cases when FSTYPE detection fail instead of just fail, then kernel panic! * $newroot is passed to other _mnt_ functions in the same mountpoint. * $copytoram code is removed since does not work with AUFS. * Misc code style fixed. Signed-off-by: Gerardo Exequiel Pozzi <vmlinuz386@yahoo.com.ar> --- archiso/hooks/archiso | 89 +++++++++++++++++++++-------------------------- archiso/install/archiso | 1 + 2 files changed, 41 insertions(+), 49 deletions(-) diff --git a/archiso/hooks/archiso b/archiso/hooks/archiso index 7b4d756..b54e1e5 100644 --- a/archiso/hooks/archiso +++ b/archiso/hooks/archiso @@ -1,48 +1,31 @@ # args: source, mountpoint -_mnt_bind() -{ - msg "::: Binding ${1} to ${2}" - mkdir -p $newroot${2} - /bin/mount -o bind ${1} $newroot${2} +_mnt_bind() { + src="${1}" + mnt="${2}" + msg "::: Binding ${src} to ${mnt}" + mkdir -p "${mnt}" + /bin/mount -o bind "${src}" "${mnt}" } -# args: /path/to/image_file -_mnt_squashfs() -{ - /sbin/modprobe -q loop > /dev/null 2>&1 - +# args: /path/to/image_file, mountpoint +_mnt_squashfs() { img="${1}" - base_img="${img##*/}"; mnt="${2}" - - # FIX: This options does not work (see FS#17182) - if [ "${copytoram}" = "y" ]; then - msg ":: Copying squashfs image to RAM" - /bin/cat ${img} > "/tmpfs/${base_img}" - img="/tmpfs/${base_img}" - fi - - msg "::: Adding new aufs branch: ${base_img%.*}" - mkdir -p "/tmpfs/mnt/loop${LOOP_NUM}" - # sometimes it takes udev a while to create device nodes - while [ ! -e "/dev/loop${LOOP_NUM}" ]; do - sleep 1 - done - if ! /sbin/losetup "/dev/loop${LOOP_NUM}" ${img}; then - echo "ERROR: Cannot mount loop device /dev/loop${LOOP_NUM}" - break - fi - /bin/mount -r -t squashfs "/dev/loop${LOOP_NUM}" "/tmpfs/mnt/loop${LOOP_NUM}" - if [ "${mnt}" = "/" ]; then - /bin/mount -t aufs -o remount,append:/tmpfs/mnt/loop${LOOP_NUM}=ro none "$newroot" + img_fullname="${img##*/}"; + img_name="${img_fullname%.*}" + tmp_mnt="/tmpfs/mnt/${img_name}" + + msg "::: Adding new aufs branch: ${img_name}" + mkdir -p "${tmp_mnt}" + /bin/mount -r -t squashfs "${img}" "${tmp_mnt}" + if [ "/${mnt#/*/}" = "/" ]; then + /bin/mount -t aufs -o remount,append:${tmp_mnt}=ro none "${mnt}" else - _mnt_bind "/tmpfs/mnt/loop${LOOP_NUM}" "${mnt}" + _mnt_bind "${tmp_mnt}" "${mnt}" fi - export LOOP_NUM=$(( $LOOP_NUM + 1 )) } -run_hook () -{ +run_hook () { if [ "x${arch}" = "x" ]; then arch="$(uname -m)" fi @@ -66,7 +49,7 @@ run_hook () } archiso_mount_handler() { - newroot="$1" + newroot="${1}" msg -n ":: Mounting tmpfs, size=${tmpfs_size}..." mount -t tmpfs -o "size=${tmpfs_size}" tmpfs /tmpfs @@ -74,10 +57,10 @@ archiso_mount_handler() { msg ":: Waiting for boot device..." while ! poll_device ${archisodevice} 30; do - echo "ERROR: boot device didn't show up after 30 seconds..." - echo " Falling back to interactive prompt" - echo " You can try to fix the problem manually, log out when you are finished" - launch_interactive_shell + echo "ERROR: boot device didn't show up after 30 seconds..." + echo " Falling back to interactive prompt" + echo " You can try to fix the problem manually, log out when you are finished" + launch_interactive_shell done FSTYPE=$(blkid -o value -s TYPE ${archisodevice} 2> /dev/null) @@ -85,26 +68,34 @@ archiso_mount_handler() { if mount -r -t "${FSTYPE}" ${archisodevice} /bootmnt > /dev/null 2>&1; then if [ -e "${isomounts}" ]; then echo "SUCCESS: Mounted archiso volume successfully." + fserror="0" else echo "ERROR: Mounting was successful, but the ${isomounts} file does not exist." - exit 1 + fserror="1" fi else echo "ERROR; Failed to mount ${archisodevice} (FS is ${FSTYPE})" - exit 1 + fserror="1" fi else echo "ERROR: ${archisodevice} found, but the filesystem type is unknown." + fserror="1" fi - msg ":: Mounting root (aufs) filesystem" - /bin/mount -t aufs -o dirs=/tmpfs=rw none $newroot + if [ "${fserror}" = "1" ]; then + echo " Falling back to interactive prompt" + echo " You can try to fix the problem manually, log out when you are finished" + launch_interactive_shell + fi + + msg -n ":: Mounting root (aufs) filesystem" + /bin/mount -t aufs -o dirs=/tmpfs=rw none "${newroot}" if [ $? -ne 0 ]; then echo "ERROR: while mounting root (aufs) filesystem." exit 1 fi + msg "done." - export LOOP_NUM="0" msg ":: Mounting images" while read img imgarch mountpoint type; do # check if this line is a comment (starts with #) @@ -115,14 +106,14 @@ archiso_mount_handler() { [ ! -r "/bootmnt/${img}" ] && continue if [ "${type}" = "bind" ]; then - _mnt_bind "/bootmnt/${img}" ${mountpoint} + _mnt_bind "/bootmnt/${img}" "${newroot}${mountpoint}" elif [ "${type}" = "squashfs" ]; then - _mnt_squashfs "/bootmnt/${img}" "${mountpoint}" + _mnt_squashfs "/bootmnt/${img}" "${newroot}${mountpoint}" fi done < "${isomounts}" # Bind our bootmnt dir into the live system - _mnt_bind /bootmnt /bootmnt + _mnt_bind /bootmnt "${newroot}/bootmnt" if [ "${FSTYPE}" = "iso9660" -o "${FSTYPE}" = "udf" ]; then if [ -d /proc/sys/dev/cdrom ]; then diff --git a/archiso/install/archiso b/archiso/install/archiso index 5978f33..4d36412 100644 --- a/archiso/install/archiso +++ b/archiso/install/archiso @@ -11,6 +11,7 @@ install () FILES="" add_dir /tmpfs add_dir /bootmnt + add_device /dev/loop0 b 7 0 SCRIPT="archiso" } -- 1.6.6.1
Am 17.02.2010 06:57, schrieb Gerardo Exequiel Pozzi:
* make /dev/loop0 at archiso install hook, to take advantage of automatic module loading. There is no need for wait cycle. * Mount squashfs images directly with mount instead of first using losetup, then mounting. These images are now mounted at /tmpfs/mnt/name-of-the-image instead of /tmpfs/mnt/loopN (count variable removed) * Use "/newroot" passed as argument to mount hook. * Drop to a recovery shell in cases when FSTYPE detection fail instead of just fail, then kernel panic! * $newroot is passed to other _mnt_ functions in the same mountpoint. * $copytoram code is removed since does not work with AUFS. * Misc code style fixed.
This looks all very good, can we get this broken up in single patches (preferably with the "mount hook" parts merged with the previous patch)?
On 02/17/2010 05:30 AM, Thomas Bächler wrote:
Am 17.02.2010 06:57, schrieb Gerardo Exequiel Pozzi:
* make /dev/loop0 at archiso install hook, to take advantage of automatic module loading. There is no need for wait cycle. * Mount squashfs images directly with mount instead of first using losetup, then mounting. These images are now mounted at /tmpfs/mnt/name-of-the-image instead of /tmpfs/mnt/loopN (count variable removed) * Use "/newroot" passed as argument to mount hook. * Drop to a recovery shell in cases when FSTYPE detection fail instead of just fail, then kernel panic! * $newroot is passed to other _mnt_ functions in the same mountpoint. * $copytoram code is removed since does not work with AUFS. * Misc code style fixed.
This looks all very good, can we get this broken up in single patches (preferably with the "mount hook" parts merged with the previous patch)?
yes, I will see what I can do, in fact I am not very friend of making several changes at once, but in this case there are several tightly linked. -- Gerardo Exequiel Pozzi ( djgera ) http://www.djgera.com.ar KeyID: 0x1B8C330D Key fingerprint = 0CAA D5D4 CD85 4434 A219 76ED 39AB 221B 1B8C 330D
On 02/17/2010 05:30 AM, Thomas Bächler wrote:
Am 17.02.2010 06:57, schrieb Gerardo Exequiel Pozzi:
* make /dev/loop0 at archiso install hook, to take advantage of automatic module loading. There is no need for wait cycle. * Mount squashfs images directly with mount instead of first using losetup, then mounting. These images are now mounted at /tmpfs/mnt/name-of-the-image instead of /tmpfs/mnt/loopN (count variable removed) Implemented in single commit. * Use "/newroot" passed as argument to mount hook. ops! This was implemented in the second patch (Not in the original
On 02/17/2010 06:15 PM, Gerardo Exequiel Pozzi wrote: posted in FS#18355)
* Drop to a recovery shell in cases when FSTYPE detection fail instead of just fail, then kernel panic! * $newroot is passed to other _mnt_ functions in the same mountpoint. * $copytoram code is removed since does not work with AUFS. * Misc code style fixed. Each in separated commits.
This looks all very good, can we get this broken up in single patches (preferably with the "mount hook" parts merged with the previous patch)?
yes, I will see what I can do, in fact I am not very friend of making several changes at once, but in this case there are several tightly linked.
Done :) broken up in five patches. -- Gerardo Exequiel Pozzi ( djgera ) http://www.djgera.com.ar KeyID: 0x1B8C330D Key fingerprint = 0CAA D5D4 CD85 4434 A219 76ED 39AB 221B 1B8C 330D
On Wed, Feb 17, 2010 at 4:53 PM, Gerardo Exequiel Pozzi <vmlinuz386@yahoo.com.ar> wrote:
Done :) broken up in five patches.
I've merged all your pending patches here: http://code.phraktured.net/cgit.cgi/archiso/ This includes the "remove old config files" one I was hesitant about... there's no sense at this point in the game of maintaining more than one set of configs Is everyone ok with pushing these to master?
On 02/17/2010 08:05 PM, Aaron Griffin wrote:
On Wed, Feb 17, 2010 at 4:53 PM, Gerardo Exequiel Pozzi <vmlinuz386@yahoo.com.ar> wrote:
Done :) broken up in five patches.
I've merged all your pending patches here: http://code.phraktured.net/cgit.cgi/archiso/
This includes the "remove old config files" one I was hesitant about... there's no sense at this point in the game of maintaining more than one set of configs
Is everyone ok with pushing these to master?
Good. Thanks Maybe, remember that all these patches depends on mkinitcpio that is not released 0.6.3, I don't know schedule plan from Thomas. If mkinitcpio will be released very soon, maybe can be a good idea to merge now, taking advantage of your available time now. Anyway, anybody interested in making archiso can "reset" your local git clone (Including Dieter that is making archiso images 2010.02 now, seems that him have some problems with enviroment. -- Gerardo Exequiel Pozzi ( djgera ) http://www.djgera.com.ar KeyID: 0x1B8C330D Key fingerprint = 0CAA D5D4 CD85 4434 A219 76ED 39AB 221B 1B8C 330D
Am 18.02.2010 00:44, schrieb Gerardo Exequiel Pozzi:
Good. Thanks
Maybe, remember that all these patches depends on mkinitcpio that is not released 0.6.3, I don't know schedule plan from Thomas. If mkinitcpio will be released very soon, maybe can be a good idea to merge now, taking advantage of your available time now.
Anyway, anybody interested in making archiso can "reset" your local git clone (Including Dieter that is making archiso images 2010.02 now, seems that him have some problems with enviroment.
I can release 0.6.3 anytime now, there's a few more patches lined up, but none of them is important.
On 02/17/2010 09:05 PM, Thomas Bächler wrote:
Am 18.02.2010 00:44, schrieb Gerardo Exequiel Pozzi:
Good. Thanks
Maybe, remember that all these patches depends on mkinitcpio that is not released 0.6.3, I don't know schedule plan from Thomas. If mkinitcpio will be released very soon, maybe can be a good idea to merge now, taking advantage of your available time now.
Anyway, anybody interested in making archiso can "reset" your local git clone (Including Dieter that is making archiso images 2010.02 now, seems that him have some problems with enviroment.
I can release 0.6.3 anytime now, there's a few more patches lined up, but none of them is important.
Great :) @Aaron: can release squashfs-tools-4.0-2 with this patch [#1] applied? [#1] http://bugs.archlinux.org/task/18277 - FS#18277 - [squashfs-tools] Patch to fix a race condition -- Gerardo Exequiel Pozzi ( djgera ) http://www.djgera.com.ar KeyID: 0x1B8C330D Key fingerprint = 0CAA D5D4 CD85 4434 A219 76ED 39AB 221B 1B8C 330D
On Wed, 17 Feb 2010 17:05:22 -0600 Aaron Griffin <aaronmgriffin@gmail.com> wrote:
On Wed, Feb 17, 2010 at 4:53 PM, Gerardo Exequiel Pozzi <vmlinuz386@yahoo.com.ar> wrote:
Done :) broken up in five patches.
I've merged all your pending patches here: http://code.phraktured.net/cgit.cgi/archiso/
This includes the "remove old config files" one I was hesitant about... there's no sense at this point in the game of maintaining more than one set of configs
Is everyone ok with pushing these to master?
if you mean with old == grub ones (because other then that, the syslinux ones are pretty much the same right?) fine by me. we've talked about it so often, just drop them. if we really need them back at some point for some reason, hey it's git. they are never "gone" Dieter PS: good work Gerardo.
On Thu, Feb 18, 2010 at 6:28 AM, Thomas Bächler <thomas@archlinux.org> wrote:
Am 18.02.2010 00:05, schrieb Aaron Griffin:
Is everyone ok with pushing these to master?
Do it!
Pushed, including 3 new patches
On 02/17/2010 07:53 PM, Gerardo Exequiel Pozzi wrote:
Done :) broken up in five patches.
* This is how looks archiso hook running: ... :: Running Hook [archiso] :: Mounting tmpfs, size=75%...done. :: Waiting for boot device... Waiting 30 seconds for device /dev/archiso ... UDF-fs: Partition marked readonly; forcing readonly mount SUCCESS: Mounted archiso volume successfully. :: Mounting root (aufs) filesystem aufs 2-standalone.tree-32-20100111 :: Mounting images ::: Adding new aufs branch: overlay loop: module loaded squashfs: version 4.0 (2009/01/31) Phillip Lougher aufs test_add:243:mount[585]: uid/gid/perm /tmpfs/mnt/overlay 0/0/0755, 0/0/01777 ::: Adding new aufs branch: core-pkgs ::: Binding /tmpfs/mnt/core-pkgs to /new_root/src/core/pkg ::: Adding new aufs branch: root-image aufs test_add:243:mount[594]: uid/gid/perm /tmpfs/mnt/root-image 0/0/0755, 0/0/01777 ::: Binding /bootmnt to /new_root/bootmnt * This is how look mounts at end of archiso hook: ... tmpfs /tmpfs tmpfs rw,relatime,size=93384k 0 0 /dev/archiso /bootmnt udf ro,relatime,utf8 0 0 none /new_root aufs rw,relatime,si=74d8f1b8 0 0 /dev/loop0 /tmpfs/mnt/overlay squashfs ro,relatime 0 0 /dev/loop1 /tmpfs/mnt/core-pkgs squashfs ro,relatime 0 0 /dev/loop1 /new_root/src/core/pkg squashfs ro,relatime 0 0 /dev/loop2 /tmpfs/mnt/root-image squashfs ro,relatime 0 0 /dev/archiso /new_root/bootmnt udf ro,relatime,utf8 0 0 -- Gerardo Exequiel Pozzi ( djgera ) http://www.djgera.com.ar KeyID: 0x1B8C330D Key fingerprint = 0CAA D5D4 CD85 4434 A219 76ED 39AB 221B 1B8C 330D
participants (4)
-
Aaron Griffin
-
Dieter Plaetinck
-
Gerardo Exequiel Pozzi
-
Thomas Bächler