4

I want to reduce the partition mounted at /tmp to 10GB and add all unused space to the / partition.

If I umount -l /tmp and run fsck.ext3 -f /dev/privg/lv_tmp, I get this:

fsck.ext3: Device or resource busy while trying to open /dev/privg/lv_tmp
Filesystem mounted or opened exclusively by another program?

What are the correct steps to do LVM repartitioning?

$ df -hl
Filesystem                 Size  Used Avail Use% Mounted on
/dev/mapper/privg-lv_root   12G  4.2G  6.9G  38% /
/dev/mapper/privg-lv_tmp    29G  3.2G   24G  12% /tmp
/dev/mapper/privg-lv_var   3.9G  1.5G  2.3G  40% /var
/dev/sda1                  494M   40M  429M   9% /boot
tmpfs                       16G     0   16G   0% /dev/shm
Warren Young
  • 72,032
user11496
  • 569

2 Answers2

2

You need to unmount the ext3 filesystem in order to shrink it. umount -l means that the filesystem will be unmounted when there is no more open file on it.

Run lsof /tmp to see what files are open on /tmp. If you're running an X server, you'll see its socket /tmp/.X11-unix/X0. You can't remove that socket¹ and still be able to connect to the X server. Other than that, most files tend to be short-lived or to belong to programs that can be restarted.

If you really want to perform the operation on a live system, you'll need to migrate to a different /tmp filesystem, at least for the duration of the operation. You could transition to tmpfs, in which /tmp is stored in RAM or swap; see this guide. In fact, tmpfs for /tmp is a common setup; you might want to stick to that and remove the /tmp partition altogether (and perhaps enlarge your swap a little instead).

Once you've been able to close everything from /tmp, you'll be able to unmount it. Don't use umount -l, it's useless here since it frees the mount point but not the device, whereas what you want is to free the device. Once /tmp is unmounted, run fsck, run resize2fs to shrink it, and shrink the LVM logical volume accordingly. Or you might in fact save time by directly shrinking the LVM volume and creating a new filesystem for /tmp. (If you have any data you want to keep in /tmp, you're doing it wrong. /tmp is for data that need not be saved between reboots, and closed files in /tmp are fair game for deletion.)

If all this seems daunting, reboot to a recovery system (live CD or USB) and operate from there.

¹ Nor can you move it to another filesystem: that would be removing the original and creating a new socket.

0

You can't unmount /tmp on a running system. You need to boot from a LiveCD or rescue CD and do it there.

Paul Tomblin
  • 1,678