Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I already have parititon contain data under lvm enviroment with centos 5.8

output of fdisk -l

root@server [~]# fdisk -l

Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          25      200781   83  Linux
/dev/sda2              26      121601   976559220   8e  Linux LVM

output of lvdisplay

# lvdisplay
  --- Logical volume ---
  LV Name                /dev/sysvg/ROOT
  VG Name                sysvg
  LV UUID                6oy3Rj-ka3K-mL9s-vjjG-1Iqw-dniq-UbWzvJ
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                919.44 GB
  Current LE             29422
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Logical volume ---
  LV Name                /dev/sysvg/TMP
  VG Name                sysvg
  LV UUID                jTKLBt-eNz0-KxmV-E5Nk-jjC0-FlRb-qny62p
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                9.88 GB
  Current LE             316
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

  --- Logical volume ---
  LV Name                /dev/sysvg/SHM
  VG Name                sysvg
  LV UUID                NpKjhl-tzzn-Dk3G-A6dl-4QJB-QCc2-IkbDH5
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                2.00 GB
  Current LE             64
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2

output of df -h

root@server [~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
                      891G  125G  721G  15% /
                      9.6G  153M  9.0G   2% /tmp
                      8.0G  8.0K  8.0G   1% /dev/shm
/dev/sda1             190M   19M  162M  11% /boot
tmpfs                 8.0G  8.0K  8.0G   1% /dev/shm

output for /etc/fstab

root@server [~]# cat /etc/fstab
/dev/sysvg/ROOT /       ext3    usrjquota=quota.user,jqfmt=vfsv0        1       1
/dev/sysvg/TMP          /tmp                    ext3    defaults        1 2
/dev/sysvg/SHM  /dev/shm        ext3    defaults,usrquota       1       2
LABEL=/boot             /boot                   ext3    defaults        1 2
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
/tmp             /var/tmp                    ext3    defaults,bind,noauto        0 0

I don't have any idea how to create swap partition , and i worried about creating cause any DATA LOSS

share|improve this question
/dev/shm isn't supposed to have backing store, it usually is an in-memory file-system. You could just re-assign that volume for swap. – Mat Jan 22 '13 at 8:05
@Mat could u please what is the steps to re-assign this volume as a swap partition ? – iLinux85 Jan 22 '13 at 9:47
Do you want to create the swap inside the LVM? – taffer Jan 22 '13 at 10:56
@taffer no matter but i want to be swap partition instead of swap file – iLinux85 Jan 22 '13 at 13:39

To create a swap partition in your lvm (supposed your volume group is called vgroup000 and you want to create a 4GB swap partition called lv_swap):

lvm lvcreate vgroup000 -n lv_swap -L 4GB
mkswap /dev/vgroup000/lv_swap

To mount it on every boot append the following line to /etc/fstab:

/dev/vgroup000/lv_swap    swap    swap    defaults    0    0

To mount it instantly:

swapon -a
share|improve this answer

To create a swap you need to do several things:

  1. have a space available where the swap will reside - either a spare block device (usually a partition) or a regular file. To create a 1GB file use e.g.:

    dd if=/dev/zero of=/path/to/swap/file bs=1M count=1k
  2. prepare the swap with the mkswap command - this erases the data on the device/file (it creates some data structures there).

  3. activate the swap with swapon /path/to/swap/device_or_file. In case of a swap file the underlying filesystem obviously has to be mounted first.

  4. put it into fstab so that it can be mounted easily:

    /path/to/swap/device_or_file    swap    swap    defaults    0    0

swapoff disables swapping to a device. Both swapon and swapoff have the -a option that enables/disables swapping to all swaps: swapon -a enables all swaps mentioned in /etc/fstab that don't have the noauto option set, swapoff -a disables all swaps.

Swapping to a file has the advantage of not needing a separate partition/device reserved just for swapping, but incurs varying overhead: reads/writes go through the filesystem layer and the file contents may be scattered across the device (fragmented) which on hard drives with spinning plates can cause slower response.

From my understanding it's not possible to hibernate (suspend to disk) with only file-swap, since on waking up, the kernel needs to read the stored image from swap and would need to mount the filesystem first, which on a hibernated system could have grave consequences.

share|improve this answer
thanks for answer but i want to create a swap partition not swap file because swap file slow in performance – iLinux85 Jan 22 '13 at 10:33
@iLinux85 "swap file slow in performance" that is not true. As long as the swap file is not fragmented there shouldn't be any noticeable performance loss when using a swap file. A swap partition however makes sense in case you have a dedicated hard drive for swap. – taffer Jan 22 '13 at 11:09
I think the key point is that all swap is horribly slow, and if you're worried about swap performance, you're tackling the problem from the wrong angle. – mattdm Jan 22 '13 at 14:06
@iLinux85 whatever you want - my answer does mention both :) – peterph Jan 22 '13 at 23:49
@taffer well, it is slower than a separate partition (which is of course slower than separate hw device) - I'm not claiming how much though. – peterph Jan 22 '13 at 23:51

You can create swap space using the following steps (here we are creating swap at /home/)

1) dd if=/dev/zero of=/home/swapfile1 bs=1024 count=8388608 (the count is a kilobyte count of swap space)

2) mkswap /home/swapfile1

3) vi /etc/fstab make entry: /home/swapfile1 swap swap defaults 0 0

4) swapon -a

share|improve this answer
Works fine, thanks! Just one security addition: I needed to do: "chmod 0600 /home/swapfile1" – markusN Jun 18 at 22:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.