Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Resize partition under Ubuntu
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Resize partition under Ubuntu

blackjack4494blackjack4494 Member
edited May 2019 in Help

Recently I got a free SSD upgrade for my server.
Instead of 20GB I now have 30GB.
But I actually never had to do such thing like resizing a partition in an existing machine.

So here is the output of lsblk

# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0     11:0    1 1024M  0 rom
vda    252:0    0   30G  0 disk
└─vda1 252:1    0   20G  0 part /

I don't have a full backup of the server so that is what I do know. Until now it was enough for me to have backups of the important services there.

So my question now is it enough to use resize2fs or do I have to use fdisk in advance to accomplish my task?

Hopefully no server will be harmed during the process :P

Comments

  • uptimeuptime Member
    edited May 2019

    use resize2fs or do I have to use fdisk in advance

    yes :)

    EDIT2:

    fdisk /dev/vda
    

    inside fdisk, type p to list partitions - note the block where /dev/vda1 starts

    take a deep breath

    then d to delete the first and only partition /dev/vda1 (this only deletes partition table info which was specifying the old 20 GB size, the filesystem itself will not be changed by this operation)

    then n to create a new 30 GB /dev/vda1 partition - just make sure this starts at the same block that the previous instance that you just deleted did. (It's nice if the old /dev/vda1 started at the default value but I won't assume that and neither should you.)

    Also, assuming this is Linux filesystem ("id 83") then no need to specify that (otherwise type t and set whatever other partition type)

    type p again to make sure your new 30 GB /dev/vda1 partition is bootable if it was before

    (type a to toggle the boot flag if necessary)

    if you've mistyped something along the way, type q to exit without saving so you can start over.

    otherwise type w to write the new partition table and exit fdisk.

    Then you're ready for the resize2fs operation - you actually will have to run e2fsck with some flag that I forget at the moment before resize2fs will do its thing ... (but resize2fs will tell you exactly what to do if you just go ahead and run it first, so that's what I usually do.)

  • MikeAMikeA Member, Patron Provider

    resize2fs /dev/vda1

  • Thanks @uptime
    I managed to sucessfully resize the partition.

    Tho I came across one important thing - it asks me whether I want to remove the ext4 signature. I used google and got results where they advised to not do it!
    Somehow the fourth search result was a link to Hetzner
    https://wiki.hetzner.de/index.php/Resize_Ext_Partition

    In the end I followed the steps (similar to yours) but I did not need e2fsck. So resize2fs did it all at the end to finish the task.

    Thanked by 1uptime
  • uptimeuptime Member

    glad to hear that worked - that "delete the existing partition" step is a fine example of Unix-style YOLO™ way ... just a bit nerve-wracking "wtf, really?" if you haven't seen it done before (and a good way to screw up your system if you mis-type something anyway). So I was a bit glib to offer that recipe from memory without triple-checking the steps described ....

    I do see the e2fsck bit included in the Hetzner writeup but perhaps it could be skipped in some situations if resizing a fresh filesystem or whatever ...

    5. do a filesystem check
    
    root@rescue ~ # e2fsck -f -C0 /dev/sda1
    
  • msg7086msg7086 Member

    sfdisk would have been easier.

    sfdisk -d /dev/vda > par.txt
    vim par.txt
    sfdisk /dev/vda < par.txt
    
    Thanked by 1uptime
  • With LVM this things are much easier

    Thanked by 1uptime
  • @uptime said:
    glad to hear that worked - that "delete the existing partition" step is a fine example of Unix-style YOLO™ way ... just a bit nerve-wracking

    Yeah I mean if you do understand that no actual data will be deleted but the partition table, you won't be that scared but still. If you fk it up and have no backup it will probably gone anyway :D

    Thanked by 1uptime
  • simlevsimlev Member

    ese_enzo said: With LVM this things are much easier

    Yes, everybody keeps saying so, please teach me how lvm can make my life easier in this instance.
    In my experience I had to:

    • enter parted
    • issue the command print
    • issue the command resizepart
    • choose the lvm partition number
    • choose 100%
    • save
    • quit

    And then:

    pvs -v --segments
    lvresize --verbose --resizefs --extents <desired total number of 4MB blocks> /dev/vg/root
    resize2fs /dev/mapper/vg-root
    

    Depending on your specific situation, the last commands may be condensed to:

    lvresize --verbose --resizefs --extents +100%FREE /dev/vg/root
    

    but in my case I wanted to leave space for a swap partition, and lvresize didn't accept --resizefs for a reason I can't remember (something else having changed).

    Thanked by 1AlwaysSkint
  • AlwaysSkintAlwaysSkint Member
    edited May 2019

    Though I use LVM, I have found no real advantage over good ol' partitioning, when not dealing with spanned volumes. Boot from systemrescueCD and you even get a GUI, to resize your partitions (gparted).
    (Never liked the concept of spanned volumes, though I dare say it's useful in large installations.)

  • simlevsimlev Member

    AlwaysSkint said: you even get a GUI, to resize your partitions (gparted)

    Yes, it must be highlighted that GParted does not fully handle lvm.

    Thanked by 1AlwaysSkint
  • AlwaysSkintAlwaysSkint Member
    edited May 2019

    @simlev said:

    AlwaysSkint said: you even get a GUI, to resize your partitions (gparted)

    Yes, it must be highlighted that GParted does not fully handle lvm.

    Aye, I didn't make that clear distinction and was referring to traditional partitioning. Much as I hate the complexity/non-intuitive webmin, it can handle LVM, though good luck when altering live production systems!

Sign In or Register to comment.