Add netboot generator script
This commit is contained in:
8
dracut/vmklive/59-mtd.rules
Normal file
8
dracut/vmklive/59-mtd.rules
Normal file
@@ -0,0 +1,8 @@
|
||||
SUBSYSTEM!="block", GOTO="ps_end"
|
||||
ACTION!="add|change", GOTO="ps_end"
|
||||
# Also don't process disks that are slated to be a multipath device
|
||||
ENV{DM_MULTIPATH_DEVICE_PATH}=="?*", GOTO="ps_end"
|
||||
|
||||
KERNEL=="mtdblock[0-9]*", IMPORT BLKID
|
||||
|
||||
LABEL="ps_end"
|
20
dracut/vmklive/61-mtd.rules
Normal file
20
dracut/vmklive/61-mtd.rules
Normal file
@@ -0,0 +1,20 @@
|
||||
SUBSYSTEM!="block", GOTO="pss_end"
|
||||
ACTION!="add|change", GOTO="pss_end"
|
||||
# Also don't process disks that are slated to be a multipath device
|
||||
ENV{DM_MULTIPATH_DEVICE_PATH}=="?*", GOTO="pss_end"
|
||||
|
||||
ACTION=="change", KERNEL=="dm-[0-9]*", ENV{DM_UDEV_DISABLE_OTHER_RULES_FLAG}!="1", GOTO="do_pss"
|
||||
KERNEL=="mtdblock*", GOTO="do_pss"
|
||||
|
||||
GOTO="pss_end"
|
||||
|
||||
LABEL="do_pss"
|
||||
# by-path (parent device path)
|
||||
ENV{DEVTYPE}=="disk", ENV{ID_PATH}=="", DEVPATH!="*/virtual/*", IMPORT PATH_ID
|
||||
ENV{DEVTYPE}=="disk", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH}"
|
||||
ENV{DEVTYPE}=="partition", ENV{ID_PATH}=="?*", SYMLINK+="disk/by-path/$env{ID_PATH}-part%n"
|
||||
|
||||
# by-label/by-uuid links (filesystem metadata)
|
||||
ENV{ID_FS_USAGE}=="filesystem|other|crypto", ENV{ID_FS_UUID_ENC}=="?*", SYMLINK+="disk/by-uuid/$env{ID_FS_UUID_ENC}"
|
||||
ENV{ID_FS_USAGE}=="filesystem|other", ENV{ID_FS_LABEL_ENC}=="?*", SYMLINK+="disk/by-label/$env{ID_FS_LABEL_ENC}"
|
||||
LABEL="pss_end"
|
56
dracut/vmklive/adduser.sh
Normal file
56
dracut/vmklive/adduser.sh
Normal file
@@ -0,0 +1,56 @@
|
||||
#!/bin/sh -x
|
||||
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
|
||||
# ex: ts=8 sw=4 sts=4 et filetype=sh
|
||||
|
||||
type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
|
||||
|
||||
echo void-live > ${NEWROOT}/etc/hostname
|
||||
|
||||
AUTOLOGIN=$(getarg live.autologin)
|
||||
USERNAME=$(getarg live.user)
|
||||
USERSHELL=$(getarg live.shell)
|
||||
|
||||
[ -z "$USERNAME" ] && USERNAME=anon
|
||||
[ -x $NEWROOT/bin/bash -a -z "$USERSHELL" ] && USERSHELL=/bin/bash
|
||||
[ -z "$USERSHELL" ] && USERSHELL=/bin/sh
|
||||
|
||||
# Create /etc/default/live.conf to store USER.
|
||||
echo "USERNAME=$USERNAME" >> ${NEWROOT}/etc/default/live.conf
|
||||
chmod 644 ${NEWROOT}/etc/default/live.conf
|
||||
|
||||
if ! grep -q ${USERSHELL} ${NEWROOT}/etc/shells ; then
|
||||
echo ${USERSHELL} >> ${NEWROOT}/etc/shells
|
||||
fi
|
||||
|
||||
# Create new user and remove password. We'll use autologin by default.
|
||||
chroot ${NEWROOT} useradd -m -c $USERNAME -G audio,video,wheel -s $USERSHELL $USERNAME
|
||||
chroot ${NEWROOT} passwd -d $USERNAME >/dev/null 2>&1
|
||||
|
||||
# Setup default root/user password (voidlinux).
|
||||
chroot ${NEWROOT} sh -c 'echo "root:voidlinux" | chpasswd -c SHA512'
|
||||
chroot ${NEWROOT} sh -c "echo "$USERNAME:voidlinux" | chpasswd -c SHA512"
|
||||
|
||||
# Enable sudo permission by default.
|
||||
if [ -f ${NEWROOT}/etc/sudoers ]; then
|
||||
echo "${USERNAME} ALL=(ALL) NOPASSWD: ALL" >> ${NEWROOT}/etc/sudoers
|
||||
fi
|
||||
|
||||
if [ -d ${NEWROOT}/etc/polkit-1 ]; then
|
||||
# If polkit is installed allow users in the wheel group to run anything.
|
||||
cat > ${NEWROOT}/etc/polkit-1/rules.d/void-live.rules <<_EOF
|
||||
polkit.addAdminRule(function(action, subject) {
|
||||
return ["unix-group:wheel"];
|
||||
});
|
||||
|
||||
polkit.addRule(function(action, subject) {
|
||||
if (subject.isInGroup("wheel")) {
|
||||
return polkit.Result.YES;
|
||||
}
|
||||
});
|
||||
_EOF
|
||||
chroot ${NEWROOT} chown polkitd:polkitd /etc/polkit-1/rules.d/void-live.rules
|
||||
fi
|
||||
|
||||
if [ -n "$AUTOLOGIN" ]; then
|
||||
sed -i "s,GETTY_ARGS=\"--noclear\",GETTY_ARGS=\"--noclear -a $USERNAME\",g" ${NEWROOT}/etc/sv/agetty-tty1/run
|
||||
fi
|
9
dracut/vmklive/copy-initramfs.sh
Normal file
9
dracut/vmklive/copy-initramfs.sh
Normal file
@@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
|
||||
# ex: ts=8 sw=4 sts=4 et filetype=sh
|
||||
|
||||
# Copy the initramfs back to the new rootfs for proper shutdown.
|
||||
KVER=$(uname -r)
|
||||
if [ -x /usr/bin/systemctl ]; then
|
||||
cp /run/initramfs/live/boot/initrd $NEWROOT/boot/initramfs-${KVER}.img
|
||||
fi
|
56
dracut/vmklive/display-manager-autologin.sh
Normal file
56
dracut/vmklive/display-manager-autologin.sh
Normal file
@@ -0,0 +1,56 @@
|
||||
#!/bin/sh
|
||||
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
|
||||
# ex: ts=8 sw=4 sts=4 et filetype=sh
|
||||
|
||||
type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
|
||||
|
||||
USERNAME=$(getarg live.user)
|
||||
[ -z "$USERNAME" ] && USERNAME=anon
|
||||
|
||||
# Configure GDM autologin
|
||||
if [ -d ${NEWROOT}/etc/gdm ]; then
|
||||
GDMCustomFile=${NEWROOT}/etc/gdm/custom.conf
|
||||
AutologinParameters="AutomaticLoginEnable=true\nAutomaticLogin=$USERNAME"
|
||||
|
||||
# Prevent from updating if parameters already present (persistent usb key)
|
||||
if ! `grep -qs 'AutomaticLoginEnable' $GDMCustomFile` ; then
|
||||
if ! `grep -qs '\[daemon\]' $GDMCustomFile` ; then
|
||||
echo '[daemon]' >> $GDMCustomFile
|
||||
fi
|
||||
sed -i "s/\[daemon\]/\[daemon\]\n$AutologinParameters/" $GDMCustomFile
|
||||
fi
|
||||
fi
|
||||
|
||||
# Configure KDM autologin
|
||||
if [ -e ${NEWROOT}/etc/kdm/kdmrc ]; then
|
||||
sed -i -e "s|^\#\(AutoLoginEnable=\).*|\1|" ${NEWROOT}/etc/kdm/kdmrc
|
||||
sed -i -e "s|^\#\(AutoLoginUser=\).*|\1$USERNAME|" ${NEWROOT}/etc/kdm/kdmrc
|
||||
fi
|
||||
|
||||
# Configure lightdm autologin.
|
||||
if [ -r ${NEWROOT}/etc/lightdm.conf ]; then
|
||||
sed -i -e "s|^\#\(default-user=\).*|\1$USERNAME|" \
|
||||
${NEWROOT}/etc/lightdm.conf
|
||||
sed -i -e "s|^\#\(default-user-timeout=\).*|\10|" \
|
||||
${NEWROOT}/etc/lightdm.conf
|
||||
fi
|
||||
|
||||
# Configure lxdm autologin.
|
||||
if [ -r ${NEWROOT}/etc/lxdm/lxdm.conf ]; then
|
||||
sed -e "s,.*autologin.*=.*,autologin=$USERNAME," -i ${NEWROOT}/etc/lxdm/lxdm.conf
|
||||
if [ -x ${NEWROOT}/usr/bin/enlightenment_start ]; then
|
||||
sed -e "s,.*session.*=.*,session=/usr/bin/enlightenment_start," -i ${NEWROOT}/etc/lxdm/lxdm.conf
|
||||
elif [ -x ${NEWROOT}/usr/bin/startxfce4 ]; then
|
||||
sed -e "s,.*session.*=.*,session=/usr/bin/startxfce4," -i ${NEWROOT}/etc/lxdm/lxdm.conf
|
||||
elif [ -x ${NEWROOT}/usr/bin/mate-session ]; then
|
||||
sed -e "s,.*session.*=.*,session=/usr/bin/mate-session," -i ${NEWROOT}/etc/lxdm/lxdm.conf
|
||||
elif [ -x ${NEWROOT}/usr/bin/cinnamon-session ]; then
|
||||
sed -e "s,.*session.*=.*,session=/usr/bin/cinnamon-session," -i ${NEWROOT}/etc/lxdm/lxdm.conf
|
||||
elif [ -x ${NEWROOT}/usr/bin/i3 ]; then
|
||||
sed -e "s,.*session.*=.*,session=/usr/bin/i3," -i ${NEWROOT}/etc/lxdm/lxdm.conf
|
||||
elif [ -x ${NEWROOT}/usr/bin/startlxde ]; then
|
||||
sed -e "s,.*session.*=.*,session=/usr/bin/startlxde," -i ${NEWROOT}/etc/lxdm/lxdm.conf
|
||||
elif [ -x ${NEWROOT}/usr/bin/startlxqt ]; then
|
||||
sed -e "s,.*session.*=.*,session=/usr/bin/startlxqt," -i ${NEWROOT}/etc/lxdm/lxdm.conf
|
||||
fi
|
||||
fi
|
22
dracut/vmklive/locale.sh
Normal file
22
dracut/vmklive/locale.sh
Normal file
@@ -0,0 +1,22 @@
|
||||
#!/bin/sh
|
||||
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
|
||||
# ex: ts=8 sw=4 sts=4 et filetype=sh
|
||||
|
||||
type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
|
||||
|
||||
LOCALE=$(getarg locale.LANG)
|
||||
[ -z "$LOCALE" ] && LOCALE="en_US.UTF-8"
|
||||
|
||||
# also enable this locale in newroot.
|
||||
echo "LANG=$LOCALE" > $NEWROOT/etc/locale.conf
|
||||
echo "LC_COLLATE=C" >> $NEWROOT/etc/locale.conf
|
||||
|
||||
# set keymap too.
|
||||
KEYMAP=$(getarg vconsole.keymap)
|
||||
[ -z "$KEYMAP" ] && KEYMAP="us"
|
||||
|
||||
if [ -f ${NEWROOT}/etc/vconsole.conf ]; then
|
||||
sed -e "s,^KEYMAP=.*,KEYMAP=$KEYMAP," -i $NEWROOT/etc/vconsole.conf
|
||||
elif [ -f ${NEWROOT}/etc/rc.conf ]; then
|
||||
sed -e "s,^#KEYMAP=.*,KEYMAP=$KEYMAP," -i $NEWROOT/etc/rc.conf
|
||||
fi
|
31
dracut/vmklive/module-setup.sh
Normal file
31
dracut/vmklive/module-setup.sh
Normal file
@@ -0,0 +1,31 @@
|
||||
#!/bin/bash
|
||||
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
|
||||
# ex: ts=8 sw=4 sts=4 et filetype=sh
|
||||
|
||||
check() {
|
||||
return 255
|
||||
}
|
||||
|
||||
depends() {
|
||||
echo dmsquash-live
|
||||
}
|
||||
|
||||
install() {
|
||||
inst /usr/bin/chroot
|
||||
inst /usr/bin/chmod
|
||||
inst /usr/bin/sed
|
||||
|
||||
if [ -e /usr/bin/memdiskfind ]; then
|
||||
inst /usr/bin/memdiskfind
|
||||
instmods mtdblock phram
|
||||
inst_rules "$moddir/59-mtd.rules" "$moddir/61-mtd.rules"
|
||||
prepare_udev_rules 59-mtd.rules 61-mtd.rules
|
||||
inst_hook pre-udev 01 "$moddir/mtd.sh"
|
||||
fi
|
||||
|
||||
inst_hook pre-pivot 01 "$moddir/adduser.sh"
|
||||
inst_hook pre-pivot 02 "$moddir/display-manager-autologin.sh"
|
||||
inst_hook pre-pivot 03 "$moddir/copy-initramfs.sh"
|
||||
inst_hook pre-pivot 04 "$moddir/locale.sh"
|
||||
inst_hook pre-pivot 05 "$moddir/services.sh"
|
||||
}
|
7
dracut/vmklive/mtd.sh
Executable file
7
dracut/vmklive/mtd.sh
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
MEMDISK=$(memdiskfind)
|
||||
if [ "$MEMDISK" ]; then
|
||||
modprobe phram phram=memdisk,$MEMDISK
|
||||
modprobe mtdblock
|
||||
printf 'KERNEL=="mtdblock0", RUN+="/sbin/initqueue --settled --onetime --unique /sbin/dmsquash-live-root /dev/mtdblock0"\n' >> /etc/udev/rules.d/99-live-squash.rules
|
||||
fi
|
29
dracut/vmklive/services.sh
Normal file
29
dracut/vmklive/services.sh
Normal file
@@ -0,0 +1,29 @@
|
||||
#!/bin/sh
|
||||
# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
|
||||
# ex: ts=8 sw=4 sts=4 et filetype=sh
|
||||
|
||||
type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
|
||||
|
||||
SERVICEDIR=$NEWROOT/etc/sv
|
||||
SERVICES="$(getarg live.services)"
|
||||
|
||||
for f in ${SERVICES}; do
|
||||
ln -sf /etc/sv/$f $NEWROOT/etc/runit/runsvdir/default/
|
||||
done
|
||||
|
||||
dhcpcd=1
|
||||
for f in connmand NetworkManager wicd; do
|
||||
if [ -e $SERVICEDIR/$f ]; then
|
||||
unset dhcpcd
|
||||
fi
|
||||
done
|
||||
|
||||
# Enable all services by default... with some exceptions.
|
||||
for f in $SERVICEDIR/*; do
|
||||
_service=${f##*/}
|
||||
case "${_service}" in
|
||||
agetty-console|agetty-generic|agetty-serial|agetty-tty[SAU]*|sulogin|dhcpcd-*|iptables|ip6tables|wpa_supplicant|pulseaudio|lvmetad|dmeventd|mdadm) ;; # ignored
|
||||
dhcpcd) [ -n "$dhcpcd" ] && ln -sf ${f##$NEWROOT} $NEWROOT/etc/runit/runsvdir/default/;;
|
||||
*) ln -sf ${f##$NEWROOT} $NEWROOT/etc/runit/runsvdir/default/;;
|
||||
esac
|
||||
done
|
Reference in New Issue
Block a user