在 Kali Linux 中更改 GRUB2 背景的 5 種方式

blackmoreops發表於2017-03-31

這是一個關於如何在 Kali Linux 中更改 GRUB 背景的簡單指南(實際上它是 Kali Linux 的 GRUB 啟動影像)。 Kali 開發團隊在這方面做的不多,他們好像太忙了,所以在這篇文章中,我會對 GRUB 解釋一二,但是不會冗長到我失去寫作的激情。 那麼我們開始吧……

這通常是所有人首先會遇到的一個問題,在哪裡設定?有很多方法來查詢 GRUB 設定。每個人都可能有自己的方法,但我發現 update-grub 是最簡單的。如果在 VMWare 或 VirtualBox 中執行 update-grub,你將看到如下所示的內容:

root@kali:~# update-grub
Generating grub configuration file ...
Found background image: /usr/share/images/desktop-base/desktop-grub.png
Found linux image: /boot/vmlinuz-4.0.0-kali1-amd64
Found initrd image: /boot/initrd.img-4.0.0-kali1-amd64
  No volume groups found
done
root@kali:~#

如果您是雙系統,或者三系統,那麼您將看到 GRUB 以及其他作業系統入口。然而,我們感興趣的部分是背景影像,這是在我這裡看到的(你會看到完全相同的內容):

Found background image: /usr/share/images/desktop-base/desktop-grub.png

GRUB 啟動影像搜尋順序

在 grub-2.02 中,對基於 Debian 的系統來說,它將按照以下順序搜尋啟動背景:

  1. /etc/default/grub 裡的 GRUB_BACKGROUND 行 
  2. /boot/grub/ 裡找到的第一個影像(如果發現多張,將以字母順序排序)
  3. /usr/share/desktop-base/grub_background.sh 中指定的
  4. /etc/grub.d/05_debian_themeWALLPAPER 行列出的

現在將此資訊留在這裡,我們會盡快重新檢查它。

Kali Linux GRUB 啟動影像

在我使用 Kali Linux 時(因為我喜歡用它做事),會發現 Kali 正在使用這裡的背景影像:/usr/share/images/desktop-base/desktop-grub.png

為了確定,我們來檢查一下這個 .png 檔案的屬性。

root@kali:~# 
root@kali:~# ls -l /usr/share/images/desktop-base/desktop-grub.png
lrwxrwxrwx 1 root root 30 Oct  8 00:31 /usr/share/images/desktop-base/desktop-grub.png -> /etc/alternatives/desktop-grub
root@kali:~#

Change GRUB background in Kali Linux - blackMORE OPs -1

什麼?它只是 /etc/alternatives/desktop-grub 的一個符號連結? 但是 /etc/alternatives/desktop-grub 不是圖片檔案。看來我也要檢查一下它的屬性。

root@kali:~# 
root@kali:~# ls -l /etc/alternatives/desktop-grub
lrwxrwxrwx 1 root root 44 Oct  8 00:27 /etc/alternatives/desktop-grub -> /usr/share/images/desktop-base/kali-grub.png
root@kali:~# 

Change GRUB background in Kali Linux - blackMORE OPs -3

好吧,真讓人費解。 /etc/alternatives/desktop-grub 也是一個符號連結,它指向 /usr/share/images/desktop-base/kali-grub.png,來自最初同樣的資料夾。呃! 無語。 但是現在我們至少可以替換該檔案並將其解決。

在替換之前,我們需要檢查 /usr/share/images/desktop-base/kali-grub.png 的屬性,以確保下載相同型別和大小的檔案。

root@kali:~# 
root@kali:~# file /usr/share/images/desktop-base/kali-grub.png
/usr/share/images/desktop-base/kali-grub.png: PNG image data, 640 x 480, 8-bit/color RGB, non-interlaced
root@kali:~# 

可以確定這是一個 PNG 影像檔案,畫素尺寸為 640 x 480。

GRUB 背景影像屬性

可以使用 PNGJPG/JPEG 以及 TGA 型別的影像檔案作為 GRUB 2 的背景。必須符合以下規範:

  • JPG/JPEG 影像必須是 8-bit (256 色)
  • 影像應該是非索引的,RGB

預設情況下,如果安裝了 desktop-base 軟體包,符合上述規範的影像將放在 /usr/share/images/desktop-base/ 目錄中。在谷歌上很容易找到類似的檔案。我也找了一個。

root@kali:~# 
root@kali:~# file Downloads/wallpaper-1.png 
Downloads/wallpaper-1.png: PNG image data, 640 x 480, 8-bit/color RGB, non-interlaced
root@kali:~# 

Change GRUB background in Kali Linux - blackMORE OPs -6

方式 1:替換影像

現在我們只需簡單的用新檔案將 /usr/share/images/desktop-base/kali-grub.png 替換掉。值得注意這是最簡單的方法,不需要修改 grub-config 檔案。 如果你對 GRUB 很熟,建議你簡單的修改 GRUB 的預設配置檔案,然後執行 update-grub

像往常一樣,我會將原檔案重新命名為 kali-grub.png.bkp 進行備份。

