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<[email protected]> > >>--- > >> 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</oldrun/archiso/used_block_devices > >for (( i=${loopdevs[*]}-1; i>=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 >
