[Lincoln LUG] disk size

Terry Froy tez+lincoln-lug at spilsby.net
Thu Oct 5 16:59:17 UTC 2017


Hi Andrew,

As long as the partition you need to grow is the one at the end of the disk, you can do this without using 3rd party tools.

The first thing you do is to take a backup of the partition table:

sfdisk -d /dev/vda > /root/sfdisk-part-backup.txt
(the -d is for dump)

Copy sfdisk-part-backup.txt over to removable media Just In Case(tm).

Once you have done this, run regular fdisk as superuser and:

* Print the partition table (making note of start sector and partition type).
* Delete the partition - this removes the partition info from the partition table - but until you enter 'w' to write the partition table, nothing on disk will be touched.
* Create a new partition - ensure the start sector matches what you noted down when you printed the partition table, the end sector should be higher than the one you noted down - otherwise, you won't be growing the partition.
* Set the partition type to match that of what you noted down.
* Print the partition table again (verifying that start sector and partition type match that of the old partition).
* If the start sector and partition type do not match, 'q' and then ENTER to exit without committing changes to disk.
* Write the partition table to disk ('w' and then ENTER).
* Quit fdisk ('q' and then ENTER).
* Reboot the machine.
* When the machine comes back up, use resize2fs or whatever utility is necessary to grow the filesystem in that partition.

It is perfectly safe to do this while the underlying filesystem is mounted as fdisk does not touch the contents of the partition, merely the information which is held about the partition.

If you get it wrong and the machine does not boot (you hit problems, etc), boot with a Live CD, insert the removable media which has the partition table backup on and then do:

cat sfdisk-part-backup.txt | sfdisk /dev/vda

This will restore the backup of the partition table and you should then be able to boot your system without removable media.

Regards,
Terry Froy
Spilsby Internet Solutions
http://www.spilsby.net/

----- Original Message -----
From: "Andrew Walmsley via Lincoln" <lincoln at mailman.lug.org.uk>
To: "Lincoln LUG mailing list" <lincoln at mailman.lug.org.uk>, "corenominal at corenominal.org" <philip.newborough at gmail.com>
Sent: Tuesday, 3 October, 2017 11:37:23 PM
Subject: [Lincoln LUG] disk size



hi everyone 


Is there a way of resizing a disk that is in use? Running a debian server (no gui) with 1 drive that was set to 5gb, which is now running out of space. yes i know its a stupid size (not my fault). Increased the vm to see 10gb. 


diskpart is no good as i'm booting to the drive which is mounting. 


What is best way round? mount a live cd? add an extra drive? 


Help! 






andy 














-- 
Lincoln mailing list
Lincoln at mailman.lug.org.uk
https://mailman.lug.org.uk/mailman/listinfo/lincoln



More information about the Lincoln mailing list