Add two parameters: img_dev=/dev/sdNM where /dev/sdNM is the device where .iso is located. img_loop=/path/to/arch.iso where /path/to/arch.iso is the full path of the .iso in the device img_dev. Original idea from Baurzhan Muftakhidinov. Signed-off-by: Gerardo Exequiel Pozzi <vmlinuz386@yahoo.com.ar> --- archiso/Makefile | 2 ++ archiso/hooks/archiso_loop_mnt | 33 +++++++++++++++++++++++++++++++++ archiso/install/archiso_loop_mnt | 18 ++++++++++++++++++ configs/syslinux-iso/mkinitcpio.conf | 2 +- 4 files changed, 54 insertions(+), 1 deletions(-) create mode 100644 archiso/hooks/archiso_loop_mnt create mode 100644 archiso/install/archiso_loop_mnt diff --git a/archiso/Makefile b/archiso/Makefile index 688eb1b..93d68af 100644 --- a/archiso/Makefile +++ b/archiso/Makefile @@ -10,6 +10,8 @@ install: all install -D -m 644 install/archiso $(DESTDIR)/lib/initcpio/install/archiso install -D -m 644 hooks/archiso_pxe_nbd $(DESTDIR)/lib/initcpio/hooks/archiso_pxe_nbd install -D -m 644 install/archiso_pxe_nbd $(DESTDIR)/lib/initcpio/install/archiso_pxe_nbd + install -D -m 644 hooks/archiso_loop_mnt $(DESTDIR)/lib/initcpio/hooks/archiso_loop_mnt + install -D -m 644 install/archiso_loop_mnt $(DESTDIR)/lib/initcpio/install/archiso_loop_mnt # install docs and examples install -d -m 755 $(DESTDIR)/usr/share/archiso/ cp -r ../configs $(DESTDIR)/usr/share/archiso/configs diff --git a/archiso/hooks/archiso_loop_mnt b/archiso/hooks/archiso_loop_mnt new file mode 100644 index 0000000..0d5eba7 --- /dev/null +++ b/archiso/hooks/archiso_loop_mnt @@ -0,0 +1,33 @@ +# vim: set ft=sh: + +run_hook () { + if [ -n "${img_dev}" ] && [ -n "${img_loop}" ]; then + mount_handler="archiso_loop_mount_handler" + fi +} + +archiso_loop_mount_handler () { + newroot="${1}" + + while [ ! -b "${img_dev}" ]; do + sleep 1 + done + + msg "::: Setup a loop device from ${img_loop} located at device ${img_dev}" + FSTYPE=$(blkid -o value -s TYPE -p ${img_dev} 2> /dev/null) + if [ -n "${FSTYPE}" ]; then + if mount -r -t "${FSTYPE}" ${img_dev} /img_dev > /dev/null 2>&1; then + _dev_loop=$(losetup -f) + losetup ${_dev_loop} /img_dev/${img_loop} + fi + fi + + archiso_mount_handler ${newroot} + + if [ "${copytoram}" = "y" ]; then + msg "::: Deataching loop device ${_dev_loop}" + losetup -d ${_dev_loop} + msg "::: Unmounting ${img_dev}" + umount ${img_dev} + fi +} diff --git a/archiso/install/archiso_loop_mnt b/archiso/install/archiso_loop_mnt new file mode 100644 index 0000000..c0d21a6 --- /dev/null +++ b/archiso/install/archiso_loop_mnt @@ -0,0 +1,18 @@ +# vim: set ft=sh: + +install () +{ + MODULES="" + + BINARIES="" + FILES="" + add_dir /img_dev + SCRIPT="archiso_loop_mnt" +} + +help () +{ +cat<<HELPEOF + This hook loads the necessary modules for boot via loop device. +HELPEOF +} diff --git a/configs/syslinux-iso/mkinitcpio.conf b/configs/syslinux-iso/mkinitcpio.conf index 15097c0..f5f8c79 100644 --- a/configs/syslinux-iso/mkinitcpio.conf +++ b/configs/syslinux-iso/mkinitcpio.conf @@ -2,5 +2,5 @@ MODULES="" BINARIES="" FILES="" -HOOKS="base udev memdisk archiso archiso_pxe_nbd pata scsi sata usb fw pcmcia filesystems usbinput" +HOOKS="base udev memdisk archiso archiso_pxe_nbd archiso_loop_mnt pata scsi sata usb fw pcmcia filesystems usbinput" COMPRESSION="lzma" -- 1.7.3.2