FAA Using LABEL together with <file> args to swapon?

Post here if you are a new Porteus member and you're looking for some help.
mysterylectricity
White ninja
White ninja
Posts: 17
Joined: 18 Feb 2015, 07:52
Distribution: 3.1
Location: San Francisco

FAA Using LABEL together with <file> args to swapon?

Post#1 by mysterylectricity » 26 Mar 2015, 05:19

Hi,

I like using LABEL in my changes= cheatcode.

I'd like to use the disk label in a swapon command, but I don't have a dedicated swap partition. Therefore I would like to refer to swap using both a LABEL designation and a file name.

I've tried the following and included the resulting error messages:

root@porteus:/# swapon -L PorteusBase1/porteus.swap
swapon: cannot find the device for PorteusBase1/porteus.swap

root@porteus:/# swapon -L PorteusBase1 porteus.swap
swapon: /dev/sdc1: read swap header failed: Invalid argument
swapon: porteus.swap: stat failed: No such file or directory

root@porteus:/dev/disk/by-label# swapon /dev/disk/by-label/PorteusBase1/porteus.swap
swapon: /dev/disk/by-label/PorteusBase1/porteus.swap: stat failed: Not a directory

I can't find any examples of swapon that do what I want, or even an indication that it's possible.

But it certainly should be.

Is my syntax bad, does swapon need fixing, or is Porteus pulling a fast one on me?

Oh: I don't want to swap within my save.dat if only because it's encrypted. I'd imagine the performance penalty would be pretty high.

Repartitioning would be an obvious workaround, but we all hate workarounds, right?

-jeff

Anecdote follows:

The biggest mistake I ever made as a UNIX consultant was to start swapping on the traditional swap partition designation of a disk that was entirely mounted as a file system, ie: the drive was mounted as /dev/sda1 and I swapped on /dev/sda3, as I recall partition 3 was typically swap (20 years ago) whereas partition 1 represented the whole disk (part 2 was typically root, part 4 was var or what have you).

The system happily started swapping straight (raw) into a chunk of the files system. Hilarity ensued.

So naturally I'm a little paranoid about swap. These days I think swapon is more careful not to do that kind of thing, and I think the practice of defining overlapping partitions is deprecated. Heck, I don't think we even had swapon back then: just mounted with type swap in fstab.

User avatar
francois
Contributor
Contributor
Posts: 6434
Joined: 28 Dec 2010, 14:25
Distribution: xfce plank porteus nemesis
Location: Le printemps, le printemps, le printemps... ... l'hiver s'essoufle.

Re: Using LABEL together with <file> args to swapon?

Post#2 by francois » 26 Mar 2015, 20:57

Welcome to porteus mysterylectricity. :)

From what I understand you can change or assign label or uuid of a specific swap partition with gparted? I hope this helps. If not just explain why. One of our devs should come by.
Prendre son temps, profiter de celui qui passe.

mysterylectricity
White ninja
White ninja
Posts: 17
Joined: 18 Feb 2015, 07:52
Distribution: 3.1
Location: San Francisco

Re: Using LABEL together with <file> args to swapon?

Post#3 by mysterylectricity » 27 Mar 2015, 22:11

@francois:

Ooops, let me clarify.

I'm successfully using LABEL as part of the from= and changes= cheatcodes in my porteus.cfg file ie:

>root@porteus:/# cat ./mnt/sdb1/boot/syslinux/porteus.cfg |grep PorteusBase1|head -n 1
APPEND initrd=initrd.xz from=LABEL:PorteusBase1 changes=LABEL:PorteusBase1/porteussave.dat noaotologin zram=2% ramsize=33% timezone=US/Pacific volume=10%

I want to reference a swapfile (as opposed to a swap partition) using LABEL as an argument to swapon.

I am confident I can use LABEL with swapon if I I create a new partition, and in the long run this is probably the way to go. But it's not on
schedule: I've ping-ponged Porteus from one thumb drive to another 3 or 4 times already this week. I haven't poked around to see if there is a way to shrink an ext4 file system to make room for a new partition.

