[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>
This commit is contained in:
parent
36f327c6d4
commit
0720ac9bd4
@ -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
|
# args: source, newroot, mountpoint
|
||||||
_mnt_fs() {
|
_mnt_fs() {
|
||||||
local img="${1}"
|
local img="${1}"
|
||||||
@ -34,8 +10,7 @@ _mnt_fs() {
|
|||||||
|
|
||||||
mkdir -p "${newroot}${mnt}"
|
mkdir -p "${newroot}${mnt}"
|
||||||
|
|
||||||
_next_loop_dev
|
ro_dev=$(losetup --find --show "${img}")
|
||||||
ro_dev=$(_make_loop_dev "${img}")
|
|
||||||
ro_dev_size=$(blockdev --getsz ${ro_dev})
|
ro_dev_size=$(blockdev --getsz ${ro_dev})
|
||||||
|
|
||||||
if [[ "${cow_persistent}" == "P" ]]; then
|
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
|
dd of="/run/archiso/cowspace/${cow_directory}/${img_name}.cow" count=0 seek=${ro_dev_size} &> /dev/null
|
||||||
fi
|
fi
|
||||||
|
|
||||||
_next_loop_dev
|
rw_dev=$(losetup --find --show "/run/archiso/cowspace/${cow_directory}/${img_name}.cow")
|
||||||
rw_dev=$(_make_loop_dev "/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}
|
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}"
|
img="/run/archiso/copytoram/${img_fullname}"
|
||||||
msg "done."
|
msg "done."
|
||||||
fi
|
fi
|
||||||
_next_loop_dev
|
|
||||||
msg ":: Mounting '${img}' (SquashFS) to '${mnt}'"
|
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}'"
|
echo "ERROR: while mounting '${img}' to '${mnt}'"
|
||||||
launch_interactive_shell
|
launch_interactive_shell
|
||||||
fi
|
fi
|
||||||
@ -130,8 +103,6 @@ _verify_checksum() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
run_hook() {
|
run_hook() {
|
||||||
modprobe loop
|
|
||||||
|
|
||||||
[[ -z "${arch}" ]] && arch="$(uname -m)"
|
[[ -z "${arch}" ]] && arch="$(uname -m)"
|
||||||
[[ -z "${cowspace_size}" ]] && cowspace_size="75%"
|
[[ -z "${cowspace_size}" ]] && cowspace_size="75%"
|
||||||
[[ -z "${copytoram_size}" ]] && copytoram_size="75%"
|
[[ -z "${copytoram_size}" ]] && copytoram_size="75%"
|
||||||
@ -166,8 +137,6 @@ run_hook() {
|
|||||||
archiso_mount_handler() {
|
archiso_mount_handler() {
|
||||||
local newroot="${1}"
|
local newroot="${1}"
|
||||||
|
|
||||||
_init_loop_dev
|
|
||||||
|
|
||||||
mountpoint -q "/run/archiso/bootmnt" || _mnt_dev "${archisodevice}" "/run/archiso/bootmnt" "-r"
|
mountpoint -q "/run/archiso/bootmnt" || _mnt_dev "${archisodevice}" "/run/archiso/bootmnt" "-r"
|
||||||
|
|
||||||
if [[ ! -f "${aitab}" ]]; then
|
if [[ ! -f "${aitab}" ]]; then
|
||||||
|
@ -10,15 +10,13 @@ run_hook () {
|
|||||||
archiso_loop_mount_handler () {
|
archiso_loop_mount_handler () {
|
||||||
newroot="${1}"
|
newroot="${1}"
|
||||||
|
|
||||||
|
local _dev_loop
|
||||||
|
|
||||||
msg ":: Setup a loop device from ${img_loop} located at device ${img_dev}"
|
msg ":: Setup a loop device from ${img_loop} located at device ${img_dev}"
|
||||||
_mnt_dev "${img_dev}" "/run/archiso/img_dev" "-r"
|
_mnt_dev "${img_dev}" "/run/archiso/img_dev" "-r"
|
||||||
|
|
||||||
_dev_loop=$(losetup -f)
|
if ! _dev_loop=$(losetup --find --show "/run/archiso/img_dev/${img_loop}"); then
|
||||||
if ! losetup "${_dev_loop}" "/run/archiso/img_dev/${img_loop}"; then
|
echo "ERROR: Setting loopback device for file '/run/archiso/img_dev/${img_loop}'"
|
||||||
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"
|
|
||||||
launch_interactive_shell
|
launch_interactive_shell
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ build ()
|
|||||||
add_binary /lib/udev/cdrom_id
|
add_binary /lib/udev/cdrom_id
|
||||||
add_binary /sbin/blockdev
|
add_binary /sbin/blockdev
|
||||||
add_binary /sbin/dmsetup
|
add_binary /sbin/dmsetup
|
||||||
|
add_binary /sbin/losetup
|
||||||
add_binary /bin/mountpoint
|
add_binary /bin/mountpoint
|
||||||
|
|
||||||
add_file /lib/udev/rules.d/60-cdrom_id.rules
|
add_file /lib/udev/rules.d/60-cdrom_id.rules
|
||||||
|
Loading…
Reference in New Issue
Block a user