ipq806x: request the first free loop device dynamically for the nbg6817 sysupgrade
[openwrt/openwrt.git] / target / linux / ipq806x / base-files / lib / upgrade / zyxel.sh
index dcd66ea2caba5d94421984dcc07dc91952369764..cf2acfcc174d5d08e9a50f9e5fca63a19d7fcb9b 100644 (file)
@@ -47,23 +47,24 @@ zyxel_do_flash() {
        }
 
        # Mount loop for rootfs_data
-       losetup -o $offset /dev/loop0 "${rootfs}" || {
+       local loopdev="$(losetup -f)"
+       losetup -o $offset $loopdev $rootfs || {
                echo "Failed to mount looped rootfs_data."
                sleep 10
                reboot -f
        }
 
        echo "Format new rootfs_data at position ${offset}."
-       mkfs.ext4 -F -L rootfs_data /dev/loop0
+       mkfs.ext4 -F -L rootfs_data $loopdev
        mkdir /tmp/new_root
-       mount -t ext4 /dev/loop0 /tmp/new_root && {
+       mount -t ext4 $loopdev /tmp/new_root && {
                echo "Saving config to rootfs_data at position ${offset}."
                cp -v /tmp/sysupgrade.tgz /tmp/new_root/
                umount /tmp/new_root
        }
 
        # Cleanup
-       losetup -d /dev/loop0 >/dev/null 2>&1
+       losetup -d $loopdev >/dev/null 2>&1
        sync
        umount -a
        reboot -f