1

I am working on a Debian 9 system. When I try to install a package, dpkg fails with following error:

Selecting previously unselected package mariadb-server-10.1.
Preparing to unpack .../3-mariadb-server-10.1_10.1.38-0+deb9u1_amd64.deb ...
/var/lib/mysql: found previous version 10.1
ERROR: There's not enough space in /var/lib/mysql/
dpkg: error processing archive /tmp/apt-dpkg-install-ShVFUI/3-mariadb-server-10.1_10.1.38-0+deb9u1_amd64.deb (--unpack):

Here is df -h:

Filesystem      Size  Used Avail Use% Mounted on
udev            3.9G     0  3.9G   0% /dev
tmpfs           791M  9.1M  782M   2% /run
/dev/sda2        55G  9.8G   43G  19% /
tmpfs           3.9G  158M  3.8G   4% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda1       511M  132K  511M   1% /boot/efi
/dev/sda5       844G  540G  261G  68% /home
/dev/sda3       9.2G  8.7G   32K 100% /var
tmpfs           791M   12K  791M   1% /run/user/1001

fdisk -l output:

Disk /dev/sda: 931.5 GiB, Disklabel type: gpt
Disk identifier: AAF695F1-3DA1-4E89-86F4-59439A75BCBB
   Device      Start        End    Sectors Size   Type
/dev/sda1       2048    1050623    1048576 512M   EFI System
/dev/sda2    1050624  118237183  117186560 55.9G  Linux filesystem
/dev/sda3 1933993984 1953523711   19529728 9.3G   Linux filesystem
/dev/sda4 1917392896 1933993983   16601088 7.9G   Linux swap
/dev/sda5  118237184 1917392895 1799155712 857.9G Linux filesystem

How can I move /var to a spacious partition (if at all possible)? Or, how can I increase the size of /dev/sda3 to, say, 30G?

  • 1
    What filesystem are you using on /var? And paste the output of fdisk -l please. – blissini Jul 9 at 9:35
  • That's going to be really difficult for 2 reasons. First, you are using all physical partitions and second, the one you want to extend is not at the end of the disk. – jordanm Jul 9 at 9:44
  • Here goes fdisk -l output: <br/> Disk /dev/sda: 931.5 GiB, Disklabel type: gpt Disk identifier: AAF695F1-3DA1-4E89-86F4-59439A75BCBB Device Start End Sectors Size Type /dev/sda1 2048 1050623 1048576 512M EFI System /dev/sda2 1050624 118237183 117186560 55.9G Linux filesystem /dev/sda3 1933993984 1953523711 19529728 9.3G Linux filesystem /dev/sda4 1917392896 1933993983 16601088 7.9G Linux swap /dev/sda5 118237184 1917392895 1799155712 857.9G Linux filesystem Partition table entries are not in disk order. – Kusan Biswas Jul 9 at 10:22
  • @jordanm I have converted physical to logical partitions. I can't remember how, but it involved writing down the start and end, and then editing the partition table … – ctrl-alt-delor Jul 9 at 11:00
  • can we see the output of sudo /sbin/parted /dev/sdb print – ctrl-alt-delor Jul 9 at 11:09
1

Your filesystem are on disk partitions and not lvm (logical volume management) or other flexible provisioning system, so I would advise against trying to move/resize partitions, it is too tricky and risky.

Concerning moving /var to another partition:

First solution

Since you have quite a lot of free space on the root / filesystem you could move /var back to it. Unfortunately /var can not be unmounted or touched when the system is running. My suggestion is to boot you system with a rescue live linux distro on a usb drive or CD, e.g. gparted, open a shell and modify the system setup on your hard disk following more or less these guidelines:

mkdir /tmp/root
mkdir /tmp/var
# mount the filesystems
mount /dev/sda2 /tmp/root
mount /dev/sda3 /tmp/var
# copy everything in /var
# do not forget the / after var in /tmp/var/
rsync -aHXA /tmp/var/ /tmp/root/var

then, with a text editor, comment out with # or remove the line relative to /dev/sda3 /var in the list of static mounts /tmp/root/var/etc/fstab. Notice that, in the live system, the device may be different than in the main system, so sda could be come sdb, please check before doing any modification.

After this modifcation /dev/sda3 is an unused partition with space available.

Second solution

If you foresee that the space requirement under /var/ comes mainly from mariadb package and all the related database files, then it would be wise to install a second hard drive or ssd and move only the /var/lib/mysql directory on that disk/partition. In this case you do not need to stop the system and boot from another distro for moving the data, but only stop the mariadb service, if already installed and active.

From your post it is not clear whether you have already an installation of mariadb or mysql package with precious files in /var/lib/mysql, since on one hand we see Selecting previously unselected package mariadb-server-10.1., on the other hand /var/lib/mysql: found previous version 10.1. Assuming that you have already one, then:

# prepare and format somehow a new disk/partition, let's call it $MYSQLDEV
# mount it in a temporary place
mkdir /tmp/mysql
mount $MYSQLDEV /tmp/mysql
# copy existing data on new partition
rsync -aHXA /var/lib/mysql /tmp/mysql
# if you are really sure you have copied everything,
# type with care and double check
rm -rf /var/lib/mysql/*
# mount filesystem in the final position
umount $MYSQLDEV
rm -f /tmp/mysql
mount $MYSQLDEV /var/lib/mysql/

After this you should put a line in yout /etc/fstab file to tell the system that the new partition has to be mounted at every boot, it will look more or less like this, by replacing $MYSQLDEV and assuming that you formatted it with ext4 format:

$MYSQLDEV /var/lib/mysql ext4 defaults 1 2
  • Thanks Davide for such an elaborated answer. Now I understand that /var partition can not be resized because it is not an LVM, and that moving /var to somewhere else can be a messy job. Therefore I went for the second solution of moving Mariadb data directory from /var/lib/mysql to somewhere else. For the time being I moved it to /opt. I plan to buy an SSD and move it there. Thanks everyone. – Kusan Biswas Jul 10 at 4:39

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.