How to create a real RAM disk that reserves memory?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












I've been shortly using the following on Linux Debian Jessie to create a "RAM disk":



mount -o size=1G -t tmpfs none /mnt/tmpfs


But I was told it doesn't reserve memory, which I didn't know.



I would like a solution, which does reserve memory.










share|improve this question



























    up vote
    2
    down vote

    favorite












    I've been shortly using the following on Linux Debian Jessie to create a "RAM disk":



    mount -o size=1G -t tmpfs none /mnt/tmpfs


    But I was told it doesn't reserve memory, which I didn't know.



    I would like a solution, which does reserve memory.










    share|improve this question

























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I've been shortly using the following on Linux Debian Jessie to create a "RAM disk":



      mount -o size=1G -t tmpfs none /mnt/tmpfs


      But I was told it doesn't reserve memory, which I didn't know.



      I would like a solution, which does reserve memory.










      share|improve this question















      I've been shortly using the following on Linux Debian Jessie to create a "RAM disk":



      mount -o size=1G -t tmpfs none /mnt/tmpfs


      But I was told it doesn't reserve memory, which I didn't know.



      I would like a solution, which does reserve memory.







      tmpfs ramdisk






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 15 at 8:59

























      asked Oct 26 '15 at 23:23









      Vlastimil

      6,8411149124




      6,8411149124




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          Add it to your /etc/fstab:



          none /mnt/tmpfs tmpfs defaults,size=1g,mode=1777 0 0


          You may also need to rebuild your initramfs, e.g.:



          sudo update-initramfs -u -k $(uname -r)


          or, to rebuild the initramfs for all kernels:



          sudo update-initramfs -u -k all


          BTW, tmpfs doesn't reserve any memory - a tmpfs filesystem only uses as much memory as required by the files it contains (and any file/directory overhead).






          share|improve this answer






















          • why do you need to update initramfs?
            – mikeserv
            Oct 27 '15 at 0:20










          • so that the tmpfs is mounted and available very early in the boot process. if that's not required then there's no need to update the initramfs just for that - but apart from taking a little time, there's no harm in doing it. it will get done next time the kernel is updated or something else triggers an update-initramfs
            – cas
            Oct 27 '15 at 0:22











          • how can it be mounted any sooner than /?
            – mikeserv
            Oct 27 '15 at 0:23










          • Note, that there is no need for update-initramfs, consider removing it from your answer for future readers.
            – Vlastimil
            Sep 27 at 22:56

















          up vote
          0
          down vote













          In fact it does not reserve any memory. That behaviour was present when using ramdisks initiated at boot time, but it was removed a long time ago.



          Currently, only the kernel and its modules can allocate a specific RAM region, or reserve an actual RAM area. Other methods will allocate memory which can be swapped to disk.



          My previous answer suggested allocating a file over a tmpfs mount point, which was then mounted as a loopback device. While it works at pre-allocating memory for the purpose of a "ramdisk", its content will be swapped, and the solution will not work if there is any swap enabled.



          Btw, this works at allocating memory because tmpfs only allocates memory as it is required to store the files it contains, which happens when the disk file is created.



          ----------------- Non working solution ------------------------------



          One thing you could do is to create a loopback file with the desired size inside the tmpfs.



          It would be something like this:



          mount -o size=1G -t tmpfs none /mnt/tmpfs
          dd if=/dev/zero of=/mnt/tmpfs/disk
          losetup /dev/loop0 /mnt/tmpfs/disk
          mkfs.ext2 /dev/loop0
          mount /dev/loop0 /mnt/static_ramdisk





          share|improve this answer






















          • use ramfs in place of tmpfs, or use brd. unix.stackexchange.com/questions/66329/… unix.stackexchange.com/questions/433712/…
            – sourcejedi
            Sep 28 at 0:32











          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',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          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%2f238810%2fhow-to-create-a-real-ram-disk-that-reserves-memory%23new-answer', 'question_page');

          );

          Post as a guest






























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          Add it to your /etc/fstab:



          none /mnt/tmpfs tmpfs defaults,size=1g,mode=1777 0 0


          You may also need to rebuild your initramfs, e.g.:



          sudo update-initramfs -u -k $(uname -r)


          or, to rebuild the initramfs for all kernels:



          sudo update-initramfs -u -k all


          BTW, tmpfs doesn't reserve any memory - a tmpfs filesystem only uses as much memory as required by the files it contains (and any file/directory overhead).






          share|improve this answer






















          • why do you need to update initramfs?
            – mikeserv
            Oct 27 '15 at 0:20










          • so that the tmpfs is mounted and available very early in the boot process. if that's not required then there's no need to update the initramfs just for that - but apart from taking a little time, there's no harm in doing it. it will get done next time the kernel is updated or something else triggers an update-initramfs
            – cas
            Oct 27 '15 at 0:22











          • how can it be mounted any sooner than /?
            – mikeserv
            Oct 27 '15 at 0:23










          • Note, that there is no need for update-initramfs, consider removing it from your answer for future readers.
            – Vlastimil
            Sep 27 at 22:56














          up vote
          1
          down vote



          accepted










          Add it to your /etc/fstab:



          none /mnt/tmpfs tmpfs defaults,size=1g,mode=1777 0 0


          You may also need to rebuild your initramfs, e.g.:



          sudo update-initramfs -u -k $(uname -r)


          or, to rebuild the initramfs for all kernels:



          sudo update-initramfs -u -k all


          BTW, tmpfs doesn't reserve any memory - a tmpfs filesystem only uses as much memory as required by the files it contains (and any file/directory overhead).






          share|improve this answer






















          • why do you need to update initramfs?
            – mikeserv
            Oct 27 '15 at 0:20










          • so that the tmpfs is mounted and available very early in the boot process. if that's not required then there's no need to update the initramfs just for that - but apart from taking a little time, there's no harm in doing it. it will get done next time the kernel is updated or something else triggers an update-initramfs
            – cas
            Oct 27 '15 at 0:22











          • how can it be mounted any sooner than /?
            – mikeserv
            Oct 27 '15 at 0:23










          • Note, that there is no need for update-initramfs, consider removing it from your answer for future readers.
            – Vlastimil
            Sep 27 at 22:56












          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          Add it to your /etc/fstab:



          none /mnt/tmpfs tmpfs defaults,size=1g,mode=1777 0 0


          You may also need to rebuild your initramfs, e.g.:



          sudo update-initramfs -u -k $(uname -r)


          or, to rebuild the initramfs for all kernels:



          sudo update-initramfs -u -k all


          BTW, tmpfs doesn't reserve any memory - a tmpfs filesystem only uses as much memory as required by the files it contains (and any file/directory overhead).






          share|improve this answer














          Add it to your /etc/fstab:



          none /mnt/tmpfs tmpfs defaults,size=1g,mode=1777 0 0


          You may also need to rebuild your initramfs, e.g.:



          sudo update-initramfs -u -k $(uname -r)


          or, to rebuild the initramfs for all kernels:



          sudo update-initramfs -u -k all


          BTW, tmpfs doesn't reserve any memory - a tmpfs filesystem only uses as much memory as required by the files it contains (and any file/directory overhead).







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Sep 27 at 23:19









          Vlastimil

          6,8411149124




          6,8411149124










          answered Oct 27 '15 at 0:18









          cas

          38k44495




          38k44495











          • why do you need to update initramfs?
            – mikeserv
            Oct 27 '15 at 0:20










          • so that the tmpfs is mounted and available very early in the boot process. if that's not required then there's no need to update the initramfs just for that - but apart from taking a little time, there's no harm in doing it. it will get done next time the kernel is updated or something else triggers an update-initramfs
            – cas
            Oct 27 '15 at 0:22











          • how can it be mounted any sooner than /?
            – mikeserv
            Oct 27 '15 at 0:23










          • Note, that there is no need for update-initramfs, consider removing it from your answer for future readers.
            – Vlastimil
            Sep 27 at 22:56
















          • why do you need to update initramfs?
            – mikeserv
            Oct 27 '15 at 0:20










          • so that the tmpfs is mounted and available very early in the boot process. if that's not required then there's no need to update the initramfs just for that - but apart from taking a little time, there's no harm in doing it. it will get done next time the kernel is updated or something else triggers an update-initramfs
            – cas
            Oct 27 '15 at 0:22











          • how can it be mounted any sooner than /?
            – mikeserv
            Oct 27 '15 at 0:23










          • Note, that there is no need for update-initramfs, consider removing it from your answer for future readers.
            – Vlastimil
            Sep 27 at 22:56















          why do you need to update initramfs?
          – mikeserv
          Oct 27 '15 at 0:20




          why do you need to update initramfs?
          – mikeserv
          Oct 27 '15 at 0:20












          so that the tmpfs is mounted and available very early in the boot process. if that's not required then there's no need to update the initramfs just for that - but apart from taking a little time, there's no harm in doing it. it will get done next time the kernel is updated or something else triggers an update-initramfs
          – cas
          Oct 27 '15 at 0:22





          so that the tmpfs is mounted and available very early in the boot process. if that's not required then there's no need to update the initramfs just for that - but apart from taking a little time, there's no harm in doing it. it will get done next time the kernel is updated or something else triggers an update-initramfs
          – cas
          Oct 27 '15 at 0:22













          how can it be mounted any sooner than /?
          – mikeserv
          Oct 27 '15 at 0:23




          how can it be mounted any sooner than /?
          – mikeserv
          Oct 27 '15 at 0:23












          Note, that there is no need for update-initramfs, consider removing it from your answer for future readers.
          – Vlastimil
          Sep 27 at 22:56




          Note, that there is no need for update-initramfs, consider removing it from your answer for future readers.
          – Vlastimil
          Sep 27 at 22:56












          up vote
          0
          down vote













          In fact it does not reserve any memory. That behaviour was present when using ramdisks initiated at boot time, but it was removed a long time ago.



          Currently, only the kernel and its modules can allocate a specific RAM region, or reserve an actual RAM area. Other methods will allocate memory which can be swapped to disk.



          My previous answer suggested allocating a file over a tmpfs mount point, which was then mounted as a loopback device. While it works at pre-allocating memory for the purpose of a "ramdisk", its content will be swapped, and the solution will not work if there is any swap enabled.



          Btw, this works at allocating memory because tmpfs only allocates memory as it is required to store the files it contains, which happens when the disk file is created.



          ----------------- Non working solution ------------------------------



          One thing you could do is to create a loopback file with the desired size inside the tmpfs.



          It would be something like this:



          mount -o size=1G -t tmpfs none /mnt/tmpfs
          dd if=/dev/zero of=/mnt/tmpfs/disk
          losetup /dev/loop0 /mnt/tmpfs/disk
          mkfs.ext2 /dev/loop0
          mount /dev/loop0 /mnt/static_ramdisk





          share|improve this answer






















          • use ramfs in place of tmpfs, or use brd. unix.stackexchange.com/questions/66329/… unix.stackexchange.com/questions/433712/…
            – sourcejedi
            Sep 28 at 0:32















          up vote
          0
          down vote













          In fact it does not reserve any memory. That behaviour was present when using ramdisks initiated at boot time, but it was removed a long time ago.



          Currently, only the kernel and its modules can allocate a specific RAM region, or reserve an actual RAM area. Other methods will allocate memory which can be swapped to disk.



          My previous answer suggested allocating a file over a tmpfs mount point, which was then mounted as a loopback device. While it works at pre-allocating memory for the purpose of a "ramdisk", its content will be swapped, and the solution will not work if there is any swap enabled.



          Btw, this works at allocating memory because tmpfs only allocates memory as it is required to store the files it contains, which happens when the disk file is created.



          ----------------- Non working solution ------------------------------



          One thing you could do is to create a loopback file with the desired size inside the tmpfs.



          It would be something like this:



          mount -o size=1G -t tmpfs none /mnt/tmpfs
          dd if=/dev/zero of=/mnt/tmpfs/disk
          losetup /dev/loop0 /mnt/tmpfs/disk
          mkfs.ext2 /dev/loop0
          mount /dev/loop0 /mnt/static_ramdisk





          share|improve this answer






















          • use ramfs in place of tmpfs, or use brd. unix.stackexchange.com/questions/66329/… unix.stackexchange.com/questions/433712/…
            – sourcejedi
            Sep 28 at 0:32













          up vote
          0
          down vote










          up vote
          0
          down vote









          In fact it does not reserve any memory. That behaviour was present when using ramdisks initiated at boot time, but it was removed a long time ago.



          Currently, only the kernel and its modules can allocate a specific RAM region, or reserve an actual RAM area. Other methods will allocate memory which can be swapped to disk.



          My previous answer suggested allocating a file over a tmpfs mount point, which was then mounted as a loopback device. While it works at pre-allocating memory for the purpose of a "ramdisk", its content will be swapped, and the solution will not work if there is any swap enabled.



          Btw, this works at allocating memory because tmpfs only allocates memory as it is required to store the files it contains, which happens when the disk file is created.



          ----------------- Non working solution ------------------------------



          One thing you could do is to create a loopback file with the desired size inside the tmpfs.



          It would be something like this:



          mount -o size=1G -t tmpfs none /mnt/tmpfs
          dd if=/dev/zero of=/mnt/tmpfs/disk
          losetup /dev/loop0 /mnt/tmpfs/disk
          mkfs.ext2 /dev/loop0
          mount /dev/loop0 /mnt/static_ramdisk





          share|improve this answer














          In fact it does not reserve any memory. That behaviour was present when using ramdisks initiated at boot time, but it was removed a long time ago.



          Currently, only the kernel and its modules can allocate a specific RAM region, or reserve an actual RAM area. Other methods will allocate memory which can be swapped to disk.



          My previous answer suggested allocating a file over a tmpfs mount point, which was then mounted as a loopback device. While it works at pre-allocating memory for the purpose of a "ramdisk", its content will be swapped, and the solution will not work if there is any swap enabled.



          Btw, this works at allocating memory because tmpfs only allocates memory as it is required to store the files it contains, which happens when the disk file is created.



          ----------------- Non working solution ------------------------------



          One thing you could do is to create a loopback file with the desired size inside the tmpfs.



          It would be something like this:



          mount -o size=1G -t tmpfs none /mnt/tmpfs
          dd if=/dev/zero of=/mnt/tmpfs/disk
          losetup /dev/loop0 /mnt/tmpfs/disk
          mkfs.ext2 /dev/loop0
          mount /dev/loop0 /mnt/static_ramdisk






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Oct 30 '15 at 15:54

























          answered Oct 27 '15 at 0:02









          OluaJho

          8412




          8412











          • use ramfs in place of tmpfs, or use brd. unix.stackexchange.com/questions/66329/… unix.stackexchange.com/questions/433712/…
            – sourcejedi
            Sep 28 at 0:32

















          • use ramfs in place of tmpfs, or use brd. unix.stackexchange.com/questions/66329/… unix.stackexchange.com/questions/433712/…
            – sourcejedi
            Sep 28 at 0:32
















          use ramfs in place of tmpfs, or use brd. unix.stackexchange.com/questions/66329/… unix.stackexchange.com/questions/433712/…
          – sourcejedi
          Sep 28 at 0:32





          use ramfs in place of tmpfs, or use brd. unix.stackexchange.com/questions/66329/… unix.stackexchange.com/questions/433712/…
          – sourcejedi
          Sep 28 at 0:32


















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f238810%2fhow-to-create-a-real-ram-disk-that-reserves-memory%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Bahrain

          Postfix configuration issue with fips on centos 7; mailgun relay