LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices


Reply
  Search this Thread
Old 09-19-2022, 06:28 AM   #1
cpaulett
LQ Newbie
 
Registered: Jul 2021
Posts: 6

Rep: Reputation: Disabled
Logical volumes +ext4 resizing while mounted


Hi everyone,

the SSD I have on the laptop I'm using right now is formatted like so:

Code:
NAME
sda
├─sda1 [/boot, fat16, 1G]
└─sda2
  └─lvm-system
  ├─lvmSystem-volSwap [swap, 8G]
  ├─lvmSystem-volRoot [/, ext4, 50G]
  └─lvmSystem-volHome [/home, ext4, 421G]
sr0
I would like to get rid of the volSwap logical volume and merge its 8G into volHome. Just to be clear, the result would be:

Code:
NAME
sda
├─sda1 [/boot, fat16, 1G]
└─sda2
  └─lvm-system
  ├─lvmSystem-volRoot [/, ext4, 50G]
  └─lvmSystem-volHome [/home, ext4, 429G]
sr0
I presume the right sequence of commands to merge volSwap into volHome would be:

Code:
# swapoff -a && lvdestroy /dev/lvmSystem/volSwap && lvextend -l +100%FREE /dev/lvmSystem/volHome
Then, I presume I would also have to resize the ext4 partition inside volHome. Since it is ext4, I would go with resize2fs:

Code:
# resize2fs /dev/lvmSystem/volHome
And also, maybe I should remove the swap volume from my fstab (?).
I wrote this topic just want to make sure the sequence I elaborated is correct, and whether or not this can be performed while the laptop is on and the partitions are mounted.

Last edited by cpaulett; 09-19-2022 at 06:29 AM.
 
Old 09-19-2022, 07:37 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,751

Rep: Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929
Why do you want to get rid of swap?

Depending on what distribution you are running and how it is configured swap might be used to hibernate the system.
 
Old 09-19-2022, 07:44 AM   #3
cpaulett
LQ Newbie
 
