[arch-releng] [RFC][archiso] A rain of patches
Note if you want to test this without using util-linux 2.21 (not released yet), must use these boot params: earlymodules=loop loop.max_loop=16 Currently archiso_shutdown is broken due recent /lib -> /usr/lib of udev. One patch in this series fixes it, this is mostly important when using cow_device otherwise there is no harm. If there any plans to make new officials images soon (before util-linux 2.21), I like to push all these patches, plus adding temporary workaround (mentioned boot params) to syslinux.cfg.
New losetup from util-linux 2.21 uses new /dev/loop-control from Linux 3.1.
Needs mkinitcpio-0.8.2+ (provides modules.devname, or workaround with earlymodules=loop)
Get advantages from it! Removing custom shell code.
Signed-off-by: Gerardo Exequiel Pozzi
Signed-off-by: Gerardo Exequiel Pozzi
* Add #!/bin/bash to install hooks and fixed vimlines.
* Removed empty variables.
* Reorder variables, adjust brace/parens in functions.
* Removed things implemented in base hook (/tmp, /etc/fstab).
Signed-off-by: Gerardo Exequiel Pozzi
Signed-off-by: Gerardo Exequiel Pozzi
Signed-off-by: Gerardo Exequiel Pozzi
Signed-off-by: Gerardo Exequiel Pozzi
Signed-off-by: Gerardo Exequiel Pozzi
Signed-off-by: Gerardo Exequiel Pozzi
This list includes block devices of:
* Boot medium [archisodevice] (only if no copytoram= is used)
* Loop medium [img_dev] (only if no copytoram= is used)
* COW space [cowdevice] (only if cowdevice= is used (no tmpfs is used))
* Loop devices used for SquashFS images.
* Loop devices used for device-mapper devices (two per each dm-device, one RO{*.fs} and one RW{*.cow})
Signed-off-by: Gerardo Exequiel Pozzi
This is just a symlink to /run/archiso/used_block_devices
Signed-off-by: Gerardo Exequiel Pozzi
* Add libraries from /usr/lib and /sbin/losetup.
* Use used_block_devices to detach loop devices.
Signed-off-by: Gerardo Exequiel Pozzi
On Thu, Feb 23, 2012 at 12:30:50AM -0300, Gerardo Exequiel Pozzi wrote:
* Add libraries from /usr/lib and /sbin/losetup. * Use used_block_devices to detach loop devices.
Signed-off-by: Gerardo Exequiel Pozzi
--- archiso/archiso_shutdown | 13 +++++-------- archiso/hooks/archiso_shutdown | 10 +++++----- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/archiso/archiso_shutdown b/archiso/archiso_shutdown index 26220a6..c430014 100644 --- a/archiso/archiso_shutdown +++ b/archiso/archiso_shutdown @@ -10,10 +10,8 @@ umount $(mount | awk '$3 ~/^\/oldroot/ {print $3}' | sort -r) # Remove all dm-snapshot devices. dmsetup remove_all
-# Remove all loopback devices made for dm-snapshots devices -# other misc loops like used for pure squashfs images -# and unmount/detach *.fs.sfs images. -for _lup in $(ls -r /dev/loop[1-9][0-9][0-9]); do +# Remove all loopback devices. +for _lup in $(grep ^/dev/loop /oldrun/archiso/used_block_devices | tac); do
Eek. Please don't do this. I have bad experiences with tac, particularly in initscripts on shutdown, because there was nowhere for tac to write to (it creates a temporary file when it reads from a pipe). "for" is no way to iterate over lines of output, either. It's a little more long winded, but I'm always in favor of doing this "correctly": mapfile -t loopdevs =0; i-- )); do if [[ ${loopdevs[i]} = /dev/loop* ]] && ! loosetup -d "${loopdevs[i]}" 2>/dev/null; then umount -d "${loopdevs[i]}" fi done unset loopdevs i
if ! losetup -d ${_lup} 2> /dev/null; then umount -d ${_lup} fi @@ -24,11 +22,10 @@ umount /oldrun/archiso/cowspace
# Unmount boot device if needed (no copytoram=y used) if [[ ! -d /oldrun/archiso/copytoram ]]; then - umount /oldrun/archiso/bootmnt - # Detach img_loop= and unmount img_dev= (archiso_loop_mnt hook) - if [[ -f /oldrun/archiso/img_dev_loop ]]; then - losetup -d $(cat /oldrun/archiso/img_dev_loop) + if [[ -d /oldrun/archiso/img_dev ]]; then umount /oldrun/archiso/img_dev + else + umount /oldrun/archiso/bootmnt fi if [[ -f /oldrun/archiso/nbd_client.pid ]]; then nbd-client -d /dev/nbd0 diff --git a/archiso/hooks/archiso_shutdown b/archiso/hooks/archiso_shutdown index 1cc6e0e..1b2689b 100644 --- a/archiso/hooks/archiso_shutdown +++ b/archiso/hooks/archiso_shutdown @@ -2,15 +2,15 @@ run_hook () { msg -n ":: Creating shutdown ramfs..."
- mkdir -p /run/initramfs/usr/bin - mkdir /run/initramfs/usr/sbin - mkdir /run/initramfs/bin - mkdir /run/initramfs/sbin - mkdir /run/initramfs/lib + for _dir in bin lib sbin usr/bin usr/lib usr/sbin; do + mkdir -p /run/initramfs/${_dir} + done cp /bin/busybox /run/initramfs/bin/ cp /lib/ld-* /run/initramfs/lib/ cp /lib/lib* /run/initramfs/lib/ + cp /usr/lib/lib* /run/initramfs/usr/lib/ cp /sbin/dmsetup /run/initramfs/sbin/ + cp /sbin/losetup /run/initramfs/sbin/ if [[ -x /bin/nbd-client ]]; then cp /bin/nbd-client /run/initramfs/bin/ fi -- 1.7.9.1
On 02/23/2012 11:55 AM, Dave Reisner wrote:
On Thu, Feb 23, 2012 at 12:30:50AM -0300, Gerardo Exequiel Pozzi wrote:
* Add libraries from /usr/lib and /sbin/losetup. * Use used_block_devices to detach loop devices.
Signed-off-by: Gerardo Exequiel Pozzi
--- archiso/archiso_shutdown | 13 +++++-------- archiso/hooks/archiso_shutdown | 10 +++++----- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/archiso/archiso_shutdown b/archiso/archiso_shutdown index 26220a6..c430014 100644 --- a/archiso/archiso_shutdown +++ b/archiso/archiso_shutdown @@ -10,10 +10,8 @@ umount $(mount | awk '$3 ~/^\/oldroot/ {print $3}' | sort -r) # Remove all dm-snapshot devices. dmsetup remove_all
-# Remove all loopback devices made for dm-snapshots devices -# other misc loops like used for pure squashfs images -# and unmount/detach *.fs.sfs images. -for _lup in $(ls -r /dev/loop[1-9][0-9][0-9]); do +# Remove all loopback devices. +for _lup in $(grep ^/dev/loop /oldrun/archiso/used_block_devices | tac); do Eek. Please don't do this. I have bad experiences with tac, particularly in initscripts on shutdown, because there was nowhere for tac to write to (it creates a temporary file when it reads from a pipe). "for" is no way to iterate over lines of output, either. It's a little more long winded, but I'm always in favor of doing this "correctly":
mapfile -t loopdevs=0; i-- )); do if [[ ${loopdevs[i]} = /dev/loop* ]]&& ! loosetup -d "${loopdevs[i]}" 2>/dev/null; then umount -d "${loopdevs[i]}" fi done unset loopdevs i
True about tac (from coreutils) but tac (from busybox) looks like does not use tempfile [#1] The problem here is that such shell code is for bash, here is ash from busybox. Thanks for review. [#1] http://git.busybox.net/busybox/tree/coreutils/tac.c
if ! losetup -d ${_lup} 2> /dev/null; then umount -d ${_lup} fi @@ -24,11 +22,10 @@ umount /oldrun/archiso/cowspace
# Unmount boot device if needed (no copytoram=y used) if [[ ! -d /oldrun/archiso/copytoram ]]; then - umount /oldrun/archiso/bootmnt - # Detach img_loop= and unmount img_dev= (archiso_loop_mnt hook) - if [[ -f /oldrun/archiso/img_dev_loop ]]; then - losetup -d $(cat /oldrun/archiso/img_dev_loop) + if [[ -d /oldrun/archiso/img_dev ]]; then umount /oldrun/archiso/img_dev + else + umount /oldrun/archiso/bootmnt fi if [[ -f /oldrun/archiso/nbd_client.pid ]]; then nbd-client -d /dev/nbd0 diff --git a/archiso/hooks/archiso_shutdown b/archiso/hooks/archiso_shutdown index 1cc6e0e..1b2689b 100644 --- a/archiso/hooks/archiso_shutdown +++ b/archiso/hooks/archiso_shutdown @@ -2,15 +2,15 @@ run_hook () { msg -n ":: Creating shutdown ramfs..."
- mkdir -p /run/initramfs/usr/bin - mkdir /run/initramfs/usr/sbin - mkdir /run/initramfs/bin - mkdir /run/initramfs/sbin - mkdir /run/initramfs/lib + for _dir in bin lib sbin usr/bin usr/lib usr/sbin; do + mkdir -p /run/initramfs/${_dir} + done cp /bin/busybox /run/initramfs/bin/ cp /lib/ld-* /run/initramfs/lib/ cp /lib/lib* /run/initramfs/lib/ + cp /usr/lib/lib* /run/initramfs/usr/lib/ cp /sbin/dmsetup /run/initramfs/sbin/ + cp /sbin/losetup /run/initramfs/sbin/ if [[ -x /bin/nbd-client ]]; then cp /bin/nbd-client /run/initramfs/bin/ fi -- 1.7.9.1
-- Gerardo Exequiel Pozzi \cos^2\alpha + \sin^2\alpha = 1
On Thu, Feb 23, 2012 at 12:13:53PM -0300, Gerardo Exequiel Pozzi wrote:
On 02/23/2012 11:55 AM, Dave Reisner wrote:
On Thu, Feb 23, 2012 at 12:30:50AM -0300, Gerardo Exequiel Pozzi wrote:
* Add libraries from /usr/lib and /sbin/losetup. * Use used_block_devices to detach loop devices.
Signed-off-by: Gerardo Exequiel Pozzi
--- archiso/archiso_shutdown | 13 +++++-------- archiso/hooks/archiso_shutdown | 10 +++++----- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/archiso/archiso_shutdown b/archiso/archiso_shutdown index 26220a6..c430014 100644 --- a/archiso/archiso_shutdown +++ b/archiso/archiso_shutdown @@ -10,10 +10,8 @@ umount $(mount | awk '$3 ~/^\/oldroot/ {print $3}' | sort -r) # Remove all dm-snapshot devices. dmsetup remove_all
-# Remove all loopback devices made for dm-snapshots devices -# other misc loops like used for pure squashfs images -# and unmount/detach *.fs.sfs images. -for _lup in $(ls -r /dev/loop[1-9][0-9][0-9]); do +# Remove all loopback devices. +for _lup in $(grep ^/dev/loop /oldrun/archiso/used_block_devices | tac); do Eek. Please don't do this. I have bad experiences with tac, particularly in initscripts on shutdown, because there was nowhere for tac to write to (it creates a temporary file when it reads from a pipe). "for" is no way to iterate over lines of output, either. It's a little more long winded, but I'm always in favor of doing this "correctly":
mapfile -t loopdevs=0; i-- )); do if [[ ${loopdevs[i]} = /dev/loop* ]]&& ! loosetup -d "${loopdevs[i]}" 2>/dev/null; then umount -d "${loopdevs[i]}" fi done unset loopdevs i
True about tac (from coreutils) but tac (from busybox) looks like does not use tempfile [#1]
The problem here is that such shell code is for bash, here is ash from busybox.
Thanks for review.
derp. carry on.
[#1] http://git.busybox.net/busybox/tree/coreutils/tac.c
if ! losetup -d ${_lup} 2> /dev/null; then umount -d ${_lup} fi @@ -24,11 +22,10 @@ umount /oldrun/archiso/cowspace
# Unmount boot device if needed (no copytoram=y used) if [[ ! -d /oldrun/archiso/copytoram ]]; then - umount /oldrun/archiso/bootmnt - # Detach img_loop= and unmount img_dev= (archiso_loop_mnt hook) - if [[ -f /oldrun/archiso/img_dev_loop ]]; then - losetup -d $(cat /oldrun/archiso/img_dev_loop) + if [[ -d /oldrun/archiso/img_dev ]]; then umount /oldrun/archiso/img_dev + else + umount /oldrun/archiso/bootmnt fi if [[ -f /oldrun/archiso/nbd_client.pid ]]; then nbd-client -d /dev/nbd0 diff --git a/archiso/hooks/archiso_shutdown b/archiso/hooks/archiso_shutdown index 1cc6e0e..1b2689b 100644 --- a/archiso/hooks/archiso_shutdown +++ b/archiso/hooks/archiso_shutdown @@ -2,15 +2,15 @@ run_hook () { msg -n ":: Creating shutdown ramfs..."
- mkdir -p /run/initramfs/usr/bin - mkdir /run/initramfs/usr/sbin - mkdir /run/initramfs/bin - mkdir /run/initramfs/sbin - mkdir /run/initramfs/lib + for _dir in bin lib sbin usr/bin usr/lib usr/sbin; do + mkdir -p /run/initramfs/${_dir} + done cp /bin/busybox /run/initramfs/bin/ cp /lib/ld-* /run/initramfs/lib/ cp /lib/lib* /run/initramfs/lib/ + cp /usr/lib/lib* /run/initramfs/usr/lib/ cp /sbin/dmsetup /run/initramfs/sbin/ + cp /sbin/losetup /run/initramfs/sbin/ if [[ -x /bin/nbd-client ]]; then cp /bin/nbd-client /run/initramfs/bin/ fi -- 1.7.9.1
-- Gerardo Exequiel Pozzi \cos^2\alpha + \sin^2\alpha = 1
On 02/23/2012 12:22 PM, Dave Reisner wrote:
On Thu, Feb 23, 2012 at 12:13:53PM -0300, Gerardo Exequiel Pozzi wrote:
On 02/23/2012 11:55 AM, Dave Reisner wrote:
On Thu, Feb 23, 2012 at 12:30:50AM -0300, Gerardo Exequiel Pozzi wrote:
* Add libraries from /usr/lib and /sbin/losetup. * Use used_block_devices to detach loop devices.
Signed-off-by: Gerardo Exequiel Pozzi
--- archiso/archiso_shutdown | 13 +++++-------- archiso/hooks/archiso_shutdown | 10 +++++----- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/archiso/archiso_shutdown b/archiso/archiso_shutdown index 26220a6..c430014 100644 --- a/archiso/archiso_shutdown +++ b/archiso/archiso_shutdown @@ -10,10 +10,8 @@ umount $(mount | awk '$3 ~/^\/oldroot/ {print $3}' | sort -r) # Remove all dm-snapshot devices. dmsetup remove_all
-# Remove all loopback devices made for dm-snapshots devices -# other misc loops like used for pure squashfs images -# and unmount/detach *.fs.sfs images. -for _lup in $(ls -r /dev/loop[1-9][0-9][0-9]); do +# Remove all loopback devices. +for _lup in $(grep ^/dev/loop /oldrun/archiso/used_block_devices | tac); do Eek. Please don't do this. I have bad experiences with tac, particularly in initscripts on shutdown, because there was nowhere for tac to write to (it creates a temporary file when it reads from a pipe). "for" is no way to iterate over lines of output, either. It's a little more long winded, but I'm always in favor of doing this "correctly":
mapfile -t loopdevs=0; i-- )); do if [[ ${loopdevs[i]} = /dev/loop* ]]&& ! loosetup -d "${loopdevs[i]}" 2>/dev/null; then umount -d "${loopdevs[i]}" fi done unset loopdevs i True about tac (from coreutils) but tac (from busybox) looks like does not use tempfile [#1]
The problem here is that such shell code is for bash, here is ash from busybox.
Thanks for review.
derp. carry on.
Hehe, anyway, in a future, I want to use losetup --detach-all (new in 2.21), then umount -d, without looking at the list. For now, this code just works and makes posible to use current losetup (booting with extra/workaround bootparams of course). Thanks you. -- Gerardo Exequiel Pozzi \cos^2\alpha + \sin^2\alpha = 1
Superseded by /run/archiso/used_block_devices
Signed-off-by: Gerardo Exequiel Pozzi
On 02/23/2012 12:30 AM, Gerardo Exequiel Pozzi wrote:
Superseded by /run/archiso/used_block_devices
Signed-off-by: Gerardo Exequiel Pozzi
--- archiso/hooks/archiso_loop_mnt | 9 ++------- 1 files changed, 2 insertions(+), 7 deletions(-) diff --git a/archiso/hooks/archiso_loop_mnt b/archiso/hooks/archiso_loop_mnt index 61ddcd4..f38d0d6 100644 --- a/archiso/hooks/archiso_loop_mnt +++ b/archiso/hooks/archiso_loop_mnt @@ -10,15 +10,13 @@ run_hook () { archiso_loop_mount_handler () { newroot="${1}"
- local _dev_loop - msg ":: Setup a loop device from ${img_loop} located at device ${img_dev}" _mnt_dev "${img_dev}" "/run/archiso/img_dev" "-r" if [[ "${copytoram}" != "y" ]]; then echo $(readlink -f ${img_dev})>> /run/archiso/used_block_devices fi
- if ! _dev_loop=$(losetup --find --show --read-only "/run/archiso/img_dev/${img_loop}"); then + if ! losetup --find --read-only "/run/archiso/img_dev/${img_loop}"; then echo "ERROR: Setting loopback device for file '/run/archiso/img_dev/${img_loop}'" launch_interactive_shell fi @@ -26,9 +24,6 @@ archiso_loop_mount_handler () { archiso_mount_handler ${newroot}
if [[ "${copytoram}" == "y" ]]; then - losetup -d ${_dev_loop} - umount /run/archiso/img_dev - else - echo ${_dev_loop}> /run/archiso/img_dev_loop + umount -d /run/archiso/img_dev fi }
oops, I made a mistake here. img_dev is not _dev_loop! Resending... -- Gerardo Exequiel Pozzi \cos^2\alpha + \sin^2\alpha = 1
Superseded by /run/archiso/used_block_devices
Signed-off-by: Gerardo Exequiel Pozzi
On Thu, 23 Feb 2012 00:52:22 -0300
Gerardo Exequiel Pozzi
Superseded by /run/archiso/used_block_devices
Signed-off-by: Gerardo Exequiel Pozzi
--- archiso/hooks/archiso_loop_mnt | 2 -- 1 files changed, 0 insertions(+), 2 deletions(-) diff --git a/archiso/hooks/archiso_loop_mnt b/archiso/hooks/archiso_loop_mnt index 61ddcd4..a02cfac 100644 --- a/archiso/hooks/archiso_loop_mnt +++ b/archiso/hooks/archiso_loop_mnt @@ -28,7 +28,5 @@ archiso_loop_mount_handler () { if [[ "${copytoram}" == "y" ]]; then losetup -d ${_dev_loop} umount /run/archiso/img_dev - else - echo ${_dev_loop} > /run/archiso/img_dev_loop fi }
maybe it's just me, but this patch and the previous version doesn't seem to have anything to do with the introduction of /run/archiso/used_block_devices other than this, all patches seem good to me! Dieter
On 02/23/2012 09:31 AM, Dieter Plaetinck wrote:
On Thu, 23 Feb 2012 00:52:22 -0300 Gerardo Exequiel Pozzi
wrote: Superseded by /run/archiso/used_block_devices
Signed-off-by: Gerardo Exequiel Pozzi
--- archiso/hooks/archiso_loop_mnt | 2 -- 1 files changed, 0 insertions(+), 2 deletions(-) diff --git a/archiso/hooks/archiso_loop_mnt b/archiso/hooks/archiso_loop_mnt index 61ddcd4..a02cfac 100644 --- a/archiso/hooks/archiso_loop_mnt +++ b/archiso/hooks/archiso_loop_mnt @@ -28,7 +28,5 @@ archiso_loop_mount_handler () { if [[ "${copytoram}" == "y" ]]; then losetup -d ${_dev_loop} umount /run/archiso/img_dev - else - echo ${_dev_loop}> /run/archiso/img_dev_loop fi } maybe it's just me, but this patch and the previous version doesn't seem to have anything to do with the introduction of /run/archiso/used_block_devices
other than this, all patches seem good to me!
Dieter
From patch 11 :) +for _lup in $(grep ^/dev/loop /oldrun/archiso/used_block_devices | tac); do ... - if [[ -f /oldrun/archiso/img_dev_loop ]]; then - losetup -d $(cat /oldrun/archiso/img_dev_loop) -- Gerardo Exequiel Pozzi \cos^2\alpha + \sin^2\alpha = 1
Am 23.02.2012 04:30, schrieb Gerardo Exequiel Pozzi:
Superseded by /run/archiso/used_block_devices
^Superseeded
On 02/23/2012 06:41 AM, Thomas Bächler wrote:
Am 23.02.2012 04:30, schrieb Gerardo Exequiel Pozzi:
Superseded by /run/archiso/used_block_devices ^Superseeded
really? I can not found "superseeded". http://www.thefreedictionary.com/superseded -- Gerardo Exequiel Pozzi \cos^2\alpha + \sin^2\alpha = 1
Am 23.02.2012 15:46, schrieb Gerardo Exequiel Pozzi:
On 02/23/2012 06:41 AM, Thomas Bächler wrote:
Am 23.02.2012 04:30, schrieb Gerardo Exequiel Pozzi:
Superseded by /run/archiso/used_block_devices ^Superseeded
really? I can not found "superseeded".
You are right. I must have been really tired.
On Thu, 23 Feb 2012 00:30:39 -0300
Gerardo Exequiel Pozzi
Note if you want to test this without using util-linux 2.21 (not released yet), must use these boot params: earlymodules=loop loop.max_loop=16
Currently archiso_shutdown is broken due recent /lib -> /usr/lib of udev. One patch in this series fixes it, this is mostly important when using cow_device otherwise there is no harm.
If there any plans to make new officials images soon (before util-linux 2.21), I like to push all these patches, plus adding temporary workaround (mentioned boot params) to syslinux.cfg.
when will util-linux 2.21 land? if it's within the year, then yes, I think I'm aiming for a release before util-linux 2.21. Dieter
On Thu, Feb 23, 2012 at 01:33:35PM +0100, Dieter Plaetinck wrote:
On Thu, 23 Feb 2012 00:30:39 -0300 Gerardo Exequiel Pozzi
wrote: Note if you want to test this without using util-linux 2.21 (not released yet), must use these boot params: earlymodules=loop loop.max_loop=16
Currently archiso_shutdown is broken due recent /lib -> /usr/lib of udev. One patch in this series fixes it, this is mostly important when using cow_device otherwise there is no harm.
If there any plans to make new officials images soon (before util-linux 2.21), I like to push all these patches, plus adding temporary workaround (mentioned boot params) to syslinux.cfg.
when will util-linux 2.21 land? if it's within the year, then yes, I think I'm aiming for a release before util-linux 2.21.
Dieter
u-l was supposed to be released yesterday. It wasn't, but it should be soon™.
On 02/23/2012 12:01 PM, Dave Reisner wrote:
On Thu, Feb 23, 2012 at 01:33:35PM +0100, Dieter Plaetinck wrote:
On Thu, 23 Feb 2012 00:30:39 -0300 Gerardo Exequiel Pozzi
wrote: Note if you want to test this without using util-linux 2.21 (not released yet), must use these boot params: earlymodules=loop loop.max_loop=16
Currently archiso_shutdown is broken due recent /lib -> /usr/lib of udev. One patch in this series fixes it, this is mostly important when using cow_device otherwise there is no harm.
If there any plans to make new officials images soon (before util-linux 2.21), I like to push all these patches, plus adding temporary workaround (mentioned boot params) to syslinux.cfg.
when will util-linux 2.21 land? if it's within the year, then yes, I think I'm aiming for a release before util-linux 2.21.
Dieter u-l was supposed to be released yesterday. It wasn't, but it should be soon™.
2.21 yupiiiiiii! -- Gerardo Exequiel Pozzi \cos^2\alpha + \sin^2\alpha = 1
participants (4)
-
Dave Reisner
-
Dieter Plaetinck
-
Gerardo Exequiel Pozzi
-
Thomas Bächler