Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
If you want to turn off swap completely, that can be done with command "swapoff". This does not require reboot, but swap will get turned back on after reboot. You can comment out the swap line in /etc/fstab if you do not want swap to get turned on after reboots.
To reduce swap partition, you will have to use parted/fdisk.
If you want to turn off swap completely, that can be done with command "swapoff". This does not require reboot, but swap will get turned back on after reboot. You can comment out the swap line in /etc/fstab if you do not want swap to get turned on after reboots.
I dont want to turn it off complete I want to reduce the amount of swap being used for example from 90Gig to 6Gig. Without the system freezing up on me.
I think Ubuntu now creates/uses a swap file instead of a swap partition. Without freezing depends on what you have running on your system but you should be able to turn swap off (swapoff command). With little effort you can easily create a swap file and switch from default to a new swap file without rebooting.
If using a swap partition you can use mkswap specifying the size without having to first resize but take note of the warning. If you specify the wrong size you could overwrite data in the adjoining partition which could lead to data lose.
From the mkswap man page
Quote:
The size parameter is superfluous but retained for backwards compatibility. (It specifies
the desired size of the swap area in 1024-byte blocks. mkswap will use the entire
partition or file if it is omitted. Specifying it is unwise – a typo may destroy your
disk.)
" Is there a way to do this on reboot with a script?" The simple answer is yes. I've never seen anyone create one but there are some super coders at LQ that could create one I suppose. Might be some web article on making one.
In general any command or set of commands can almost always be placed in a script. Once script may be used upon completion of some task to start a new task or write changes or whatnot.
Having too much swap isn't usually a terrible thing.
I've never tried this but I suppose one could create a new swap (file or partition), mount it then change swappiness to force new to basically take control then remove/reduce old one. I think there is some flush swap command that would insure that the old swap is almost or totally empty. Silly swap is an odd deal sometimes. Some bits get put there seemingly no matter how much ram you have.
One could use a live cd to change it or maybe single user mode to fix all of this.
Some distro's have installers or tools to do this task. I get the feeling I have tried this on Opensuse maybe or red hat.
If it were me, I'd boot to a Live CD of something (likely GPartED) and shrink the swap partition--after backing stuff up to external media, because, when you muck about with partitions, you never can predict . . . .
In these days of multi-GBs of RAM, 90GB is a bit high for a single user machine (I can't speak to a server in a thin-client environment--that's a whole nother horse). I've got 16GB RAM in this box and 4 GB swap, and swap is hardly ever touched.
Distribution: Mainly Devuan, antiX, & Void, with Tiny Core, Fatdog, & BSD thrown in.
Posts: 5,487
Rep:
Backing up your data is always sensible before messing with filesystems.
What you need to do is first unmount your present swap partition, using
Code:
sudo swapoff /dev?
(enter your partition number).
Then using fdisk or similar program, alter the size of your swap partition on your disk, write it out to disk, then run
Code:
sudo mkswap /dev?
(your partition number), then
Code:
sudo swapon /dev?
(your partition number).
That should have you back up & running with your newly sized swap partition.
The free space created can then be merged into a present partition, (possible risk of data loss), or, easiest option, just create a new partition, & put a file system on it, which can then be added to your /etc/fstab file.
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,800
Rep:
Quote:
Originally Posted by frankbell
I've got 16GB RAM in this box and 4 GB swap, and swap is hardly ever touched.
May depend a lot on what you're doing on the system. Here I have 8GB of physical memory and 4X that in swap space and swap can still get hammered at times. Not frequently but I'd rather have the swap space than receive an "uh uh... not enough memory" message. Disk space is cheap nowadays.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.