Creative Swap Setup – External USB Stick as Swap Disk on Persistent Live Ubuntu

dhubs

Active Member
Joined
Nov 5, 2024
Messages
135
Reaction score
68
Credits
2,225
Hey all,:)

This might sound a bit unusual (or even a "bad idea" in the SSD wear sense), but hear me out:

I’ve got an old Core2 Duo laptop with 4 GB RAM that my wife uses. She runs a damned old Ubuntu system (guess its so damned old and based on the archaic 12.04 [do not kill me for t his fact)) - its all served from a persistent 16 GB USB 2.0 flash drive.
the details i have to mention here: No internal drive is used — partly for simplicity (my wife loves the simple things), partly for saving money. It runs decently for years and years, but as you can imagine, things get tight with RAM under heavier loads.

So i need to do some changes now. And here i am.

Now here's my thought: I’ve got an old 4 GB USB stick lying around. I'd like to use that specifically as a swap device. That way, swap doesn’t eat up the main USB’s limited write cycles and performance. Yes, I know flash memory and swap don’t mix ideally, but it’s a short-term solution and I’m okay sacrificing that old stick in the name of science.

So the challenge:

Use the 4GB USB stick as a swap partition or file

Automatically activate it on boot (from the main persistent live USB)

All without touching the internal HDD

Anyone done something similar? Got pointers for setting this up reliably via fstab, rc.local, or even udev rules (since device names might jump around)?

I figure this could be a fun experiment or useful for someone else booting live systems with constrained RAM.

Appreciate any input!

Cheers - and have a great day - :cool:
 
Last edited:


@dhubs :-

She runs Ubuntu 12.04 from a persistent 16 GB USB 2.0 flash drive.

Crikey. You ARE aware that 'Precise Pangolin' went EOL around a decade ago, I take it? I do hope your missus doesn't go online with the thing..... o_O

Anyways....

I guess you could say I do summat similar. I have two drives in my HP desktop rig; a 1TB Crucial MX500 SSD, and a Seagate Barracuda 3TB HDD.

The Crucial houses all my Puppies, and all the 'portable' software apps I use. The Seagate is used for all my Puppy 'stuff ' & dev work, along with my media library.

It's a well-known fact that you really shouldn't set-up swap - whether a partition OR a swap-file - on an SSD. So, in my case the main 'swap' partition is set-up on the secondary 'data' drive.....which is the Seagate.

It auto-mounts at boot.....and Puppy finds it and automatically uses it as & when necessary.

(Technically speaking, with 32GB RAM I don't really need swap.....but it gets used when I suspend each night, 'cos this is where the HP saves the contents of RAM. The swap partition is 64GB in size - yah, it sounds like overkill, I know - but this is down to the fact that the HP insists on saving the entire contents of RAM, regardless of whether it's all being used or not! And I'm simply following the old 'rule-of-thumb', which states your swap partition should be twice the size of your RAM.

It's not like I don't have the space to spare....)
hat-tip6.gif


One of our senior Puppians put together a wee utility to make udev-rules easy-to-use for creating 'permanent' mount-points for specific drives (usually USB drives, because as you're no doubt aware, these won't always get mounted in the same place at boot). I would 'share', but because it's highly 'Puppy-specifc' I doubt it would work for you.....especially with the way mainstream distros like to account for & list every package used on a system.

It's only a bunch of scripts, when all's said & done...but to answer your question in a nutshell, yes; it's definitely 'do-able'. You create your swap-file or swap partition wherever you like, then set it to auto-mount at boot. It'll find it alright.

(shrug...)


Mike. ;)
 
Last edited:
my opinion is that this feels more like a "just because you can doesnt mean you should" situation. but hey, lets break it down:

so, something that old is probably using usb2.0 ports, thats ~35mb/second on a good day. that's really slow for swap. if the wife is in no hurry then it's not a big deal, but that'd be a deal breaker for me. https://wiki.archlinux.org/title/Swap <-- some documentation related to swap

you totally can do this - from my understanding you'd just edit fstab and then hopefully the usb flash drives never get moved to different usb ports since that'd cause problems. I use external storage drives for the data I care about, and I just set up fstab so the drives automount at boot --> https://wiki.archlinux.org/title/Fstab - I never change which ports my external storage connects to, so it works for me.

personally, I'd recommend getting a mid-range mini desktop for the wife - ~$300 or less for pretty decent modern hardware.
 
Simple solution...add more Ram or if it's a very old computer...get a newer one...problem solved.
1744866321516.gif
 
Hey MikeWalsh & theLegionWithin dear Mike W0BTU and bob446

thanks for chiming in, really appreciate all your insights.

btw: this is so great - i love this forum so much.. :)


@MikeWalsh: Haha, yeah, I do know Precise Pangolin has long since wandered off into the EOL sunset — but it’s been surprisingly stable for this specific use-case. My wife mostly uses it offline or for really light browsing, and she loves the no-maintenance, no-distraction experience. It's one of those “if it ain’t broke...” scenarios — and trust me, I've tried offering upgrades.

I really like your note about swap on a secondary drive. While obviously not ideal on flash memory, my thought here is to sacrifice this old 4GB stick as a kind of poor-man's swap partition — just to offload pressure from the main persistent USB stick and give the system a bit more breathing room. This isn't about perfection — just about squeezing some extra usefulness out of junk drawer hardware.

Also, I might look into udev rules for consistent mounting — even if your script is Puppy-specific, it might give me some hints. If you're ever in the mood to share it or point to the logic, I'd definitely peek!

@theLegionWithin: 100% agree with the “just because you can…” angle — this is definitely more of a "let's see if it works without exploding" type project. I'm under no illusion that USB2 swap is fast — but for light use (and because she rarely runs anything RAM-heavy), even 20–30MB/s might help reduce the occasional slowdowns. Think of it more like a buffer to prevent crashes than a performance solution.


Also yeah, fstab is where I’m headed, probably with UUID to avoid mount issues if ports change. That Arch wiki is gold, thanks for linking it!

TL;DR:
  • Not really a production-ready setup — just trying to extend usefulness of an old rig .... hehe
  • Will set up swap on an old 4GB stick via fstab (with UUIDs for consistency) - according to your tipps.
  • Accepting the risk for the benefit of offloading main USB's wear - hmmm.
  • Definitely open to modernizing eventually, but this is a fun hack for now

Thanks again for all the helpful feedback you four guys — and hey, I’ll share results once it’s set up, just in case someone else wants to try this swap-on-junkstick idea.


Your ideas and thoughts are great and help alot here. :)

keep up this awesome place - the great forum for linux..


greetings and happy easter to all of you and your families ;)
 
Last edited:


Follow Linux.org

Staff online

Members online


Top