Registered: Jul 2021
Posts: 6

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
Why do you want to get rid of swap?
I recently switched to the linux-hardened kernel on Arch, and it currently does not support hibernation (see https://bugs.archlinux.org/task/63648). So, those 8G of swap are currently useless as I plan to stick to the Hardened kernel (I plan on re-compiling the hardened kernel to enable hibernation support, but not in the near future).
 
Old 09-19-2022, 07:52 AM   #4
suramya
Member
 
Registered: Jan 2022
Location: Earth
Distribution: Debian
Posts: 249

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by cpaulett View Post
And also, maybe I should remove the swap volume from my fstab (?).
I wrote this topic just want to make sure the sequence I elaborated is correct, and whether or not this can be performed while the laptop is on and the partitions are mounted.
Never resize partitions when they are mounted as it will cause dataloss. You should boot with a LiveCD and do the operations from there. Also ensure that you have a verified backup before making the changes in case things go wrong.
 
Old 09-19-2022, 08:18 AM   #5
cpaulett
LQ Newbie
 
Registered: Jul 2021
Posts: 6

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by suramya View Post
Never resize partitions when they are mounted as it will cause dataloss. You should boot with a LiveCD and do the operations from there. Also ensure that you have a verified backup before making the changes in case things go wrong.
Ok, thank you. Concerning the commands I wrote, are they correct? Or is there something to be changed?
 
Old 09-19-2022, 08:28 AM   #6
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,141

Rep: Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123
Quote:
Originally Posted by suramya View Post
Never resize partitions when they are mounted as it will cause dataloss. You should boot with a LiveCD and do the operations from there. Also ensure that you have a verified backup before making the changes in case things go wrong.
The general sentiment is ok (backup, then play), but the assertion is not. Resizing online with modern filesystems is fine - ext4 included.

lvextend accepts the " -r" parameter to manage the filesystem resize concurrently.
I am not familiar with lvdestroy - lvremove maybe ?.
 
Old 09-19-2022, 08:34 AM   #7
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,751

Rep: Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929Reputation: 5929
I am an advocate for having swap regardless of memory size for just in case use.
8GB is only about 2% of the total linux space.
 
Old 09-19-2022, 08:37 AM   #8
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,783

Rep: Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214
The ext4 filesystem can be safely enlarged while it is mounted. You just cannot shrink it while mounted.

You can enlarge the LV and the filesystem together by including the "--resizefs" ("-r") option in your lvextend command: :
Code:
lvextend -l +100%FREE -r /dev/lvmSystem/volHome
                      ^^
 
Old 09-19-2022, 08:41 AM   #9
cpaulett
LQ Newbie
 
Registered: Jul 2021
Posts: 6

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by rknichols View Post
The ext4 filesystem can be safely enlarged while it is mounted. You just cannot shrink it while mounted.

You can enlarge the LV and the filesystem together by including the "--resizefs" ("-r") option in your lvextend command: :
Code:
lvextend -l +100%FREE -r /dev/lvmSystem/volHome
                      ^^
Didn't know about that! Cool. One less possible source of mistakes. Thanks a lot
 
Old 09-19-2022, 08:45 AM   #10
cpaulett
LQ Newbie
 
Registered: Jul 2021
Posts: 6

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by syg00 View Post
The general sentiment is ok (backup, then play), but the assertion is not. Resizing online with modern filesystems is fine - ext4 included.
I am not familiar with lvdestroy - lvremove maybe ?.
That's also what I knew. However, since I found a few diverging opinions online I decided to double-check before attempting.

Quote:
Originally Posted by syg00 View Post
I am not familiar with lvdestroy - lvremove maybe ?.
My bad. It is indeed lvremove.
 
Old 09-19-2022, 02:42 PM   #11
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,345

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
You must disable the swap partition before you remove it.

The swapon command will tell you if it is active, and if so then the swapoff command should disable it.
If it was active then check /etc/fstab to see if it is listed as swap there and remove the entry so it does not activate on the next boot.

If the swapoff command was able to disable that partition then the lvremove command can be used to free up that space within the VG. It might however require a reboot after the /etc/fstab changes to ensure it is not in use; then do the lvremove.

Finally the lvextend command as shown in post #6 above can be used to expand the LV and fill the newly released space. All should be able to be done with the system active as long as the swap space is not actively being used.

Use 'man swapoff' or 'man swapon' to check all that is documented for those tools.

Last edited by computersavvy; 09-19-2022 at 02:49 PM.
 
Old 09-25-2022, 03:43 PM   #12
suramya
Member
 
Registered: Jan 2022
Location: Earth
Distribution: Debian
Posts: 249

Rep: Reputation: 102Reputation: 102
Quote:
Originally Posted by syg00 View Post
The general sentiment is ok (backup, then play), but the assertion is not. Resizing online with modern filesystems is fine - ext4 included.

lvextend accepts the " -r" parameter to manage the filesystem resize concurrently.
I am not familiar with lvdestroy - lvremove maybe ?.
Just because you can doesn't mean you should. Resizing mounted partitions is technically feasible as you mentioned but is potentially risky enough that most partitioning software stop you from resizing a mounted disk. I tested with gparted and it wouldn't allow me to resize a mounted partition and only after I unmounted it I was allowed to resize.

The time savings you would get from resizing a mounted Root partition are miniscule enough that it is not worth the risk in my opinion. Plus unmounting the root partition will sure cause issues with the functioning of the OS anyways so there is that...

- Suramya
 
Old 09-26-2022, 08:41 AM   #13
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,783

Rep: Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214
Quote:
Originally Posted by suramya View Post
The time savings you would get from resizing a mounted Root partition are miniscule enough that it is not worth the risk in my opinion. Plus unmounting the root partition will sure cause issues with the functioning of the OS anyways so there is that...
Enlarging a mounted ext4 filesystem is a routine and quite safe operation. The existing structures that would need to grow (the block group descriptor tables) are by default created with enough space reserved to allow the filesystem to grow to 1024 times its initial size.
 
  


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
Resizing large iSCSI volumes on CentOS lancherider Linux - Server 2 08-20-2013 01:29 PM
Mounting Logical Volumes acidblue Fedora 6 01-28-2006 10:02 PM
I did not know about logical volumes gezi Linux - Newbie 5 04-27-2005 09:26 AM
FC3 slow boot: scans logical volumes..? tardigrade Fedora 1 04-03-2005 01:45 AM
how to read the output of df -k and about logical volumes commands jdara1 Linux - Software 3 05-23-2003 12:22 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 04:14 AM.

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