Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have just completed building a test system. It has a boot area (kernel) and a LVM2 volume.
I would like to reduce the size of the LVM2 volume to add a swap partition to the system. I have found lots of information of growing but the info on reduction is very confusing. I am lost and am appealing. I saw this, but found that the problem being addressed does not match mine.
Here's my single drive system info. And, I would like to have a 16GB Swap partition.
Code:
# mount
/dev/mapper/pve-root on / type ext3 (rw,errors=remount-ro)
tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755)
proc on /proc type proc (rw,noexec,nosuid,nodev)
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
procbususb on /proc/bus/usb type usbfs (rw)
udev on /dev type tmpfs (rw,mode=0755)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620)
/dev/mapper/pve-data on /var/lib/vz type ext3 (rw)
/dev/sda1 on /boot type ext3 (rw)
# df -l
dev/mapper/pve-root ... /
tmpfs ... /lib/ini/rw
udev ... /dev
tmpfs ... /dev/shm
/dev/mapper/pve-data ... /var/lib/vz
/dev/sda1 ... /boot
# fdisk -l
Disk /dev/sda: 500.1 GB, 500107862016 bytes
255 heads, 63 sectors/track, 60801 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000
Device Boot Start End Blocks Id System
/dev/sda1 * 1 66 524288 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 66 60801 487859712 8e Linux LVM
Disk /dev/dm-0: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000
Disk /dev/dm-1: 103.0 GB, 103079215104 bytes
255 heads, 63 sectors/track, 12532 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000
Disk /dev/dm-2: 387.9 GB, 387901816832 bytes
255 heads, 63 sectors/track, 47159 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x00000000
# lvdisplay
--- Logical volume ---
LV Name /dev/pve/swap
VG Name pve
LV UUID fSULxh-H69J-3iu6-6fGv-zyUf-vux4-KUMMp9
LV Write Access read/write
LV Status available
# open 1
LV Size 4.00 GB
Current LE 1024
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:0
--- Logical volume ---
LV Name /dev/pve/root
VG Name pve
LV UUID 64Zfbj-BOdy-Icqm-93wW-Hv6V-eChf-c3ROyL
LV Write Access read/write
LV Status available
# open 1
LV Size 96.00 GB
Current LE 24576
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:1
--- Logical volume ---
LV Name /dev/pve/data
VG Name pve
LV UUID jSTxnG-kpLx-eyac-SWwy-hgoY-Wy9N-lPgf0l
LV Write Access read/write
LV Status available
# open 1
LV Size 361.26 GB
Current LE 92483
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:2
# vgdisplay
--- Volume group ---
VG Name pve
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 1
Act PV 1
VG Size 465.26 GB
PE Size 4.00 MB
Total PE 119106
Alloc PE / Size 118083 / 461.26 GB
Free PE / Size 1023 / 4.00 GB
VG UUID EPCWMl-xc1n-3xUB-V5TD-YQ1l-6pZY-4NZ464
# pvdisplay -m
--- Physical volume ---
PV Name /dev/sda2
VG Name pve
PV Size 465.26 GB / not usable 1.50 MB
Allocatable yes
PE Size (KByte) 4096
Total PE 119106
Free PE 1023
Allocated PE 118083
PV UUID JogU1D-cKPA-dQNL-2EwU-YTZT-4kV2-iGkHk6
--- Physical Segments ---
Physical extent 0 to 1023:
Logical volume /dev/pve/swap
Logical extents 0 to 1023
Physical extent 1024 to 25599:
Logical volume /dev/pve/root
Logical extents 0 to 24575
Physical extent 25600 to 118082:
Logical volume /dev/pve/data
Logical extents 0 to 92482
Physical extent 118083 to 119105:
FREE
BACKUP is not a problem. I OK on this. But, maybe a recommendation on how I should proceed. What should I designate to reduce? And which toolset? I venturing into a new world of reduction. GParted is not a help.
Add the following line at the bottom of your /etc/fstab so the file will load as a swapfile when you reboot.
/swapfile_01 swap swap defaults 0 0
Reducing the size of ext3 file systems didn't always go well for me in the past. It's doable but do you REALLLY need it?
Why do you need the added swap? If you do a free and look at the cached, buffers and free that's what your processes will use (ie apps). The used memory is a cache of your disk so if you need to read from it, the reads will be faster.
I just went through a good deal of research on reducing an LVM2 VG/LV, as an exercise (I had installed CentOS with 'defaults' and it does a big LVM on the whole disk). I wanted to gain experience with LVM so I thought I'd try it. I have a fair amount of Linux experience as well as other OS'es and I can tell you it is *possible* to do it but only if you are absolutely desperate.
Long story short, I searched LQ, CentOS.org, and many other sites for LVM info (tldp.org LVM-HOWTO, and Redhat Mag LVM2/resize fs, and some others) and had a plan to do it, until I got to the 'pvresize' step. The PE's were spread out over the whole disk and while they (apparently) can be moved, it's a bear. I did not continue as this was just a learning exercise.
So unless you have no other choice, I'd suggest you make another choice. If you want to do it as a learning tool, on a test system, by all means give it a try!
I have a new system with little to no data that cannot be recreated. I don't think I have any PEs that are scattered about as you have.
Did you find a paper or a solution that led you to try this? I like to use it if you can point me to one.
There's lots of experiences on increasing, but the reductions seemingly are very lacking.
If anyone has any solutions tucked away or any knowledge I'll give it a run. I had hope that I could publish something with Pics for others to use as a guide for how to reduce a single drive system where the LVM has consumed the total drive. And, like me, they would want to reduce it for a good reason.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.