LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 09-28-2012, 11:01 AM   #1
ted_chou12
Member
 
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 421
Blog Entries: 28

Rep: Reputation: 2
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

Last edited by ted_chou12; 09-28-2012 at 11:05 AM.
 
Old 09-28-2012, 01:23 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 11,817

Rep: Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724Reputation: 724
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.
 
Old 09-28-2012, 01:43 PM   #3
JaseP
Senior Member
 
Registered: Jun 2002
Location: Eastern PA, USA
Distribution: K/Ubuntu 10.04/12.04, Scientific Linux 6.3, Android-x86, Maemo
Posts: 1,658

Rep: Reputation: 138Reputation: 138
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.
 
Old 09-28-2012, 02:27 PM   #4
rmknox
Member
 
Registered: May 2010
Posts: 351

Rep: Reputation: 29
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

Last edited by rmknox; 09-28-2012 at 04:11 PM. Reason: add detail
 
1 members found this post helpful.
Old 09-28-2012, 10:14 PM   #5
ted_chou12
Member
 
Registered: Aug 2010
Location: Zhongli, Taoyuan
Distribution: slackware, windows, debian (armv4l GNU/Linux)
Posts: 421
Blog Entries: 28

Original Poster
Rep: Reputation: 2
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
 
Old 09-28-2012, 10:42 PM   #6
rmknox
Member
 
Registered: May 2010
Posts: 351

Rep: Reputation: 29
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Three disk partitioning questions (fdisk) benav Linux - Newbie 4 07-14-2011 05:22 PM
Safe to resize used partitions? pickarooney Linux - Software 6 12-25-2006 06:10 AM
Hoe safe to resize partitions? heffo_j Linux - Hardware 2 07-02-2006 10:04 AM
Safe to resize linux partition? Mackentack Linux - Newbie 4 05-02-2005 06:18 AM
Safe to resize root partition with PM8? Ohmn Mandriva 6 07-09-2004 09:29 AM


All times are GMT -5. The time now is 02:56 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration