partitioning - I have a Linux swap partition but how do I set it up permanently?

06
2014-04
  • Xian

    I have a laptop with 2GB RAM and not the funds to buy more RAM. Ever since I installed 64-BIT Mint (MATE desktop), I am using more than 1GB RAM compared to between 170 - 500MB when I was in 32-BIT Cinnamon.

    I have created a swap partition and now I want to set it permanently so that it is activated upon startup/reboot. Can someone please help me with the commands to use in ROOT terminal for this?

    Thanks!

    PS: Below is a list of fdisk -l, showing drive partitions

    255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x000814ae
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1   *        2048      718847      358400    7  HPFS/NTFS/exFAT
    /dev/sda2          718848   571549695   285415424    7  HPFS/NTFS/exFAT
    /dev/sda3       571549696   781264895   104857600    7  HPFS/NTFS/exFAT
    /dev/sda4       781264896   976771071    97753088    f  W95 Ext'd (LBA)
    /dev/sda5       781266944   966531071    92632064    7  HPFS/NTFS/exFAT
    /dev/sda6       966533120   976771071     5118976   82  Linux swap / Solaris
    
    Disk /dev/sdb: 8100 MB, 8100249600 bytes
    204 heads, 51 sectors/track, 1520 cylinders, total 15820800 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x000d308d
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1            2048    15820799     7909376   83  Linux
    

    Here is my fstab file contents:

    # /etc/fstab: static file system information.
    #
    # Use 'blkid' to print the universally unique identifier for a
    # device; this may be used with UUID= as a more robust way to
    # name devices that works even if disks are added and removed. 
    # See fstab(5).
    #
    # <file system>          unt point>   <type> <options>    <dump>  <pass>
    /host/linuxmint/disks/root.disk /     ext4   loop,errors=remount-ro 0 1
    /host/linuxmint/disks/swap.disk none  swap   loop,sw                0 0
    
    # a swapfile is not a swap partition, so no using swapon|off from here on
    #use  dphys-swapfile swap[on|off]  for that
    
  • Answers
  • Hennes

    Start your favourite editor and open /etc/fstab. Since this is a system wide configuration file you will either need to do this as root (or any other account with uid 0) or you need to start the editor with extra rights (sudo).
    Find an empty line and add /dev/sda6 swap swap defaults 0 0.

    Save, then test with 'swapon -a`.


    Explanation:

    /etc/fstab contains information about which partitions to mounts and which filesystems those partitions are formatted with. Most of these will get automatically added when you boot. (Exception: noauto option).

    The swap partition is treated as any other partition, except that is has no mount point.

    This is how a typical fstab file might look:

    # file system  mount-point  type     options    dump     fsck_order
    #
    /dev/sda1      /            ext2      defaults            0   0
    /dev/sda2      /usr         ext2      defaults            0   1
    /dev/sda3      /usr/local   ext2      defaults            0   1
    /dev/sda4      /home        ext2      defaults, noatime   0   1
    
    # Disk 2
    # 
    /dev/sdb1      /tmp         ext2      defaults, noatime   0   0
    /dev/sdb2      swap         swap      defaults            0   0
    

    After you made en entry in fstab you can test this by turning on all standard swap locations with the command swapon -a.


  • Related Question

    ubuntu - How change linux swap disk priority permanently
  • tony_sid

    I'm using two swap disks. Changing the order they are in in /etc/fstab and using "pri" in fstab doesn't have any effect.

    This is what it looks like /etc/fstab

    #swap on other disk
    UUID=90a1550c-84d6-4bde-8bc1-7c15292980f1 none            swap    sw,pri=-1              0       0
    
    #swap on same disk
    UUID=13b70e65-f1c3-4728-920f-9e92467d1df0 none            swap    sw,pri=-2              0       0
    

    This is the output of swapon -s

    Filename            Type        Size       Used   Priority
    /dev/sda1           partition   2562328 176    -1
    /dev/sdb1           partition   2562328 0      -2
    

    Its opposite of what it is in fstab, and changes to fstab have no effect.


  • Related Answers
  • eigenein

    Actually, the order doesn't affect priority. However, the pri setting is what you need. Could you add some lines of /etc/fstab that don't work for you?