9

I am having a question that do all the linux distros boot files,grub files and kernel files , that are main to run them and only the iso image of the distro is different?

I have Fedora installed on my system and can replace it with manjaro by changing the grub entry? How safe it is?

15

Various distributions of course have different packages of pretty much everything. Nevertheless, three components are typically rather well isolated from each other: bootloader, kernel, userspace programs.

  1. Bootloader needs to be able to boot various kernels, otherwise its usability would be quite limited.

  2. The kernel doesn't really depend much on the userspace, since it is providing a basic environment for the userspace to run in.

  3. The userspace has some dependence on the kernel, but usually not for the basic tasks. It may be requiring various kernel functionality for certain aspects (even rather substantial), but it is often possible to use kernel from another distribution from "around the same time" (couple of months of difference should not matter, unless the userspace is using some bleeding edge features). If you just want to do piece-wise bootstrap of new distribution:

    • run dist-A
    • install dist-B-without-kernel (e.g in chroot)
    • boot B-with-kernel-A
    • install kernel-B
    • boot dist-B-with-kernel-B

it should work just fine (source: "been there, done that"). Depending on your particular usecase (kernel features needed by the userspace), you may even be able to run happily a "foreign" kernel without issues.

6
  • The ability of different kernels to be used with most of the userspace from different distributions has been one of the key things that allowed containers to work usefully. The main issue would be more hardware specific components shared between kernel and userspace like graphics and audio. – user1937198 Dec 25 '20 at 19:10
  • @user1937198 Speaking as someone who actually has to deal with cross-distro portability involving kernel ABIs, there’s a lot more than just hardware interfaces that are problematic.Containers work not because of userspace portability, but because very few people care about doing the myriad things that aren’t portable in containers. – Austin Hemmelgarn Dec 26 '20 at 18:49
  • 1
    You forgot one more huge thing. The init system. Previously there was only one: sysV init. These days there are 3 big ones SysV, Upstart and Systemd in addition there are several more init systems out there like initNg, OpenRC etc. Most init systems are just extensions or modifications to SysV init so their startup scripts are often compatible but Upstart and Systemd both completely change the syntax of startup scripts in incompatible ways – slebetman Dec 26 '20 at 21:40
  • @slebetman well, init system is part of userspace. (And IIRC at least systemd is capable to use init scripts to some basic degree) – peterph Dec 27 '20 at 20:43
  • unrelated, how cool would it be to swap out a bsd kernel and have everything work ;) – ThorSummoner Dec 29 '20 at 21:37
7

Less drastic would be to install a new distro in a separate partition, or on a separate disk, and use to original grub to let you choose which one to boot (dual boot). This would allow you to migrate anything you want to keep from your old system.

6

All Linux distros do not have the same boot, grub and kernel files. The safest way to change distros is by erasing the current OS and installing the new OS over it in the same place on the disk.

In the below screenshot are shown 4 different options for installing Manjaro in the Partitions screen of the Manjaro installer.

enter image description here

Selecting the Erase disk option in this screen installs Manjaro on the entire disk, and in this screen it also reserves space for a swap partition (shown in yellow) in place of the existing Ubuntu swap partition (shown in green). Selecting the Replace a partition overwrites one partition and installs Manjaro Linux in it. Selecting the Manual partitioning option gives the user the option to manually create partition(s) for installing Manjaro in whatever partitioning scheme that the user specifies.

5
  • 2
    I’d call this answer as factually incorrect. Linux maintains decent separation of functionality and as long as bootloader (grub in this case I presume) is pointed to the correct kernel and initramfs files all should work just fine. Succeeding in this endeavor may however require good understanding of how things in boot sequence work, but this is different answer from “no they are all different”. – Alexey Kamenskiy Dec 25 '20 at 17:42
  • Also worth pointing out that while the content may be slightly different, pretty much all popular distros follow FHS, so the locations of files are going to be the same (which would add to the support of doing what is asked) – Alexey Kamenskiy Dec 25 '20 at 17:45
  • "the safest way [...] is by erasing the current OS" hmm. – Michael Homer Dec 25 '20 at 20:59
  • Thanks everyone, now i will install any operating system after erasing the whole disk only. – Vedant Nandwana Dec 26 '20 at 3:11
  • @VedantNandwana If this answered your question, you can mark this answer as accepted by clicking the gray check mark beside the answer to change its color to green. – karel Dec 26 '20 at 5:52
2

Focussing on the question as asked, and not continuing into the implications.

First, to state two things which should be obvious: computers with different architectures etc. will not be using the same files, and computers from different manufacturers etc. might use the same files if they are only superficially different (different variant of an AMD video card or similar).

For any given architecture there is a dominant boot loader, some parts of which may be in a boot sector while other parts may be in a file. So for x86 there's GRUB (but also LILO etc. as alternatives), SPARC uses SILO (with GRUB as an alternative), ARM occasionally uses Das U-Boot and so on. The boot loader loads the kernel binary, and also optionally the initrd file, in some cases this may be done over a LAN.

There is only one Linux kernel, owned by Linus Torvalds, and built using the source files he releases possibly with distro-specific ("out-of-tree") patches.

The kernel binary obviously varies depending on the architecture, and to some extent what hardware is attached to the CPU. It also varies depending on whether it expects entries in the /dev directory to be predefined, or creates them on-the-fly using e.g. Udev.

A kernel might or might not be built to expect an initrd file, which is basically a compressed filesystem containing programs and configuration files needed immediately after boot. A PC will generally use an initrd file, something like a Kobo reader or a Raspberry Pi will not; I'd note here that this made it fairly easy for the community of Kobo owners to patch in extra functionality since they didn't need the tools to rebuild an initrd.

If an initrd is used, the kernel will eventually be told to use some other device as the root of its filesystem. The content of this device will vary depending on the distro, and this will potentially affect not just what programs and configuration files are present but also how the programs are built (static vs dynamic linkage of core libraries etc.).

When the system configuration is changed or updates, the programs and configuration information in the root filesystem may be used to rebuild an initrd. As a specific example, this happens regularly on Debian-based distreaux, since various configuration files are referred to before the kernel switches from the initrd to the main filesystem.

So the answer to the OP's question is a resounding "maybe".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.