5

I have the following situation:

enter image description here

Where I would like to extend the size of nvme0n1 from 8GB to 78 GB using the command line.

Adding also fdisk as requested in comments:

enter image description here

Any help is appreciated.

Melebius
  • 11,121
  • 8
  • 50
  • 77
criticalth
  • 151
  • 1
  • 7
  • Try using `sudo resize2fs /dev/nvme0n1p1` – Mohammad Kholghi Oct 02 '19 at 08:07
  • 1
    I ran it and I get "The filesystem is already 2096891 (4k) blocks long. Nothing to do!" – criticalth Oct 02 '19 at 08:10
  • First, create a new partition using `sudo fdisk /dev/nvme`, then format it and after all, resize your partition using `resize2fs`. – Mohammad Kholghi Oct 02 '19 at 08:18
  • @MohammadKholghi Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): n All space for primary partitions is in use. – criticalth Oct 02 '19 at 08:20
  • 1
    Please add a screenshot of `fdisk -l /dev/nvme` to your question. – Mohammad Kholghi Oct 02 '19 at 08:24
  • Do this carefully. I don't accept any responsibilities for data loss: https://askubuntu.com/questions/24027/how-can-i-resize-an-ext-root-partition-at-runtime – Mohammad Kholghi Oct 02 '19 at 08:31
  • Be carefull. It doens't use `fdisk /dev/sda1`, but `fdisk /dev/sda`. So you should use `fdisk /dev/nvme`. To find the correct device, do `ls /dev/nvme*`. I repeat: don't call `fdisk` for a partition, but call it with the whole device. – Mohammad Kholghi Oct 02 '19 at 08:34
  • I don't think you can do this while the root filesystem is mounted. Why not do this with a livedisk/usb? – PonJar Oct 02 '19 at 08:34
  • @PonJar It's possible using `Gparted`. I did the same some minutes age. – Mohammad Kholghi Oct 02 '19 at 08:39
  • @MohammadKholghi please stop suggesting dangerous and/or wrong solutions. You can not expand a mouted filesystem/partition in Ubuntu. – Soren A Oct 02 '19 at 08:59
  • @SorenA Absolutely Using a live media is the best way, but I did extend my root partition some minutes ago. Just need to run `partprobe` to `inform the OS of partition table changes`, according to last line of `fdisk` output or `man partprobe`. Or, at last, after a normal restart everything will be fine automatically. – Mohammad Kholghi Oct 02 '19 at 09:10
  • 1
    Please do not [post screenshots of the terminal](https://meta.askubuntu.com/q/8713/250300). Paste the text directly to your question and apply [code formatting](https://askubuntu.com/editing-help#code). – Melebius Oct 02 '19 at 09:22

2 Answers2

2

This looks like an AWS EC2 instance you are adding a new volume to. You started correctly by listing the available devices.

Then, you need to create a file system on the new device (use sudo file -s to check if there is a file system already) with:

sudo mkfs -t ext4 /dev/nvme0n1p1

Then, make a directory on where you want to mount it:

sudo mkdir /mydata

And mount it:

sudo mount /dev/nvme0n1p1 /mydata

Finally, add it to fstab for auto mounting by editing fstab (back it up first) using:

sudo nano /etc/fstab

with the info from:

sudo lsblk -o +UUID

Test by unmounting the file system and then mounting it again with the next commands:

sudo umount /mydata
sudo mount -a

Hope this helps.

BeastOfCaerbannog
  • 12,964
  • 10
  • 49
  • 77
DGenchev
  • 136
  • 3
1

Unfortunately, you cannot extend your root partition since it’s filling all of the available space on the device nvme0n1. If you want to utilize the space of the device nvme1n1, you can:

  • Use LVM for your root partition. A logical volume can spread across multiple disks using LVM. However, this would need reinstalling your system or backing it up, preparing LVM volumes and restoring current data.
  • Use nvme1n1 for a partition below your root, e.g. a separate /home or /var partition.

See also

Melebius
  • 11,121
  • 8
  • 50
  • 77