Following is how parted print looks like:

(parted) print                                                            

Model: VMware Virtual disk (scsi)
Disk /dev/sda: 26.8GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
 1      32.3kB  271MB   271MB   primary  ext2         boot 
 2      271MB   1349MB  1078MB  primary  linux-swap        
 3      1349MB  26.8GB  25.5GB  primary               lvm  

The volume group created on /dev/sda3 looks like the following

  --- Volume group ---
  VG Name               rootvg
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  8
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                7
  Open LV               7
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               23.62 GB
  PE Size               128.00 MB
  Total PE              189
  Alloc PE / Size       162 / 20.25 GB
  Free  PE / Size       27 / 3.38 GB
  VG UUID               1Wzcpj-bNMD-cIYr-pOwA-1jdP-f9wE-wiEitV

That means there is 3.38G unused space.

I want to resize my swap partition /dev/sda2 to use 1GB out of the above space. How can I achieve that?


Linux can use multiple swap partitions as part of it's swap pool, so what your asking is easily acheived by creating a swap volume inside of the LVM and turning it on. Here's an overview:

Use lvcreate to create the logical volume:

lvcreate -n swap2 -L 1G rootvg

Format the space as swap space:

mkswap /dev/rootvg/swap2

Activate the swap space:

swapon /dev/rootvg/swap2

Don't forget to update your fstab to mount the new swapspace at boot time. This should be as simple as copying the existing line that mounts /dev/sda2 as swap and changing that to /dev/rootvg/swap2.

| improve this answer | |
  • Thanks for the response; isn't it recommend to have swap in contiguous space ? – ring bearer Jun 9 '11 at 14:29
  • 1
    I'd be interested to hear about why that is. Never heard that before. – Kyle Smith Jun 9 '11 at 14:36
  • 3
    @ring bearer - I think you might be confused by the recommendation that the logical volume use contiguous space when using it for swap. You can use the '-C' option to lvcreate to ensure it allocates accordingly. – JimB Jun 9 '11 at 14:55
  • @JimB +1. Didn't know about the -C option. – Kyle Smith Jun 9 '11 at 14:58
  • @JimB - is /dev/sda2 and lvm swap being non contiguous a concern? – ring bearer Jun 10 '11 at 15:15

You can't directly extend your existing swap partition, because it's a physical dos partition, and not in lvm.

You you can create a new 1G lvm volume, then mkswap and swapon. The kernel will make use of both swap areas seamlessly.

| improve this answer | |
  • +1 for "You can't directly extend your existing swap partition" – ring bearer Jun 10 '11 at 15:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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