LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 07-04-2017, 01:12 PM   #1
Ook
Member
 
Registered: Apr 2004
Location: Hell, Arizona (July - 118 degrees)
Distribution: Slackware 14.2 soon to be Slackware 15
Posts: 699

Rep: Reputation: 131Reputation: 131
Swapfile help - can't create large swap partition


I need some help understanding what I'm doing and seeing:

Slackware 14.2 64 bit.
16GB ram
2TB drive

I'm setting up the system to hibernate. So I'm trying to create a swap file large enough to hold system ram, in my case 20GB just for SNG. This is based on the assumption that I actually do need this much swap space, do I?

I create the partition, set it to type 82. I ran mkswap /dev/sda4, and I see:

Setting up swapspace version 1, size = 4 GiB (4320874496 bytes)

Why is it only using 4GB when the partition is much bigger?

So my questions (yes I googled and otherwise searched and searched and did not find the answer maybe I just missed it?)

To hibernate a system with 16GB ram, do I need a swap partition at least that big?

Why, when I make the partition 20GB, mkswap says the actual partition is only 4GB in size?

How, then, (assuming this is necessary) can I make a 20GB partition a swap file such that the entire partition is used?
 
Old 07-04-2017, 01:57 PM   #2
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
you forgot to show what or how you created this swap file. it might be just your syntax
Code:
userx%slackwhere ⚡ ~ ⚡> sudo fallocate -l 16G /run/media/userx/3TB-External/swapfile 
userx%slackwhere ⚡ ~ ⚡> sudo mkswap /run/media/userx/3TB-External/swapfile
Setting up swapspace version 1, size = 16 GiB (17179865088 bytes)
no label, UUID=773d1c8c-ec35-4ecb-96a0-5edd32ca764b
userx%slackwhere ⚡ ~ ⚡> sudo chmod 0600  /run/media/userx/3TB-External/swapfile
userx%slackwhere ⚡ ~ ⚡> sudo swapon /run/media/userx/3TB-External/swapfile 


userx%slackwhere ⚡ ~ ⚡> cat /proc/swaps
Filename                                Type            Size    Used    Priority
/dev/mmcblk0p1                          partition       15158268        0       -1
/run/media/userx/3TB-External/swapfile  file            16777212        0       -2

Last edited by BW-userx; 07-04-2017 at 01:58 PM.
 
2 members found this post helpful.
Old 07-04-2017, 02:07 PM   #3
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 16,292

Rep: Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322
Read man mkswap.
 
Old 07-04-2017, 02:46 PM   #4
Ook
Member
 
Registered: Apr 2004
Location: Hell, Arizona (July - 118 degrees)
Distribution: Slackware 14.2 soon to be Slackware 15
Posts: 699

Original Poster
Rep: Reputation: 131Reputation: 131
Quote:
Originally Posted by BW-userx View Post
you forgot to show what or how you created this swap file. it might be just your syntax
Code:
userx%slackwhere ⚡ ~ ⚡> sudo fallocate -l 16G /run/media/userx/3TB-External/swapfile 
userx%slackwhere ⚡ ~ ⚡> sudo mkswap /run/media/userx/3TB-External/swapfile
Setting up swapspace version 1, size = 16 GiB (17179865088 bytes)
no label, UUID=773d1c8c-ec35-4ecb-96a0-5edd32ca764b
userx%slackwhere ⚡ ~ ⚡> sudo chmod 0600  /run/media/userx/3TB-External/swapfile
userx%slackwhere ⚡ ~ ⚡> sudo swapon /run/media/userx/3TB-External/swapfile 


userx%slackwhere ⚡ ~ ⚡> cat /proc/swaps
Filename                                Type            Size    Used    Priority
/dev/mmcblk0p1                          partition       15158268        0       -1
/run/media/userx/3TB-External/swapfile  file            16777212        0       -2
Sorry for lack of details. This is what I did.

1) use cfdisk to create 20GB partition, type 82
2) mkswap /dev/sda4

That is all - just those two steps. That is where I see "Setting up swapspace version 1, size = 4 GiB"

At that point I stopped because I can't (yet) figure out how to make the swapspace bigger.
 
Old 07-04-2017, 02:51 PM   #5
Ook
Member
 
Registered: Apr 2004
Location: Hell, Arizona (July - 118 degrees)
Distribution: Slackware 14.2 soon to be Slackware 15
Posts: 699

Original Poster
Rep: Reputation: 131Reputation: 131
Quote:
Originally Posted by business_kid View Post
Read man mkswap.
Interesting enough, the size option, which man mkswap insists is superfluous, actually seems to work. There must be some default that sets it at 4GB, but I was able to use the size option to force it bigger. Go figure....

From man: "mkswap will use the entire partition or file if it is omitted".

This appears to not be true. If I omit the size, it does not use the entire partition, it only uses 4GB of a 20GB partition.

Last edited by Ook; 07-04-2017 at 03:02 PM.
 
Old 07-04-2017, 02:58 PM   #6
volkerdi
Slackware Maintainer
 
