Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have just upgraded my cpu/mobo/RAM and I would like to now increase the swap size without having to reformat my entire drive. Is this possible? My hard drive set up is as follows.

mount 
/dev/mapper/ubuntu-root on / type ext4 (rw,errors=remount-ro) 
proc on /proc type proc (rw,noexec,nosuid,nodev) 
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev) 
none on /sys/fs/fuse/connections type fusectl (rw) 
none on /sys/kernel/debug type debugfs (rw) 
none on /sys/kernel/security type securityfs (rw) 
udev on /dev type devtmpfs (rw,mode=0755) 
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620) 
tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755) 
none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880) 
none on /run/shm type tmpfs (rw,nosuid,nodev) 
none on /run/user type tmpfs (rw,noexec,nosuid,nodev,size=104857600,mode=0755)
/dev/sda1 on /boot type ext2 (rw) 
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev)
gvfsd-fuse on /run/user/raph/gvfs type fuse.gvfsd-fuse (rw,nosuid,nodev,user=raph)

sudo fdisk -l

Disk /dev/sda: 200.0 GB, 200049647616 bytes
    255 heads, 63 sectors/track, 24321 cylinders, total 390721968 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x0007f9dc

Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048      499711      248832   83  Linux
/dev/sda2          501758   390721535   195109889    5  Extended
/dev/sda5          501760   390721535   195109888   8e  Linux LVM

Disk /dev/mapper/ubuntu-root: 198.8 GB, 198784843776 bytes
    255 heads, 63 sectors/track, 24167 cylinders, total 388251648 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00000000

Disk /dev/mapper/ubuntu-root doesn't contain a valid partition table

Disk /dev/mapper/ubuntu-swap_1: 1006 MB, 1006632960 bytes
    255 heads, 63 sectors/track, 122 cylinders, total 1966080 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00000000

Disk /dev/mapper/ubuntu-swap_1 doesn't contain a valid partition table
share|improve this question

1 Answer 1

up vote 1 down vote accepted

Back up your data before you do follow the steps below. This usually works without any issues but that doesn't account for bugs, power failures, etc.

  1. Use e2resize to shrink the root logical volume (/dev/mapper/ubuntu-root) first.
  2. Then use lvresize to shrink the logical volume to the size of the filesystem you just shrunk.
  3. Now when you use vgdisplay, you'll notice there's some free space (extents) in that volume group.
  4. Temporarily disable your swap with swapoff -a
  5. You can use lvextend to expand /dev/mapper/ubuntu-swap_1 by with the extents you've just gained from shrinking the root LV.
  6. Create and re-enable your swap with mkswap /dev/mapper/ubuntu-swap_1 && swapon -a
share|improve this answer
1  
Should I be doing this from a live cd/usb stick? –  Raphael Jan 20 '13 at 14:39
    
You can but you don't need to. You don't even need to reboot your machine to do this. –  Marcin Kaminski Jan 20 '13 at 23:54
    
Just a small thing but e2resize doesn't seem to exist for 12.10. Do you mean resize2fs ? –  Raphael Apr 12 '13 at 9:29

Your Answer

 
discard

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.