Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I recently upgraded the harddrive from 20GB to 50Gb using the web interface of my cloud service.

But df -h:

  Filesystem      Size  Used Avail Use% Mounted on
  /dev/vda1        20G   19G   47M 100% /
  udev            488M  4.0K  488M   1% /dev
  tmpfs           200M  264K  199M   1% /run
  none            5.0M     0  5.0M   0% /run/lock
  none            498M     0  498M   0% /run/shm
  none            100M     0  100M   0% /run/user

Clearly not a 50 GB partition.

fdisk -l gives:

Disk /dev/vda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders, total 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
Disk identifier: 0x00064eed

 Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    41940991    20969472   83  Linux

Disk /dev/sda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders, total 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
Disk identifier: 0x00064eed

Device Boot Start End Blocks Id System /dev/sda1 * 2048 41940991 20969472 83 Linux

How do i proceed from here to make the partition a 50GB without loosing data.

OS is Ubuntu 12.10.

Update and "solution" After some help from the accepted solution i created mounted a new partition in the remaining 30GB free space and mounted it as my biggest subdirectory, /var:

Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        20G  7.7G   12G  42% /
udev            487M  4.0K  487M   1% /dev
tmpfs           200M  268K  199M   1% /run
none            5.0M     0  5.0M   0% /run/lock
none            498M     0  498M   0% /run/shm
none            100M     0  100M   0% /run/user
/dev/vda2        30G   13G   17G  43% /var
share|improve this question

2 Answers 2

up vote 1 down vote accepted

If there's only one partition, do this:

  • fdisk /dev/<drive>
    • p - observe current partitions.
    • d - delete entire the partition.
    • n - make new primary partition #1. Make sure it spans the whole disk (I've been able to just accept all the defaults)
    • a - make that partition bootable again.
    • p - make sure it looks like the output of the first print.
    • If needed, use t to change the partition type to match first print.
    • If everything looks right, w to write changes.
  • resize2fs /dev/<drive>1.

These steps have worked for me every time for VMs on my XenServer cluster.

As always, if there's any really important data, make sure you have a recent backup.

share|improve this answer
    
Doesn't the -d delete it? Does that mean lost data? And to be clear i should run fdisk with all the specified options? –  Rasmus Feb 2 '13 at 23:42
    
You should be good to go as long as the output of the second print looks the same as the first print - difference being partition size. The data is still there, you're just overwriting the partition table. Things become a bit more complicated if you have multiple partitions or are using LVM. –  livingstaccato Feb 3 '13 at 0:30
    
Also, from Wikipedia, "When a partition is deleted, its entry is removed from a table and the data is no longer accessible. The data remains on the disk until being overwritten." - en.m.wikipedia.org/wiki/Disk_partitioning#section_5 –  livingstaccato Feb 3 '13 at 0:31
    
Also, those weren't command line options I provided. Those are the commands you'd execute "in" fdisk. –  livingstaccato Feb 3 '13 at 0:47
    
Okay. Perhaps i will try on a random drive first. Would i know i had a LVM, since it is running from some virtualization software i have no clue of how works. At least i know i never installed some, and it is a one partition disk. –  Rasmus Feb 3 '13 at 1:05

If you are running an ubuntu-cloud image, it should have the cloud-init package installed by default, which should take care of this for you automatically.

share|improve this answer
    
But what to do when it doesn't? –  Rasmus Feb 3 '13 at 11:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.