This question already has an answer here:

I would like to extend a partition without booting from a LiveCD and also from the command line, because I'm writing a bash script.

GParted Partition Manager

I want to extend the /dev/sda5 partition. I already tried sudo resize2fs /dev/sda5 1G which didn't work.

marked as duplicate by Rod Smith, Sumeet Deshmukh, Eric Carvalho, Charles Green, David Foerster Jul 6 '17 at 8:49

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    The key symbol indicates that partition /dev/sda5 is mounted. Unmount it! After that you can expand it into the unallocated space to the right. – sudodus Jul 4 '17 at 13:53
  • @sudodus I unmounted it and ran sudo resize2fs /dev/sda5 1G again. Then I get the error message that the new size is too big even tough the unallocated space is big enough. – B. Krauss Jul 4 '17 at 13:58
  • You must expand the partition (the container) before you expand the file system. gparted will do both for you (and can be installed if you run a system with a graphical window manager or desktop environment). Otherwise you must do it in steps for example starting with the text mode tool parted. – sudodus Jul 4 '17 at 14:21
  • I've looked at your gparted screenshot, and it looks kind of messed up. As it sits right now, you'll only be able to gain an additional 2G to sda5. Why use sda5 vs using space on sda1? Why use command line vs gparted GUI? Using gparted, I can outline the steps, but I'll need more information before I do. Please start new comments to me with @heynnema or I may miss them. – heynnema Jul 4 '17 at 21:05
  • @heynnema I want to use the command line and parted, because I am writing a script which extends one partition. And that script is run by a AI machine. But thanks anyway. – B. Krauss Jul 6 '17 at 7:12