Managing Swap Partitions on a Multiboot Debian Linux PC
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.
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.
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.
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"
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.
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.
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.
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,680
Rep:
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.