Unexpected output from lvextend when increasing the swap size after enlarging the swap volume
- Anmelden oder Registrieren um Kommentare zu schreiben
I am stuck. I am in the process of increasing the swap partition. I am following this tutorial: https://trisquel.info/en/wiki/how-resize-trisquels-default-encrypted-partitions
On this step (from the tutorial):
$ sudo lvextend -l +100%FREE /dev/vgtrisquel/swap_1
Size of logical volume vgtrisquel/swap_1 changed from <7.86 GiB (2012 extents) to 7.88 GiB (2018 extents).
I have this output instead:
# lvextend -l +100%FREE /dev/x220-vg/swap_1
New size (4084 extents) matches existing size (4084 extents).
I do not understand lvextend and this process well enough to figure out what to do next. I am stuck on a live system.
Any help would be appreciated.
For information, below are all the commands I ran before (I increased /root).
trisquel@trisquel:~$ df -h
Filesystem Size Used Avail Use% Mounted on
tmpfs 369M 6.1M 363M 2% /run
/dev/sdb1 2.9G 2.9G 0 100% /cdrom
/cow 1.8G 20M 1.8G 2% /
/dev/disk/by-label/writable 26G 3.8M 24G 1% /var/log
tmpfs 1.8G 0 1.8G 0% /dev/shm
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 1.8G 8.0K 1.8G 1% /tmp
tmpfs 369M 160K 369M 1% /run/user/999
# Enable LVM encrypted partition (I am using the same title as in the tutorial for clarity)
trisquel@trisquel:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
loop0 7:0 0 2.8G 1 loop /rofs
sda 8:0 0 931.5G 0 disk
├─sda1 8:1 0 487M 0 part
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 931G 0 part
sdb 8:16 1 28.7G 0 disk
├─sdb1 8:17 1 2.9G 0 part /cdrom
├─sdb2 8:18 1 1M 0 part
└─sdb3 8:19 1 25.8G 0 part /var/log
trisquel@trisquel:~$ sudo cryptsetup open /dev/sda5 mydisk
Enter passphrase for /dev/sda5:
trisquel@trisquel:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
loop0 7:0 0 2.8G 1 loop /rofs
sda 8:0 0 931.5G 0 disk
├─sda1 8:1 0 487M 0 part
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 931G 0 part
└─mydisk 253:0 0 931G 0 crypt
├─x220--vg-root 253:1 0 27.9G 0 lvm
├─x220--vg-swap_1 253:2 0 976M 0 lvm
└─x220--vg-home 253:3 0 902.1G 0 lvm
sdb 8:16 1 28.7G 0 disk
├─sdb1 8:17 1 2.9G 0 part /cdrom
├─sdb2 8:18 1 1M 0 part
└─sdb3 8:19 1 25.8G 0 part /var/log
$ sudo e2fsck -f /dev/x220-vg/home
e2fsck 1.46.5 (30-Dec-2021)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/x220-vg/home: 20/59121664 files (0.0% non-contiguous), 3993318/236486656 blocks
trisquel@trisquel:~$ sudo resize2fs -p /dev/x220-vg/home 870g
resize2fs 1.46.5 (30-Dec-2021)
Resizing the filesystem on /dev/x220-vg/home to 228065280 (4k) blocks.
Begin pass 3 (max = 7217)
Scanning inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/x220-vg/home is now 228065280 (4k) blocks long.
trisquel@trisquel:~$ sudo e2fsck -f /dev/x220-vg/home
e2fsck 1.46.5 (30-Dec-2021)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/x220-vg/home: 20/57016320 files (0.0% non-contiguous), 3861144/228065280 blocks
trisquel@trisquel:~$ sudo -i
root@trisquel:~# lvreduce -L -32G /dev/x220-vg/home
WARNING: Reducing active logical volume to 870.12 GiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce x220-vg/home? [y/n]: y
Size of logical volume x220-vg/home changed from 902.12 GiB (230944 extents) to 870.12 GiB (222752 extents).
Logical volume x220-vg/home successfully resized.
root@trisquel:~# lvextend -L -32G /dev/x220-vg/root
Size may not be negative.
Invalid argument for --size: -32G
Error during parsing of command line.
root@trisquel:~# lvextend -L +32G /dev/x220-vg/root
Size of logical volume x220-vg/root changed from <27.94 GiB (7152 extents) to <59.94 GiB (15344 extents).
Logical volume x220-vg/root successfully resized.
root@trisquel:~# e2fsck -f /dev/x220-vg/root
e2fsck 1.46.5 (30-Dec-2021)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/x220-vg/root: 88727/1831424 files (0.1% non-contiguous), 629226/7323648 blocks
root@trisquel:~# resize2fs /dev/x220-vg/root
resize2fs 1.46.5 (30-Dec-2021)
Resizing the filesystem on /dev/x220-vg/root to 15712256 (4k) blocks.
The filesystem on /dev/x220-vg/root is now 15712256 (4k) blocks long.
root@trisquel:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
loop0 7:0 0 2.8G 1 loop /rofs
sda 8:0 0 931.5G 0 disk
├─sda1 8:1 0 487M 0 part
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 931G 0 part
└─mydisk 253:0 0 931G 0 crypt
├─x220--vg-root 253:1 0 59.9G 0 lvm
├─x220--vg-swap_1 253:2 0 976M 0 lvm
└─x220--vg-home 253:3 0 870.1G 0 lvm
sdb 8:16 1 28.7G 0 disk
├─sdb1 8:17 1 2.9G 0 part /cdrom
├─sdb2 8:18 1 1M 0 part
└─sdb3 8:19 1 25.8G 0 part /var/log
root@trisquel:~# sudo e2fsck -f /dev/x220-vg/home
e2fsck 1.46.5 (30-Dec-2021)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/x220-vg/home: 20/57016320 files (0.0% non-contiguous), 3861144/228065280 blocks
root@trisquel:~# sudo resize2fs -p /dev/x220-vg/home 855g
resize2fs 1.46.5 (30-Dec-2021)
Resizing the filesystem on /dev/x220-vg/home to 224133120 (4k) blocks.
Begin pass 3 (max = 6960)
Scanning inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/x220-vg/home is now 224133120 (4k) blocks long.
root@trisquel:~# lvreduce -L -15G /dev/x220-vg/home
WARNING: Reducing active logical volume to 855.12 GiB.
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce x220-vg/home? [y/n]: y
Size of logical volume x220-vg/home changed from 870.12 GiB (222752 extents) to 855.12 GiB (218912 extents).
Logical volume x220-vg/home successfully resized.
root@trisquel:~# lvextend -L +15G /dev/x220-vg/swap_1
Size of logical volume x220-vg/swap_1 changed from 976.00 MiB (244 extents) to 15.95 GiB (4084 extents).
Logical volume x220-vg/swap_1 successfully resized.
root@trisquel:~# lvextend -l +100%FREE /dev/x220-vg/swap_1
New size (4084 extents) matches existing size (4084 extents).
# lvextend -l +100%FREE /dev/x220-vg/swap_1
New size (4084 extents) matches existing size (4084 extents).
My understanding (just reading that) is that your disk(s) is/are entirely partitioned. As a consequence, the extension taking 100% of the (nonexistent) free space is no extension: the new size equals the existing size.
That is also the feeling I had when I read the output of this command. From what we see of the output of 'lvextend', I assumed that the the space exists - and indeed the output of lsblk shows that the swap partition was extended to 16GB (from less than 1GB).
root@trisquel:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
loop0 7:0 0 2.8G 1 loop /rofs
sda 8:0 0 931.5G 0 disk
├─sda1 8:1 0 487M 0 part
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 931G 0 part
└─mydisk 253:0 0 931G 0 crypt
├─x220--vg-root 253:1 0 59.9G 0 lvm
├─x220--vg-swap_1 253:2 0 16G 0 lvm
└─x220--vg-home 253:3 0 855.1G 0 lvm
sdb 8:16 1 28.7G 0 disk
├─sdb1 8:17 1 2.9G 0 part /cdrom
├─sdb2 8:18 1 1M 0 part
└─sdb3 8:19 1 25.8G 0 part /var/log
However, I also understand that once the space is created, it needs be "set up" (man page) by running mkswap. At least that's what I understood from reading the manual and around the web. mkswap's man page also says that "After creating the swap area, you need the swapon command to start using it".
I went ahead and ran these (as per the tutorial also):
trisquel@trisquel:~$ sudo mkswap /dev/x220-vg/swap_1
mkswap: /dev/x220-vg/swap_1: warning: wiping old swap signature.
Setting up swapspace version 1, size = 16 GiB (17129533440 bytes)
no label, UUID=35452c9a-ec01-424a-9e57-fd0640444cfe
That is where I am at after I ran mkswap:
trisquel@trisquel:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
loop0 7:0 0 2.8G 1 loop /rofs
sda 8:0 0 931.5G 0 disk
├─sda1 8:1 0 487M 0 part
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 931G 0 part
└─mydisk 253:0 0 931G 0 crypt
├─x220--vg-root 253:1 0 59.9G 0 lvm
├─x220--vg-swap_1 253:2 0 16G 0 lvm
└─x220--vg-home 253:3 0 855.1G 0 lvm
sdb 8:16 1 28.7G 0 disk
├─sdb1 8:17 1 2.9G 0 part /cdrom
├─sdb2 8:18 1 1M 0 part
└─sdb3 8:19 1 25.8G 0 part /var/log
trisquel@trisquel:~$ free
total used free shared buff/cache available
Mem: 3774272 1354028 730084 441744 1690160 1741316
Swap: 0 0 0
I am posting the outputs of 'lsblk' and 'free' to show that there is no entry for x220--vg-swap in the column MOUNTPOINTS, and that the row 'Swap' shown by the command 'free' is still 0.
Now I run swapon:
trisquel@trisquel:~$ sudo swapon /dev/x220-vg/swap_1
trisquel@trisquel:~$ swapon
NAME TYPE SIZE USED PRIO
/dev/dm-2 partition 16G 0B -2
I can now see the swap allocation in 'free':
trisquel@trisquel:~$ free -m
total used free shared buff/cache available
Mem: 3685 1270 1349 421 1065 1761
Swap: 16335 0 16335
However, when I run the next command of the tutorial, 'vgchange' tells me that:
trisquel@trisquel:~$ sudo vgchange -an
Logical volume x220-vg/swap_1 in use.
Can't deactivate volume group "x220-vg" with 1 open logical volume(s)
Expected outcome is:
$ sudo vgchange -an
0 logical volume(s) in volume group "vgtrisquel" now active
Since 'vgchange' tells me device is used I check lsblk.
root@trisquel:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
loop0 7:0 0 2.8G 1 loop /rofs
sda 8:0 0 931.5G 0 disk
├─sda1 8:1 0 487M 0 part
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 931G 0 part
└─mydisk 253:0 0 931G 0 crypt
├─x220--vg-root 253:1 0 59.9G 0 lvm
├─x220--vg-swap_1 253:2 0 16G 0 lvm [SWAP]
└─x220--vg-home 253:3 0 855.1G 0 lvm
sdb 8:16 1 28.7G 0 disk
├─sdb1 8:17 1 2.9G 0 part /cdrom
├─sdb2 8:18 1 1M 0 part
└─sdb3 8:19 1 25.8G 0 part /var/log
which shows that x220-vg/swap_1 is mounted; but I am not surprised to see this since on the man page we can read that swapon "enables devices and files for paging and swapping". The tutorial also goes along the same line:
and now we mount it on the live session,
$ sudo swapon /dev/vgtrisquel/swap_1
however, in the tutorial, the output of lsblk is different. The entry in the 'MOUNTPOINTS' column for 'vgtrisquel-swap_1' is empty, and 'vschange' outputs that no logical device is 'active'.
PS I read about swapoff on the man page of swapon, but I am reluctant to try because I somehow read online that it "removes" the swap allocation, but maybe I am misunderstanding this.
Any help would be welcomed.
lsblk shows that the swap partition was extended to 16GB (from less than 1GB).
Yes, 'lvextend -L +15G /dev/x220-vg/swap_1' did it. I tend to believe 'lvextend -l +100%FREE /dev/vgtrisquel/swap_1' alone is enough and the manual should be edited. However, I cannot confirm it: I do not use LVM.
and now we mount it on the live session
I think that should be edited too: swap is "enabled" and not "mounted" (what would imply a possible access through the file hierarchy).
I read about swapoff on the man page of swapon, but I am reluctant to try because I somehow read online that it "removes" the swap allocation, but maybe I am misunderstanding this.
swapoff just disables the swap, if possible (in particular if there is enough free RAM to take its content back). swapon can then enable it again.
# swapoff /dev/dm-2
made it possible for me to get 'sudo vgchange -an' to output '0 logical volume(s) in volume group "x220-vg" now active'.
I don't know if that was the proper way to do it.
Before this, the output of 'sudo vgchange -an' was: 'Can't deactivate volume group "x220-vg" with 1 open logical volume(s)'.
'lvdisplay' showed 'x220--vg-swap_1' as '# open 2'.
and 'lvremove /dev/x220-vg/swap_1' printed 'Logical volume x220-vg/swap_1 in use.'
Conversations around the web about troubleshooting why the logical volume was in use led me to try all the following commands (below) to find out if or which process was using the logical volume, in vain. In my case, no outputs of these commands showed that me that the lv was in use. I am posting the commands below, in case this can help someone. Explanations of the commands can be found on man pages.
root@trisquel:~# dmsetup info -c
Name Maj Min Stat Open Targ Event UUID
mydisk 253 0 L--w 3 1 0 CRYPT-LUKS2-redacted-mydisk
x220--vg-home 253 3 L--w 0 1 0 LVM-redacted
x220--vg-root 253 1 L--w 0 2 0 LVM-redacted
x220--vg-swap_1 253 2 L--w 2 2 0 LVM-redacted
root@trisquel:~# lsof | grep "253,3"
root@trisquel:~# cat /proc/mounts | grep sda5
I was able to run the last command of the tutorial and re-encrypt the disk.
However, the command free now outputs no swap:
$ free -m
total used free shared buff/cache available
Mem: 3685 1530 639 731 1516 1179
Swap: 0 0 0
But if I reopen the encrypted LVM, the size of the partitions looks as expected, after increasing the size of root and swap:
root@trisquel:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
loop0 7:0 0 2.8G 1 loop /rofs
sda 8:0 0 931.5G 0 disk
├─sda1 8:1 0 487M 0 part
├─sda2 8:2 0 1K 0 part
└─sda5 8:5 0 931G 0 part
└─mydisk 253:0 0 931G 0 crypt
├─x220--vg-root 253:1 0 59.9G 0 lvm
├─x220--vg-swap_1 253:2 0 16G 0 lvm
└─x220--vg-home 253:3 0 855.1G 0 lvm
sdb 8:16 1 28.7G 0 disk
├─sdb1 8:17 1 2.9G 0 part /cdrom
├─sdb2 8:18 1 1M 0 part
└─sdb3 8:19 1 25.8G 0 part /var/log
I'll check what the command free outputs again when I run the installed system, if that makes any difference (maybe I need to run swapon?).
I don't know if running swapoff had unwanted effect.
As I wrote:
swapoff just disables the swap, if possible (in particular if there is enough free RAM to take its content back). swapon can then enable it again.
To have it enabled at init, I believe a line should be added to /etc/fstab:
$ echo '/dev/x220-vg/swap_1 none swap sw 0 0' | sudo tee -a /etc/fstab
Do not forget the -a option or you will lose the current content of /etc/fstab! If the init then enables the swap, it is one more step to add to the manual.
Remark: the second field of fstab specifies the mount point and 'man fstab' clearly says: "For swap partitions, this field should be specified as `none'". Here is a confirmation that the manual should not talk about "mounting" the swap.
Thanks for following up. I don't know if I need to run the command you suggest: after I left the live system, I booted from the installed system, and that's where I am at right now:
~$ cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# systemd generates mount units based on this file, see systemd.mount(5).
# Please run 'systemctl daemon-reload' after making changes here.
#
#
/dev/mapper/x220--vg-root / ext4 errors=remount-ro 0 1
# /boot was on /dev/sdb1 during installation
UUID=redacted /boot ext2 defaults 0 2
/dev/mapper/x220--vg-home /home ext4 defaults 0 2
/dev/mapper/x220--vg-swap_1 none swap sw 0 0
~$ swapon --show
NAME TYPE SIZE USED PRIO
/dev/dm-2 partition 16G 768K -2
~$ free -h
total used free shared buff/cache available
Mem: 3.6Gi 923Mi 252Mi 220Mi 2.4Gi 2.2Gi
Swap: 15Gi 0.0Ki 15Gi
I understand from these outputs that the swap partition is active, but please, let me know if you see something.
PS I plan to add 4GB of RAM, hence the swap partition of 16GB. I followed some of Red Hat's suggestions I found on their website (i.e. twice the amount of RAM if RAM is between 2 and 8GB and if allowing for hibernation).
/dev/mapper/x220--vg-swap_1 none swap sw 0 0
That is the line you already have to enable the swap at init. If it works, then there is no problem, is there?
For a desktop system, I would say that as much swap as RAM is enough: you would not bear using a system that swaps for so long that it would fill a whole 8-GB partition: you would close applications before. You would not hibernate a system that swaps either.
Last year, I wrote a manual about hibernation: https://trisquel.info/en/wiki/hibernation-aka-suspend-disk. Prospero and Avron improved it.
That is the line you already have to enable the swap at init. If it works, then there is no problem, is there?
I am good as far as I understand. But for the wiki itself, I don't know if the last steps should be modified yet, or whether we should wait to see if someone else reproduces the issue I got. Which is, to sum up all of the above, that I was not able to complete the step of the wiki about deactivating the volume group (that is the command '$ sudo vgchange -an'), until I ran '$ swapoff /dev/dm-2'. Then I was able to deactivate the volume group, and finally close/encrypt the disk.
PS I got '/dev/dm-2' from the output of '$ swapon --show'.
For a desktop system, I would say that as much swap as RAM is enough: you would not bear using a system that swaps for so long that it would fill a whole 8-GB partition: you would close applications before. You would not hibernate a system that swaps either.
Thank you for adding this, and posting a link to the guide. I missed it.
[1] https://trisquel.info/en/wiki/how-resize-trisquels-default-encrypted-partitions
The swapon was only for confirmation purposes as an encrypted swap partition is not loaded on a LiveISO session.
I suppose I added that step once I was back on the non-live session, but yeah, active luks partitions are required to be closed to unmount the volumen, as stated on the first section of the guide.
I'll try to recreate that VM and confirm that step on later on the week.
Regards o/
Thanks for writing that guide.
To me, the things to fix would be:
- remove the duplicate command to enlarge swap
- remove the swapon, it really has no use
Besides, the vm I have from the latest aramo installer, but without LVM and ciphering, uses UUID in the fstab. If it is the same when LVM and ciphering are used, the line for swap in fstab needs update. I will make another vm to check.
Sorry that I did not have time to do it so far, but I also wanted to do some simplification as with --resizefs, the lvresize command does the file system check, resizes the file system and the logical volume, which is more convenient than 3 separate commands. I'll try doing that soon.
Please feel free to take the lead to improve it and fix, clean redundant options, I'll appreciate some help on it.