0

This is my current setup:

Disk /dev/sda: 546.8 GiB, 587127480320 bytes, 1146733360 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
Disklabel type: gpt
Disk identifier: 3C89EF9D-3E76-4949-8989-AA8C05C3BF77

Device         Start        End   Sectors   Size Type
/dev/sda1       2048       4095      2048     1M BIOS boot
/dev/sda2       4096   41947135  41943040    20G Linux swap
/dev/sda3   41947136  775950335 734003200   350G Linux filesystem
/dev/sda4  775950336 1146730495 370780160 176.8G Linux filesystem

lsblk -f
NAME   FSTYPE LABEL    UUID                                 MOUNTPOINT
sda
├─sda1
├─sda2 swap            7624e18c-da83-45ac-aeae-9c0864209d7e [SWAP]
├─sda3 ext4            bf9be40b-0aca-4332-8070-820a5373ac6b /var
└─sda4 ext4            d06d9bbf-210b-4df2-8f05-d9a53ed43b3c /
sdb
└─sdb1 vfat   USB DISK DEF8-5885
sr0

Filesystem      Size  Used Avail Use% Mounted on
udev             12G     0   12G   0% /dev
tmpfs           2.4G  1.3M  2.4G   1% /run
/dev/sda4       173G   59G  106G  36% /
tmpfs            12G     0   12G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs            12G     0   12G   0% /sys/fs/cgroup
/dev/sda3       344G   56G  271G  17% /var
tmpfs           2.4G     0  2.4G   0% /run/user/1000
tmpfs           2.4G     0  2.4G   0% /run/user/1001

How can i move some disk space from /dev/sda3 into /dev/sda4? Is it possible?

I might need some extra space in / partition and the space allocated to /var is too much for my needs

7
  • 1
    Do you have good backups? Any move of left side of a partition can be very slow and any interruption corrupts the data. You have to use live installer so partitions are unmounted, shrink sda4, move sda4 right & then expand sda3. How full are partitions? Post this above in question. lsblk -f Commented Mar 1, 2023 at 18:29
  • 1
    Please edit your question and explain what you need. It is very likely you don't actually need to change the partitions and you can simply move data to another partition and then use a symlink to access it. For example, you can move /var to wherever /dev/sda4 is mounted and then make /var a symlink pointing there. That will free up a lot of space. So if you explain what the end objective is here (e.g. "I want more space for root" or "more space for /home") and show us the mount points (the output of df -h) we might be able to give you a better solution. Commented Mar 1, 2023 at 18:39
  • 1
    Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented Mar 1, 2023 at 18:46
  • df is a better tool to look at partition size, what is used and left. Commented Mar 1, 2023 at 18:59
  • You can move space, by moving non-space (files) in the opposite direction. Commented Mar 1, 2023 at 19:00

1 Answer 1

0

While my initial reaction was the same as ctrl-alt-delor (you can't move space - you can move data) it's not quite as simple as that. Most OS expect certain things to be on certain paths. Ubuntu is no exception. So while you could move something from sda4 (/) to sda3 (/var) you will likely break something as a result. It MIGHT be possible to fix this by adding a symlink. For example:

mv /usr/local /var/userlocal
ln -s /var/usrlocal /usr/local

should mostly work however if you were to try...

mv /home /var/newhome
ln -s /var/newhome /home

...then you'll find you run into lots of issues with AppArmor.

But there are solutions - I'll come back to that later.

The first thing to do is to find out where in the directory tree all the space is getting used up. But looking at your 'df' output - it's not too bad (on my daily driver, / is about 11G and I've had server running with around 5G). So it looks like you want to provide space for the future - so you should know where its going. Running lots of du -sh / is usually the answer there.

Typically on a Linux system, its /var and /home that accumulate data. Since you've already got /var on its own partition, that only leaves /home as the likely place where you want more space. So you'd need to shrink sda3 then create a new partition/filesystem in between the current sda3 and sda4.

But before you attempt that there are some additional things to do....

Your disk is GPT so fortunately you don't have to worry about primary and extended partitions.

I suspect that when you insert a new partition, the new partition will become sda4 and your root filesystem will move to sda5. You need to update your fstab to use UUIDs or labels rather than partition numbers. You will also need to point grub to the new location.

Personally, I would not even attempt this.

I'd buy/borrow another disk, make sure the data was properly backed up then wipe the old disk and reinstall / restore. And I would make sure that '/' was at the front of the new disk if it needed multiple partitions.

OTOH you currenty have enough space that you could swap /var and /home quite easily (safest to this in single user mode):

cd /
cp -r -p /var/* /newvar/
umount /var
rmdir /var
mv /newvar /var

Then comment out the mount for /var in /etc/fstab. Make sure your computer reboots happily and works then apply the reverse process for /home (again in single user mode):

mkdir /newhome
mount /dev/sda3 /newhome
# get rid of the old /var content...
rm -r -f /newhome/*

cp -r -p /home/* /newwhome/
mv /home /oldhome

Then go back to your fstab, uncomment the entry for sda3 and change the mount point to /home. Reboot and test. If all good, delete /oldhome

4
  • Most OS expect certain things to be on certain paths. Yes, but if you create a symbolic link on the old path pointing to the new path, the OS will follow the link. I haven't known AppArmor to control things under /home. Commented Mar 1, 2023 at 23:51
  • I am new to this kind of stuff. So apologize if i am saying "stupid" things. Can´t i just resize sda3 to a smaller size and then claim the free space into sda4 all using cfdisk? Commented Mar 2, 2023 at 10:15
  • @Sotto Voce - yes, it does on Ubuntu. Commented Mar 2, 2023 at 13:01
  • @Bananas17 You would be adding space at the beginning of the partition. The resize2fs man page does explicitly address how it behaves on a raw partition but it does say that doing this with LVM will trash your data. (adding space at the end is fine) Commented Mar 2, 2023 at 13:04

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.