LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 05-03-2019, 07:40 AM   #1
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Rep: Reputation: 103Reputation: 103
extending lvm/partition fdisk on Ubuntu 18.04


Hi,

I need to extend my lvm partition (I added 20GB to get 50GB in total), but I'm a little bit worried about editing the partition in fdisk. Normally, I delete the whole partition and recreate it with the full size that I'm permited, but in this case, the start sector of the newly created partition would be different from the current start sector used by sda2:
Code:
Command (m for help): p
Disk /dev/sda: 50 GiB, 53687091200 bytes, 104857600 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
Disklabel type: dos
Disk identifier: 0x3f82960d

Device     Boot   Start      End  Sectors  Size Id Type
/dev/sda1  *       2048  1499135  1497088  731M 83 Linux
/dev/sda2       1501182 62912511 61411330 29.3G  5 Extended
/dev/sda5       1501184 62912511 61411328 29.3G 8e Linux LVM
As you can see, the start sector of sda2 is 1501182, and I've no idea why that is, that is to say, I've no idea why it doesn't start from the following sector after the sector sda1 ends, i.e. 1499136. So if I delete partitions 2 and 5 and recreate them, then fdisk would say the default is the next sector (1499136) and not the starting sector currently being used by sda2.
So I guess the question would be, if, after deleting sda2 and sda5, I recreate partition sda2 starting from 1501182 (so keeping the same starting sector), would I then be able to extend my partition without any problems?

Last edited by vincix; 05-03-2019 at 07:56 AM.
 
Old 05-03-2019, 08:21 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,724

Rep: Reputation: 5918Reputation: 5918Reputation: 5918Reputation: 5918Reputation: 5918Reputation: 5918Reputation: 5918Reputation: 5918Reputation: 5918Reputation: 5918Reputation: 5918
sda2 is an extended partition which allows legacy MBR to have more then 4 partitions and is basically a container for logical partitions. Logical partitions have an ID>4.

I would increase sda2 to include the additional space. You can either create a new logical partition/PV and extend your root logical volume or extend sda5,PV and then enlarge your /root logical volume.
 
Old 05-03-2019, 08:56 AM   #3
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,780

Rep: Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213
Your partitions are actually nicely aligned. The placement of the extended partition, /dev/sda2, causes the actual data partition, /dev/sda5, to start exactly on a megabyte boundary. What is important is that your new /dev/sda5 start at exactly sector 1501184 as it does now.

You should be able to have fdisk create the new partitions with the current starting addresses. You don't have to accept the default. It's a lot easier, though, if you can use gparted to extend the partitions. It would just be a matter of selecting "Move/Resize" and then dragging the end of the partition to the end of the disk.
 
1 members found this post helpful.
Old 05-03-2019, 09:06 AM   #4
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Original Poster
Rep: Reputation: 103Reputation: 103
This is actually a server running as a virtual machine, so gparted is out of the question. I think I'm going to be using fdisk as it is. Thank you for the information!
 
Old 05-03-2019, 05:09 PM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,130

Rep: Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121Reputation: 4121
Quote:
Originally Posted by michaelk View Post
I would increase sda2 to include the additional space. You can either create a new logical partition/PV and extend your root logical volume or extend sda5,PV and then enlarge your /root logical volume.
By far the best option for a server IMHO.
Haven't done it in a while, but I think cfdisk would allow you to create a logical partition in the free space, and cfdisk will automagically enlarge the extended to cope. Then simply pvcreate.
 
Old 05-07-2019, 10:56 AM   #6
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Original Poster
Rep: Reputation: 103Reputation: 103
Am I mistaken, or is gparted not a graphical-only app? How would that be the best option? I'm probably missing something.

Anyway, I don't understand what happened exactly, but to be able create the same start sector (1501184) for sda5, I had to create sda2 starting with 1499136, otherwise 1501184 for sda5 would have been out of range! Really weird. So I deleted sda2 and 5, then I recreated both, sda2 with the default start sector, as I said, and the sda5 started also by default on the same initial sector (1501184). I had to restart the server unfortunately, as fdisk required me to. Then I expanded the pv and lv. Didn't try to do that before reboot so I'm not sure if it had worked, but I guess it shouldn't have worked, because the table information hadn't been changed.
 
Old 05-07-2019, 03:38 PM   #7
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,780

Rep: Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213
Yes, gparted is a GUI application.

fdisk can be quite anal about enforcing megabyte alignments, leading to pointless empty space between the start of the extended partition and the start of the first logical drive therein. There are some annoying ways to work around that, but as long as you have that logical drive with the correct starting sector you're OK.

Indeed, trying to expand the PV and LV would accomplish nothing until the system has been rebooted so that the kernel recognizes the new partition sizes. Fortunately, you can do that while the system is online.
 
1 members found this post helpful.
Old 05-08-2019, 02:56 PM   #8
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Original Poster
Rep: Reputation: 103Reputation: 103
Thanks for the answer.
I'm still puzzled by the suggestion, that is to say, installing a GUI app on a linux server. It's safe to assume that I'm not running any gui apps on it and I wouldn't install all those gtk dependencies and what not I've nothing against gui interfaces, there are very useful for various contexts, but I would expect linux to be able to provide (which it does) the necessary cli tools to solve these types of problems. I'm guessing parted would have been enough, if fdisk is so fickle

Sorry, later on did I realise that there was no mention of the word "server" in my posts, so probably that's where the misunderstanding stemmed from (although I'm posting in the Linux-Server thread )

Last edited by vincix; 05-08-2019 at 03:00 PM.
 
Old 05-09-2019, 08:59 AM   #9
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,780

Rep: Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213
I wasn't intending to suggest that you install a GUI on your server, just acknowledging that gparted is indeed a GUI aplication and thus not a suitable tool for your environment. I could have been clearer about that. Sorry for the misunderstanding.
 
1 members found this post helpful.
Old 05-10-2019, 03:38 AM   #10
vincix
Senior Member
 
Registered: Feb 2011
Distribution: Ubuntu, Centos
Posts: 1,240

Original Poster
Rep: Reputation: 103Reputation: 103
Yeah, no worries, I was more interested in making this clearer to myself Thank you for your answers.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Extending a partition with LVM, "device not found" koichirose Ubuntu 10 04-07-2015 04:38 PM
extending volume group vs extending physical volume which is better ? Gil@LQ Linux - Server 2 08-19-2013 10:13 AM
extending existing windows-partition and changing os on linux partition ungua General 8 05-05-2009 11:01 AM
Extending LVM partition?? your_shadow03 Linux - Newbie 3 01-16-2009 02:43 AM
Extending home partition with LVM The_Outlander Slackware 2 01-03-2007 08:13 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 02:43 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration