在Kali Linux中更改GRUB2背景的5種方式
這是一個關于如何在 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 的系統來說,它將按照以下順序搜索啟動背景:
- /etc/default/grub 里的 GRUB_BACKGROUND 行
- 在 /boot/grub/ 里找到的第一個圖像(如果發現多張,將以字母順序排序)
- 在 /usr/share/desktop-base/grub_background.sh 中指定的
- 在 /etc/grub.d/05_debian_theme 里 WALLPAPER 行列出的
現在將此信息留在這里,我們會盡快重新檢查它。
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:~#
什么?它只是 /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:~#
好吧,真讓人費解。 /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 背景圖像屬性
可以使用 PNG, JPG/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:~#
方式 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:~#
現在我們將下載的文件重命名為 kali-grub.png。
- root@kali:~#
- root@kali:~# cp Downloads/wallpaper-1.png /usr/share/images/desktop-base/kali-grub.png
- root@kali:~#
最后執行命令 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:~#
下次重新啟動你的 Kali Linux 時,你會看到 GRUB 背景變成了你自己的圖像(GRUB 啟動界面)。
下面是我現在正在使用的新 GRUB 啟動背景。你呢?要不要試試這個辦法?
這是最簡單最安全的辦法,最糟的情況也不過是在 GRUB 看到一個藍色的背景,但你依然可以登錄后修復它們。現在如果你有信心,讓我們嘗試一個改變 GRUB 設置的更好的方法(有點復雜)。后續步驟更加有趣,而且可以在任何使用 GRUB 引導的 Linux 上使用。
現在回憶一下 GRUB 在哪 4 個地方尋找啟動背景圖像?再看一遍:
- /etc/default/grub 里的 GRUB_BACKGROUND 行
- 在 /boot/grub/ 里找到的第一個圖像(如果發現多張,將以字母順序排序)
- 在 /usr/share/desktop-base/grub_background.sh 中指定的
- 在 /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 顏色的工作方式,你就是行家了。