Skip to content

Commit 993af77

Browse files
authored
[Update] Install a Custom Linux Distribution on a Compute Instance
Fixes: #7402
1 parent e40d2fb commit 993af77

1 file changed

Lines changed: 60 additions & 27 deletions

File tree

  • docs/guides/tools-reference/custom-kernels-distros/install-a-custom-distribution

docs/guides/tools-reference/custom-kernels-distros/install-a-custom-distribution/index.md

Lines changed: 60 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -251,34 +251,67 @@ Next, you need to determine which partition your root file system is installed o
251251
252252
Depending upon your distribution, it may use different parameters for your root disk under the "options" section. These can be adjusted as needed. Note that you're using `/dev/sda` instead of the `sda1` root partition that was identified previously.
253253

254-
1. Confirm the location of your `grub.cfg` file. Some distributions (notably, CentOS and Fedora) place this file under the `/boot/grub2` directory, while others have it under `/boot/grub`. Your new setup uses Linode's *Grub 2* mode, which looks for a configuration file under `/boot/grub/grub.cfg`. You can confirm if your `grub.cfg` is located in the necessary spot with the `ls` command:
254+
1. Confirm the location of your `grub.cfg` file. Some distributions (notably, CentOS and Fedora) place this file under the `/boot/grub2` directory, while others have it under `/boot/grub`. Your new setup uses Linode's *Grub 2* mode, which looks for a configuration file under `/boot/grub/grub.cfg`.
255+
Use the following script to detect the correct path and set up the expected location without creating an unnecessary symlink:
256+
257+
```bash
258+
if [ -f /boot/grub2/grub.cfg ] && [ -f /boot/grub/grub.cfg ]; then
259+
# Both exist — /boot/grub/grub.cfg is already in the right place
260+
GRUB_CFG=/boot/grub/grub.cfg
261+
echo "Using existing /boot/grub/grub.cfg"
262+
elif [ -f /boot/grub2/grub.cfg ]; then
263+
# Only grub2 path exists — create the directory and symlink
264+
mkdir -p /boot/grub
265+
ln -s /boot/grub2/grub.cfg /boot/grub/grub.cfg
266+
GRUB_CFG=/boot/grub/grub.cfg
267+
echo "Created symlink: /boot/grub/grub.cfg -> /boot/grub2/grub.cfg"
268+
elif [ -f /boot/grub/grub.cfg ]; then
269+
# Already in the standard location
270+
GRUB_CFG=/boot/grub/grub.cfg
271+
echo "Using existing /boot/grub/grub.cfg"
272+
else
273+
echo "ERROR: grub.cfg not found in /boot/grub/ or /boot/grub2/"
274+
echo "Run 'update-grub' or 'grub2-mkconfig' first to generate it."
275+
exit 1
276+
fi
277+
```
278+
279+
This script defaults to `/boot/grub2/grub.cfg` when both paths exist on systems like CentOS/Fedora, and only creates the symlink when `/boot/grub2/grub.cfg` exists but `/boot/grub/grub.cfg` does not. This avoids overwriting an existing config with a symlink.
280+
281+
1. Open your `grub.cfg` file and replace all instances of the old partition location and UUID with the new intended location. Run the following commands, replacing the UUID value with the one for your current root partition (determined in step 2 of the current section).
282+
283+
Change these example lines in `grub.cfg` referencing the old partition:
284+
285+
```
286+
linux /boot/vmlinuz-5.10.0-19-amd64 root=/dev/sda1 ro quiet
287+
```
288+
```
289+
search --no-floppy --fs-uuid --set=root 59a7ea75-58c8-46cc-8b71-86f07b56f41f
290+
```
291+
```
292+
set root='hd0,msdos1'
293+
linux /vmlinuz root=UUID=59a7ea75-58c8-46cc-8b71-86f07b56f41f ro
294+
```
295+
296+
To these lines pointing to `/dev/sda`):
297+
298+
```
299+
linux /boot/vmlinuz-5.10.0-19-amd64 root=/dev/sda ro quiet
300+
```
301+
```
302+
search --no-floppy --set=root /dev/sda
303+
```
304+
```
305+
set root='hd0'
306+
linux /vmlinuz root=/dev/sda ro
307+
```
308+
309+
The specific lines in your file vary by distribution and kernel version. The general rule is: replace every occurrence of `/dev/sda1` with `/dev/sda`, and replace every occurrence of the UUID (`59a7ea75-58c8-46cc-8b71-86f07b56f41f` in this example with your actual UUID from step 2) with `/dev/sda`.
255310
256-
```command {title="Lish console or Glish command prompt"}
257-
ls -la /boot/grub/grub.cfg
258-
```
259-
260-
The output should display information for that file, if it exists.
261-
262-
``` {title="Lish console or Glish command prompt"}
263-
-r--r--r-- 1 root root 5235 Dec 28 08:05 /boot/grub/grub.cfg
264-
```
265-
266-
If the Grub config is located under `/boot/grub2` instead, create a symlink to provide the correct configuration to the bootloader:
267-
268-
```command {title="Lish console or Glish command prompt"}
269-
mkdir /boot/grub
270-
ln -s /boot/grub2/grub.cfg /boot/grub/grub.cfg
271-
```
272-
273-
1. Open your `grub.cfg` file and replace all instances of the old partition location and UUID with the new intended location. Run the following commands, replacing the UUID value with the one for your current root partition (determined in step 2 of the current section). You may also need to make adjustments to the following commands if your root partition is at a location other than `/dev/sda1`:
274-
275-
```command {title="Lish console or Glish command prompt"}
276-
sed -i -e 's$/dev/sda1$/dev/sda$g' /boot/grub/grub.cfg
277-
sed -i -e 's$--fs-uuid --set=root 59a7ea75-58c8-46cc-8b71-86f07b56f41f$--set=root /dev/sda$g' /boot/grub/grub.cfg
278-
sed -i -e 's$root=UUID=59a7ea75-58c8-46cc-8b71-86f07b56f41f$root=/dev/sda$g' /boot/grub/grub.cfg
279-
```
311+
{{< note >}}
312+
If your root partition is at a location other than `/dev/sda1`, adjust accordingly.
313+
{{< /note >}}
280314
281-
Keep in mind that if your `grub.cfg` is located under `/boot/grub2`, you should adjust this command to reflect that.
282315
283316
### Transfer the System to a New Ext4 Disk
284317
@@ -346,4 +379,4 @@ You now should have a Linux system that's compatible with the Linode Platform. F
346379

347380
## Save the System as a Custom Image
348381

349-
If you wish to save a copy of this system to quickly deploy later, you may want to use Linode's Custom Image feature. This lets you create a Compute Instance based on this system without needing to go through this guide again. See [Capture an Image](/docs/products/tools/images/guides/capture-an-image/) for instructions on creating the image.
382+
If you wish to save a copy of this system to quickly deploy later, you may want to use Linode's Custom Image feature. This lets you create a Compute Instance based on this system without needing to go through this guide again. See [Capture an Image](/docs/products/tools/images/guides/capture-an-image/) for instructions on creating the image.

0 commit comments

Comments
 (0)