add lvm space from a regular partition

Hi,

I have red hat enterprise 4. I would like to add more space on my lvm from the first partition that is not lvm type.

Here's the config

[root@local ~]# fdisk -l

Disk /dev/sda: 73.4 GB, 73406611456 bytes
255 heads, 63 sectors/track, 8924 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        1033     8193150   82  Linux swap
/dev/sda3            1034        2053     8193150   83  Linux
/dev/sda4            2054        8924    55191307+   5  Extended
/dev/sda5            2054        2563     4096543+  83  Linux
/dev/sda6            2564        3073     4096543+  83  Linux

Disk /dev/sdb: 73.4 GB, 73406611456 bytes
128 heads, 32 sectors/track, 35003 cylinders
Units = cylinders of 4096 * 512 = 2097152 bytes

I want to delete /dev/sda6 and add it to /dev/sdb (lvm). Is that possible? If yes, can you give me the instructions.

Thanks for any comment you may add.

Of course it's possible. Move away anything residing on /dev/sda6, unmount it, change the partition type to Linux LVM (8e). pvcreate, vgextend, and you're done.

Sorry about that

let me test

sample code:

ls -la
rm -fr

end testing

thanks again!

You need using Logical Volume when you use LVM to store your data.

Yes it is possible. The commands you need are

  • fdisk (or parted) to change the partition type of /dev/sda6 to 8e (logical partition)
  • pvcreate /dev/sda6 to create a new physical volume
  • vgextend to add the physical partition to an existing volume group
  • lventend to increase the logical volume
  • resize2fs to increase the size of the filesystem

I did extend the uservg but the size is not what I expected, look on my code or execution

Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          25      200781   83  Linux
/dev/sda2              26         662     5116702+  83  Linux
/dev/sda3             663        1044     3068415   83  Linux
/dev/sda4            1045        2610    12578895    5  Extended
/dev/sda5            1045        1426     3068383+  83  Linux
/dev/sda6            1427        1808     3068383+  83  Linux
/dev/sda7            1809        1935     1020096   82  Linux swap

Command (m for help): n
First cylinder (1936-2610, default 1936):
Using default value 1936
Last cylinder or +size or +sizeM or +sizeK (1936-2610, default 2610): +2000M

Command (m for help): t
Partition number (1-8): 8
Hex code (type L to list codes): 8e
Changed system type of partition 8 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          25      200781   83  Linux
/dev/sda2              26         662     5116702+  83  Linux
/dev/sda3             663        1044     3068415   83  Linux
/dev/sda4            1045        2610    12578895    5  Extended
/dev/sda5            1045        1426     3068383+  83  Linux
/dev/sda6            1427        1808     3068383+  83  Linux
/dev/sda7            1809        1935     1020096   82  Linux swap
/dev/sda8            1936        2179     1959898+  8e  Linux LVM

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.
[root@localhost ~]# vgdisplay
  --- Volume group ---
  VG Name               uservg
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  6
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               20.00 GB
  PE Size               4.00 MB
  Total PE              5119
  Alloc PE / Size       1280 / 5.00 GB
  Free  PE / Size       3839 / 15.00 GB
  VG UUID               RC3a86-rTJr-lTTC-7jrz-yiH0-B47h-nYKoLB
****15G ====>  uservg

[root@localhost ~]# mkfs.ext3 /dev/sda8
mke2fs 1.35 (28-Feb-2004)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
123648 inodes, 246991 blocks
12349 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=255852544
8 block groups
32768 blocks per group, 32768 fragments per group
15456 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376

Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 26 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

[root@localhost ~]# pvcreate /dev/sda8
  Physical volume "/dev/sda8" successfully created

[root@localhost ~]# vgextend uservg /dev/sda8
  /dev/cdrom: open failed: No medium found
  Volume group "uservg" successfully extended

[root@localhost ~]# vgdisplay
  --- Volume group ---
  VG Name               uservg
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  7
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                1
  Open LV               1
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               20.94 GB
  PE Size               4.00 MB
  Total PE              5360
  Alloc PE / Size       1280 / 5.00 GB
  Free  PE / Size       4080 / 15.94 GB
  VG UUID               RC3a86-rTJr-lTTC-7jrz-yiH0-B47h-nYKoLB
***not even 1G????????????????????

It only added half of it. Is that suppose to be like that? Thanks.

---------- Post updated at 02:28 PM ---------- Previous update was at 02:16 PM ----------

My mistake, it's really just

/dev/sda8               972404     17632    905376   2% /second
[root@localhost /]#

When I created to a regular linux partition, no space.. MY BAD!

Two comments:

  1. You can use the partprobe utility after fdisk to update the kernel partition information.

  2. You do not need to create a filesystem before using pvcreate.