# Disable Swap partition

## Boczkowski_D

I would like to disable swap partition. I have finally 2GB of RAM and would like to try how my box would work without disk access for memory demands. Is it so simple to remove it only from fstab or something else should be done? The other question is whether it is possible to reuse swap space if disabled. My fstab file looks this way:

```

/dev/sda1               /mnt/win/c      ntfs            defaults,noatime        0 0

/dev/sda2               /               ext3            noatime                 1 2

/dev/sda5               /home           ext3            noatime                 0 1

/dev/sda6               none            swap            sw                      0 0

/dev/sda7               /mnt/win/d      vfat            defaults,noatime,user,umask=000 0 0

/dev/sda8               /mnt/win/e      vfat            defaults,noatime,user   0 0

/dev/sda9               /mnt/win/f      vfat            defaults,noatime,user   0 0

/dev/sr0                /mnt/cdrom0     auto            noauto,user             0 0

shm                     /dev/shm        tmpfs           nodev,nosuid,noexec     0 0

```

The best way would be to enlarge /home partition with swap space. Is it doable without loosing data?

----------

## mbar

Yeah, commenting out swap from fstab is sufficient, but requires reboot.

If you do not want to reboot now, use:

```
swapoff /dev/sda6
```

----------

## wcg

Reusing it as a file system requires reformatting it. A swap partition has

a different disk format than a filesystem intended for normal files.

(mkswap vs mke2fs, etc).

----------

## Hu

 *Boczkowski_D wrote:*   

> The best way would be to enlarge /home partition with swap space. Is it doable without loosing data?

 Assuming that the partitions are physically adjacent, then yes, you can grow sda5 after you delete sda6.  However, you would then need to rewrite all references sda7 and above.

----------

## Boczkowski_D

Well, I am not sure if sda5 and sda6 are aligned. Is it possible to check that?

I can use cfdisk to delete /home/sda6 partition and then make sda5 bigger. Will it format sda5 at once? How shall I do that safely? Some guide is desirable...

----------

## NeddySeagoon

Boczkowski_D,

```
fdisk -l /dev/sda
```

will tell you where the partitions are on the disk

----------

## Boczkowski_D

It seems sda5 and sda6 are next to each other:

```

panda darek # fdisk -l /dev/sda

Disk /dev/sda: 160.0 GB, 160041885696 bytes

255 heads, 63 sectors/track, 19457 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x48784877

   Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1        1305    10482381    7  HPFS/NTFS

/dev/sda2            1306        2550    10000462+  83  Linux

/dev/sda3            2551       19457   135805477+   f  W95 Ext'd (LBA)

/dev/sda5            2551        3172     4996183+  83  Linux

/dev/sda6            3173        3264      738958+  82  Linux swap / Solaris

/dev/sda7            3265        7181    31463271    b  W95 FAT32

/dev/sda8            7182       11098    31463271    b  W95 FAT32

/dev/sda9           11099       19457    67143636    b  W95 FAT32

```

Neddy, what should be next steps then to recover the swap space?

----------

## NeddySeagoon

Boczkowski_D,

```
/dev/sda5            2551        3172     4996183+  83  Linux

/dev/sda6            3173        3264      738958+  82  Linux swap / Solaris 
```

That looks good.

Delete both partitions 5 and 6.  That will cause partitions 7, 8 and 9 to become 5,6 and 7.

Your data is till there but meanwhile you have destroyed to pointers to it.

Make a new partition, it will be partition 8, filling the space.  As partition 8 now starts where partition 5 was, your Linux is available again.

However, the filesystem size is as yet, unchanged so you now have the same filesystem which is smaller than the partition that holds it.

The last step is to grow the filesystem into the empty space.  How you do that is filesystem dependent.

This a dangerous operation to do without validated backups. So start out by making and validating two copies of your valuable data.

Its very important that /dev/sda8 and /dev/sda5 both start in *identical* places.  When you write the new partition table for /dev/sda8 it must overwrite the old disused /dev/sda5 entry exactly or it will destroy the start of your filesystem

Parted can do this for you but thats what it does behind your pack.

----------

## Boczkowski_D

Neddy,

I am a bit confused. From your description it seems I need to take 3 steps, but step:

 *Quote:*   

> 
> 
> Make a new partition, it will be partition 8, filling the space. 
> 
> 

 

and step:

 *Quote:*   

> 
> 
> The last step is to grow the filesystem into the empty space.
> 
> 

 

are actually the same ones, right?

The other thing is when resize is done and data is missing will I get the running box again? I thought about just copying /home partition content to the windows partition and bring them back after operation is completed.

----------

## NeddySeagoon

Boczkowski_D,

No data is ever missing - unless you mess up making the new partition. The pointers to the data are missing but the data is completely untouched.

 *Quote:*   

> Make a new partition, it will be partition 8, filling the space. 

 and *Quote:*   

> The last step is to grow the filesystem into the empty space. 

 are not the same thing.

Normally, when you make a partition then make a filesystem on it, the filesystem fills the partition.  When you resize the partition, thats all that happens. You are making a bigger partition under your existing filesystem. The filesystem will not grow to fill the new space. You will need to use a filesystem utility to do the grow.  The exact command depends on your filesystem type

As Hu has said, you will need to fix /etc/fstab and grub.conf to point to the new partition and if your /boot is there, you will need to chroot into the /dev/sda8 install and reinstall grub to the MBR, or it will look for grub.con on /dev/sda5 still, so your system won't boot.

parted (or gparted?) can hide most of this from you.

----------

## Boczkowski_D

It's been a while from last post, but since then I haven't gone anywhere. I believe I need your close assistance, Neddy.

Print option under parted shows:

```

(parted) print                                                            

Model: ATA WDC WD1600JB-00G (scsi)

Disk /dev/sda: 160GB

Sector size (logical/physical): 512B/512B

Partition Table: msdos

Number  Start   End     Size    Type      File system     Flags

 1      32.3kB  10.7GB  10.7GB  primary   ntfs            boot

 2      10.7GB  21.0GB  10.2GB  primary   ext3

 3      21.0GB  160GB   139GB   extended                  lba

 5      21.0GB  26.1GB  5116MB  logical   ext3

 6      26.1GB  26.8GB  757MB   logical   linux-swap(v1)

 7      26.8GB  59.1GB  32.2GB  logical   fat32

 8      59.1GB  91.3GB  32.2GB  logical   fat32

 9      91.3GB  160GB   68.8GB  logical   fat32

```

From what you wrote I need to do following:

1) Delete partitions 5 and 6 with parted:

```

(parted) rm 6

(parted) rm 5

```

2) Create new partition ( 8 ) in released space

```

(parted) mkpart logical ext3 2551 3264

```

3) Grow filesystem for empty space

```

(parted) mkfs 8 ext3

```

or

```

# mkfs.ext3 /dev/sda8

```

Please check if these steps are correct. The only thing that I am worried about is man for parted doesn't show ext3 support. Maybe in this case it will be better to use cfdisk?

----------

## NeddySeagoon

Boczkowski_D,

You must not make a new filesystem in sda8 that *WILL DESTROY* your data.

Everything except the mkfs commands looks ok.

You can use any partition tool you like as you will not use any partitioning tool to adjust your filesystems.

Once sda8 exists, your old filesystem will be there but it will not fill the new partition.

As we know your filesystem is ext3, you need resize2fs to grow the filesystem to fit the new partition size.

Read 

```
man resize2fs
```

 to find out what to do

Be sure ti fix /etc/fstab and grub.conf as required before you reboot.

----------

