How to resize an LVM root partition

68495 pts.
Tags:
Linux administration and management
Linux servers
LVM
LVM2
Ubuntu Server 10.04 LTS
Ubuntu Servers
VMware Server
I'm trying to resize the root partition of an Ubuntu 10.04 server which is an LVM partition, but I don't seem to find the correct way to do it. This is my current partition table:
Disk /dev/sda: 16.1 GB, 16106127360 bytes
255 heads, 63 sectors/track, 1958 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0004f39a

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          32      248832   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              32         523     3942401    5  Extended
Partition 2 does not end on cylinder boundary.
/dev/sda5              32         523     3942400   8e  Linux LVM
The first thing I've been trying to do is resizing the physical volume, but although pvresize's output tells me that the volume was resized, it keeps showing the same size, so I must be missing something.
root@v-ubuntu-server:~# pvs
  PV         VG              Fmt  Attr PSize PFree
  /dev/sda5  v-ubuntu-server lvm2 a-   3.76g 40.00m
root@v-ubuntu-server:~# pvresize /dev/sda5
  Physical volume "/dev/sda5" changed
  1 physical volume(s) resized / 0 physical volume(s) not resized
root@v-ubuntu-server:~# pvs
  PV         VG              Fmt  Attr PSize PFree
  /dev/sda5  v-ubuntu-server lvm2 a-   3.76g 40.00m
This is a virtual non-production server and I have a backup of the virtual disk, so I can play with the partition table without much worries. As I understand, I should resize the pv (which is already part of a physical group), or create a new pv and add it to the physical group, which will allow me to extend or resize the logical volume.  Am I correct ? As shown above, the disk capacity is 16.1 GB., but the pv is only ~4 GB. Can somebody tell me what is the exact (and complete) procedure to increase the size of the root partition in this case ? Thank you.

Software/Hardware used:
Ubuntu server 10.04 running as a virtual server on VMWare server 2.02

Answer Wiki

Thanks. We'll let you know when a new response is added.

This is how I did it without the need to unmount the filesystem. Any suggestions or comments are welcome.

<b>I used ‘parted’ to create a new partition, because fdisk didn’t allow me to do it using all the available disk space (not sure why):</b>

<pre>root@v-ubuntu-server:~# parted
GNU Parted 2.2
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mkpart
Partition type? primary/logical? p
File system type? [ext2]? ext3
Start? 4295MB
End? 16.1GB
(parted) print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 16.1GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system Flags
1 1049kB 256MB 255MB primary ext2 boot
2 257MB 4294MB 4037MB extended
5 257MB 4294MB 4037MB logical lvm
3 4295MB 16.1GB 11.8GB primary

(parted) quit</pre>

<b>Then I used ‘fdisk’ to change the new partition’s system type (and rebooted):</b>

<pre>root@v-ubuntu-server:~# fdisk /dev/sda
Command (m for help): t
Partition number (1-5): 3
Hex code (type L to list codes): 8e
Changed system type of partition 3 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/sda: 16.1 GB, 16106127360 bytes
255 heads, 63 sectors/track, 1958 cylinders, total 31457280 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0004f39a
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 499711 248832 83 Linux
/dev/sda2 501758 8386559 3942401 5 Extended
/dev/sda3 8388608 31457279 11534336 8e Linux LVM
/dev/sda5 501760 8386559 3942400 8e Linux LVM

Command (m for help): w
The partition table has been altered!

root@v-ubuntu-server:~#reboot</pre>

<b>Then I used ‘pvcreate’ to create a new physical volume on the new partition:</b>

<pre>root@v-ubuntu-server:~# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created
root@v-ubuntu-server:~# pvdisplay
--- Physical volume ---
PV Name /dev/sda5
VG Name v-ubuntu-server
PV Size 3.76 GiB / not usable 2.00 MiB
Allocatable yes
PE Size 4.00 MiB
Total PE 962
Free PE 10
Allocated PE 952
PV UUID OpMrER-MOYR-Gvbs-Tj5C-p7qk-RVKQ-Uj0t8j
"/dev/sda3" is a new physical volume of "11.00 GiB"
--- NEW Physical volume ---
PV Name /dev/sda3
VG Name
PV Size 11.00 GiB
Allocatable NO
PE Size 0
Total PE 0
Free PE 0
Allocated PE 0
PV UUID NBMuFT-OScr-Gi2V-YrbZ-FvKJ-42Ba-erFXAn</pre>

