8

Is there an easy way to decrease the disk volume on a Ubuntu server?

I run a virtual environment and need to decrease my disk volume since I'm running out of space in my non virtual environment.

fossfreedom
  • 172,746
Nhimself
  • 141
  • 1
    I have a strong suspicion Nhimself uses "decrease" where he actually means "increase" - everything suddenly makes sense if you read it like this. – Sergey Sep 09 '11 at 11:35
  • Are you running the Ubuntu server on a virtual server? or are you running a virtual server on a Ubuntu server? "in other words im running out of space? " is this a question? I suggest you read this FAQ – Alvar Sep 12 '11 at 19:24
  • @Sergey:He could also mean, "decrease the volume of the virtual hard disk." He could have created a (fixed or dynamic) virtual hard disk that took up a certain proportion of the host OS's partition and now he is running out of room for the host OS. I've increased the size of virtual hard disks before but never decreased them... – adempewolff May 22 '12 at 14:30
  • @adempewolff - I think you may be right... – Sergey May 22 '12 at 23:19
  • For understandable reasons it looks like virtualbox won't let you resize to a smaller disk size. However there is the VBoxManage modifyhd yourdisk.vdi –compact command which looks like it might work for your purpose. See this tutorial, http://michaelcole.com/node/13, linux guest, windows host, but the syntax for the Vboxmanage command is essentially the same I think. Basically, 1. backup data, 2. zerofill guest OS, and 3. run vboxmanage ...and you should be set. Assuming this is what you were asking... – adempewolff May 23 '12 at 13:52

4 Answers4

4

I think you will have to use resize2fs.

You will have to:
1. boot from a livecd,
2. then set the partiotion as ext2,
3. and run something like resize2fs /dev/sda1 8000M.

Here is a more extensive step by step instructions.

desgua
  • 32,917
0

You will need to first resize the filesystem, then the partition table, and then tell the virtual hypervisor to resize its own disk. As somebody else stated, booting it in a liveCD and then using gparted is VERY easy to do. In fact its the only way to do it if you have the filesystem mounted, which will always be the case for your root filesystem.

If you just want to resize /home or some other thing you can unmount..

umount /dev/sda4

parted will show you the start/stop with parted -l

Model: ATA Hitachi HTS54323 (scsi)
Disk /dev/sda: 320GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt

Number  Start   End    Size    File system     Name                  Flags
 1      20.5kB  210MB  210MB   fat32           EFI System Partition  boot
 2      210MB   160GB  160GB   hfs+            Mac HD
 3      160GB   162GB  2000MB  linux-swap(v1)
 4      162GB   320GB  158GB   ext4

If I wanted to resize /dev/sda4:

parted resize /dev/vda1 162GB 300GB

Then I'd just have to tell the virtual disk provider to shrink its disk to the appropriate size.

Note that this is fairly dangerous, so backup any important data.

SpamapS
  • 19,820
  • parted can't resize the filesystem; you'll need to run resize2fs ( for ext[234] ) to do that first, or better yet, just stick to using gparted – psusi Feb 21 '12 at 03:34
-1

If you meant you want to resize your filesystem which is probably ext* have a look at this guide http://www.howtoforge.com/linux_resizing_ext3_partitions

If you meant you want to reduce your disk usage by removing temporary and cache data have a look at this: http://www.webupd8.org/2009/04/clean-unnecessary-temporarily-files-in.html

lhw
  • 127
-2

Beside resizing your partition using a LiveCD and gparted you could change the amount of space reserved by root (in percent):

sudo tune2fs -m 10 /dev/sda1

But this only affects non root user!

You can also create quotas for specific users using the quota utility (User Quotas with Ubuntu)

falstaff
  • 955
  • 1
    the normal percentage of reserved blocks is 5%, my understanding is that your command will reserve 10% for use by the privileged user only - how is it going to free up any space? I'd say it'll decrease the amount of free space – Sergey Sep 09 '11 at 11:32