Registered: Dec 2002
Location: Minnesota
Distribution: Slackware! :-)
Posts: 2,504

Rep: Reputation: 8461Reputation: 8461Reputation: 8461Reputation: 8461Reputation: 8461Reputation: 8461Reputation: 8461Reputation: 8461Reputation: 8461Reputation: 8461Reputation: 8461
Formatting as ext4 might not be a bad idea... only to see if you get a 20GB ext4 volume, or if something else is going on.

I have a 16GB swap partition here, so I know that mkswap should be able to handle that (no extra options were needed... made mine just like you have attempted to).
 
1 members found this post helpful.
Old 07-04-2017, 03:01 PM   #7
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
I always bump up he size I want because it usually gets set smaller when using
16GB =~ 15.3GB so I'll just tell it something like 16.5GB and take that extra if I get any. When using cfdisk btw.
 
1 members found this post helpful.
Old 07-04-2017, 03:18 PM   #8
Ook
Member
 
Registered: Apr 2004
Location: Hell, Arizona (July - 118 degrees)
Distribution: Slackware 14.2 soon to be Slackware 15
Posts: 699

Original Poster
Rep: Reputation: 131Reputation: 131
Thank you everyone.

For reasons unknown to me, I use fdisk instead of cfdisk to delete and recreate the partition. And then it worked, it used the entire 20GB. I really have not the slightest clue why. Are there known issues with cfdisk vs fdisk? Or is the phase of the moon sort of thing? Or maybe I just did something stupid with cfdisk and really did not have the swap file I had?

So just to see, I repeated my steps, used cfdisk to create the partition. And this time I get:

Setting up swapspace version 1, size = 20.5 GiB

At which point I realized that this is the Independence Day (In the USA) and I'm sure I can find something better to do than bang my head against the keyboard on a nice day like this trying to create a swap file that now happily works as advertised. It is a balmy 107F (42 C) outside (Phoenix, AZ, USA - 107 is nice considering it was 121 last week), and my swimming pool is calling my name. Maybe the BBQ grill is also clamoring for my attention.
 
3 members found this post helpful.
Old 07-04-2017, 03:26 PM   #9
Ook
Member
 
Registered: Apr 2004
Location: Hell, Arizona (July - 118 degrees)
Distribution: Slackware 14.2 soon to be Slackware 15
Posts: 699

Original Poster
Rep: Reputation: 131Reputation: 131
My last post seems to have vanished...maybe i stupidly forgot to click "Post Quick Reply"....

So I used fdisk to create the partition instead of cfdisk, and when I did mkswap worked as expected, it used the entire partition. Wtf. Idk. Time to go outside and swim in the pool and BBQ dead animals...
 
Old 07-04-2017, 03:28 PM   #10
perbh
Member
 
Registered: May 2008
Location: Republic of Texas
Posts: 393

Rep: Reputation: 81
You did say it was sda4, didn't you? Since you were using 'fdisk' I will presume you have the old 'dos' disk-partitions in which case remember there are only 3 primary partitions available and sda4 should be an extended partition which spans the remainder of the disk. maybe (since it not clear from your post), it should've been sda5 ??

Of course, you can also use the 4th partition for whatever you want, but then you can't have any more

Last edited by perbh; 07-04-2017 at 03:31 PM.
 
1 members found this post helpful.
Old 07-04-2017, 03:28 PM   #11
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
that's a capital idea -- dead animals taste better cooked.
 
1 members found this post helpful.
Old 07-04-2017, 03:39 PM   #12
Ook
Member
 
Registered: Apr 2004
Location: Hell, Arizona (July - 118 degrees)
Distribution: Slackware 14.2 soon to be Slackware 15
Posts: 699

Original Poster
Rep: Reputation: 131Reputation: 131
Quote:
Originally Posted by perbh View Post
You did say it was sda4, didn't you? Since you were using 'fdisk' I will presume you have the old 'dos' disk-partitions in which case remember there are only 3 primary partitions available and sda4 should be an extended partition which spans the remainder of the disk. maybe (since it not clear from your post), it should've been sda5 ??

Of course, you can also use the 4th partition for whatever you want, but then you can't have any more
In this case that is OK, I only need the four. But on this topic - fdisk -l shows:

Disk /dev/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x05305af2

Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 125831167 125829120 60G 83 Linux
/dev/sda2 125831168 251660287 125829120 60G 83 Linux
/dev/sda3 251660288 1910507519 1658847232 791G 83 Linux
/dev/sda4 1910507520 1953525167 43017648 20.5G 82 Linux swap

Are there better ways than the old 'dos' disk-partitions? The reason I did it that way is because that's how I've done it for ummmmm way too many years...
 
Old 07-04-2017, 03:43 PM   #13
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
Code:
GPT also allows for a nearly unlimited number of partitions. Again, the limit
here will be your operating system—Windows allows up to 128 partitions on a GPT 
drive, and you don't have to create an extended partition to make them work. On 
an MBR disk, the partitioning and boot data is stored in one place.
if you're using more partitions than MBR allows.

