commit
2697bdad1e
6 changed files with 374 additions and 30 deletions
2
Makefile
2
Makefile
|
@ -74,12 +74,14 @@ LIBS_ISO = \
|
|||
|
||||
CPIOHOOKS = \
|
||||
initcpio/hooks/miso \
|
||||
initcpio/hooks/miso_overlayfs \
|
||||
initcpio/hooks/miso_loop_mnt \
|
||||
initcpio/hooks/miso_pxe_common \
|
||||
initcpio/hooks/miso_pxe_http
|
||||
|
||||
CPIOINST = \
|
||||
initcpio/inst/miso \
|
||||
initcpio/inst/miso_overlayfs \
|
||||
initcpio/inst/miso_loop_mnt \
|
||||
initcpio/inst/miso_pxe_common \
|
||||
initcpio/inst/miso_pxe_http \
|
||||
|
|
257
initcpio/hooks/miso_overlayfs
Normal file
257
initcpio/hooks/miso_overlayfs
Normal file
|
@ -0,0 +1,257 @@
|
|||
# kernel_cmdline <param> <default>
|
||||
# Looks for a parameter on the kernel's boot-time command line.
|
||||
#
|
||||
# returns: 0 if param was found. Also prints its value if it was a K=V param.
|
||||
# 1 if it was not. Also prints value passed as <default>
|
||||
#
|
||||
|
||||
kernel_cmdline ()
|
||||
{
|
||||
for param in $(/bin/cat /proc/cmdline); do
|
||||
case "${param}" in
|
||||
$1=*) echo "${param##*=}"; return 0 ;;
|
||||
$1) return 0 ;;
|
||||
*) continue ;;
|
||||
esac
|
||||
done
|
||||
[ -n "${2}" ] && echo "${2}"
|
||||
return 1
|
||||
}
|
||||
|
||||
# 1$ : kernel argument to check
|
||||
overlay_arg_available() {
|
||||
for arg in $(echo "$(kernel_cmdline overlay)" | /bin/sed 's/,/ /g')
|
||||
do
|
||||
[ "${arg}" == "$1" ] && return 0
|
||||
done
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
# args: source, mountpoint
|
||||
_mnt_bind() {
|
||||
local src="${1}"
|
||||
local mnt="${2}"
|
||||
msg "::: Binding ${src} to ${mnt}"
|
||||
mkdir -p "${mnt}"
|
||||
/bin/mount -o bind "${src}" "${mnt}"
|
||||
}
|
||||
|
||||
# args: /path/to/image_file, mountpoint
|
||||
_mnt_squashfs() {
|
||||
local img="${1}"
|
||||
local mnt="${2}"
|
||||
local img_fullname="${img##*/}";
|
||||
local img_name="${img_fullname%.*}"
|
||||
local tmp_mnt="/ro_branch/${img_name}"
|
||||
|
||||
if [ "${copytoram}" = "y" ]; then
|
||||
msg -n ":: Copying squashfs image to RAM..."
|
||||
/bin/cp "${img}" "/copytoram/${img_fullname}"
|
||||
if [ $? -ne 0 ]; then
|
||||
echo ">> ERROR: while copy ${img} to /copytoram/${img_fullname}"
|
||||
launch_interactive_shell
|
||||
fi
|
||||
img="/copytoram/${img_fullname}"
|
||||
msg "done."
|
||||
fi
|
||||
|
||||
mkdir -p "${tmp_mnt}"
|
||||
/bin/mount -r -t squashfs "${img}" "${tmp_mnt}"
|
||||
if [ $? -ne 0 ]; then
|
||||
echo ">> ERROR: while mounting ${img} to ${tmp_mnt}"
|
||||
launch_interactive_shell
|
||||
fi
|
||||
|
||||
if [ "/${mnt#/*/}" = "/" ]; then
|
||||
overlayfs="${overlayfs}:${tmp_mnt}"
|
||||
else
|
||||
_mnt_bind "${tmp_mnt}" "${mnt}"
|
||||
fi
|
||||
}
|
||||
|
||||
run_hook() {
|
||||
modprobe loop
|
||||
if [ "x${arch}" = "x" ]; then
|
||||
arch="$(uname -m)"
|
||||
fi
|
||||
|
||||
if [ "x${rw_branch_size}" = "x" ]; then
|
||||
rw_branch_size="75%"
|
||||
fi
|
||||
|
||||
if [ "x${copytoram_size}" = "x" ]; then
|
||||
copytoram_size="75%"
|
||||
fi
|
||||
|
||||
if [ "x${misobasedir}" = "x" ]; then
|
||||
misobasedir="manjaro"
|
||||
fi
|
||||
|
||||
if [ "x${isomounts}" != "x" ]; then
|
||||
isomounts="/bootmnt/${isomounts}"
|
||||
else
|
||||
isomounts="/bootmnt/${misobasedir}/isomounts"
|
||||
fi
|
||||
|
||||
# set mount handler for miso
|
||||
mount_handler="miso_mount_handler"
|
||||
}
|
||||
|
||||
testdevice() {
|
||||
fstype=$( blkid -s TYPE -o value ${MDEV} )
|
||||
mount -r -t ${fstype} -o noatime "${MDEV}" "/bootmnt" >/dev/null 2>/dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
if [ -f "/bootmnt/.miso" ]; then
|
||||
msg "::: INFO: miso system at ${MDEV}"
|
||||
found="yes"
|
||||
else
|
||||
/bin/umount "/bootmnt/" 2>/dev/null
|
||||
msg "::: INFO: No miso system at ${MDEV}"
|
||||
MDEV=""
|
||||
fi
|
||||
else
|
||||
msg ">> ERROR: Couldn't mount ${MDEV}"
|
||||
MDEV=""
|
||||
fi
|
||||
}
|
||||
|
||||
probedevice() {
|
||||
|
||||
if [[ -n "${ip}" && -n "${miso_http_srv}" && -f "${isomounts}" ]]; then
|
||||
found="yes"
|
||||
return
|
||||
fi
|
||||
|
||||
# Loop device test every second up to some limit
|
||||
if [ "x${usbdelay}" != "x" ]; then
|
||||
waittime=${usbdelay}
|
||||
else
|
||||
waittime=35
|
||||
fi
|
||||
waitcount=0
|
||||
while [ ${waittime} -ne ${waitcount} ]; do
|
||||
# first we look for root, e.g. /dev/sda1 to see if .miso will be found
|
||||
if [ "x${root}" != "x" ]; then
|
||||
[ ${waitcount} -eq 0 ] && msg ":: Looking for ${root}"
|
||||
if [ -e ${root} ]; then
|
||||
MDEV=${root}
|
||||
testdevice
|
||||
fi
|
||||
fi
|
||||
|
||||
# if still not found, we will look for misolabel
|
||||
if [ "x${misolabel}" != "x" ]; then
|
||||
[ ${waitcount} -eq 0 ] && msg ":: Looking for LABEL ${misolabel}"
|
||||
MDEV=$( blkid -L ${misolabel} )
|
||||
if [ "x${MDEV}" != "x" ]; then
|
||||
testdevice
|
||||
else
|
||||
msg "::: INFO: LABEL ${misolabel} is not valid!"
|
||||
misolabel=""
|
||||
fi
|
||||
fi
|
||||
|
||||
# still nothing found, we will look for boot device
|
||||
if [ -z "${found}" ]; then
|
||||
[ ${waitcount} -eq 0 ] && msg ":: Looking for boot device"
|
||||
if [ "x${nocd}" = "x" ]; then
|
||||
# Look for CD
|
||||
cdroms=$( /bin/cat /proc/sys/dev/cdrom/info | { while read a b c; do
|
||||
if [ "${a}" = "drive" -a "${b}" = "name:" ]; then
|
||||
echo "${c}"
|
||||
break
|
||||
fi
|
||||
done
|
||||
} )
|
||||
for i in ${cdroms}; do
|
||||
MDEV=/dev/${i}
|
||||
testdevice
|
||||
if [ "x${MDEV}" != "x" ]; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# Test partitions
|
||||
if [ "x${MDEV}" = "x" ]; then
|
||||
for d in /dev/sd[a-z][0-9]*; do
|
||||
MDEV=${d}
|
||||
testdevice
|
||||
if [ "x${MDEV}" != "x" ]; then
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
[ "x${MDEV}" != "x" ] && break
|
||||
|
||||
/bin/sleep 1
|
||||
waitcount=$(( ${waitcount} + 1 ))
|
||||
done
|
||||
}
|
||||
|
||||
miso_mount_handler() {
|
||||
local newroot="${1}"
|
||||
local found
|
||||
local overlayfs
|
||||
|
||||
# Probe all devices
|
||||
probedevice
|
||||
|
||||
if [ -z "${found}" ]; then
|
||||
echo ">> ERROR: unable to find boot device"
|
||||
echo " Falling back to interactive prompt"
|
||||
echo " You can try to fix the problem manually, log out when you are finished"
|
||||
launch_interactive_shell
|
||||
fi
|
||||
|
||||
if [ "${copytoram}" = "y" ]; then
|
||||
msg -n ":: Mounting /copytoram (tmpfs) filesystem, size=${copytoram_size}..."
|
||||
mount -t tmpfs -o "size=${copytoram_size}",mode=0755 copytoram /copytoram
|
||||
msg "done."
|
||||
fi
|
||||
|
||||
msg -n ":: Mounting rw_branch (tmpfs) filesystem, size=${rw_branch_size}..."
|
||||
mount -t tmpfs -o "size=${rw_branch_size}",mode=0755 rw_branch /rw_branch
|
||||
msg "done."
|
||||
|
||||
msg ":: Mounting images"
|
||||
while read img imgarch mountpoint type kernelarg; do
|
||||
# check if this line is a comment (starts with #)
|
||||
[ "${img#"#"}" != "${img}" ] && continue
|
||||
|
||||
[ "$imgarch" != "$arch" ] && continue
|
||||
|
||||
[ ! -r "/bootmnt/${misobasedir}/${img}" ] && continue
|
||||
|
||||
# check if the overlay should be loaded
|
||||
overlay_arg_available "$kernelarg"
|
||||
|
||||
|
||||
if [ $? == 1 ] && [ "$kernelarg" != "" ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
if [ "${type}" = "bind" ]; then
|
||||
_mnt_bind "/bootmnt/${misobasedir}/${img}" "${newroot}${mountpoint}"
|
||||
elif [ "${type}" = "squashfs" ]; then
|
||||
_mnt_squashfs "/bootmnt/${misobasedir}/${img}" "${newroot}${mountpoint}"
|
||||
fi
|
||||
done < "${isomounts}"
|
||||
|
||||
msg "Mounting ${overlayfs:1}"
|
||||
mkdir -p "/rw_branch/upper"
|
||||
mkdir -p "/rw_branch/work"
|
||||
mount -t overlay overlay -olowerdir="${overlayfs:1}",upperdir="/rw_branch/upper",workdir="/rw_branch/work" "${newroot}/"
|
||||
|
||||
if [ "${copytoram}" = "y" ]; then
|
||||
/bin/umount /bootmnt
|
||||
else
|
||||
_mnt_bind /bootmnt "${newroot}/bootmnt"
|
||||
fi
|
||||
}
|
||||
|
||||
# vim:ft=sh:ts=4:sw=4:et:
|
31
initcpio/inst/miso_overlayfs
Normal file
31
initcpio/inst/miso_overlayfs
Normal file
|
@ -0,0 +1,31 @@
|
|||
#!/bin/bash
|
||||
|
||||
build() {
|
||||
add_module "cdrom"
|
||||
add_module "overlay"
|
||||
add_module "squashfs"
|
||||
add_module "isofs"
|
||||
add_module "loop"
|
||||
add_module "usb_storage"
|
||||
add_module "sd_mod"
|
||||
add_module "sr_mod"
|
||||
add_module "virtio_pci"
|
||||
add_module "virtio_blk"
|
||||
|
||||
add_dir /rw_branch
|
||||
add_dir /ro_branch
|
||||
add_dir /copytoram
|
||||
add_dir /bootmnt
|
||||
|
||||
add_runscript
|
||||
|
||||
add_binary /usr/lib/udev/cdrom_id
|
||||
add_binary blockdev
|
||||
add_binary losetup
|
||||
add_binary mountpoint
|
||||
|
||||
add_file /usr/lib/udev/rules.d/60-cdrom_id.rules
|
||||
}
|
||||
|
||||
# vim: set ft=sh ts=4 sw=4 et:
|
||||
|
|
@ -393,7 +393,6 @@ download_to_cache(){
|
|||
pacman -v -Sp $2 --noconfirm > "$1"/cache-packages.txt
|
||||
sed -ni '/.pkg.tar.xz/p' "$1"/cache-packages.txt
|
||||
sed -i "s/.*\///" "$1"/cache-packages.txt
|
||||
rm -rf "$1/etc"
|
||||
}
|
||||
|
||||
# $1: image path
|
||||
|
|
111
lib/util-iso.sh
111
lib/util-iso.sh
|
@ -108,7 +108,6 @@ copy_livecd_helpers(){
|
|||
copy_cache_xorg(){
|
||||
msg2 "Copying xorg package cache ..."
|
||||
rsync -v --files-from="${work_dir}/pkgs-image/cache-packages.txt" /var/cache/pacman/pkg "${work_dir}/pkgs-image/opt/livecd/pkgs"
|
||||
rm -f "${work_dir}/pkgs-image/cache-packages.txt"
|
||||
}
|
||||
|
||||
# $1: image path
|
||||
|
@ -229,17 +228,27 @@ make_image_custom() {
|
|||
msg "Prepare [${custom} installation] (${custom}-image)"
|
||||
local path="${work_dir}/${custom}-image"
|
||||
mkdir -p ${path}
|
||||
umount_image_handler
|
||||
aufs_mount_root_image "${path}"
|
||||
if [[ ${use_overlayfs} == "true" ]];then
|
||||
mkdir -p "${work_dir}/work"
|
||||
mount -t overlay overlay -olowerdir="${work_dir}/root-image",upperdir="${path}",workdir="${work_dir}/work" "${path}"
|
||||
else
|
||||
umount_image_handler
|
||||
aufs_mount_root_image "${path}"
|
||||
fi
|
||||
chroot_create "${path}" "${packages}"
|
||||
clean_up_image "${path}"
|
||||
pacman -Qr "${path}" > "${path}/${custom}-image-pkgs.txt"
|
||||
cp "${path}/${custom}-image-pkgs.txt" ${cache_dir_iso}/${iso_name}-${custom}-${dist_release}-${arch}-pkgs.txt
|
||||
[[ -d ${custom}-overlay ]] && copy_overlay_custom
|
||||
configure_custom_image "${path}"
|
||||
${is_custom_pac_conf} && clean_pacman_conf "${path}"
|
||||
umount_image_handler
|
||||
aufs_clean "${path}"
|
||||
if [[ ${use_overlayfs} == "true" ]];then
|
||||
umount "${path}"
|
||||
rm -rf "${work_dir}/work"
|
||||
else
|
||||
umount_image_handler
|
||||
aufs_clean "${path}"
|
||||
fi
|
||||
clean_up_image "${path}"
|
||||
: > ${work_dir}/build.${FUNCNAME}
|
||||
msg "Done [${custom} installation] (${custom}-image)"
|
||||
fi
|
||||
|
@ -250,15 +259,23 @@ make_image_livecd() {
|
|||
msg "Prepare [livecd installation] (livecd-image)"
|
||||
local path="${work_dir}/livecd-image"
|
||||
mkdir -p ${path}
|
||||
umount_image_handler
|
||||
if [[ -n "${custom}" ]] ; then
|
||||
aufs_mount_custom_image "${path}"
|
||||
aufs_append_root_image "${path}"
|
||||
if [[ ${use_overlayfs} == "true" ]];then
|
||||
mkdir -p "${work_dir}/work"
|
||||
if [[ -n "${custom}" ]] ; then
|
||||
mount -t overlay overlay -olowerdir="${work_dir}/${custom}-image":"${work_dir}/root-image",upperdir="${path}",workdir="${work_dir}/work" "${path}"
|
||||
else
|
||||
mount -t overlay overlay -olowerdir="${work_dir}/root-image",upperdir="${path}",workdir="${work_dir}/work" "${path}"
|
||||
fi
|
||||
else
|
||||
aufs_mount_root_image "${path}"
|
||||
umount_image_handler
|
||||
if [[ -n "${custom}" ]] ; then
|
||||
aufs_mount_custom_image "${path}"
|
||||
aufs_append_root_image "${path}"
|
||||
else
|
||||
aufs_mount_root_image "${path}"
|
||||
fi
|
||||
fi
|
||||
chroot_create "${path}" "${packages}"
|
||||
clean_up_image "${path}"
|
||||
pacman -Qr "${path}" > "${path}/livecd-image-pkgs.txt"
|
||||
copy_overlay_livecd "${path}"
|
||||
# copy over setup helpers and config loader
|
||||
|
@ -266,10 +283,16 @@ make_image_livecd() {
|
|||
copy_startup_scripts "${path}/usr/bin"
|
||||
configure_livecd_image "${path}"
|
||||
${is_custom_pac_conf} && clean_pacman_conf "${path}"
|
||||
# Clean up GnuPG keys?
|
||||
if [[ ${use_overlayfs} == "true" ]];then
|
||||
umount "${path}"
|
||||
rm -rf "${work_dir}/work"
|
||||
else
|
||||
umount_image_handler
|
||||
aufs_clean "${path}"
|
||||
fi
|
||||
# Clean up GnuPG keys
|
||||
rm -rf "${path}/etc/pacman.d/gnupg"
|
||||
umount_image_handler
|
||||
aufs_clean "${path}"
|
||||
clean_up_image "${path}"
|
||||
: > ${work_dir}/build.${FUNCNAME}
|
||||
msg "Done [livecd-image]"
|
||||
fi
|
||||
|
@ -280,12 +303,21 @@ make_image_xorg() {
|
|||
msg "Prepare [pkgs-image]"
|
||||
local path="${work_dir}/pkgs-image"
|
||||
mkdir -p ${path}/opt/livecd/pkgs
|
||||
umount_image_handler
|
||||
if [[ -n "${custom}" ]] ; then
|
||||
aufs_mount_custom_image "${path}"
|
||||
aufs_append_root_image "${path}"
|
||||
if [[ ${use_overlayfs} == "true" ]];then
|
||||
mkdir -p "${work_dir}/work"
|
||||
if [[ -n "${custom}" ]] ; then
|
||||
mount -t overlay overlay -olowerdir="${work_dir}/${custom}-image":"${work_dir}/root-image",upperdir="${path}",workdir="${work_dir}/work" "${path}"
|
||||
else
|
||||
mount -t overlay overlay -olowerdir="${work_dir}/root-image",upperdir="${path}",workdir="${work_dir}/work" "${path}"
|
||||
fi
|
||||
else
|
||||
aufs_mount_root_image "${path}"
|
||||
umount_image_handler
|
||||
if [[ -n "${custom}" ]] ; then
|
||||
aufs_mount_custom_image "${path}"
|
||||
aufs_append_root_image "${path}"
|
||||
else
|
||||
aufs_mount_root_image "${path}"
|
||||
fi
|
||||
fi
|
||||
download_to_cache "${path}" "${packages}"
|
||||
copy_cache_xorg
|
||||
|
@ -295,11 +327,18 @@ make_image_xorg() {
|
|||
done
|
||||
fi
|
||||
cp ${PKGDATADIR}/pacman-gfx.conf ${path}/opt/livecd
|
||||
rm -r ${path}/var
|
||||
make_repo "${path}/opt/livecd/pkgs/gfx-pkgs" "${path}/opt/livecd/pkgs"
|
||||
configure_xorg_drivers "${path}"
|
||||
umount_image_handler
|
||||
aufs_clean "${path}"
|
||||
if [[ ${use_overlayfs} == "true" ]];then
|
||||
umount "${path}"
|
||||
rm -rf "${work_dir}/work"
|
||||
else
|
||||
umount_image_handler
|
||||
aufs_clean "${path}"
|
||||
fi
|
||||
rm -r ${path}/var
|
||||
rm -rf "${work_dir}/pkgs-image/etc"
|
||||
rm -f "${work_dir}/pkgs-image/cache-packages.txt"
|
||||
: > ${work_dir}/build.${FUNCNAME}
|
||||
msg "Done [pkgs-image]"
|
||||
fi
|
||||
|
@ -314,18 +353,32 @@ make_image_boot() {
|
|||
cp ${work_dir}/root-image/boot/vmlinuz* ${path_iso}/${arch}/${iso_name}
|
||||
local path="${work_dir}/boot-image"
|
||||
mkdir -p ${path}
|
||||
umount_image_handler
|
||||
if [[ -n "${custom}" ]] ; then
|
||||
aufs_mount_custom_image "${path}"
|
||||
aufs_append_root_image "${path}"
|
||||
if [[ ${use_overlayfs} == "true" ]];then
|
||||
mkdir -p "${work_dir}/work"
|
||||
if [[ -n "${custom}" ]] ; then
|
||||
mount -t overlay overlay -olowerdir="${work_dir}/${custom}-image":"${work_dir}/root-image",upperdir="${path}",workdir="${work_dir}/work" "${path}"
|
||||
else
|
||||
mount -t overlay overlay -olowerdir="${work_dir}/root-image",upperdir="${path}",workdir="${work_dir}/work" "${path}"
|
||||
fi
|
||||
else
|
||||
aufs_mount_root_image "${path}"
|
||||
umount_image_handler
|
||||
if [[ -n "${custom}" ]] ; then
|
||||
aufs_mount_custom_image "${path}"
|
||||
aufs_append_root_image "${path}"
|
||||
else
|
||||
aufs_mount_root_image "${path}"
|
||||
fi
|
||||
fi
|
||||
copy_initcpio "${path}" || die "Failed to copy initcpio."
|
||||
gen_boot_image "${path}"
|
||||
mv ${path}/boot/${iso_name}.img ${path_iso}/${arch}/${iso_name}.img
|
||||
[[ -f ${path}/boot/intel-ucode.img ]] && copy_ucode "${path}" "${path_iso}"
|
||||
umount_image_handler
|
||||
if [[ ${use_overlayfs} == "true" ]];then
|
||||
umount "${path}"
|
||||
rm -rf "${work_dir}/work"
|
||||
else
|
||||
umount_image_handler
|
||||
fi
|
||||
rm -R ${path}
|
||||
: > ${work_dir}/build.${FUNCNAME}
|
||||
msg "Done [${iso_name}/boot]"
|
||||
|
|
|
@ -376,6 +376,8 @@ init_buildiso(){
|
|||
[[ -z ${iso_compression} ]] && iso_compression='xz'
|
||||
|
||||
[[ -z ${iso_checksum} ]] && iso_checksum='md5'
|
||||
|
||||
[[ -z ${use_overlayfs} ]] && use_overlayfs='false'
|
||||
}
|
||||
|
||||
load_config(){
|
||||
|
|
Loading…
Reference in a new issue