LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 07-24-2015, 12:58 AM   #1
jimz
LQ Newbie
 
Registered: Jul 2015
Distribution: Debian 8
Posts: 2

Rep: Reputation: Disabled
Question Managing Swap Partitions on a Multiboot Debian Linux PC


I am a Linux newbie. I've wanted to learn Linux for years, so after retiring recently, I decided that a good and useful learning project would be to build a Linux server to be used as a backup for the data on my Windows PCs. I built a new PC and installed Debian 7 / KDE. Although the initial stages of this went well, I realized that I needed to develop a lot more Linux expertise before trusting it, so I built another PC and this is where I've run into an issue (actually, the first issue that I've not been able to resolve with simple google queries).

I used Gparted to partition a 1T GPT hard drive as follows:

SDA1 - 200M for UEFI (ESP, Boot)
SDA2 - 150G EXT4 for Debian 8.1 Linux-1 - to be configured for VM using KVM
SDA3 - 50G Swap (to be used by Linux-1)
SDA4 - 190G EXT4 for Linux-VM1 - to be used as a Linux booted in a VM
SDA5 - 190G EXT4 for Linux-VM2 - to be used as a Linux booted in a VM
SDA6 - 190G EXT4 for Linux-VM3 - to be used as a Linux booted in a VM
SDA7 - 190G EXT4 for Linux-2 - to be used as a natively booted Linux
SDA8 - 10G Swap for Linux-2
SDA9 - 10G Swap for Linux-VM1
SDA10 - 10G Swap for Linux-VM2
SDA11 - 10G Swap for Linux-VM3

I installed Debian 8.1 as my Linux-1 in SDA2 from a Debian 8.1 Live USB stick. The install went fine but once booted, I noticed that all of the created Swap partitions were active on the system and not just the planned SDA3 partition. I've since learned that I needed to tell the installer to ignore the other swap partitions. That said, I removed (commented out) the SDA8,9,10,11 statements from /etc/fstab. To my surprise, this had no effect. After a reboot, all of the swap partitions were again active. I then issued swapoff on the unwanted partitions and used Gparted to change the filesystems from SWAP to EXT4 on those partitions. Upon reboot, only the SDA3 swap partition was active as desired.

Next, I installed Linux 8.1 as my Linux-2 system, again from a Live USB, this time to the SDA7 partition. I directed the installer to not use the SDA3 swap partition, and directed it to set the SDA8 partition as swap. Once the installation was complete and the new system booted, to my surprise, both the SDA3 and SDA8 swap partitions were in use. Linux-2's /etc/fstab only included a line for the SDA8 swap partition, but again Linux activated all swap partitions (two at this time).

So, my question is how do I configure Linux-1 to use only the SDA3 swap partition and Linux-2 to use only the SDA8 swap partition? Simply updating /etc/fstab doesn't appear to be effective. In booting each system, all partitions marked as swap are always activated.

At some point, I intend to install Debian 8.1 three more times, each in a separate VM under the Linux-1 KVM. Again, I had intended to provide a single unique swap partition to each system. This would make for the five swap partitions on the hard drive. Hopefully, the solution to my problem will address these other three systems also.

Thanks
 
Old 07-24-2015, 03:08 AM   #2
Dman58
Member
 
Registered: Nov 2010
Location: The Danger Zone
Distribution: Slackware & everything else in a VM
Posts: 294

Rep: Reputation: 31
Hi and welcome to Linux. My first suggestion to you would be to keep things a little simpler. Instead of having all those SWAP partitions just make 1 that they can all share. Depending on how much system RAM you have installed you may never even use the SWAP and those sizes were way too big in my opinion. Multiple distributions of Linux or even the same distro in multiple occurrences can share SWAP no problem. Next if you plan on using multiple Virtual Machines why not just make a large single partition for them to share?

These are only just suggestions but I believe it will help your understanding if you tone it down a little bit and start smaller. Partitioning and being new to the scenario can have a lot of interesting consequences.
 
Old 07-24-2015, 05:44 AM   #3
fatmac
LQ Guru
 
Registered: Sep 2011
Location: Upper Hale, Surrey/Hants Border, UK
Distribution: Mainly Devuan, antiX, & Void, with Tiny Core, Fatdog, & BSD thrown in.
Posts: 5,491

Rep: Reputation: Disabled
Welcome aboard.

I suggest you learn to walk before trying to run.

How much do you understand about Linux(?); looking at your post, not a lot.

An OS will use all available swap space as default.

I don't understand why you want to install so many copies of an OS, especially as you are just starting to learn.

Quote:
.....build a Linux server to be used as a backup for the data on my Windows PCs.
For this you would only need one copy of a Linux distro.
 
Old 07-24-2015, 06:22 AM   #4
Head_on_a_Stick
Senior Member
 
Registered: Dec 2014
Location: London, England
Distribution: Debian stable (and OpenBSD-current)
Posts: 1,187

Rep: Reputation: 285Reputation: 285Reputation: 285
Just to note: if your distributions are using systemd to boot up, it will mount any swap partitions automatically.

As mentioned, just use one swap partition and share it between all your systems.

If they are using systemd [1] then remove the swap line from /etc/fstab and let it automount (the partition will be reformatted if you install more distributions and this will cause errors on boot if you leave the same lines in your fstab).

10GiB of swap is excessive -- you only need slightly more swap than RAM and that would only be for hibernating; if you have more than 2GiB of RAM you will probably never actually use your swap at all unless you run VMs or compile large programs from source.

[1] Check for systemd by running this command:
Code:
cat /proc/1/comm
If you're running systemd then it will output "systemd"; if you're not then it will say "init"
 
Old 07-24-2015, 07:59 AM   #5
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
I suspect you are trying to provide for virtual machines (the "swap for Linux VM-1").

By default the linux startup will use every swap partition available.

If you are planning for virtual machines, allocate it during the creation and installation of the virtual machine.

The advantage is that it is easier to give different VMs different sizes depending on what the VM is for. This also lets you use the space for something else if it isn't occupied by swap...

Linux doesn't actually need a swap partition except when you are planning on a large server where you expect more applications to use lots of memory (more than available physical memory), or are planning on a laptop where you want to put the system to sleep instead of shutting down the system (sleep copies system memory to swap, then stops), usually done when you close the laptop (the close switch signals the sleep, and only takes a few seconds). Shutdown can take a while as it has to terminate processes (that may also save state)... and reboot doesn't restart those applications. Startup is also faster after the sleep as it just copies memory from swap, and resumes. All processes are still running as if nothing had happened - except the time jump caused during the sleep.

Last edited by jpollard; 07-24-2015 at 08:01 AM.
 
Old 07-24-2015, 01:42 PM   #6
jimz
LQ Newbie
 
Registered: Jul 2015
Distribution: Debian 8
Posts: 2

Original Poster
Rep: Reputation: Disabled
Wow, I'm impressed with the number and speed of responses. Thanks to all of you.

I should have included a little more background in my initial post as it may have saved some of you some effort. I did spend considerable time reading a number of articles, wiki's, Debian installation doc, etc about Linux swap. I do understand that with a 4G PC (that's what I built) I would most likely not even need swap partitions. This is especially true given that these systems are for learning and not a production environment - no stress is expected (although at some point along my learning path, I'll likely impose stress just to see how the system reacts). I also realize that the swap partitions I created (50G and 10g in size) were excessive. Again, the PC is much more than needed and the 1T disk will never be consumed, so I used easy to remember partition sizes since I don't have disk space constraints.

What I've learned from the responses above is (1) Linux with systemd will locate and activate all defined swap partitions and (2) mutliple instances of Linux can share a swap partition, I assume, as long as only one instance is running at a time. This would be the case if I were to boot Linux-1 or Linux-2. Only one system would be running. But, in the case where I want to boot Linux-1 running as a KVM and then boot one or more guest Linux systems in VMs under Linux-1's control, I will have at least two (Linux-1 and Linux-VM1) Linux systems running concurrently and they will need to have dedicated swap partitions. So, my question still stands - is there a way to configure Linux to use a specific swap partition and not all that exist on the disk?

BTW, I realize that I've bitten off a bigger chunk than one would expect for a newbie given my planned multiple Linux system PC. My experience (guess I need to expose this) is as an IBM mainframe assembler programmer and system programmer working with multiple OSes including VS1, SVS, MVS, and VM starting back in 1973. In my experience, you tend to learn a lot more by stretching. Eventually I'll get back to completing my Linux backup server. For now, I want to experiment and the reason for wanting to run a KVM Linux is to allow me to easily try new things with Linux in a VM and then once understood, throw it away and try something else. What I learn in the VM Linux systems I'll then apply to the Linux-2 base system and eventually to the separate Linux backup server.

I certainly undestand the strategy of starting simple. I did that with my server Linux system. That's what led me to build this second PC and install multiple Linux systems. I clearly have a lot to learn and appreciate all of the information available on the net and through forums like this. Thanks again.
 
Old 07-24-2015, 06:44 PM   #7
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by jimz View Post
Wow, I'm impressed with the number and speed of responses. Thanks to all of you.

I should have included a little more background in my initial post as it may have saved some of you some effort. I did spend considerable time reading a number of articles, wiki's, Debian installation doc, etc about Linux swap. I do understand that with a 4G PC (that's what I built) I would most likely not even need swap partitions. This is especially true given that these systems are for learning and not a production environment - no stress is expected (although at some point along my learning path, I'll likely impose stress just to see how the system reacts). I also realize that the swap partitions I created (50G and 10g in size) were excessive. Again, the PC is much more than needed and the 1T disk will never be consumed, so I used easy to remember partition sizes since I don't have disk space constraints.

What I've learned from the responses above is (1) Linux with systemd will locate and activate all defined swap partitions and(2) mutliple instances of Linux can share a swap partition, I assume, as long as only one instance is running at a time. This would be the case if I were to boot Linux-1 or Linux-2. Only one system would be running. But, in the case where I want to boot Linux-1 running as a KVM and then boot one or more guest Linux systems in VMs under Linux-1's control, I will have at least two (Linux-1 and Linux-VM1) Linux systems running concurrently and they will need to have dedicated swap partitions. So, my question still stands - is there a way to configure Linux to use a specific swap partition and not all that exist on the disk?
As I said, it is easier to define a swap within the virtual disk than it is to import one from external partition. That WOULD be faster, but you don't need fast.
Quote:

BTW, I realize that I've bitten off a bigger chunk than one would expect for a newbie given my planned multiple Linux system PC. My experience (guess I need to expose this) is as an IBM mainframe assembler programmer and system programmer working with multiple OSes including VS1, SVS, MVS, and VM starting back in 1973. In my experience, you tend to learn a lot more by stretching. Eventually I'll get back to completing my Linux backup server. For now, I want to experiment and the reason for wanting to run a KVM Linux is to allow me to easily try new things with Linux in a VM and then once understood, throw it away and try something else. What I learn in the VM Linux systems I'll then apply to the Linux-2 base system and eventually to the separate Linux backup server.

I certainly undestand the strategy of starting simple. I did that with my server Linux system. That's what led me to build this second PC and install multiple Linux systems. I clearly have a lot to learn and appreciate all of the information available on the net and through forums like this. Thanks again.
The general topic of what you are doing is "dual booting linux", which can also apply to also having partitions set aside for other systems such as BSD or Windows even.
 
Old 07-24-2015, 07:35 PM   #8
273
LQ Addict
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,680

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
I would suggest that, if you wish to play with virtual machines a lot, it is probably worth doubling your RAM. Probably not necessary but if you think that something like Ubuntu with a few applications may take 1-2GB of RAM if you have that as your base system and something similar as a guest you could start hitting swap. Don't get me wrong, this laptop has 6GB of RAM and I've run a Debian VM under Windows 8.1 and a couple of Linux VMs under Debian and not had any problems but if you start playing around with RAM 4GB seems a little small -- I tend to guess about 1-2GB as "normal working RAM" for a Linux machine so you've possibly "only got 2 instances worth" there.
 
  


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
LXer: Managing Swap in Linux: Devices, Files, and Swap Priorities LXer Syndicated Linux News 0 01-15-2014 05:31 PM
managing vfat partitions from linux bldrco Linux - Software 2 02-05-2010 01:23 PM
Linux Partitions, Multiboot Kryptos Linux - Newbie 2 11-12-2007 11:26 PM
multiboot system swap part ? Mandle Linux - Newbie 2 04-28-2006 11:22 AM
swap partitions on multiboot system gargamel Linux - General 5 05-23-2004 06:28 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:57 PM.

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