You are not logged in.
I have a 2TB hdd, which originally contained one big ntfs partition containing all the data. I wish to eventually use the drive completely as one big lvm container, because of the flexibility lvm provides.
I started by backing up some of the data externally and shrinking the ntfs partition, keeping the same start sector. Then I created an lvm PV, VG and a bunch of LVs and copied the backup back into the new logical volumes. It all works fine. Now I've managed to shrink the ntfs partition even further and am trying to extend the PV to the left without breaking anything. Here's the latest fdisk output:
Disk /dev/sdc: 1.8 TiB, 2000398934016 bytes, 3907029168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0x6ae365c5
Device Boot Start End Sectors Size Id Type
/dev/sdc1 411648 1812703231 1812291584 864.2G 7 HPFS/NTFS/exFAT
/dev/sdc2 * 3821486080 3898816511 77330432 36.9G 83 Linux
/dev/sdc4 2152366080 3821486079 1669120000 795.9G 8e Linux LVM
A small side note, in attempting to do this, I tried the following:
Using fdisk, I deleted the sdc4, the partition which was the VG. Then created a new partition with start 1812291585; right next to (now smaller) ntfs partition. When I rebooted, pvdisplay showed no volumes; could not do pvresize. I am not sure if I had set the new partition type correctly to lvm (8e). Anyway, to get my data back, I reverted the old partition definition; after reboot everything seems to work again.
So the question is, how can I expand the PV to the left, with least amount of data transfer. From how I understand lvm works, it should be doable with no data transfer, meta data excluded.
I'd rather not create a new PV; it has a MBR table, I am limited to 4 primary partitions. I cannot continue this strategy until I eventually put all the data into lvm.
Here's some more information
sudo pvdisplay
--- Physical volume ---
PV Name /dev/sdc4
VG Name MainVolGroup
PV Size 795.90 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 203749
Free PE 0
Allocated PE 203749
PV UUID zOVoH6-ulaa-DB70-EmOP-4UgV-k3Es-ZK3r18
sudo vgdisplay
--- Volume group ---
VG Name MainVolGroup
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 9
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 4
Open LV 0
Max PV 0
Cur PV 1
Act PV 1
VG Size 795.89 GiB
PE Size 4.00 MiB
Total PE 203749
Alloc PE / Size 203749 / 795.89 GiB
Free PE / Size 0 / 0
VG UUID NUSnNO-bOOO-xFqi-KyPK-tLHQ-vSuF-B1P6YB
sudo lvdisplay
--- Logical volume ---
LV Path /dev/MainVolGroup/Photos
LV Name Photos
VG Name MainVolGroup
LV UUID 93goGD-ebd0-Q4KZ-Xp3i-FJjn-C5rp-2NanV6
LV Write Access read/write
LV Creation host, time jArch, 2015-12-02 19:03:35 +0530
LV Status available
# open 0
LV Size 300.00 GiB
Current LE 76800
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:0
--- Logical volume ---
LV Path /dev/MainVolGroup/LinuxPackages
LV Name LinuxPackages
VG Name MainVolGroup
LV UUID tdNx2A-HYAd-JpSN-R4xt-NHMY-kb79-232Wmc
LV Write Access read/write
LV Creation host, time jArch, 2015-12-02 19:31:37 +0530
LV Status available
# open 0
LV Size 50.00 GiB
Current LE 12800
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:1
--- Logical volume ---
LV Path /dev/MainVolGroup/Archive
LV Name Archive
VG Name MainVolGroup
LV UUID yXArxd-EeMp-NdPc-ktU5-B9db-7kz9-HA5iBy
LV Write Access read/write
LV Creation host, time jArch, 2015-12-02 20:36:40 +0530
LV Status available
# open 0
LV Size 300.00 GiB
Current LE 76800
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:2
--- Logical volume ---
LV Path /dev/MainVolGroup/Multimedia2
LV Name Multimedia2
VG Name MainVolGroup
LV UUID I19s4O-Buc3-K75h-zkLp-Ouds-Es99-Of22r1
LV Write Access read/write
LV Creation host, time jArch, 2015-12-02 22:30:04 +0530
LV Status available
# open 0
LV Size 145.89 GiB
Current LE 37349
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 254:3
Last edited by jinal (2015-12-10 21:01:04)
Offline
Someone asked the same thing yesterday on IRC.
I don't know of a tool that extends PV to the left. It can be done manually be editing LVM metadata, but it has pitfalls - you have to extend left by exact multiple of PE-Size OR adapt the 1st PE Offset accordingly so that your existing PE will still have the correct alignment. LVM allocates space in chunks of 4MiB, if your partition starts at the wrong offset each PE will be 3MiB of old PE + 1 MiB of following old PE and the data you see is garbage.
The easy obvious way is to create a new partition in the free space and just add yet another PV to your VG.
If that's not possible because of msdos partitions, it may be possible to losslessly convert from msdos to gpt partitioning scheme.
If that's not possible either (because Windows or whatever) and you're not confident about your metadata editing skills [do it wrong and all data gone], you're left with moving all data in the partition itself.
Offline
Thanks, frostschutz for detailed answer. I am feeling adventurous .. I might try messing with lvm metadata. Any additional information you can give in this direction? Even a set of search terms will be a good start.
Offline
If you add 1000 PE (4000 MiB if your PE size is 4 MiB) to the left of the PV, in the metadata all PE references _for that PV only_ have to be increased by 1000.
So if in the metadata a segment says
stripes = [
"pv0", 832
]
You have to change it to 1832 instead, if you added exactly 1000 PE to the left.
Do not confuse this with the start_extent value which references to the logical offset of the LV which remains unchanged, so the first segment of each LV will always have start_extent 0, and if there are other segments they may have start_extent=2048 or what ever. Those do not change.
To be on the safe side you should run such experiments in read only mode on an overlay (google kernel raid wiki overlay) before commiting it to disk. And of course you should always have a backup of your data regardless.
Offline
That's great, thanks frostschutz! I'll need time to experiment with this.
Meanwhile, if someone else is in similar situation, here are some links I've found useful so far.
To create an read only overlay(as suggested by frostschutz): https://raid.wiki.kernel.org/index.php/ … erlay_file
Typical LVM Physical Volume Layout : https://www.centos.org/docs/5/html/Clus … lumes.html
Also more information about my system from vgcfgbackup:
# Generated by LVM2 version 2.02.133(2) (2015-10-30): Thu Dec 3 20:06:42 2015
contents = "Text Format Volume Group"
version = 1
description = "vgcfgbackup -f VG_Info MainVolGroup"
creation_host = "jArch" # Linux jArch 4.2.5-1-ARCH #1 SMP PREEMPT Tue Oct 27 08:13:28 CET 2015 x86_64
creation_time = 1449153402 # Thu Dec 3 20:06:42 2015
MainVolGroup {
id = "NUSnNO-bOOO-xFqi-KyPK-tLHQ-vSuF-B1P6YB"
seqno = 9
format = "lvm2" # informational
status = ["RESIZEABLE", "READ", "WRITE"]
flags = []
extent_size = 8192 # 4 Megabytes
max_lv = 0
max_pv = 0
metadata_copies = 0
physical_volumes {
pv0 {
id = "zOVoH6-ulaa-DB70-EmOP-4UgV-k3Es-ZK3r18"
device = "/dev/sdc4" # Hint only
status = ["ALLOCATABLE"]
flags = []
dev_size = 1669117952 # 795.897 Gigabytes
pe_start = 2048
pe_count = 203749 # 795.895 Gigabytes
}
}
logical_volumes {
Photos {
id = "93goGD-ebd0-Q4KZ-Xp3i-FJjn-C5rp-2NanV6"
status = ["READ", "WRITE", "VISIBLE"]
flags = []
creation_host = "jArch"
creation_time = 1449063215 # 2015-12-02 19:03:35 +0530
segment_count = 1
segment1 {
start_extent = 0
extent_count = 76800 # 300 Gigabytes
type = "striped"
stripe_count = 1 # linear
stripes = [
"pv0", 0
]
}
}
LinuxPackages {
id = "tdNx2A-HYAd-JpSN-R4xt-NHMY-kb79-232Wmc"
status = ["READ", "WRITE", "VISIBLE"]
flags = []
creation_host = "jArch"
creation_time = 1449064897 # 2015-12-02 19:31:37 +0530
segment_count = 1
segment1 {
start_extent = 0
extent_count = 12800 # 50 Gigabytes
type = "striped"
stripe_count = 1 # linear
stripes = [
"pv0", 76800
]
}
}
Archive {
id = "yXArxd-EeMp-NdPc-ktU5-B9db-7kz9-HA5iBy"
status = ["READ", "WRITE", "VISIBLE"]
flags = []
creation_host = "jArch"
creation_time = 1449068800 # 2015-12-02 20:36:40 +0530
segment_count = 1
segment1 {
start_extent = 0
extent_count = 76800 # 300 Gigabytes
type = "striped"
stripe_count = 1 # linear
stripes = [
"pv0", 89600
]
}
}
Multimedia2 {
id = "I19s4O-Buc3-K75h-zkLp-Ouds-Es99-Of22r1"
status = ["READ", "WRITE", "VISIBLE"]
flags = []
creation_host = "jArch"
creation_time = 1449075604 # 2015-12-02 22:30:04 +0530
segment_count = 1
segment1 {
start_extent = 0
extent_count = 37349 # 145.895 Gigabytes
type = "striped"
stripe_count = 1 # linear
stripes = [
"pv0", 166400
]
}
}
}
}
I do not yet know how to edit the lvm metadata(or create a modified copy of original in the correct sector). I suspect I would have to use something like 'dd'.
Any additional help is welcome. I'll post if there are any updates.
Last edited by jinal (2015-12-03 17:41:15)
Offline
I am no longer pursuing this. Decided to move data out and create a new LVM VG. Marking as closed.
Offline
Please don't use [Closed] as it denotes a locked thread. Use [Solved] or [Resolved] or [Abandoned] or [Gave Up] instead...
Offline
Sorry, my bad. Changed it to [Abandoned] . Thanks
Offline