Resizing disk partitions

Trying to resize ext3 filesystem /home from 8GB to 4GB.
Less than 1GB of data on it.

Started out by going into init 1 and
unmounting the filesystem.

Next tried using parted, but it flames out with filesystem
has unknown flags. So moved on to using

e2fsck -f /dev/hda2

resize2fs -p /dev/hda2 4G

This ran a nifty little process and then ended saying all was well.

Restarted the box and booted into runlevel 5.
Pull up the partitions table using the YaST partitioner
tool…old partition aizes still there, no size change.
Go into shell, df -v, old sizes still in place.

So what exactly did the system think it was doing when I was at
runlevel 1?? It seems to have done nothing.

I was a bit curious as to your views on this resizing, now that some time has gone by.

I’m thinking of changing around the partitions on the family Dell Studio 1537 laptop today. I plan to downsizing a loglical /dev/sda7 (131 GB) ext3 to 100 GB, and then create a /dev/sda8 of 31GB which my wife will be able to use to install winXP. There is already Vista on a primary /dev/sda3, so the speculation is that will work.

While I plan to do a re-install of openSUSE-11.1 (so as to have a clean KDE-4.3 as opposed to its older KDE-3.5.10) and reformat the / and /home (which is backed up), I was thinking it might be fun to play around first, and see if I could resize the /home without losing data (and then reformat it per my plan). The idea being I might learn something at no risk.

Instead of run level 1, I plan to do this from a live CD. …

So to resize, am I correct that all you did was

 # e2fsck -f /dev/hda2
# resize2fs -p /dev/hda2 4G

There are some guides on resizing ext3, but they all assume a 2.4.x kernel and an older version of resize2fs, and hence they convert the ext3 to an ext2 prior to the resize. From what I have read that conversion to ext2 should not be necessary. Those guides:

Which has me thinking I could simply from the liveCD:

  • e2fsck -f /dev/sda7
  • use “resize2fs /dev/sda7 100G” to resize the file system.
  • use fdisk to resize the partition: delete the old partition (purportedly no data will be lost ). There is guidance on using fdisk here, for doing that: How To Resize ext3 Partitions Without Losing Data | HowtoForge - Linux Howtos and Tutorials Create a new one of the desired size (which is tricky and caution needed - again see the two URLs above that describe how). Save changes.
  • use “resize2fs /dev/sda7” (no size this time) to resize the file system to the maximum available.

… I have not decided yet if I will try this … It boils down to how much time I have to play on this today. Its really a matter of time spent learning something, as opposed to data loss concerns (as I plan to wipe the /sda7 partition anyway).

That is to say not necessary on a 2.6.27 kernel with the latest resize2fs.

The only way to go, in my opinion. Download Parted Magic, boot onto the CD, and use Parted in that.

I wonder if the version of Parted that came with 11.1 was old, or had bugs? I’ve had trouble with it as well. But the version on the Parted Magic CD flies like a bird.

The wife just got up, and after some discussion we both 'nix’d the idea for now. … ie we are not going to downsize openSUSE-11.1 nor install WinXP yet.

The reason being winXP on Virtual Box is working ok again (after having some tlc applied to it) and we are leaving on a vacation in less than 2 weeks, and we don’t want to risk my messing things up now. … So this is another task shelved until after we return from vacation.

I have both gparted live CD and Parted Magic. I assume, though, one still needs to run e2fsck, resize2fs (twice), and fdisk to resize (as opposed to using the program gparted). The concern with using gparted is it would lose data.

This interests me too. I’m about to reduce my XP partition right down to the minimum and then increase my /home partion slightly and create a new partition remaining space to install 11.2 test releases on to.

I’m torn between just biting the bullet and backing up the data, resizing everything and then doing a clean install of 11.1; or trying to resize the partions and hopefully keeping everything in tact.

suse tpx60s wrote:

>
> This interests me too. I’m about to reduce my XP partition right down to
> the minimum and then increase my /home partion slightly and create a new
> partition remaining space to install 11.2 test releases on to.
>
> I’m torn between just biting the bullet and backing up the data,
> resizing everything and then doing a clean install of 11.1; or trying to
> resize the partions and hopefully keeping everything in tact.

Resizing XP can get to be a real PITA. Some tips from some long discussions
over the last couple of years:

  1. From XP, turn off the off the swap file (“virtual memory”) then boot to
    safe mode and delete the swap file. Remember to turn the swap file back on
    after you get the partition resized.

  2. From XP, defrag until you get as many of the files to the front as
    possible. Running on a mounted partition, about the best you will achieve
    is about 50% of the original size - no matter how much free space there
    is - because of open system files that M$ puts at the center of the disk.

The best result I’ve been able to get is to mount the disk in another
machine and defrag/compress it from another copy of XP so that there are no
open files, period. Then resize before you return the disk to the boot
position.

Any way you go, XP and its’ brethren are tedious to reduce if you want to
reduce the partition beyond 50-60% of the original (initial creation) size.

Also be aware of a potential trap here. In the typical case, the XP
partition is the first primary on the disk and any free space will be
before the existing Linux partitions. You can only extend partitions from
the end, not the beginning, of an existing partition so unless you free up
enough space to create a new partition big enough to hold a copy of one of
your existing partitions - or at least all the data on it - you have no
good way to actually use the freed space. And then there is the problem of
grub - unless you move your / partition to the newly created partition you
boot fails because the partition map changes and grub gets lost.

Have fun :wink:


Will Honea

Thanks for the tips. So if you can only extend a partition from the end, is it possible for me to move all the partitions to fill the empty space created by shrinking the XP partition, effectively moving the free space to the end of the disk?

Every way I look at this makes me think I’ll just be better off saving my Linux data and doing a factory restore from the recovery partition, shrink the partition and reinstall the few apps I need in XP; then partition the rest of the disk for a fresh 11.1 and 11.2 install. I just don’t have the time for that at the moment.

suse tpx60s wrote:

>
> Thanks for the tips. So if you can only extend a partition from the end,
> is it possible for me to move all the partitions to fill the empty space
> created by shrinking the XP partition, effectively moving the free space
> to the end of the disk?
>
> Every way I look at this makes me think I’ll just be better off saving
> my Linux data and doing a factory restore from the recovery partition,
> shrink the partition and reinstall the few apps I need in XP; then
> partition the rest of the disk for a fresh 11.1 and 11.2 install. I just
> don’t have the time for that at the moment.

You can play musical chairs any way you want and with a little planning
things could work out pretty simply. Here’s an example.

Let’s say you machine came with XP, no recovery (maintenance) partition, so
XP has the whole disk. For illustration purposes, let’s assume a 100GB
drive. You boot XP and then shut down. You boot your favorite partition
editor tool and you shrink XP as far as it will go. Best you will do at
this point is free something under 50GB because XP has put files at the
midpoint of the drive - 50GB out. Now, XP will run fine with 10GB or a
little less but you can’t get there from here. You only have less than
50GB free for Linux. If you had planned ahead and shrunk the XP partition
before you ever booted it, you might get it down close the 10 GB or so
range but you didn’t because that’s what you want to do now.

OK, you put Linux on 3 (sda2 as /, sda3 as /home, sda4 as swap. XP is on
sda1) new partitions that fill the rest of the disk and they are all
primaries - you’re SOL because you just filled all 4 MBR partition table
entries so you can’t create any more. OK, let’s put all 3 Linux partitions
into and extended partition and logical partitions; Linux uses sda5, 6, and
7. Now you have some play room. There are some other quirks due to MBR
partition table order and such but that’s just going to confuse matters and
shouldn’t cause a problem. FYI, with just a single Win partition, I
allocate two more primaries and and extended partition just to insure an
order in the table I’m sure will work for any OS but that’s not really
relvant to the problem.

OK, you manage to shrink XP to 10GB. That leaves you with a free space hole
between XP and your first Linux partition of some 40GB. Figure out how
much room you have to have to hold you root partition - use df. Allow a
comfortable fudge factor and allocate a PRIMARY partition at the head of
the free space. Note that this becomes sda2 and this is not the final
size - you’ll expand it later. If your original root partition was sda2,
it will shift to being sda3, so it WILL NOT BOOT unless /home was on a
logical partition (sda5 or higher)! Use a live cd and copy the entire
original root partition to the new sda2. If the original root partition
was sda2, you’re home free - it will start to boot (but it won’t complete
since you have an extra partiton between / and /home right now unless /home
was on sda5+). If the original / partiton was sda2 and is now sda3, you
can delete sda3 and probably boot very happily. Assuming / was originally
on a primary partition as sda2, deleting it after the copy will leave you
with another hole. Repeat the process of creating a new partition but make
it just a little larger than the data size in your /home. Copy /home
contents to this, free the original /home and you have an even bigger free
space. Delete and recreate /swap at the head of this and every thing is
free to the end of the disk. Play with the mapping you want in that free
space and repeat the process above to finally get things where you want
them in the sizes desired. Draw lots of pictures of the drive map and that
should be fairly straight forward. If all you Linux partitions were on an
extended partition, things get sticky. Just remember that the partition
assignment (sda1,1,3,etc.) is affect by any partitions you create or delete
and you should be OK. Also bear in mind that XP will be very unhappy if
you move it to any partition that does not start where the original started
or if you try to add a partition ahead of it.

If you elect to re-install XP and do it from recovery disks you should know
that most of these recoveries recreate the original disk map and will
overwrite anything you have added. Of all the ones I’ve messed with, only
IBM/Lenovo was nice enough to restore to whatever drive C you provide and
don’t mess with existing partitioning - the rest just seem to grab the
whole disk.

If you decide to press on, email me directly and I’ll try and help you as I
can - the email address here is valid.

I think that backing up your /home and starting over might be simpler. The
only time I do the image copy thing is when re-configuring a system running
lot’s of added apps that install in the / patriron (/opt, /user, etc) and
would have to be re-installed and tweeked.


Will Honea

Thanks Will, that was useful. I’m going to need to think about which way to go. Both the start again or partition manipulation options will take a lot of time. I like the start again option as it’s clean but it’s going to be a lot of work as I have a few apps installed into /opt and have made a lot of custom tweaks to config and script files. I’m not sure I’ll find or remember them all when it comes to trying to back them up.

On the other hand moving and resizing partitions is a little simpler and will not require me to have to re-tweak my system. I can wipe the NTFS partition so I can resize it to 10-15GB and then do the install through the recovery utility. I have a Thinkpad so it’s recovery plays nice with other partitions and will not mess the other partitions up - I hope.

Now just to find some time.

suse tpx60s wrote:

>
> Thanks Will, that was useful. I’m going to need to think about which way
> to go. Both the start again or partition manipulation options will take
> a lot of time. I like the start again option as it’s clean but it’s
> going to be a lot of work as I have a few apps installed into /opt and
> have made a lot of custom tweaks to config and script files. I’m not
> sure I’ll find or remember them all when it comes to trying to back them
> up.
>
> On the other hand moving and resizing partitions is a little simpler
> and will not require me to have to re-tweak my system. I can wipe the
> NTFS partition so I can resize it to 10-15GB and then do the install
> through the recovery utility. I have a Thinkpad so it’s recovery plays
> nice with other partitions and will not mess the other partitions up - I
> hope.
>
> Now just to find some time.

After getting so long winded, I neglected to mention the most obvious
solution which may be what you need. Once you have a bootable Linux system
after the first round of this circle-jerk, you can do just about everything
from a running Linux system. If I have room in the newly freed area, I
find it almost as quick to create a new partition big enough to hold my
system of choice and do a fresh install formatting only / and using the
existing /home. You may have to reinstall a few apps to get those running,
but virtually all your config and app specific info will be intact on /home
partition. The only app I run that is too much of a pin to re-install is
DB2. No matter which way you go, the long pole in the tent is usually the
size of the data you have in /home. You really need enough room to contain
a copy of that with enough free space to expand things.


Will Honea

On Sat, 29 Aug 2009 08:06:03 GMT, oldcpu
<oldcpu@no-mx.forums.opensuse.org> wrote:

>
>GofBorg;1897806 Wrote:
>> Trying to resize ext3 filesystem /home from 8GB to 4GB.I was a bit curious as to your views on this resizing, now that some
>time has gone by.
>
>I’m thinking of changing around the partitions on the family Dell
>Studio 1537 laptop today. I plan to downsizing a loglical /dev/sda7
>(131 GB) ext3 to 100 GB, and then create a /dev/sda8 of 31GB which my
>wife will be able to use to install winXP. There is already Vista on a
>primary /dev/sda3, so the speculation is that will work.
>
>While I plan to do a re-install of openSUSE-11.1 (so as to have a clean
>KDE-4.3 as opposed to its older KDE-3.5.10) and reformat the / and /home
>(which is backed up), I was thinking it might be fun to play around
>first, and see if I could resize the /home without losing data (and then
>reformat it per my plan). The idea being I might learn something at no
>risk.
>
>Instead of run level 1, I plan to do this from a live CD. …
>
>So to resize, am I correct that all you did was
>
>Code:
>--------------------
> # e2fsck -f /dev/hda2
> # resize2fs -p /dev/hda2 4G
>--------------------
>
>
>There are some guides on resizing ext3, but they all assume a 2.4.x
>kernel and an older version of resize2fs, and hence they convert the
>ext3 to an ext2 prior to the resize. From what I have read that
>conversion to ext2 should not be necessary. Those guides:
>- ‘howto resize an ext3 partition without losing
> databyusefulfor.com/nothing’ (http://tinyurl.com/nkmq79)
>- ‘How To Resize ext3 Partitions Without Losing Data | HowtoForge -
> Linux Howtos and Tutorials’
> (http://howtoforge.org/linux_resizing_ext3_partitions)
>
>
>Which has me thinking I could simply from the liveCD:
>- e2fsck -f /dev/sda7
>- use “resize2fs /dev/sda7 100G” to resize the file
> system.
>- use fdisk to resize the partition: delete the old partition
> (purportedly no data will be lost ). There is guidance on using fdisk
> here, for doing that: ‘How To Resize ext3 Partitions Without Losing
> Data | HowtoForge - Linux Howtos and Tutorials’
> (http://howtoforge.org/linux_resizing_ext3_partitions) Create a new
> one of the desired size (which is tricky and caution needed - again
> see the two URLs above that describe how). Save changes.
>- use “resize2fs /dev/sda7” (no size this time) to
> resize the file system to the maximum available.
>
>… I have not decided yet if I will try this … It boils down to how
>much time I have to play on this today. Its really a matter of time
>spent learning something, as opposed to data loss concerns (as I plan to
>wipe the /sda7 partition anyway).

Personally i consistently use parted from the cli for this, i also
prefer doing it from a live disc. That way none of the partitions on
the HD are in use.

On Sat, 29 Aug 2009 08:16:01 GMT, oldcpu
<oldcpu@no-mx.forums.opensuse.org> wrote:

>
>smpoole7;2032926 Wrote:
>> The only way to go, in my opinion. Download Parted Magic, boot onto the
>> CD, and use Parted in that…
>I have both gparted and Parted Magic. I assume, though, one still
>needs to run e2fsck, resize2fs (twice), and fdisk to resize (as opposed
>to using the program gparted). The concern with using gparted is it
>would lose data.

The last i heard gparted is a gui wrapper around parted of cli. Be
that as it may, i am still comfortable enough at cli to just use
parted directly.

On Sat, 29 Aug 2009 14:37:21 GMT, Will Honea <whonea@yahoo.com> wrote:

>suse tpx60s wrote:
>
>>
>> This interests me too. I’m about to reduce my XP partition right down to
>> the minimum and then increase my /home partion slightly and create a new
>> partition remaining space to install 11.2 test releases on to.
>>
>> I’m torn between just biting the bullet and backing up the data,
>> resizing everything and then doing a clean install of 11.1; or trying to
>> resize the partions and hopefully keeping everything in tact.
>
>Resizing XP can get to be a real PITA. Some tips from some long discussions
>over the last couple of years:
>
>1. From XP, turn off the off the swap file (“virtual memory”) then boot to
>safe mode and delete the swap file. Remember to turn the swap file backon
>after you get the partition resized.
>
>2. From XP, defrag until you get as many of the files to the front as
>possible. Running on a mounted partition, about the best you will achieve
>is about 50% of the original size - no matter how much free space there
>is - because of open system files that M$ puts at the center of the disk.
>
>The best result I’ve been able to get is to mount the disk in another
>machine and defrag/compress it from another copy of XP so that there areno
>open files, period. Then resize before you return the disk to the boot
>position.
>
>Any way you go, XP and its’ brethren are tedious to reduce if you want to
>reduce the partition beyond 50-60% of the original (initial creation) size.
>
>Also be aware of a potential trap here. In the typical case, the XP
>partition is the first primary on the disk and any free space will be
>before the existing Linux partitions. You can only extend partitions from
>the end, not the beginning, of an existing partition so unless you free up
>enough space to create a new partition big enough to hold a copy of one of
>your existing partitions - or at least all the data on it - you have no
>good way to actually use the freed space. And then there is the problemof
>grub - unless you move your / partition to the newly created partition you
>boot fails because the partition map changes and grub gets lost.
>
>Have fun :wink:

I have extended then toward the front. But it is about 3 to 5 times
the work. I had the backups, i just did not need them. Oh, and it is
about 12 times the work if you move the beginning of an extended
partition.

Parted Magic (latest verison 4.4) also has Clonezilla (image backup program) on board, as also SuperGrubDisk (to fix GRUB bootloader errors), (Parted Magic 4.4).

It is also easier to use for partitioning, esp for those new to CLI (command-line) & less chance of errors at the cmd-line…

On Fri, 04 Sep 2009 21:16:03 GMT, zmdmw52
<zmdmw52@no-mx.forums.opensuse.org> wrote:

>
>JosephKK;2035805 Wrote:
>> On Sat, 29 Aug 2009 08:16:01 GMT, oldcpu
>> <oldcpu@no-mx.forums.opensuse.org> wrote:
>>
>> >
>> >smpoole7;2032926 Wrote:
>> >> The only way to go, in my opinion. Download Parted Magic, boot onto
>> the
>> >> CD, and use Parted in that…
>> >I have both gparted and Parted Magic. I assume, though, one still
>> >needs to run e2fsck, resize2fs (twice), and fdisk to resize (as
>> opposed
>> >to using the program gparted). The concern with using gparted is it
>> >would lose data.
>>
>> The last i heard gparted is a gui wrapper around parted of cli. Be
>> that as it may, i am still comfortable enough at cli to just use
>> parted directly.
>Parted Magic (latest verison 4.4) also has Clonezilla (image backup
>program) on board, as also SuperGrubDisk (to fix GRUB bootloader
>errors), (‘Parted Magic 4.4’ (http://tinyurl.com/kusoc9)).
>
>It is also easier to use for partitioning, esp for those new to CLI
>(command-line) & less chance of errors at the cmd-line…

Looks interesting. Is it truly FOSS?

How about making a backup of a partition you want to move & resize with the linux dd command on a external medium, then delete the partition, create a new one with the same size and type and use dd again to copy back the data you just backuped and then resize it to the size you want ?

MfG, MEX

What makes you think otherwise ? I don’t see any programs in PartedMagicthat are non-FOSS- Programs

This is the DistroWatch page: DistroWatch.com: Parted Magic