diff options
author | Gerardo Exequiel Pozzi <vmlinuz386@yahoo.com.ar> | 2012-01-09 20:33:35 -0300 |
---|---|---|
committer | Gerardo Exequiel Pozzi <vmlinuz386@yahoo.com.ar> | 2012-01-11 04:44:41 -0300 |
commit | 0720ac9bd4ee82d924f6c0e568aa4477297772d1 (patch) | |
tree | 82c52c6ff5eba0d714748d8793c26248e04e89b5 /archiso/hooks | |
parent | 36f327c6d45bf739587e89fa102e5beb400b6281 (diff) | |
download | archiso32-0720ac9bd4ee82d924f6c0e568aa4477297772d1.tar.xz |
[archiso] Refactor: Use losetup from util-linux
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 <vmlinuz386@yahoo.com.ar>
Diffstat (limited to 'archiso/hooks')
-rw-r--r-- | archiso/hooks/archiso | 37 | ||||
-rw-r--r-- | archiso/hooks/archiso_loop_mnt | 10 |
2 files changed, 7 insertions, 40 deletions
diff --git a/archiso/hooks/archiso b/archiso/hooks/archiso index 2635a4c..3518d16 100644 --- a/archiso/hooks/archiso +++ b/archiso/hooks/archiso @@ -1,27 +1,3 @@ -# Initialize loopback device logic (we using on-demand mode) -# args: none -_init_loop_dev() { - loop_dev_count=99 - loop_dev_range=$(cat /sys/block/loop0/range) - loop_dev_minor=$((loop_dev_count*loop_dev_range)) -} - -# Call this function before _make_loop_dev() each time. -# args: none -_next_loop_dev() { - loop_dev_count=$((loop_dev_count+1)) - loop_dev_minor=$((loop_dev_count*loop_dev_range)) -} - -# Setup a loopback device for image passed as argument and echo the path to loopback device used. -# args: /path/to/image_file -_make_loop_dev() { - local img="${1}" - mknod /dev/loop${loop_dev_count} b 7 ${loop_dev_minor} &> /dev/null - losetup /dev/loop${loop_dev_count} "${img}" &> /dev/null - echo /dev/loop${loop_dev_count} -} - # args: source, newroot, mountpoint _mnt_fs() { local img="${1}" @@ -34,8 +10,7 @@ _mnt_fs() { mkdir -p "${newroot}${mnt}" - _next_loop_dev - ro_dev=$(_make_loop_dev "${img}") + ro_dev=$(losetup --find --show "${img}") ro_dev_size=$(blockdev --getsz ${ro_dev}) if [[ "${cow_persistent}" == "P" ]]; then @@ -54,8 +29,7 @@ _mnt_fs() { dd of="/run/archiso/cowspace/${cow_directory}/${img_name}.cow" count=0 seek=${ro_dev_size} &> /dev/null fi - _next_loop_dev - rw_dev=$(_make_loop_dev "/run/archiso/cowspace/${cow_directory}/${img_name}.cow") + rw_dev=$(losetup --find --show "/run/archiso/cowspace/${cow_directory}/${img_name}.cow") echo "0 ${ro_dev_size} snapshot ${ro_dev} ${rw_dev} ${cow_persistent} 8" | dmsetup create ${dm_snap_name} @@ -85,9 +59,8 @@ _mnt_sfs() { img="/run/archiso/copytoram/${img_fullname}" msg "done." fi - _next_loop_dev msg ":: Mounting '${img}' (SquashFS) to '${mnt}'" - if ! mount -r $(_make_loop_dev "${img}") "${mnt}" &> /dev/null ; then + if ! mount -r "${img}" "${mnt}" &> /dev/null ; then echo "ERROR: while mounting '${img}' to '${mnt}'" launch_interactive_shell fi @@ -130,8 +103,6 @@ _verify_checksum() { } run_hook() { - modprobe loop - [[ -z "${arch}" ]] && arch="$(uname -m)" [[ -z "${cowspace_size}" ]] && cowspace_size="75%" [[ -z "${copytoram_size}" ]] && copytoram_size="75%" @@ -166,8 +137,6 @@ run_hook() { archiso_mount_handler() { local newroot="${1}" - _init_loop_dev - mountpoint -q "/run/archiso/bootmnt" || _mnt_dev "${archisodevice}" "/run/archiso/bootmnt" "-r" if [[ ! -f "${aitab}" ]]; then diff --git a/archiso/hooks/archiso_loop_mnt b/archiso/hooks/archiso_loop_mnt index e52dc69..664f3a5 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" - _dev_loop=$(losetup -f) - if ! losetup "${_dev_loop}" "/run/archiso/img_dev/${img_loop}"; then - echo "ERROR: Setting loopback device '${_dev_loop}'" - echo " for file '/run/archiso/img_dev/${img_loop}'" - echo " Falling back to interactive prompt" - echo " You can try to fix the problem manually, log out when you are finished" + if ! _dev_loop=$(losetup --find --show "/run/archiso/img_dev/${img_loop}"); then + echo "ERROR: Setting loopback device for file '/run/archiso/img_dev/${img_loop}'" launch_interactive_shell fi |