How to create swap file on ext4

6,817

It's possible the problem is because it's in the /mnt directory or it could be a security issue world readable swap isn't great. Try this tutorial and see if you have better results.

http://www.cyberciti.biz/faq/linux-add-a-swap-file-howto/

Share:
6,817

Related videos on Youtube

Levan
Author by

Levan

Updated on September 18, 2022

Comments

  • Levan
    Levan over 1 year

    My friend whats to create a 4GB swap file on his ext4 file system. because he is using a chromebook acer c7 the way he installed he did not have a chance to specify swap partition

    and now he want to create a swap file on his file system.

    This is the guide he is following

    http://ubuntuforums.org/showthread.php?t=1618220&p=10098565#post10098565

    First you have to create a 2GiB file, for example in /mnt:

    sudo dd if=/dev/zero of=/mnt/swap bs=1M count=2048
    

    Then format the file to swap:

    sudo mkswap /mnt/swap
    

    Add the swap file to the system:

    sudo swapon /mnt/swap
    

    Check it out, i.e.:

    free -m
    

    Edit the fstab file:

    gksu gedit /etc/fstab
    

    and add this line at the end of the file:

    /mnt/swap  none  swap  sw
    

    Save the file and exit. That's all.

    This is what he is getting

    enter image description here

    user@chrubuntu:~$ sudo swapon /mnt/swap
    swapon: /mnt/swap: swapon failed: Invalid argument
    

    and his fstab looks like this

    fstab

    any way to fix this ??

    One more thing he is using ubuntu 14.04 and it is not a fresh install

    Thank you for your time

    • jkt123
      jkt123 almost 10 years
      Does he get the error you've mentioned both times he tries to run swapon, or just after he's added it to the fstab file?
    • Levan
      Levan almost 10 years
      Thank you for the reply he follows the above guide that i mantioned before this step every thing works Add the swap file to the system: sudo swapon /mnt/swap imgur.com/rFP0gbc
    • Levan
      Levan almost 10 years
      @psusi Thank you for the reply again this is what it say ser@chrubuntu:~$ uname -a Linux chrubuntu 3.4.0 #1 SMP Fri Apr 11 19:07:10 PDT 2014 x86_64 x86_64 x86_64 GNU/Linux user@chrubuntu:~$
    • Levan
      Levan almost 10 years
      @psusi I have a question, what do you think if he manually upgrades to the latest kernel?? will his chrome book still boot or it is too dangerous
    • psusi
      psusi almost 10 years
      I don't know enough about it, but it certainly appears to have a custom, older, kernel, but if you check its config file in /boot, you may find that it was built without CONFIG_SWAP, so doesn't support swap.
    • Levan
      Levan almost 10 years
      @psusi thank you you have been tremendous help, crazy thing is that he can not even upgrade to a newer kernel
  • Levan
    Levan almost 10 years
    Thank you for the reply I will tell him and notify you about the result
  • Levan
    Levan almost 10 years
    Small preamble this is the UUID=c8a5817e-90d3-48f3-976a-8e80de5e6a4b he got this is the command he used sudo swapon -U c8a5817e-90d3-48f3-976a-8e80de5e6a4b and sadly this is what terminal told him swapon cannot find the device
  • Levan
    Levan almost 10 years
    sorry @Elder Geek small mix up this is what he got user@chrubuntu:~$ ls -a /mnt . .. swap user@chrubuntu:~$ I do not understand did not the terminal say that it created a file ??
  • psusi
    psusi almost 10 years
    That's definitely not going to work; uuid recognition only works on partitions, not files.
  • Levan
    Levan almost 10 years
    @psusi any suggestions ??? and thank you fore the reply
  • Elder Geek
    Elder Geek almost 10 years
    @Levan just double-checking