root@kali:~# 
root@kali:~# mv /usr/share/images/desktop-base/kali-grub.png /usr/share/images/desktop-base/kali-grub.png.bkp
root@kali:~# 

Change GRUB background in Kali Linux - blackMORE OPs -4

現在我們將下載的檔案重新命名為 kali-grub.png

root@kali:~# 
root@kali:~# cp Downloads/wallpaper-1.png /usr/share/images/desktop-base/kali-grub.png
root@kali:~# 

Change GRUB background in Kali Linux - blackMORE OPs -5

最後執行命令 update-grub

root@kali:~# update-grub
Generating grub configuration file ...
Found background image: /usr/share/images/desktop-base/desktop-grub.png
Found linux image: /boot/vmlinuz-4.0.0-kali1-amd64
Found initrd image: /boot/initrd.img-4.0.0-kali1-amd64
  No volume groups found
done
root@kali:~#

Change GRUB background in Kali Linux - blackMORE OPs -7

下次重新啟動你的 Kali Linux 時,你會看到 GRUB 背景變成了你自己的影像(GRUB 啟動介面)。

下面是我現在正在使用的新 GRUB 啟動背景。你呢?要不要試試這個辦法?

Change GRUB background in Kali Linux - blackMORE OPs -9

這是最簡單最安全的辦法,最糟的情況也不過是在 GRUB 看到一個藍色的背景,但你依然可以登入後修復它們。現在如果你有信心,讓我們嘗試一個改變 GRUB 設定的更好的方法(有點複雜)。後續步驟更加有趣,而且可以在任何使用 GRUB 引導的 Linux 上使用。

現在回憶一下 GRUB 在哪 4 個地方尋找啟動背景影像?再看一遍:

  1. /etc/default/grub 裡的 GRUB_BACKGROUND 行 
  2. /boot/grub/ 裡找到的第一個影像(如果發現多張,將以字母順序排序)
  3. /usr/share/desktop-base/grub_background.sh 中指定的
  4. /etc/grub.d/05_debian_theme 裡 WALLPAPER 行列出的

那麼我們再在 Kali Linux 上(或任意使用 GRUB2 的 Linux系統)試一下新的選擇。

方式 2:在 GRUB_BACKGROUND 中定義影像路徑

所以你可以根據上述的查詢優先順序使用上述任一項,將 GRUB 背景影像改為自己的。以下是我自己系統上  /etc/default/grub 的內容。

root@kali:~# vi /etc/default/grub

按照 GRUB_BACKGROUND="/root/World-Map.jpg" 的格式新增一行,其中 World-Map.jpg 是你要作為 GRUB 背景的影像檔案。

# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
#   info -f grub -n 'Simple configuration'

GRUB_DEFAULT=0
GRUB_TIMEOUT=15
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet"
GRUB_CMDLINE_LINUX="initrd=/install/gtk/initrd.gz"
GRUB_BACKGROUND="/root/World-Map.jpg"

一旦使用上述方式完成更改,務必執行 update-grub 命令,如下所示。

root@kali:~# update-grub
Generating grub configuration file ...
Found background: /root/World-Map.jpg
Found background image: /root/World-Map.jpg
Found linux image: /boot/vmlinuz-4.0.0-kali1-amd64
Found initrd image: /boot/initrd.img-4.0.0-kali1-amd64
  No volume groups found
done
root@kali:~#

現在重啟機器,你會在 GRUB 看到自定義的影像。

方式 3:把影像檔案放到 /boot/grub/ 資料夾

如果沒有在 /etc/default/grub 檔案中指定 GRUB_BACKGROUND 項,理論上 GRUB 應當使用在 /boot/grub/ 資料夾找到的第一個影像檔案作為背景。如果 GRUB 在 /boot/grub/ 找到多個影像檔案,它會按字母排序並使用第一個影像檔案。

方式 4:在 grub_background.sh 指定影像路徑

如果沒有在 /etc/default/grub 檔案中指定 GRUB_BACKGROUND 項,而且 /boot/grub/ 目錄下沒有影像檔案,GRUB 將會開始在 /usr/share/desktop-base/grub_background.sh 檔案中指定的影像路徑中搜尋。Kali Linux 是在這裡指定的。每個 Linux 發行版都有自己的特色。

方式 5:在 /etc/grub.d/05_debian_theme 檔案的 WALLPAPER 一行指定影像

這是 GRUB 搜尋背景影像的最後一個位置。如果在其他部分都沒有找到,它將會在這裡查詢。

結論

這篇文章較長,但我想介紹一些基礎但很重要的東西。如果你有仔細閱讀,你會理解如何在 Kali Linux 上來回跟蹤符號連結。當你需要在一些 Linux 系統上查詢 GRUB 背景影像的位置時,你會感到得心應手。只要再多閱讀一點來理解 GRUB 顏色的工作方式,你就是行家了。


via: https://www.blackmoreops.com/2015/11/27/change-grub-background-in-kali-linux/

作者:https://www.blackmoreops.com/ 譯者:fuowang 校對:wxy

本文由 LCTT 原創編譯,Linux中國 榮譽推出

相關文章