LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   fdisk resize partitioning of a system disk (safe?) (https://www.linuxquestions.org/questions/linux-newbie-8/fdisk-resize-partitioning-of-a-system-disk-safe-4175429459/)

ted_chou12 09-28-2012 11:01 AM

fdisk resize partitioning of a system disk (safe?)
 
Hi, I currently have a system disk with 3 partitions all ext3, but currently I am experiencing lack of space in sda1 (system disk), so I wish to resize it and make it bigger. I want to know if this would erase any data on sda1.

current
sda1 63 7807589 3903763
sda2 7807590 8803619 498015
sda3 8803620 156301487 73748934

afterwards
sda1 63 50000000 24999968.5
sda2 50000001 50996030 498014.5
sda3 50996031 156301487 52652728

sda1 is system boot disk with / root directory. sda2 is swap only about 512mb big and sda3 is what i mount to /mnt for media and stuff.

This is the current sda:
Code:

Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders, total 156301488 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: 0x5560f0fb

  Device Boot      Start        End      Blocks  Id  System
/dev/sda1  *          63    7807589    3903763+  83  Linux
/dev/sda2        7807590    8803619      498015  83  Linux
/dev/sda3        8803620  156301487    73748934  83  Linux

I don't want to erase any stuff on my current system disk sda1 and also on the media sda3. (ofcourse sda2 is swap, thus blank)
I have already tried this on a flash disk (2gb) and this does not cause files in the 2 partitions to erase when I resize them with fdisk. But I wish to confirm this with more experienced linux experts here.
Thanks,
Ted

michaelk 09-28-2012 01:23 PM

In a nutshell no. The correct utility to use is gparted running from a live CD or USB drive. There are actually several steps that are required that fdisk is incapable of doing. I am not sure what you were actually doing with your test disk but fdisk can not shrink or move a filesystem.

Basically you want to shrink sda3 and move it to the end of the disk.
Move sda2 next to sda3
Enlarge sda1

Always backup any and all important data just in case something bad happens.

JaseP 09-28-2012 01:43 PM

Also,...to add to MichaelK's reply,... I highly recommend you do each step separately, one at a time...

Gparted becomes inefficient when you have it try to do multiple steps in the same procedure.

rmknox 09-28-2012 02:27 PM

I have done exactly what you want to do - here is an outline - I'll give more detail if you care

Buy a second disk. If the current disk is full - buy a bigger disk. Disks are cheap. You can get an 80 gb maxtor used on ebay including delivery for $25, same price for pata or sata - just be careful to get the right one.

Create 3 partitions on the second disk. First bigger than current, second and third same size as current.

From either your existing disk or a live CD, copy the three existing partitions to the new partitions on the second disk.

Chalk up the cost of the new disk to experience.

if old disk is on sda and new is on sdb

dd if=/dev/sda of=/dev/sdb count = 63
use fdisk to modify partition sizes on sdb
dd if=/dev/sda1 of=/dev/sdb1
dd if=/dev/sda2 of=/dev/sdb2
dd if=/dev/sda3 of=/dev/sdb3

Now booted from a live CD - run 2 utilities to resize the file system in the first partition - to take advantage of the new space.. I am not with my notes but will modify this later to tell you their names - one is a variation on fschk the other on fsresize
Finally - keep the first disk to use for full backups

If it is smaller than new disk, make 2 partitions on it to hold the boot and active but not the swap. Then once a week used dd to backup the boot and active partitions. You may need to do these backups from a live CD - depending on some details.

The advantage of this 2 disk approach is that you never modify the good existing disk till after you are up and running on the new disk

Explanation
step 1 - causes anything currently used by the boot loader to be transferred
step 2 - modifies the partition table in the first sector
steps 3-5 move the contents of the exis

ted_chou12 09-28-2012 10:14 PM

Thanks everyone! I guess I have done it the hard way. For the sake of timezone, I done it last night and took me quite a while to get the system back to work:
dd if=/dev/sda1 of=/path to backup
simply format the whole disk with fdisk and make2..smt. ext3.
dd if=/path to backup of=/dev/sdf1 (on another linux machine, cause the old one doesnt even turn on now)
resize2fs /dev/sdf1 (also done on the other linux machine)
now I face booting problems with lilo:
insert live cd and bios startup with cd in command line:
root=/dev/sda1
bootup into cmd:
lilo
restart and face forced f2sck check problem, now I can boot but I have some messed up files in lost+found.

I will learn that tip for next time, rmknox.

Thanks,
Ted

rmknox 09-28-2012 10:42 PM

Hi Ted

Just to complete my description, at the end the first partiton has been expanded but the file system needs to be resized take advantage of the extra space.

Booted from a live CD

e2fsck -f /dev/sdb1
resize2fs /dev/sdb1

Cheers


All times are GMT -5. The time now is 06:19 AM.