<b>Then I used ‘vgextend’ to extend the volume group:</b>

<pre>root@v-ubuntu-server:~# vgextend v-ubuntu-server /dev/sda3
Volume group "v-ubuntu-server" successfully extended
root@v-ubuntu-server:~# vgdisplay
--- Volume group ---
VG Name v-ubuntu-server
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 14.75 GiB
PE Size 4.00 MiB
Total PE 3777
Alloc PE / Size 952 / 3.72 GiB
Free PE / Size 2825 / 11.04 GiB
VG UUID 6ezLMq-gXF2-33aW-IG25-mL3h-1VEb-0gXJea</pre>

<b>Then I used ‘lvextend’ to extend the logical volumne:</b>

<pre>root@v-ubuntu-server:~# lvextend /dev/v-ubuntu-server/root /dev/sda3
Extending logical volume root to 14.50 GiB
Logical volume root successfully resized

root@v-ubuntu-server:~# lvdisplay
--- Logical volume ---
LV Name /dev/v-ubuntu-server/root
VG Name v-ubuntu-server
LV UUID 1w688l-2PCs-ABuf-FVOz-Vql1-ADJM-jelQaL
LV Write Access read/write
LV Status available
# open 1
LV Size 14.50 GiB
Current LE 3712
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 251:0</pre>

<b>And finally, I used ‘resize2fs’ to resize the file system:</b>

<pre>root@v-ubuntu-server:~# resize2fs /dev/v-ubuntu-server/root
resize2fs 1.41.11 (14-Mar-2010)
Filesystem at /dev/v-ubuntu-server/root is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1

Performing an on-line resize of /dev/v-ubuntu-server/root to 3801088 (4k) blocks.
The filesystem on /dev/v-ubuntu-server/root is now 3801088 blocks long.

root@v-ubuntu-server:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/v--ubuntu--server-root
15G 701M 13G 6% /
none 1.1G 188K 1.1G 1% /dev
none 1.1G 0 1.1G 0% /dev/shm
none 1.1G 36K 1.1G 1% /var/run
none 1.1G 0 1.1G 0% /var/lock
none 1.1G 0 1.1G 0% /lib/init/rw
/dev/sda1 228M 17M 200M 8% /boot
root@v-ubuntu-server:~#exit</pre>

And that was it.

The last two steps were mentioned in the answer below, but some other things needed to be done before, and it wasn’t necessary to use a live cd and unmount the filesystem.

If there is a better way to do it, please share it.

Thanks,

CarlosDL

———————

The partition that is to be resized must be unmounted when u do the resizing; obviously this is not possible if this is the partition that holds all important system files like as per ur q.
Therefore u have to download a Live Linux-CD such as Knoppix from which u boot later on (if you have physical access to the system). you need a rescue system on that system that you can boot into (instead of Knoppix), and this rescue system must have the following tools:
fdisk, umount, fsck, tune2fs, e2fsck, resize2fs.

If you want to resize partitions on production systems i.e /, please back up your data before, because it is possible you lose all your data if you don’t calculate the size of your new partition correctly.
When you’ve booted using rescue cd,

* if you expand a partition, first allocate new space using lvextend, then use filesystem to that partition
* if you shrink a partition, first use filesystem to shrink it, after that use lvreduce
* dont’ use lvresize
For ur better understand, I put here as :
Here’s how I would extend my root partition, which is:

/dev/VolGrp00/LVRoot
sudo lvextend -L +1GB /dev/VolGrp00/LVRoot
sudo resize2fs /dev/VolGrp00/LVRoot

It may be ask to run filesystem checking, so do as you have done earlier.

Hope it will help you some.

-Rechil

Discuss This Question: 3  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • carlosdl
    Thanks Rechil. I know this can be done on-line, I just don't seem to find the exact procedure. In your example, before using lvextend, you must have added some space to the VolGrp00 group, right ? how did you do it ? did you create a new pv, or did you resize an existing pv ? how did you do it ?
    68,495 pointsBadges:
    report
  • Subhendu Sen
    Dear Carlosdl, I didn't mention the full procedure in my earlier answer. Just I gave you, the brief discussion on the matter. As of your last question I didn't create a new PV, rather I re-sized the existing PV. Hope it will help you.
    27,510 pointsBadges:
    report
  • Mihajlo
    Works perfectly on ubuntu 11.10 server, thanks!
    10 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following