Does the bootloader load the kernel fully into memory












0














I read that the bootloader (Grub, or U-boot etc. ) locates the kernel (from maybe the HDD, or even flash memory if it's an embedded system) and loads it into memory on startup.



Now, does this mean that the bootloader loads the kernel fully into available RAM and then passes control to it? My guess is that the kernel will not fully fit into the RAM and so there will be swapping of the kernel instructions from RAM to the storage device and vice-versa.



What I don't understand is, the bootloader has stopped executing at this stage and the kernel has taken over, so how can the bootloader take care about loading the rest of the kernel in and out of memory if it doesn't fully fit at first?










share|improve this question





























    0














    I read that the bootloader (Grub, or U-boot etc. ) locates the kernel (from maybe the HDD, or even flash memory if it's an embedded system) and loads it into memory on startup.



    Now, does this mean that the bootloader loads the kernel fully into available RAM and then passes control to it? My guess is that the kernel will not fully fit into the RAM and so there will be swapping of the kernel instructions from RAM to the storage device and vice-versa.



    What I don't understand is, the bootloader has stopped executing at this stage and the kernel has taken over, so how can the bootloader take care about loading the rest of the kernel in and out of memory if it doesn't fully fit at first?










    share|improve this question



























      0












      0








      0







      I read that the bootloader (Grub, or U-boot etc. ) locates the kernel (from maybe the HDD, or even flash memory if it's an embedded system) and loads it into memory on startup.



      Now, does this mean that the bootloader loads the kernel fully into available RAM and then passes control to it? My guess is that the kernel will not fully fit into the RAM and so there will be swapping of the kernel instructions from RAM to the storage device and vice-versa.



      What I don't understand is, the bootloader has stopped executing at this stage and the kernel has taken over, so how can the bootloader take care about loading the rest of the kernel in and out of memory if it doesn't fully fit at first?










      share|improve this question















      I read that the bootloader (Grub, or U-boot etc. ) locates the kernel (from maybe the HDD, or even flash memory if it's an embedded system) and loads it into memory on startup.



      Now, does this mean that the bootloader loads the kernel fully into available RAM and then passes control to it? My guess is that the kernel will not fully fit into the RAM and so there will be swapping of the kernel instructions from RAM to the storage device and vice-versa.



      What I don't understand is, the bootloader has stopped executing at this stage and the kernel has taken over, so how can the bootloader take care about loading the rest of the kernel in and out of memory if it doesn't fully fit at first?







      linux memory startup boot-loader






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 18 '18 at 23:12

























      asked Dec 18 '18 at 22:55









      Engineer999

      1143




      1143






















          2 Answers
          2






          active

          oldest

          votes


















          1














          The kernel is fully loaded into RAM on startup, and it is not swapped. The kernel does not know and does not care where it is loaded from. It could be loaded from the network, and it is hard to swap over tftp.






          share|improve this answer





















          • You could sell t-shirts with “it is hard to swap over tftp”! 🤣
            – Stephen Kitt
            Dec 19 '18 at 7:07










          • Where does virtual memory come into all this?
            – Engineer999
            Dec 19 '18 at 21:57



















          0














          It's more accurate to say that the bootloader loads the entirety of what it's told to load as the kernel into memory. it doesn't really have to be the kernel itself, it could be a second-stage bootloader (and in most cases, this is actually what's technically happening, because GRUB jumps to a decompression routine that extracts the real kernel), or it could be a type-1 hypervisor which then loads and executes the Linux kernel.



          Put simply, it all has to fit in memory and have enough space left over for things like userspace, or the system can't boot (this is part of why it's so hard to build a Linux system that runs with less than about 64M of RAM these days). The same can be said about every other UNIX system I know of (SVR4, BSD, Solaris, IRIX, Ultrix, Xenix, etc). It's just too much of a pain to handle swapping of memory in kernel-space for it to be worth implementing.






          share|improve this answer





















          • could you explain where virtual memory and the MMU comes into all this then?
            – Engineer999
            Dec 19 '18 at 21:58










          • The kernel itself provides all the abstractions for virtual memory, both those used internally and those for userspace. GRUB intentionally doesn't use virtual memory (because it would have to stick around in the background to keep providing it, which is not what a bootloader is for), and a lot of the early startup code in the kernel doesn't either because there are somethings that really do just need to be done before setting up virtual memory.
            – Austin Hemmelgarn
            Dec 20 '18 at 12:38











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "106"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f489787%2fdoes-the-bootloader-load-the-kernel-fully-into-memory%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          The kernel is fully loaded into RAM on startup, and it is not swapped. The kernel does not know and does not care where it is loaded from. It could be loaded from the network, and it is hard to swap over tftp.






          share|improve this answer





















          • You could sell t-shirts with “it is hard to swap over tftp”! 🤣
            – Stephen Kitt
            Dec 19 '18 at 7:07










          • Where does virtual memory come into all this?
            – Engineer999
            Dec 19 '18 at 21:57
















          1














          The kernel is fully loaded into RAM on startup, and it is not swapped. The kernel does not know and does not care where it is loaded from. It could be loaded from the network, and it is hard to swap over tftp.






          share|improve this answer





















          • You could sell t-shirts with “it is hard to swap over tftp”! 🤣
            – Stephen Kitt
            Dec 19 '18 at 7:07










          • Where does virtual memory come into all this?
            – Engineer999
            Dec 19 '18 at 21:57














          1












          1








          1






          The kernel is fully loaded into RAM on startup, and it is not swapped. The kernel does not know and does not care where it is loaded from. It could be loaded from the network, and it is hard to swap over tftp.






          share|improve this answer












          The kernel is fully loaded into RAM on startup, and it is not swapped. The kernel does not know and does not care where it is loaded from. It could be loaded from the network, and it is hard to swap over tftp.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 19 '18 at 7:04









          Johan Myréen

          7,44011524




          7,44011524












          • You could sell t-shirts with “it is hard to swap over tftp”! 🤣
            – Stephen Kitt
            Dec 19 '18 at 7:07










          • Where does virtual memory come into all this?
            – Engineer999
            Dec 19 '18 at 21:57


















          • You could sell t-shirts with “it is hard to swap over tftp”! 🤣
            – Stephen Kitt
            Dec 19 '18 at 7:07










          • Where does virtual memory come into all this?
            – Engineer999
            Dec 19 '18 at 21:57
















          You could sell t-shirts with “it is hard to swap over tftp”! 🤣
          – Stephen Kitt
          Dec 19 '18 at 7:07




          You could sell t-shirts with “it is hard to swap over tftp”! 🤣
          – Stephen Kitt
          Dec 19 '18 at 7:07












          Where does virtual memory come into all this?
          – Engineer999
          Dec 19 '18 at 21:57




          Where does virtual memory come into all this?
          – Engineer999
          Dec 19 '18 at 21:57













          0














          It's more accurate to say that the bootloader loads the entirety of what it's told to load as the kernel into memory. it doesn't really have to be the kernel itself, it could be a second-stage bootloader (and in most cases, this is actually what's technically happening, because GRUB jumps to a decompression routine that extracts the real kernel), or it could be a type-1 hypervisor which then loads and executes the Linux kernel.



          Put simply, it all has to fit in memory and have enough space left over for things like userspace, or the system can't boot (this is part of why it's so hard to build a Linux system that runs with less than about 64M of RAM these days). The same can be said about every other UNIX system I know of (SVR4, BSD, Solaris, IRIX, Ultrix, Xenix, etc). It's just too much of a pain to handle swapping of memory in kernel-space for it to be worth implementing.






          share|improve this answer





















          • could you explain where virtual memory and the MMU comes into all this then?
            – Engineer999
            Dec 19 '18 at 21:58










          • The kernel itself provides all the abstractions for virtual memory, both those used internally and those for userspace. GRUB intentionally doesn't use virtual memory (because it would have to stick around in the background to keep providing it, which is not what a bootloader is for), and a lot of the early startup code in the kernel doesn't either because there are somethings that really do just need to be done before setting up virtual memory.
            – Austin Hemmelgarn
            Dec 20 '18 at 12:38
















          0














          It's more accurate to say that the bootloader loads the entirety of what it's told to load as the kernel into memory. it doesn't really have to be the kernel itself, it could be a second-stage bootloader (and in most cases, this is actually what's technically happening, because GRUB jumps to a decompression routine that extracts the real kernel), or it could be a type-1 hypervisor which then loads and executes the Linux kernel.



          Put simply, it all has to fit in memory and have enough space left over for things like userspace, or the system can't boot (this is part of why it's so hard to build a Linux system that runs with less than about 64M of RAM these days). The same can be said about every other UNIX system I know of (SVR4, BSD, Solaris, IRIX, Ultrix, Xenix, etc). It's just too much of a pain to handle swapping of memory in kernel-space for it to be worth implementing.






          share|improve this answer





















          • could you explain where virtual memory and the MMU comes into all this then?
            – Engineer999
            Dec 19 '18 at 21:58










          • The kernel itself provides all the abstractions for virtual memory, both those used internally and those for userspace. GRUB intentionally doesn't use virtual memory (because it would have to stick around in the background to keep providing it, which is not what a bootloader is for), and a lot of the early startup code in the kernel doesn't either because there are somethings that really do just need to be done before setting up virtual memory.
            – Austin Hemmelgarn
            Dec 20 '18 at 12:38














          0












          0








          0






          It's more accurate to say that the bootloader loads the entirety of what it's told to load as the kernel into memory. it doesn't really have to be the kernel itself, it could be a second-stage bootloader (and in most cases, this is actually what's technically happening, because GRUB jumps to a decompression routine that extracts the real kernel), or it could be a type-1 hypervisor which then loads and executes the Linux kernel.



          Put simply, it all has to fit in memory and have enough space left over for things like userspace, or the system can't boot (this is part of why it's so hard to build a Linux system that runs with less than about 64M of RAM these days). The same can be said about every other UNIX system I know of (SVR4, BSD, Solaris, IRIX, Ultrix, Xenix, etc). It's just too much of a pain to handle swapping of memory in kernel-space for it to be worth implementing.






          share|improve this answer












          It's more accurate to say that the bootloader loads the entirety of what it's told to load as the kernel into memory. it doesn't really have to be the kernel itself, it could be a second-stage bootloader (and in most cases, this is actually what's technically happening, because GRUB jumps to a decompression routine that extracts the real kernel), or it could be a type-1 hypervisor which then loads and executes the Linux kernel.



          Put simply, it all has to fit in memory and have enough space left over for things like userspace, or the system can't boot (this is part of why it's so hard to build a Linux system that runs with less than about 64M of RAM these days). The same can be said about every other UNIX system I know of (SVR4, BSD, Solaris, IRIX, Ultrix, Xenix, etc). It's just too much of a pain to handle swapping of memory in kernel-space for it to be worth implementing.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 19 '18 at 20:27









          Austin Hemmelgarn

          5,99111016




          5,99111016












          • could you explain where virtual memory and the MMU comes into all this then?
            – Engineer999
            Dec 19 '18 at 21:58










          • The kernel itself provides all the abstractions for virtual memory, both those used internally and those for userspace. GRUB intentionally doesn't use virtual memory (because it would have to stick around in the background to keep providing it, which is not what a bootloader is for), and a lot of the early startup code in the kernel doesn't either because there are somethings that really do just need to be done before setting up virtual memory.
            – Austin Hemmelgarn
            Dec 20 '18 at 12:38


















          • could you explain where virtual memory and the MMU comes into all this then?
            – Engineer999
            Dec 19 '18 at 21:58










          • The kernel itself provides all the abstractions for virtual memory, both those used internally and those for userspace. GRUB intentionally doesn't use virtual memory (because it would have to stick around in the background to keep providing it, which is not what a bootloader is for), and a lot of the early startup code in the kernel doesn't either because there are somethings that really do just need to be done before setting up virtual memory.
            – Austin Hemmelgarn
            Dec 20 '18 at 12:38
















          could you explain where virtual memory and the MMU comes into all this then?
          – Engineer999
          Dec 19 '18 at 21:58




          could you explain where virtual memory and the MMU comes into all this then?
          – Engineer999
          Dec 19 '18 at 21:58












          The kernel itself provides all the abstractions for virtual memory, both those used internally and those for userspace. GRUB intentionally doesn't use virtual memory (because it would have to stick around in the background to keep providing it, which is not what a bootloader is for), and a lot of the early startup code in the kernel doesn't either because there are somethings that really do just need to be done before setting up virtual memory.
          – Austin Hemmelgarn
          Dec 20 '18 at 12:38




          The kernel itself provides all the abstractions for virtual memory, both those used internally and those for userspace. GRUB intentionally doesn't use virtual memory (because it would have to stick around in the background to keep providing it, which is not what a bootloader is for), and a lot of the early startup code in the kernel doesn't either because there are somethings that really do just need to be done before setting up virtual memory.
          – Austin Hemmelgarn
          Dec 20 '18 at 12:38


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Unix & Linux Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f489787%2fdoes-the-bootloader-load-the-kernel-fully-into-memory%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Morgemoulin

          Scott Moir

          Souastre