After some days of researching, I have 3 approaches to the problem of creating custom entries for running a Systemd
Debian without graphical desktop from the Grub
. I think that the best approach is 1.
1. Creating a new /etc/grub.d/* configuration file
To do that, i copied /etc/grub.d/10_linux
file as a template:
sudo cp /etc/grub.d/10_linux /etc/grub.d/11_multiuser
The original file creates the root entry for the latest kernel and also the "Advanced options" submenu. So, I edited my 11_multiuser
file a little bit, just to create a new submenu for the multiuser options, and create inside a new option for each kernel, for the multiuser mode. Here I'll add a patch with the modified lines:
--- /etc/grub.d/10_linux
+++ /etc/grub.d/11_multiuser
@@ -118,6 +118,8 @@
case $type in
recovery)
title="$(gettext_printf "%s, with Linux %s (%s)" "${os}" "${version}" "$(gettext "${GRUB_RECOVERY_TITLE}")")" ;;
+ multiuser)
+ title="$(gettext_printf "%s, with Linux %s (multiuser)" "${os}" "${version}")" ;;
init-*)
title="$(gettext_printf "%s, with Linux %s (%s)" "${os}" "${version}" "${type#init-}")" ;;
*)
@@ -227,57 +229,18 @@
boot_device_id=
title_correction_code=
-cat << 'EOF'
-function gfxmode {
- set gfxpayload="${1}"
-EOF
-if [ "$vt_handoff" = 1 ]; then
- cat << 'EOF'
- if [ "${1}" = "keep" ]; then
- set vt_handoff=vt.handoff=7
- else
- set vt_handoff=
- fi
-EOF
-fi
-cat << EOF
-}
-EOF
-
-# Use ELILO's generic "efifb" when it's known to be available.
-# FIXME: We need an interface to select vesafb in case efifb can't be used.
-if [ "x$GRUB_GFXPAYLOAD_LINUX" != x ] || [ "$gfxpayload_dynamic" = 0 ]; then
- echo "set linux_gfx_mode=$GRUB_GFXPAYLOAD_LINUX"
-else
- cat << EOF
-if [ "\${recordfail}" != 1 ]; then
- if [ -e \${prefix}/gfxblacklist.txt ]; then
- if hwmatch \${prefix}/gfxblacklist.txt 3; then
- if [ \${match} = 0 ]; then
- set linux_gfx_mode=keep
- else
- set linux_gfx_mode=text
- fi
- else
- set linux_gfx_mode=text
- fi
- else
- set linux_gfx_mode=keep
- fi
-else
- set linux_gfx_mode=text
-fi
-EOF
-fi
-cat << EOF
-export linux_gfx_mode
-EOF
-
# Extra indentation to add to menu entries in a submenu. We're not in a submenu
# yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
submenu_indentation=""
-is_top_level=true
+# para el menu de multiuser
+submenu_indentation="$grub_tab"
+if [ -z "$boot_device_id" ]; then
+ boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
+fi
+gettext_printf "Agregando entradas multiuser...\n" >&2
+echo "submenu '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote) (MultiUser)' \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {"
+is_top_level=false
while [ "x$list" != "x" ] ; do
linux=`version_find_latest $list`
case $linux in
@@ -331,34 +294,9 @@
linux_root_device_thisversion=${GRUB_DEVICE}
fi
- if [ "x$is_top_level" = xtrue ] && [ "x${GRUB_DISABLE_SUBMENU}" != xy ]; then
- linux_entry "${OS}" "${version}" simple \
- "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
-
- submenu_indentation="$grub_tab"
-
- if [ -z "$boot_device_id" ]; then
- boot_device_id="$(grub_get_device_id "${GRUB_DEVICE}")"
- fi
- # TRANSLATORS: %s is replaced with an OS name
- echo "submenu '$(gettext_printf "Advanced options for %s" "${OS}" | grub_quote)' \$menuentry_id_option 'gnulinux-advanced-$boot_device_id' {"
- is_top_level=false
- fi
-
- linux_entry "${OS}" "${version}" advanced \
- "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}"
-
- for supported_init in ${SUPPORTED_INITS}; do
- init_path="${supported_init#*:}"
- if [ -x "${init_path}" ] && [ "$(readlink -f /sbin/init)" != "${init_path}" ]; then
- linux_entry "${OS}" "${version}" "init-${supported_init%%:*}" \
- "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT} init=${init_path}"
- fi
- done
- if [ "x${GRUB_DISABLE_RECOVERY}" != "xtrue" ]; then
- linux_entry "${OS}" "${version}" recovery \
- "${GRUB_CMDLINE_LINUX_RECOVERY} ${GRUB_CMDLINE_LINUX}"
- fi
+ linux_entry "${OS}" "${version}" multiuser \
+ "${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT} systemd.unit=multi-user.target"
+
list=`echo $list | tr ' ' '\n' | fgrep -vx "$linux" | tr '\n' ' '`
done
With this solution, if I add/remove kernels, or perform some action that involves any reconfiguration of the grub menu, my desired multiuser entries will be automatically added for each kernel. Also, I think (but not completely sure) that, if i update the grub, my new configuration file 11_multiuser
won't be removed, given that it's not part of the Grub's predefined configuration files.
2. Modifying /etc/grub.d/10_linux file
This is another approach, but i think this is worse than the first one. This way, you are modifying the official file, so you could break the Grub's configuration and the whole system startup. Also, if any update leads to the file replacement, you could loose your configuration. There is only one advantage on doing this: you could insert your multiuser entries in the "Advanced options" submenu.The patch added for the first approach is partially valid for this. Anyway, I totally disagree this approach.
3. Modifying /etc/grub.d/40_custom file
This file is intended to insert specific entries. You could copy the entry from /boot/grub/grub.cfg
and paste it in this file adding the systemd.. It is perfectly ok, but the problem is that you must do it for every kernel you want. Also, when removing/adding new kernels to the system, you must maintain this file manually. Plus, these entries appears at the end of the grub menu, and if you have other operating systems like Windows, then your custom entries will be separated from the first Linux entries.