[archiso] Add archiso_shutdown hook.
STATUS: Working (std boot, loop_mnt, pxe) with copytoram=[y|n]. NEEDS: initscript > 2011.07.3, mkinitcpio > 0.7.2, mkinitcpio-busybox > 1.18.5-1 Purpose: we need this for propertly unmount $cow_device, used for persistent dm-snapshot devices. This hook is based on work from Tom Gundersen[#1], but adapted for archiso things (specially the shutdown script) [#1] http://mailman.archlinux.org/pipermail/arch-projects/2011-July/001549.html [#2] http://projects.archlinux.org/initscripts.git/commit/?id=1fa7b4b453e96533ae1db3630031285e5fc302b3 [#3] http://mailman.archlinux.org/pipermail/arch-projects/2011-August/001749.html Signed-off-by: Gerardo Exequiel Pozzi <vmlinuz386@yahoo.com.ar>
This commit is contained in:
parent
908551ef02
commit
59ad1113d9
3
README
3
README
@ -121,7 +121,8 @@ if nothing is specified on command line.
|
|||||||
* archiso_pxe_nbd
|
* archiso_pxe_nbd
|
||||||
+ mkinitcpio-nfs-utils for ipconfig
|
+ mkinitcpio-nfs-utils for ipconfig
|
||||||
+ nbd for nbd-client
|
+ nbd for nbd-client
|
||||||
|
* archiso_shutdown
|
||||||
|
+ (none)
|
||||||
|
|
||||||
|
|
||||||
*** Image types generated by mkarchiso.
|
*** Image types generated by mkarchiso.
|
||||||
|
@ -12,6 +12,9 @@ install-hooks:
|
|||||||
# hooks/install are needed by mkinitcpio
|
# hooks/install are needed by mkinitcpio
|
||||||
install -D -m 644 hooks/archiso $(DESTDIR)/lib/initcpio/hooks/archiso
|
install -D -m 644 hooks/archiso $(DESTDIR)/lib/initcpio/hooks/archiso
|
||||||
install -D -m 644 install/archiso $(DESTDIR)/lib/initcpio/install/archiso
|
install -D -m 644 install/archiso $(DESTDIR)/lib/initcpio/install/archiso
|
||||||
|
install -D -m 755 archiso_shutdown $(DESTDIR)/lib/initcpio/archiso_shutdown
|
||||||
|
install -D -m 644 hooks/archiso_shutdown $(DESTDIR)/lib/initcpio/hooks/archiso_shutdown
|
||||||
|
install -D -m 644 install/archiso_shutdown $(DESTDIR)/lib/initcpio/install/archiso_shutdown
|
||||||
install -D -m 644 archiso_pxe_nbd $(DESTDIR)/lib/initcpio/archiso_pxe_nbd
|
install -D -m 644 archiso_pxe_nbd $(DESTDIR)/lib/initcpio/archiso_pxe_nbd
|
||||||
install -D -m 644 hooks/archiso_pxe_nbd $(DESTDIR)/lib/initcpio/hooks/archiso_pxe_nbd
|
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 install/archiso_pxe_nbd $(DESTDIR)/lib/initcpio/install/archiso_pxe_nbd
|
||||||
@ -32,6 +35,9 @@ uninstall:
|
|||||||
rm -f $(DESTDIR)/usr/bin/testiso
|
rm -f $(DESTDIR)/usr/bin/testiso
|
||||||
rm -f $(DESTDIR)/lib/initcpio/hooks/archiso
|
rm -f $(DESTDIR)/lib/initcpio/hooks/archiso
|
||||||
rm -f $(DESTDIR)/lib/initcpio/install/archiso
|
rm -f $(DESTDIR)/lib/initcpio/install/archiso
|
||||||
|
rm -f $(DESTDIR)/lib/initcpio/archiso_shutdown
|
||||||
|
rm -f $(DESTDIR)/lib/initcpio/hooks/archiso_shutdown
|
||||||
|
rm -f $(DESTDIR)/lib/initcpio/install/archiso_shutdown
|
||||||
rm -f $(DESTDIR)/lib/initcpio/archiso_pxe_nbd
|
rm -f $(DESTDIR)/lib/initcpio/archiso_pxe_nbd
|
||||||
rm -f $(DESTDIR)/lib/initcpio/hooks/archiso_pxe_nbd
|
rm -f $(DESTDIR)/lib/initcpio/hooks/archiso_pxe_nbd
|
||||||
rm -f $(DESTDIR)/lib/initcpio/install/archiso_pxe_nbd
|
rm -f $(DESTDIR)/lib/initcpio/install/archiso_pxe_nbd
|
||||||
|
43
archiso/archiso_shutdown
Normal file
43
archiso/archiso_shutdown
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# /oldroot depends on things inside /oldroot/run/archiso...
|
||||||
|
mkdir /oldrun
|
||||||
|
mount --move /oldroot/run /oldrun
|
||||||
|
|
||||||
|
# Unmount all mounts now.
|
||||||
|
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
|
||||||
|
if ! losetup -d ${_lup} 2> /dev/null; then
|
||||||
|
umount -d ${_lup}
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Unmount the space used to store *.cow.
|
||||||
|
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)
|
||||||
|
umount /oldrun/archiso/img_dev
|
||||||
|
fi
|
||||||
|
if [[ -f /oldrun/archiso/nbd_client.pid ]]; then
|
||||||
|
nbd-client -d /dev/nbd0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# reboot / poweroff / halt, depending on the argument passed by init
|
||||||
|
# if something invalid is passed, we halt
|
||||||
|
case "$1" in
|
||||||
|
reboot|poweroff|halt) "$1" -f ;;
|
||||||
|
*) halt -f;;
|
||||||
|
esac
|
22
archiso/hooks/archiso_shutdown
Normal file
22
archiso/hooks/archiso_shutdown
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
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
|
||||||
|
cp /bin/busybox /run/initramfs/bin/
|
||||||
|
cp /lib/ld-* /run/initramfs/lib/
|
||||||
|
cp /lib/lib* /run/initramfs/lib/
|
||||||
|
cp /sbin/dmsetup /run/initramfs/sbin/
|
||||||
|
if [[ -x /bin/nbd-client ]]; then
|
||||||
|
cp /bin/nbd-client /run/initramfs/bin/
|
||||||
|
fi
|
||||||
|
|
||||||
|
chroot /run/initramfs /bin/busybox --install
|
||||||
|
cp /shutdown /run/initramfs/
|
||||||
|
|
||||||
|
msg "done."
|
||||||
|
}
|
13
archiso/install/archiso_shutdown
Normal file
13
archiso/install/archiso_shutdown
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
build() {
|
||||||
|
SCRIPT="archiso_shutdown"
|
||||||
|
add_binary /lib/initcpio/archiso_shutdown /shutdown
|
||||||
|
}
|
||||||
|
|
||||||
|
help () {
|
||||||
|
cat <<HELPEOF
|
||||||
|
This hook will create a shutdown initramfs in /run/initramfs
|
||||||
|
that we can pivot to on shutdown in order to unmount / and
|
||||||
|
and others mount points, dm-snapshot devices and loopback devices.
|
||||||
|
Mostly usefull for dm-snapshot persistent.
|
||||||
|
HELPEOF
|
||||||
|
}
|
@ -43,10 +43,11 @@ make_customize_root_image() {
|
|||||||
make_setup_mkinitcpio() {
|
make_setup_mkinitcpio() {
|
||||||
if [[ ! -e ${work_dir}/build.${FUNCNAME} ]]; then
|
if [[ ! -e ${work_dir}/build.${FUNCNAME} ]]; then
|
||||||
local _hook
|
local _hook
|
||||||
for _hook in archiso archiso_pxe_nbd archiso_loop_mnt; do
|
for _hook in archiso archiso_shutdown archiso_pxe_nbd archiso_loop_mnt; do
|
||||||
cp /lib/initcpio/hooks/${_hook} ${work_dir}/root-image/lib/initcpio/hooks
|
cp /lib/initcpio/hooks/${_hook} ${work_dir}/root-image/lib/initcpio/hooks
|
||||||
cp /lib/initcpio/install/${_hook} ${work_dir}/root-image/lib/initcpio/install
|
cp /lib/initcpio/install/${_hook} ${work_dir}/root-image/lib/initcpio/install
|
||||||
done
|
done
|
||||||
|
cp /lib/initcpio/archiso_shutdown ${work_dir}/root-image/lib/initcpio
|
||||||
cp /lib/initcpio/archiso_pxe_nbd ${work_dir}/root-image/lib/initcpio
|
cp /lib/initcpio/archiso_pxe_nbd ${work_dir}/root-image/lib/initcpio
|
||||||
: > ${work_dir}/build.${FUNCNAME}
|
: > ${work_dir}/build.${FUNCNAME}
|
||||||
fi
|
fi
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
HOOKS="base udev memdisk archiso archiso_pxe_nbd archiso_loop_mnt pata scsi sata usb fw pcmcia filesystems usbinput"
|
HOOKS="base udev memdisk archiso_shutdown archiso archiso_pxe_nbd archiso_loop_mnt pata scsi sata usb fw pcmcia filesystems usbinput"
|
||||||
COMPRESSION="xz"
|
COMPRESSION="xz"
|
||||||
|
Loading…
Reference in New Issue
Block a user