systemd multiuser.targetを実行するためのdebian grubカスタムエントリを作成します。

systemd multiuser.targetを実行するためのdebian grubカスタムエントリを作成します。

Debian Stretchがあり、グラフィックデスクトップなしでシステムを実行するためのカスタムGrubエントリが必要です。私はそれが他のランレベルを実行するのと同じくらい簡単だと思いましたが、それについて読んでからすべてがsystemd違うことに気づきました。

読んだ後この問題Red Hatの紹介とこの他Debian Jessieの場合、ターゲットについて知り、systemd私がやりたいことはmulti-user.targetで実行されると思いました。

見つけました。このFedoraリンクこのアーチLinuxカーネルリンクともう一つ。彼らは両方とも、グルーブメニュー項目の「linux」行に追加できる「systemd.unit」オプションがあると説明しました。そのため、カスタムメニュー項目の作成方法を説明するリンクを検索しました。これ。ただし、grub画面の「e」キーを使用して自分の自動grubエントリを調べると、リンク内のエントリよりも複雑になります。問題は、カスタムメニュー項目のすべての内容をコピーする必要があるかどうかわからないことです。

 setparams 'Debian gnu/linux, con linux 4.8.0-2-amd64'
 load_video
 insmod gzio
 if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
 insmod part-msdos
 insmod ext2
 set root='hd0,msdos5'
 if [ x$feature_platform_search_hint = xy ]; then
    search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos5 --hint-efi=hd0,msdos5 --hint-baremetal=ahci0,msdos5  3202c741-ef05-40e4-9368-8617e7b1fb3c
else
    search --no-floppy --fs-uuid --set=root 3202c741-ef05-40e4-9368-8617e7b1fb3c
fi
echo 'Cargando Linux 4.8...'
linux /vmlinuz-4.8.0-2-amd64 root=UUID=17f74892-fe09-46ec-91ca-2dca457565a1 ro quiet
echo 'Cargando imagen de memoria inicial...'
initrd /initrd.img-4.8.0-2-amd64

これは最後のコアに対して自動的に生成された項目です。これらすべての項目をカスタムメニュー項目にコピーし、項目のみを変更できます。

linux /vmlinuz-4.8.0-2-amd64 root=UUID=17f74892-fe09-46ec-91ca-2dca457565a1 ro quiet

ラインは

linux /vmlinuz-4.8.0-2-amd64 root=UUID=17f74892-fe09-46ec-91ca-2dca457565a1 ro quiet systemd.unit=multi-user.target

ベストアンサー1

数日間の研究Systemdの終わりにGrub

1. 新しい /etc/grub.d/* 構成ファイルを作成します。

そのために/etc/grub.d/10_linuxファイルをテンプレートにコピーしました。

sudo cp /etc/grub.d/10_linux /etc/grub.d/11_multiuser

ソースファイルは、最新のカーネルのルートエントリと「詳細オプション」サブメニューを生成します。そのため11_multiuser、マルチユーザーオプションの新しいサブメニューと、マルチユーザーモードの各コアの新しいオプションを作成するためにいくつかのファイルを編集しました。ここに修正された行を含むパッチを追加します。

--- /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

このソリューションでは、コアの追加と削除、またはグルーブメニューの再編成に関連するタスクを実行すると、必要なマルチユーザーエントリが各コアに自動的に追加されます。また、grubを更新すると、新しいプロファイルが11_multiuserGrubの定義済みプロファイルの一部ではないため、削除されないと思います(完全にはわかりません)。

2. /etc/grub.d/10_linux ファイルの修正

ここに別のアプローチがありますが、最初のアプローチよりも悪いと思います。これにより、公式ファイルが変更されるため、Grubの構成やシステム全体の起動が中断される可能性があります。また、更新によってファイルが置き換えられると、構成が失われる可能性があります。これには唯一の利点があります。詳細オプションサブメニューにマルチユーザーエントリを挿入できることです。この部分では、最初の方法に追加されたパッチが有効です。とにかく私はこのアプローチに完全に同意しない。

3. /etc/grub.d/40_custom ファイルの変更

このファイルは特定の項目を挿入するように設計されています。そのエントリをこのファイルにコピーして/boot/grub/grub.cfg貼り付け、systemdを追加できます。まったく問題ありませんが、問題は、必要なすべてのコアに対してこれを行う必要があることです。また、新しいカーネルがシステムに削除/追加されると、このファイルを手動で維持する必要があります。また、これらのエントリはgrubメニューの末尾に表示されるため、別のオペレーティングシステム(Windowsなど)を使用している場合、カスタムエントリは最初のLinuxエントリと区別されます。

おすすめ記事