[SOLVED] extending lvm/partition fdisk on Ubuntu 18.04
Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
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.
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.
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!
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.
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.
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.
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 )
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.