User Tools

Site Tools


linux:system:disk:clone-system

This is an old revision of the document!


GRUB 2


Grub Configuration

GRUB settings are stored in the following locations:

  • /etc/default/grub file Edit this file to change GRUB2’s settings.
  • /etc/grub.d/ directory contains additional scripts that are loaded by the /etc/default/grub file. For example, on Ubuntu, there are scripts here that configure the default theme. There’s also an os-prober script that checks the system’s internal hard drives for other installed operating systems — Windows, other Linux distributions, Mac OS X, and so on — and automatically adds them to GRUB2’s menu.
  • /boot/grub/grub.cfg file that’s created by update-grub and read at boot.

When you run the update-grub command, GRUB automatically combines the settings from the /etc/default/grub file, the scripts from the /etc/grub.d/ directory, and everything else, creating a /boot/grub/grub.cfg file that’s read at boot. In other words, to customize your GRUB2 settings, you’ll have to edit the /etc/default/grub file and then run the update-grub command. Subsequently install/update the Grub loader in the disk.

  # /etc/default/grub
  # update-grub
  # grub-install /dev/sdX
  # grub-install --recheck /dev/sdX

Probe installed OS

Open a terminal and run the os-prober command with root privileges. This will search for other operating system installations besides the current distro you’re booted into.

$ sudo os-prober

It should find your Linux distro, the Windows installation, and possibly a memory test installation or recovery partition. To add these findings to the GRUB menu, execute the update-grub command with root permissions.

$ sudo update-grub

The output should show that Windows 10 has been found and added to the GRUB boot menu.

Repair, Restore, or Reinstall Grub 2 with Live USB

Grub 2 typically gets overridden when you install Windows or another Operating System. To make Linux control the boot process, you need Reinstall (Repair/Restore) Grub using a Live CD.

Create a live USB and boot system from USB

Mount the partition your broken Linux installation is on. If you are not sure which it is, launch GParted (included in the Live CD) and find out. It is usually a EXT4 Partition. Replace the XY with the drive letter, and partition number, for example: sudo mount /dev/sda1 /mnt.

# mount /dev/sdXY /mnt

Now bind the directories that grub needs access to to detect other operating systems, like so.

# mount --bind /dev /mnt/dev
# mount --bind /dev/pts /mnt/dev/pts
# mount --bind /proc /mnt/proc
# mount --bind /sys /mnt/sys

Internet access For internet access inside chroot:

# mv /mnt/etc/resolv.conf /mnt/etc/resolv.conf.org
# cp /etc/resolv.conf /mnt/etc/resolv.conf

Now we jump into that using chroot.

# chroot /mnt

Now install, check, and update grub. This time you only need to add the drive letter (usually a) to replace X, for example: grub-install /dev/sda, grub-install –recheck /dev/sda.

# grub-install /dev/sdX
# grub-install --recheck /dev/sdX

Alternatively, in case of persistent problems, you can purge and reinstall grub2, make new config files:

apt-get remove --purge grub-pc grub-common
apt-get install grub-pc
grub-mkconfig
update-grub
grub-install /dev/sda

Now grub is back, all that is left is to exit the chrooted system and unmount everything:

# exit
# umount /mnt/sys
# umount /mnt/proc
# umount /mnt/dev/pt
# umount /mnt/dev
# umount /mnt

Shut down and turn your computer back on, and you will be met with the default Grub2 screen.

Customize boot layout

For customizing the layout of the Grub startup screen at boot, the files are located in:/boot/grub. The sample below illustrates adding a background image and changing the font size. Copy the background images to the folder: /boot/grub. Remember that other partitions might not yet be mounted and available at boot time.

Find screen resolution

To find the possible screen resolutions for Grub, do to the command line when Grub starts, by pressing 'c' in the menu to enter the command line. On the command line press:

videoinfo

Then a list of possible option will be shown.

Configure screen resolution and background image

Grub prefers png images instead of jpg images. Update /etc/default/grub as follows:

#nano /etc/default/grub

Modify Lines:

GRUB_BACKGROUND=/boot/grub/Katwijk-Silouet-edge-grain1-grub-1920x1080.png
GRUB_GFXMODE=1920x1080

If you change this file, run 'update-grub' afterwards to update /boot/grub/grub.cfg.

update-grub

Currently a grub2 wallpaper image cannot be larger than 1024×768px, and it will (configured by default) be stretched to match your gfx resolution. One way to give the illusion of a 16:9 grub wallpaper is to take an existing 16×9 wallpaper and scale it to the 4:3 image of size 1024×768, and set the grub gfx mode for example to GRUB_GFXMODE=1920×1080, when grub loads and stretches that image its aspect ratio will appear similar to the original.

linux/system/disk/clone-system.1694172704.txt.gz · Last modified: by 127.0.0.1