I know swapon can take a file as an argument.

So it would seem trivial to do something like: swapon -L PorteusBase1/porteus.swap

But it doesn't work. Swapon doesn't use the same naming convention,

I'm thinking I can achieve what I want with a loop mount. I'll work on that.

Meanwhile here's some actual console dialog to illustrate the problem:

Code: Select all

>root@porteus:/# cat ./mnt/sdb1/boot/syslinux/porteus.cfg |grep PorteusBase1|head -n 1
APPEND initrd=initrd.xz from=LABEL:PorteusBase1 changes=LABEL:PorteusBase1/porteussave.dat noaotologin zram=2% ramsize=33% timezone=US/Pacific volume=10%

>root@porteus:/# blkid |grep orteus
/dev/sdb1: LABEL="PorteusBase1" UUID="6979fbff-7159-4bee-91df-18095e6f4203" TYPE="ext4" 
/mnt/sdb1/porteussave.dat: UUID="e27b191f-c493-43c0-a4b6-337458217323" TYPE="crypto_LUKS" 

>root@porteus:/# free -m
             total       used       free     shared    buffers     cached
Mem:          3752       1546       2206          0        126        741
-/+ buffers/cache:        678       3074
Swap:           75          0         75

>root@porteus:/# mkfileswap /mnt/sdb1/porteus.swap 1000
Creating empty file /mnt/sdb1/porteus.swap, size 1000 MB
Formating the file with Linux Swap filesystem...
Activating swap...

>root@porteus:/# free -m
             total       used       free     shared    buffers     cached
Mem:          3752       2580       1172          0        127       1746
-/+ buffers/cache:        707       3045
Swap:         1075          0       1075

>root@porteus:/# swapoff /mnt/sdb1/porteus.swap

>root@porteus:/# swapon -L PorteusBase1
swapon: /dev/sdb1: read swap header failed: Invalid argument

>root@porteus:/# swapon -L PorteuBase1/porteus.swap
swapon: cannot find the device for PorteuBase1/porteus.swap

>root@porteus:/# swapon -L PorteusBase1 porteus.swap
swapon: /dev/sdb1: read swap header failed: Invalid argument
swapon: porteus.swap: stat failed: No such file or directory

mysterylectricity
White ninja
White ninja
Posts: 17
Joined: 18 Feb 2015, 07:52
Distribution: 3.1
Location: San Francisco

Re: Using LABEL together with <file> args to swapon?

Post#4 by mysterylectricity » 28 Mar 2015, 01:49

Hmmm, I'm not finding the right args for loop either. It seems to suffer from the same limitations as swapon.

mloop fails to recognize the file (as type swap).

Looks like my best bet for now is to study the mloop script. It's full of living examples that do almost the very thing I want to do. I was never very handy with scripts but not bad with clever command lines so I should be able to pull off a minor genetic modification of mloop with a copy, paste, and maybe changing 20 characters.

It seems like a nice feature for mloop to have in the long run... unless I'm missing something...

I'll post code back when I'm done but if someone beat me to it I wouldn't be offended :)

Take care this weekend!

-Jeff

mysterylectricity
White ninja
White ninja
Posts: 17
Joined: 18 Feb 2015, 07:52
Distribution: 3.1
Location: San Francisco

Re: FAA Using LABEL together with <file> args to swapon?

Post#5 by mysterylectricity » 26 Apr 2015, 08:54

I haven't had much time to look at this. I suspect the solution may be to drop all references by LABEL and focus on reference by UUID.

I forget if I tried that yet.

If not I'll have a good look at mloop as I promised. Eventually.

For now I'm focusing on using Porteus in production.

My workaround for the issue and a few other little snags is to have removed the hard drives from all
of my laptops.

Now, my boot flash is always sda. No remapping or worrying about trashing local hard drives.... for now.

-jeff

Post Reply