In this example, we will extend the size of a Linux Logical Volume.
Before starting, I want to give a general information about Linux LVM..
LVM is a logical volume manager for the Linux kernel. It manages disk drives and similar mass-storage devices.
In LVM, disk partitions are assigned to the physical volumes, physical volumes are assigned to Volume Groups and Logical Volumes are related to Logical Volumes, which placed on top of the filesystems.
Any type of filesystem can be created on the logical volumes, including as swap space.
Physical Volumes -> Volume Groups -> Logical Volumes -> Filesystem
Now, lets get to work;
We will extend the size of the logical volume which is mounted to root. We will do this online..
First we check the disk sizes using fdisk command.
root@erman ERBANT]# fdisk -l
Disk /dev/sda: 429.4 GB, 429496729600 bytes
255 heads, 63 sectors/track, 52216 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 33418 268325662+ 8e Linux LVM
you can see that /dev/sda is a 429 GB sized disk.. It has two partitions sda1 and sda2 , and it has free space, that means another partition can be created on it.
[root@erman ERBANT]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
261932172 217235312 31391416 88% /
/dev/sda1 101086 12746 83121 14% /boot
none 2913928 0 2913928 0% /dev/shm
We first create a new partition(sda3) on the disk /dev/sda using fdisk .. We will use the extra space that our storage admin have assigned to our linux server..
If the OS can not see the newly added disk, you can scan the scsi bus to make the OS see the new disk/new size of the disk ..
echo "- - -" > /sys/class/scsi_host/host0/scan
[root@erman ~]# fdisk /dev/sda
The number of cylinders for this disk is set to 52216.
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)
Disk /dev/sda: 429.4 GB, 429496729600 bytes
255 heads, 63 sectors/track, 52216 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 33418 268325662+ 8e Linux LVM
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (33419-52216, default 33419):
Using default value 33419
Last cylinder or +size or +sizeM or +sizeK (33419-52216, default 52216):
Using default value 52216
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
So , we created a new partition (/dev/sda3) in the disk /dev/sda..
We use partprobe to make the OS recognize the newly created partition. partprobe is a program that informs the operating system kernel of partition table changes, by requesting that the operating system re-read the partition table.
[root@erman ~]# partprobe
Next, we create a filesystem using mkfs on the new partition;
mkfs.ext3 /dev/sda3
Lets look at our physical volumes;
[root@erman ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name VolGroup00
PV Size 255.88 GB / not usable 0
Allocatable yes
PE Size (KByte) 32768
Total PE 8188
Free PE 5
Allocated PE 8183
PV UUID B0fUIm-FO21-toMI-drZo-XKhR-gS79-ZQ6JuF
So here we see that, we have one physical volume /dev/sda2 which size is 255 GB.. This physical volume is assigned to Volume Group VolGroup00..
We add another physical volume using newly created partition /dev/sda3 with the following command;
[root@erman ~]# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created
So we created our new physical volume , lets look to physical volumes again;
[root@erman ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name VolGroup00
PV Size 255.88 GB / not usable 0
Allocatable yes
PE Size (KByte) 32768
Total PE 8188
Free PE 5
Allocated PE 8183
PV UUID B0fUIm-FO21-toMI-drZo-XKhR-gS79-ZQ6JuF
--- NEW Physical volume ---
PV Name /dev/sda3
VG Name
PV Size 144.00 GB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 9xMM1S-Me5o-vcHo-WGOd-YbFn-DOuu-Msx0NL
What wee see from above is ,our new physical volume is created with size of 144GB , which is actually the size of the related partition. (/dev/sda3)
So far so good;
So far, we created a new partition using available space, created an ext3 filesystem on it and we created a physical volume using the newly created partition.
Subsequently, we will extend the VolumeGroup VolGroup00 using the new physical volume ;
vgextend VolGroup00 /dev/sda3
Next we check the logical volumes and extent the Logical Volume size with the available size of the related Volume Group..
root@erman ~]# lvdisplay
--- Logical volume ---
LV Name /dev/VolGroup00/LogVol00 --> the LV that we will extend.
VG Name VolGroup00
LV UUID cILSJp-4ksS-mETv-vSDC-237v-Z0it-Vhw806
LV Write Access read/write
LV Status available
# open 1
LV Size 253.78 GB
Current LE 8121
Segments 1
Allocation inherit
Read ahead sectors 0
Block device 253:0
--- Logical volume ---
LV Name /dev/VolGroup00/LogVol01
VG Name VolGroup00
LV UUID gJQCEa-D8ot-C19G-kGDo-lnpz-E1FH-b6gJQC
LV Write Access read/write
LV Status available
# open 1
LV Size 1.94 GB
Current LE 62
Segments 1
Allocation inherit
Read ahead sectors 0
Block device 253:1
--- Volume group ---
VG Name VolGroup00
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
Here, we extend the size of the Logical Volume LogVol00
lvextend -L +144G /dev/VolGroup00/LogVol00 (I used +144G to extend the logical volume, as I know there is 144 GB more to extend.. you can use other argument with lvextend command something like extend using all the available space etc..)
Finally, we extend the filesystem on the logical volume we just extend using the resize2fs..
resize2fs /dev/VolGroup00/LogVol00
To extend an ext3/ext4 partition and filesystem (without LVM), you can refer the following link;
Linux -- How to extend a Linux partition and ext3/ext4 filesystem.
Before starting, I want to give a general information about Linux LVM..
LVM is a logical volume manager for the Linux kernel. It manages disk drives and similar mass-storage devices.
In LVM, disk partitions are assigned to the physical volumes, physical volumes are assigned to Volume Groups and Logical Volumes are related to Logical Volumes, which placed on top of the filesystems.
Any type of filesystem can be created on the logical volumes, including as swap space.
Physical Volumes -> Volume Groups -> Logical Volumes -> Filesystem
Now, lets get to work;
We will extend the size of the logical volume which is mounted to root. We will do this online..
First we check the disk sizes using fdisk command.
root@erman ERBANT]# fdisk -l
Disk /dev/sda: 429.4 GB, 429496729600 bytes
255 heads, 63 sectors/track, 52216 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 33418 268325662+ 8e Linux LVM
you can see that /dev/sda is a 429 GB sized disk.. It has two partitions sda1 and sda2 , and it has free space, that means another partition can be created on it.
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
261932172 217235312 31391416 88% /
/dev/sda1 101086 12746 83121 14% /boot
none 2913928 0 2913928 0% /dev/shm
We first create a new partition(sda3) on the disk /dev/sda using fdisk .. We will use the extra space that our storage admin have assigned to our linux server..
If the OS can not see the newly added disk, you can scan the scsi bus to make the OS see the new disk/new size of the disk ..
echo "- - -" > /sys/class/scsi_host/host0/scan
[root@erman ~]# fdisk /dev/sda
The number of cylinders for this disk is set to 52216.
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)
Disk /dev/sda: 429.4 GB, 429496729600 bytes
255 heads, 63 sectors/track, 52216 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 33418 268325662+ 8e Linux LVM
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (33419-52216, default 33419):
Using default value 33419
Last cylinder or +size or +sizeM or +sizeK (33419-52216, default 52216):
Using default value 52216
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
So , we created a new partition (/dev/sda3) in the disk /dev/sda..
We use partprobe to make the OS recognize the newly created partition. partprobe is a program that informs the operating system kernel of partition table changes, by requesting that the operating system re-read the partition table.
[root@erman ~]# partprobe
Next, we create a filesystem using mkfs on the new partition;
mkfs.ext3 /dev/sda3
Lets look at our physical volumes;
[root@erman ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name VolGroup00
PV Size 255.88 GB / not usable 0
Allocatable yes
PE Size (KByte) 32768
Total PE 8188
Free PE 5
Allocated PE 8183
PV UUID B0fUIm-FO21-toMI-drZo-XKhR-gS79-ZQ6JuF
So here we see that, we have one physical volume /dev/sda2 which size is 255 GB.. This physical volume is assigned to Volume Group VolGroup00..
We add another physical volume using newly created partition /dev/sda3 with the following command;
[root@erman ~]# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created
So we created our new physical volume , lets look to physical volumes again;
[root@erman ~]# pvdisplay
--- Physical volume ---
PV Name /dev/sda2
VG Name VolGroup00
PV Size 255.88 GB / not usable 0
Allocatable yes
PE Size (KByte) 32768
Total PE 8188
Free PE 5
Allocated PE 8183
PV UUID B0fUIm-FO21-toMI-drZo-XKhR-gS79-ZQ6JuF
--- NEW Physical volume ---
PV Name /dev/sda3
VG Name
PV Size 144.00 GB
Allocatable NO
PE Size (KByte) 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID 9xMM1S-Me5o-vcHo-WGOd-YbFn-DOuu-Msx0NL
What wee see from above is ,our new physical volume is created with size of 144GB , which is actually the size of the related partition. (/dev/sda3)
So far so good;
So far, we created a new partition using available space, created an ext3 filesystem on it and we created a physical volume using the newly created partition.
Subsequently, we will extend the VolumeGroup VolGroup00 using the new physical volume ;
vgextend VolGroup00 /dev/sda3
Next we check the logical volumes and extent the Logical Volume size with the available size of the related Volume Group..
root@erman ~]# lvdisplay
--- Logical volume ---
LV Name /dev/VolGroup00/LogVol00 --> the LV that we will extend.
VG Name VolGroup00
LV UUID cILSJp-4ksS-mETv-vSDC-237v-Z0it-Vhw806
LV Write Access read/write
LV Status available
# open 1
LV Size 253.78 GB
Current LE 8121
Segments 1
Allocation inherit
Read ahead sectors 0
Block device 253:0
--- Logical volume ---
LV Name /dev/VolGroup00/LogVol01
VG Name VolGroup00
LV UUID gJQCEa-D8ot-C19G-kGDo-lnpz-E1FH-b6gJQC
LV Write Access read/write
LV Status available
# open 1
LV Size 1.94 GB
Current LE 62
Segments 1
Allocation inherit
Read ahead sectors 0
Block device 253:1
--- Volume group ---
VG Name VolGroup00
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
Here, we extend the size of the Logical Volume LogVol00
lvextend -L +144G /dev/VolGroup00/LogVol00 (I used +144G to extend the logical volume, as I know there is 144 GB more to extend.. you can use other argument with lvextend command something like extend using all the available space etc..)
Finally, we extend the filesystem on the logical volume we just extend using the resize2fs..
resize2fs /dev/VolGroup00/LogVol00
To extend an ext3/ext4 partition and filesystem (without LVM), you can refer the following link;
Linux -- How to extend a Linux partition and ext3/ext4 filesystem.
No comments :
Post a Comment
If you will ask a question, please don't comment here..
For your questions, please create an issue into my forum.
Forum Link: http://ermanarslan.blogspot.com.tr/p/forum.html
Register and create an issue in the related category.
I will support you from there.