Score:-1

Extending a partition in ubuntu 14

ng flag

I've been trying to follow several of the guides and articles on this forum and others on how to extend my current Linux LVM partition.

Here are the current partitions I have. I don't understand how both sda2 and sda5 are the same blocks is my first issue. And my second is that I don't know which to select to extend?

:/var$ sudo fdisk -l

Disk /dev/sda: 2199.0 GB, 2199023255552 bytes
255 heads, 63 sectors/track, 267349 cylinders, total 4294967296 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: 0x0005011b

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      499711      248832   83  Linux
/dev/sda2          501758  1782577151   891037697    5  Extended
/dev/sda5          501760  1782577151   891037696   8e  Linux LVM

Disk /dev/mapper/webserver--vg-root: 908.1 GB, 908129730560 bytes
255 heads, 63 sectors/track, 110407 cylinders, total 1773690880 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: 0x00000000

Disk /dev/mapper/webserver--vg-root doesn't contain a valid partition table

Disk /dev/mapper/webserver--vg-swap_1: 4290 MB, 4290772992 bytes
255 heads, 63 sectors/track, 521 cylinders, total 8380416 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: 0x00000000

Disk /dev/mapper/webserver--vg-swap_1 doesn't contain a valid partition table

How do I extend these properly without risking losing data? I am concerned I am going to mess up this server and its contents.

Thank you

Adding the output for lvdisplay:

--- Logical volume ---
LV Path                /dev/webserver-vg/root
LV Name                root
VG Name                webserver-vg
LV UUID                UfPECP-g3Ed-BYTv-GV1x-mkMk-Of1e-ujcM1t
LV Write Access        read/write
LV Creation host, time webserver, 2015-02-10 10:09:20 -0500
LV Status              available
 open                 1
LV Size                845.76 GiB
Current LE             216515
Segments               2
Allocation             inherit
Read ahead sectors     auto
- currently set to     256
Block device           252:0

--- Logical volume ---
LV Path                /dev/webserver-vg/swap_1
LV Name                swap_1
VG Name                webserver-vg
LV UUID                Hi6pMH-wrXI-H1MC-91Iu-V2ev-xven-Cna9Hc
LV Write Access        read/write
LV Creation host, time webserver, 2015-02-10 10:09:20 -0500
LV Status              available
 open                 2
LV Size                4.00 GiB
Current LE             1023
Segments               1
Allocation             inherit
Read ahead sectors     auto
- currently set to     256
Block device           252:1
in flag
Ubuntu 14.04 has reached its end of life. Update to a supported version.
Score:1
in flag

sda5 is a logical partition. It resides within the Extended partition (sda2). I'm assuming this is an older machine/install using Master Boot Record (MBR). Even under MBR, the Extended partition isn't really necessary. Having a Primary/Extended/Logical partition was for backwards comparability with earlier versions of DOS/Windows (Linux supports 4 primary partitions on MBR where DOS/Win95 only supported primary/extended, and newer GPT partitions elimination the limitations entirely).

/dev/mapper/webserver--vg-root is a logical volume, that resides within sda5. Logical volumes are used to abstract away the underlying disk. You can use vgdisplay to display the volume group (there should be one) and lvdisplay to list the individual volumes within that group (you should have two, one for swap and the other for root).

Did you copy your partitions to a larger hard drive? If so, you would need to adjust sda2 and sda5 to have the same start block, but a new ending block (the end of the disk). You can do that with fdisk by deleting and recreating the partition. After this is done, vgextend can be used on the entire volume group to extend it to the end of the partition. You can then use the various lv* commands (lvdisplay, lvextend, etc.) to extend or move around the individual volumes.

Be sure to backup all your data before changing partitions or volume groups

The following set of commands should work for your situation. You may have to install parted. Alternatively, you could install cloud-utils and use the growpart command:

# via parted
parted /dev/sda resize 2 100%
parted /dev/sda resize 5 100%

# OR using cloud-utils / growpart
growpart /dev/sda 2
growpart /dev/sda 5

# Then have Linux re-read your partition talbe
partprobe /dev/sda

# Then expand your Physical Volume

pvresize /dev/sda5

# Extend the logical root volume
lvextend -l +100%FREE /dev/webserver-vg/root

# Extend the filesystem (assuming you're using ext2/3/4)
resize2fs /dev/webserver-vg/root
HaydBooksIt avatar
ng flag
Thank you for your detailed response! I have provided more space through the VMware ESXi where I expanded the available space from the 840~ GB to roughly 2TB. Now I want to extend the existing partition so I don't run out of space and have to clear logs down so often. lvdisplay output is as follows; --- Logical volume --- LV Path /dev/webserver-vg/root LV Name root VG Name webserver-vg LV UUID UfPECP-g3Ed-BYTv-GV1x-mkMk-Of1e-ujcM1t LV Write Access read/write
HaydBooksIt avatar
ng flag
LV Creation host, time webserver, 2015-02-10 10:09:20 -0500 LV Status available # open 1 LV Size 845.76 GiB Current LE 216515 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 252:0 --- Logical volume --- LV Path /dev/webserver-vg/swap_1 LV Name swap_1 VG Name webserver-vg LV UUID Hi6pMH-wrXI-H1MC-91Iu-V2ev-xven-Cna9Hc
in flag
Don't add code down in comments. Add them to the bottom of your original question. Approve the edit I made to format your original code correctly (not sure if you can, might need a mod). Since you're on VMWare, snapshot the volume first to back it up. Use fdisk and delete `sda2` and `sda5`. Recreate them with the same start block and the new end block. `partprobe` will refresh the partition table. `vgextend` will extend the volume group, then `lvextend` can extend the volume and then finally `resize2fs` (assuming ext2,3,4) will resize your filesystem.
HaydBooksIt avatar
ng flag
My main concern is losing data. I have Veeam backups, but have not had to restore any of these Ubuntu ones before. So I would prefer not having to. Do I have to delete sda2 and sda5 to achieve extending? I know this may be a frustrating question for me to ask, since I'm asking for help. I just was hoping to extend by just adding blocks to the end, but I suppose that may just not be possible?
in flag
I submitted another formatting edit. 4 spaces before a line puts it in a code block (or using three backticks before and after). You're not deleting the partition in fdisk. You're modifying the partition table. So you delete it and recreate it with the same start value and new end value. If you're uncomfortable with this concept, you can use `parted` and the `resizepart` command, first on `sda2` and then on `sda5`. I've updated my answer. I have not tested it, so please ensure you have backups.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.