I've LVM maybe something to look into as well. I do not use that, I still use MBR because I do not slice up my HDD that many times.

Code:
Device     Boot     Start       End   Sectors   Size Id Type
/dev/sda1  *         2048   1026047   1024000   500M  7 HPFS/NTFS/exFAT
/dev/sda2         1028160 204902463 203874304  97.2G  7 HPFS/NTFS/exFAT
/dev/sda3       204906496 205828095    921600   450M 27 Hidden NTFS WinRE
/dev/sda4       205828096 488397167 282569072 134.8G  5 Extended
/dev/sda5       205830144 249968639  44138496    21G 83 Linux
/dev/sda6       249970688 303507455  53536768  25.5G 83 Linux
/dev/sda7       303509504 488396799 184887296  88.2G 83 Linux
well maybe I do

Last edited by BW-userx; 07-04-2017 at 03:46 PM.
 
1 members found this post helpful.
Old 07-04-2017, 04:11 PM   #14
clavisound
LQ Newbie
 
Registered: Apr 2011
Posts: 15

Rep: Reputation: 1
Quote:
Originally Posted by Ook View Post
To hibernate a system with 16GB ram, do I need a swap partition at least that big?
To be safe yes plus the video card memory. In reality if you don't use all that memory (RAM + GPU RAM) it swaps only the used memory with compression.

I suppose the kernel flushes caches e.t.c, but I don't examined that, just a guess.

Code:
Before Hibernation
bash-4.3$ free
              total        used        free      shared  buff/cache   available
Mem:        6029464     1146492     2536188       82888     2346784     4497060
Swap:       4186108           0     4186108

After Hibernation buffers / caches are half and 10% memory less is used. The image to swap was 2GiB instead of 3GiB. (used + buff/cache)
bash-4.3$ free
              total        used        free      shared  buff/cache   available
Mem:        6029464     1025128     3867864       72112     1136472     4630012
Swap:       4186108           0     4186108
 
1 members found this post helpful.
Old 07-04-2017, 09:57 PM   #15
bassmadrigal
LQ Guru
 
Registered: Nov 2003
Location: West Jordan, UT, USA
Distribution: Slackware
Posts: 8,792

Rep: Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656
Quote:
Originally Posted by Ook View Post
Are there better ways than the old 'dos' disk-partitions? The reason I did it that way is because that's how I've done it for ummmmm way too many years...
What you refer to as dos disk-partitions is actually called MBR partitions (Master Boot Record). This is what allows a max of 4 primary partitions (or 3 primary with an extended partition that allows many more logical partitions). This is an old system that has since been superseded by GPT partitions (GPT stands for GUID Partition Tables, and GUID stands for Global Unique IDentifier -- gotta love acronyms within acronyms).

GPT removes the requirement of no more than 4 primary partitions. It also provides a unique identifier (part of the GUID in the GPT) for each partition, which allows for easier referencing of partitions (although, the kernel added support for kinda unique identifiers for MBR partitions later). GPT partitions are required for UEFI support and is part of the UEFI standard (which is what is replacing BIOS on systems). While UEFI requires GPT, the reverse is not the same. GPT can be used with "legacy" BIOS systems. GPT also supports drives larger than 2TB (although, supposedly MBR will support drives larger than 2TB if you use 4K sectors). In addition, GPT has partition tables backed up at various locations on the drive, so if one part become corrupted, you'll likely be able to recover using another part. I believe MBR only has one place it stores the table.

Overall, other than partitioning, you'll likely notice no difference between the two. I have a mix of GPT and MBR on my desktop, MBR for 2TB and under drives and GPT for any over that. But with any new drives, I'll probably switch to GPT for all future partitioning, because that is going to be the only option soon (plus, almost all my drives are larger than 2TB... my only newer one that isn't is my NVMe drive, but that will be a boot drive, and I'm considering using UEFI, which requires GPT).

There is also LVM that BW-userx mentioned. This is a much more advanced version of the extended partition with logical partitions. It allows easy resizing and moving of partitions, snapshots, and it allows partitions to span across multiple disks. Many people find it easier to encrypt with LVM, although, that isn't a requirement. Unless you have an LVM aware bootloader (according to the Arch Wiki, GRUB is the only bootloader that supports LVM booting), you will need a separate /boot/ partition on an MBR or GPT partitioned disk.
 
1 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Raspberry Pi swapfile or swap partition Duglas Linux - Embedded & Single-board computer 10 10-24-2015 08:23 AM
Possibility to create swap partition if extended partition is out of space? bhavisavla Linux - Newbie 1 09-12-2011 06:39 AM
How to create a partition for swap from existing partition g4ur4v Linux - Newbie 3 08-16-2011 04:06 PM
Need to create a swap partition dotancohen Linux - General 4 07-30-2005 12:39 PM
Create swap partition? mikeshn Linux - General 6 11-28-2002 02:42 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 02:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration