-   Linux - Newbie (
-   -   how to reduce swap space and reclaim the space (

grantm 07-28-2003 10:09 PM

how to reduce swap space and reclaim the space
Hi All,

Newbie here .... just installed Redhat 9 (everything). I pretty much used the default partition profile and am regretting it now. I have a 7GB hard drive and here is how it's set up ...


# fdisk -l
Disk /dev/hdb: 7003 MB, 7003586560 bytes
255 heads, 63 sectors/track, 851 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

  Device Boot    Start      End    Blocks  Id  System
/dev/hdb1  *        1        13    104391  83  Linux
/dev/hdb2            14      110    779152+  82  Linux swap
/dev/hdb3          111      851  5952082+  83  Linux

# df
Filesystem          1K-blocks      Used Available Use% Mounted on
/dev/hdb3              5858544  5050696    510244  91% /
/dev/hdb1              101089      9275    86595  10% /boot
none                    386196        0    386196  0% /dev/shm

Since I'm only using this box as a desktop I really don't need the 768MB of swap space (I have 768MB of main memory).

Is there any way I can reduce the swap space to 128MB and reclaim the space onto /dev/hdb3 without destroying the contents of it ??

I tried parted and was able to resize the swap but I'm guessing I'm SOL when it comes to moving the start of hdb3 (I didn't try it ... too scared).

Thanks !!

Azmeen 07-28-2003 10:19 PM

Go with parted... it's pretty safe :)

Any way, if you did cock up, there's not much to recover since your system is still in it's virgin stages.

So if you're too scared to use parted, then might as well install again.

grantm 07-28-2003 11:37 PM

OK, I went for it.

Using parted from rescue disk....

Resized swap to 128MB .... good.
went to resize /dev/hdb3 to reclaim the space and got ....

No Implementation: This ext2 filesystem has a rather strange layout! Parted can't resize this (yet).


Printout from parted ...


Disk geometry for /dev/hdb: 0.000-6679.140 megabytes
Disk label type: msdos
Minor    Start      End    Type      Filesystem  Flags
1          0.031    101.975  primary  ext3        boot
2        101.975    227.482  primary  linux-swap
3        862.866  6675.446  primary  ext3

Parted says it's an ext3 filesystem and then changes it's mind and thinks it's actually an ext2 filesystem ??? :scratch:

I dunno. Looks like I'll probably have to start from scratch :cry:

rleesBSD 11-19-2007 12:32 PM

Turn your swap off and use fdisk
I have had good success reducing the swap file thusly:

0. BACKUP your data:

- I like to boot from a live cd, and then dd the entire drive over to another one.

1. Make sure you have sufficient physical memory to hold the swap file contents, and then
turn the swap off with something like:

- sync
- swapoff -Lswap (substitute your values)
- swapon -s (status check to be sure that it worked)
- (if status check reveals a swap line-item, then you specified incorrect swap label.

2. Run fdisk and:

- List partitions with "p" command
- Delete the partition that is home for your swap file with "d" command
- Create a smaller Linux-Swap partition with "n" command
- Make sure it is a Linux-Swap partition (type 82) (Change with "t" command)
- Create a new Linux partition for new file system in rescued space ("n" and "t" commands)
- Write partition table with "w" command

3. The new table won't be used until the next reboot.

4. After reboot, make sure your swap is made and turned on.

- mkswap /dev/hda4 -Lswap (substitute your values)
- swapon -Lswap
- swapon -s (check to make sure swap is turned on)

5. Create a mount point for your new file system partition (mkdir ...)

6. Make the new file system in the new partition:
- mkfs /dev/hda2 (or whatever partition it happens to be)

7. Mount the new fs and enjoy:
- mount /dev/hda2 /newmountpoint...

Note the extreme importance of syncing and turning
the swap off before you change any partitions.


This works for me, but your mileage may vary. Use at your own risk!

mymailbox83 08-16-2012 04:03 AM

Reduce Swap Space
Hi all,

My self vasanth. I have installed RHEL 9 in my laptop through Vmware. for swap space i have given 3GB i want to reduce it to 500mb. Because my through Vmware for my linux partion it took only 256 as physical memory. so i need to give only 500mb for swap space.
kindly help me for the same.


chrism01 08-16-2012 07:49 AM

There is no such thing as 'RHEL 9'; you probably mean RH9 aka Shrike, which is years out of date.(!)
Please get eg Centos 6.3 which is a free version of RHEL(!) 6.3; the latest from Redhat

syg00 08-16-2012 08:00 AM

When is jeremy going to lock these old threads .... :banghead:

chrism01 08-16-2012 08:05 AM

I meant to add he should start a new thread as well ... :(

All times are GMT -5. The time now is 11:55 PM.