A Beginner's Guide To LVM - Page 5
On this page
5 Adding A Hard Drive And Removing Another One
We haven't used /dev/sdf until now. We will now create the partition /dev/sdf1 (25GB) and add that to our fileserver volume group.
fdisk /dev/sdf
server1:~# fdisk /dev/sdf
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.
The number of cylinders for this disk is set to 10443.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): <-- m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help): <-- n
Command action
e extended
p primary partition (1-4)
<-- p
Partition number (1-4): <-- 1
First cylinder (1-10443, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-10443, default 10443): <-- +25000M
Command (m for help): <-- t
Selected partition 1
Hex code (type L to list codes): <-- 8e
Changed system type of partition 1 to 8e (Linux LVM)
Command (m for help): <-- w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
Let's prepare /dev/sdf1 for LVM:
pvcreate /dev/sdf1
server1:~# pvcreate /dev/sdf1
Physical volume "/dev/sdf1" successfully created
Add /dev/sdf1 to our fileserver volume group:
vgextend fileserver /dev/sdf1
Run
vgdisplay
VG Size should now be bigger than before:
server1:~# vgdisplay
--- Volume group ---
VG Name fileserver
System ID
Format lvm2
Metadata Areas 5
Metadata Sequence No 12
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 5
Act PV 5
VG Size 116.43 GB
PE Size 4.00 MB
Total PE 29805
Alloc PE / Size 11776 / 46.00 GB
Free PE / Size 18029 / 70.43 GB
VG UUID iWr1Vk-7h7J-hLRL-SHbx-3p87-Rq47-L1GyEO
That's it. /dev/sdf1 has been added to the fileserver volume group.
Now let's remove /dev/sdb1. Before we do this, we must copy all data on it to /dev/sdf1:
pvmove /dev/sdb1 /dev/sdf1
This can take some minutes:
server1:~# pvmove /dev/sdb1 /dev/sdf1
/dev/sdb1: Moved: 1.9%
/dev/sdb1: Moved: 3.8%
/dev/sdb1: Moved: 5.8%
/dev/sdb1: Moved: 7.8%
/dev/sdb1: Moved: 9.7%
/dev/sdb1: Moved: 11.6%
/dev/sdb1: Moved: 13.6%
/dev/sdb1: Moved: 15.6%
/dev/sdb1: Moved: 17.5%
/dev/sdb1: Moved: 19.4%
/dev/sdb1: Moved: 21.4%
[...]
/dev/sdb1: Moved: 85.7%
/dev/sdb1: Moved: 87.7%
/dev/sdb1: Moved: 89.7%
/dev/sdb1: Moved: 91.7%
/dev/sdb1: Moved: 93.6%
/dev/sdb1: Moved: 95.5%
/dev/sdb1: Moved: 97.5%
/dev/sdb1: Moved: 99.4%
/dev/sdb1: Moved: 100.0%
Next we remove /dev/sdb1 from the fileserver volume group:
vgreduce fileserver /dev/sdb1
server1:~# vgreduce fileserver /dev/sdb1
Removed "/dev/sdb1" from volume group "fileserver"
vgdisplay
server1:~# vgdisplay
--- Volume group ---
VG Name fileserver
System ID
Format lvm2
Metadata Areas 4
Metadata Sequence No 16
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 3
Open LV 3
Max PV 0
Cur PV 4
Act PV 4
VG Size 93.14 GB
PE Size 4.00 MB
Total PE 23844
Alloc PE / Size 11776 / 46.00 GB
Free PE / Size 12068 / 47.14 GB
VG UUID iWr1Vk-7h7J-hLRL-SHbx-3p87-Rq47-L1GyEO
Then we run
pvremove /dev/sdb1
/dev/sdb1 shouldn't be listed as a physical volume anymore:
pvdisplay
server1:~# pvdisplay
--- Physical volume ---
PV Name /dev/sdc1
VG Name fileserver
PV Size 23.29 GB / not usable 0
Allocatable yes
PE Size (KByte) 4096
Total PE 5961
Free PE 1682
Allocated PE 4279
PV UUID 40GJyh-IbsI-pzhn-TDRq-PQ3l-3ut0-AVSE4B
--- Physical volume ---
PV Name /dev/sdd1
VG Name fileserver
PV Size 23.29 GB / not usable 0
Allocatable yes
PE Size (KByte) 4096
Total PE 5961
Free PE 4681
Allocated PE 1280
PV UUID 4mU63D-4s26-uL00-r0pO-Q0hP-mvQR-2YJN5B
--- Physical volume ---
PV Name /dev/sde1
VG Name fileserver
PV Size 23.29 GB / not usable 0
Allocatable yes
PE Size (KByte) 4096
Total PE 5961
Free PE 5705
Allocated PE 256
PV UUID 3upcZc-4eS2-h4r4-iBKK-gZJv-AYt3-EKdRK6
--- Physical volume ---
PV Name /dev/sdf1
VG Name fileserver
PV Size 23.29 GB / not usable 0
Allocatable yes (but full)
PE Size (KByte) 4096
Total PE 5961
Free PE 0
Allocated PE 5961
PV UUID 1xgo2I-SBjj-0MAz-lmDu-OLZ1-3NdO-mLkS20
You could now remove /dev/sdb from the system (if this was a real system and not a virtual machine).