LiTWol @ Oleg Terenchuk

  • Contact
  • Tips & Tricks
  • About me

User login

  • Request new password
To prevent automated spam submissions leave this field empty.

litwol's tweets

  • Doing something differently leads to something exceptional — 2 years 32 weeks ago
  •  
  • 1 of 9
  • ››
more
Home

fdisk resize/grow physical partition without losing data on linode.com

Submitted by litwol on Sun, 11/20/2011 - 20:16

Linode.com have yet again increased members' hdd storage for free (article) and I ended up with physical VPS disk of 20GB and pre-increase partition of 16GB. Most users can resize their disk image in linode dashboard and after reboot VPS will recognize increased disk size and all will be zen. But if you're a power user like me (with endless experiments' inflicted headaches) you are probably using raw disk image with multiple partitions one of which is for LVM and you want to grow it to occupy all the extra space. Read on.

For the impatient:
Resizing single physical partition to occupy entire drive space is done using fdisk by first deleting your existing patition and then recreating it with EXACTLY SAME STARTING SECTOR NUMBER. ending sector can be anything you want (by default fdisk selects very last sector number to give your partition maximum size). If everything done correctly your data will be unharmed on next reboot.

Long version:
Initially this is what my disk looked like (using fdisk -u sectors -l )

Disk /dev/xvdc: 20.8 GB, 20765999104 bytes
255 heads, 63 sectors/track, 2524 cylinders, total 40558592 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: 0x00000000

    Device Boot      Start         End      Blocks   Id  System
/dev/xvdc1              63    32162129    16081033+  8e  Linux LVM

Few very important things to note here, and make sure to write them down as they will be crucial to final steps of resizing filesystem):
1) starting sector is "63". it is crucial, without this information your resize will fail.
2) partition system id is "8e" which in human terms is called 'Linux LVM'

Lets begin
1) reboot into "Rescue" mode on your linode dashboard. Be sure to note which device your LVM drive is mapped to (my mapped to /dev/xvdc)
2) delete and recreate larger partition using fdisk

$ fdisk -u sectors /dev/xvdc
(fdisk) Command (m for help): d
(fdisk) Partition number (1-4): 1
(fdisk) Command (m for help): n
(fdisk) Partition type:
p primary
e extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (63-40558591, default 63): 63
Last sector, +sectors or +size{K,M,G} (63-40558591, default 40558591): [PRESS ENTER TO ACCEPT LARGEST DEFAULT]
(fdisk) Command (m for help): t
Partition number (1-4): 1
Hex Code (type L to list codes): 8e
(fdisk) Command (m for help): w

3) reboot into normal non-rescue OS on your linode.

At this on my linode fdisk reported the following (compare with above initial fdisk -l)

Disk /dev/xvdc: 20.8 GB, 20765999104 bytes
255 heads, 63 sectors/track, 2524 cylinders, total 40558592 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: 0x00000000

    Device Boot      Start         End      Blocks   Id  System
/dev/xvdc1              63    40558591    20279264+  8e  Linux LVM

Since you are using LVM you already probably know that increasing physical partition does not automatically resize your logical partitions. I am leaving it as exercise to the reader to find out how to resize their lvm volumes. (hint first look at pvresize, then use lvresize on individual logical volumes to redistribute new free space as necessary).

Tags:
  • fdisk
  • tips

2 reponses to "fdisk resize/grow physical partition without losing data on linode.com"

1. Thanks, was a bit unsure

Submitted by Anonymous on Thu, 03/22/2012 - 04:43.

Is the fdisk -u sectors really needed?

Thanks anyway

  • reply

2. Yes it is necessary.

Submitted by litwol on Tue, 03/27/2012 - 18:02.

Yes it is necessary. Depending on your operating system, it may have different default enabled for fdisk. passing explicit unit flag ensures consistency in what you are doing.

  • reply

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <h2> <br>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Lines and paragraphs break automatically.

More information about formatting options

To prevent automated spam submissions leave this field empty.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.

LiTWoL © Oleg Terenchuk - Hosted on Linode.com 512