LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
LinkBack Search this Thread
Old 06-15-2013, 12:17 AM   #1
Z038
Member
 
Registered: Jan 2006
Distribution: Slackware
Posts: 767

Rep: Reputation: 154Reputation: 154
LVM expand swap logical volume


I have a laptop using LVM with Luks encryption. There is one physical volume, and three logical volumes. I would like to shrink the /home lv by 1 GB and expand swap by 1 GB. I realize that will most likely make swap non-contiguous, but I don't think that will cause any problems.

Here is what I have now:

Code:
# pvscan
  PV /dev/mapper/lukssda2   VG vg00   lvm2 [37.16 GiB / 168.00 MiB free]
  Total: 1 [37.16 GiB] / in use: 1 [37.16 GiB] / in no VG: 0 [0   ]

# lvscan
  ACTIVE            '/dev/vg00/root' [10.00 GiB] inherit
  ACTIVE            '/dev/vg00/swap' [1.00 GiB] inherit
  ACTIVE            '/dev/vg00/home' [26.00 GiB] inherit
Is it possible to shrink/expand logical volumes that are active? Or will I need to boot a live CD like systemrescue cd to shrink home and expand swap?
 
Old 06-15-2013, 12:26 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 11,801

Rep: Reputation: 923Reputation: 923Reputation: 923Reputation: 923Reputation: 923Reputation: 923Reputation: 923Reputation: 923
Each swap extent must be contiguous - LVM, being a(nother) block device driver will ensure it looks contiguous. If mkswap accepts it, you're o.k.
Personally I'd simply create another swap extent and add them both to fstab. I doubt you can "extend" a swap, but I've never tried. mkswap will use the entire (possibly larger) lv.
 
1 members found this post helpful.
Old 06-15-2013, 12:54 AM   #3
Z038
Member
 
Registered: Jan 2006
Distribution: Slackware
Posts: 767

Original Poster
Rep: Reputation: 154Reputation: 154
I suppose I could shrink vg00/home by 2 GB and create a new 2GB swap in the freed up space, then delete the old swap and add its space back to /home.

Am I right that this needs to be done while the partitions are not in use?
 
Old 06-15-2013, 03:21 AM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 11,801

Rep: Reputation: 923Reputation: 923Reputation: 923Reputation: 923Reputation: 923Reputation: 923Reputation: 923Reputation: 923
Take a Gig from home, add it to the vg containing the swap. "swapoff", "mkswap", "swapon".
So long as you don't mount the swap by UUID all done - else adjust as necessary as the mkswap will change the UUID.

This will all work (online) so long as the swapoff works. If not, liveCD.
 
Old 06-15-2013, 04:19 AM   #5
xrgm
LQ Newbie
 
Registered: Dec 2012
Location: Joure, Netherlands
Posts: 7

Rep: Reputation: Disabled
Another option is to create a swap file, which is the least work. It is explained here: http://linuxpoison.blogspot.nl/2008/...le-adding.html
 
1 members found this post helpful.
Old 06-15-2013, 02:25 PM   #6
Z038
Member
 
Registered: Jan 2006
Distribution: Slackware
Posts: 767

Original Poster
Rep: Reputation: 154Reputation: 154
syg00 and xrgm, thank you. You both suggested just adding an additional swap file, and that is what I did. I shrank my /home logical volume by 1G and created an additional 1G swap logical volume.

Here is what I did, partly based on the instructions I found on this blog: http://linux-bsd-sharing.blogspot.co...m-logical.html

Code:
# telinit 1
# umount /home
# lvscan -vvvv &> lvscan.txt
# e2fsck -f /dev/vg00/home
# resize2fs -p /dev/vg00/home 25G
# lvreduce -L 25G /dev/vg00/home

Run fsck again to make sure all is well, and also resize2fs without a size to 
verify the current size is as expected.
# e2fsck -f /dev/vg00/home
# resize2fs -p /dev/vg00/home

# mount /dev/vg00/home /home

Make a new swap volume.

# lvcreate -v -Z y -L 1G -n swap2 vg00
Gives error:
/dev/vg00/swap2: not found: device not cleared
Aborting. Failed to wipe start of new LV.
  Found volume group "vg00"
  Removing vg00-swap2 (253:4)
  Creating volume group backup "/etc/lvm/backup/vg00" (seqno 15).

Edit /etc/lvm/lvm.conf to add "verify_udev_operations=1" based on advice found here:
http://comments.gmane.org/gmane.linux.lvm.devel/6739

# lvcreate -v -Z y -L 1G -n swap2 vg00
This time it worked!  Logical volume "swap2" created.
From above link, "This normally means that udev rules are wrong."

# vgscan --mknodes
# vgchange -ay
# lvscan -vvvv &> lvscan2.txt
# mkswap /dev/vg00/swap2

Edit /etc/fstab to add new swap device.
/dev/vg00/swap   none   swap   defaults,pri=2   0   0
/dev/vg00/swap2  none   swap   defaults,pri=1   0   0

# swapon -va

# shutdown -r now
Now "free -m" shows that I have 2GB total swap space.
 
Old 06-15-2013, 03:00 PM   #7
Z038
Member
 
Registered: Jan 2006
Distribution: Slackware
Posts: 767

Original Poster
Rep: Reputation: 154Reputation: 154
Here is how it ended up:

Code:
# pvscan
  PV /dev/mapper/lukssda2   VG vg00   lvm2 [37.16 GiB / 168.00 MiB free]
  Total: 1 [37.16 GiB] / in use: 1 [37.16 GiB] / in no VG: 0 [0   ]


# lvscan
  ACTIVE            '/dev/vg00/root' [10.00 GiB] inherit
  ACTIVE            '/dev/vg00/swap' [1.00 GiB] inherit
  ACTIVE            '/dev/vg00/home' [25.00 GiB] inherit
  ACTIVE            '/dev/vg00/swap2' [1.00 GiB] inherit
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LVM Mount Physical Volume/Logical Volume without a working Volume Group mpivintis Linux - Newbie 10 01-11-2014 07:02 AM
HELP! Restoring a LVM Logical Volume Checksumfail Linux - Server 2 12-18-2012 12:07 AM
Extended LVM Volume group and Logical Volume. But space not usable linuxlover.chaitanya Linux - Server 1 11-19-2012 09:37 AM
Extending logical volume LogVol01 Insufficient allocatable logical exte swap space umeshsharma Linux - Newbie 4 06-22-2009 12:26 PM
Shrinking a Logical Volume With LVM jimmyjiang Red Hat 1 02-28-2008 04:45 PM


All times are GMT -5. The time now is 03:07 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration