1

I want to upgrade Linux kernel from 3.16 to 4.3. Unfortunately when I run aptitude install linux-image-4.3.0-1-amd64 installation fails due to no space on rootfs partition. 117MB left, 174MB needed.

I have no old kernels to remove to free up more disk space (except the one that I'm using right now):

root@host:/# aptitude search linux-image | grep ^i
ip  linux-image-3.16.0-4-amd64      - Linux 3.16 for 64-bit PCs

I tried to free up space using aptitude clean, apt-get autoremove, but it didn't help because /var is a separate partition. AFAIK those commands removes content of the /var/cache/apt/archives directory, so it cannot help.

I considered to temporarily mount --bind / /home/rootfs (as suggested here), but rootfs probably cannot be safely remounted.

My file system disk space usage:

root@host:/# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda6       454M  310M  117M  73% /
udev             10M     0   10M   0% /dev
tmpfs           1,6G   19M  1,6G   2% /run
/dev/sda7        23G   13G  8,8G  59% /usr
tmpfs           3,9G   52M  3,9G   2% /dev/shm
tmpfs           5,0M  4,0K  5,0M   1% /run/lock
tmpfs           3,9G     0  3,9G   0% /sys/fs/cgroup
/dev/sda4       250G  187G   64G  75% /media/Windows/C
/dev/sda5       500G  428G   73G  86% /media/Windows/D
/dev/sda2        96M   25M   72M  26% /boot/efi
/dev/sda8       7,3G  966M  5,9G  14% /var
/dev/sda9        14G   37M   13G   1% /tmp
/dev/sda11      126G   95G   25G  80% /home
tmpfs           797M   20K  797M   1% /run/user/112
tmpfs           797M   24K  797M   1% /run/user/1000

du -mx / | sort -n result: link.

OS version:

root@host:/# cat /etc/debian_version 
stretch/sid

/boot content:

root@host:/# du -sh /boot/*
156K    /boot/config-3.16.0-4-amd64
25M     /boot/efi
8,8M    /boot/grub
16M     /boot/initrd.img-3.16.0-4-amd64
16M     /boot/initrd.img-3.16.0-4-amd64.old-dkms
2,6M    /boot/System.map-3.16.0-4-amd64
3,0M    /boot/vmlinuz-3.16.0-4-amd64
  • Is there any clever and safe way to free up rootfs partition or temporarily move current kernel to another partition?
  • Is it safe to move some rootfs content to another partition and create symbolic links pointing to them?

I know that there is plenty of similar problems, but most of them end up with removing old kernels which I don't have.

  • 1
    Sometimes there are old files in /boot from previous kernels left which you can delete safely. Please list /boot. – jofel Jan 10 '16 at 14:59
  • I added /boot content to my question. It seems that those files belongs to currently installed kernel. – patryk.beza Jan 10 '16 at 15:06
  • 1
    I believe your best bet is to extend the /boot partition. I'm pretty sure it has to be a separate, primary partition. Here Fedora suggested 500MiB, and that seems to be roomy but not overly so (3 kernels plus assorted junk fit comfortably). – vonbrand Jan 10 '16 at 15:57
  • 1
    AFAIK You can at least delete the *.old-dkms file if you current system boots without problem - it is just a backup / failback file. – jofel Jan 10 '16 at 17:14
  • 2
    @jofel No! /bin, /sbin, /lib and /etc need to be on the root partition, because they contain files that are needed to mount the other partitions. – Gilles Jan 10 '16 at 22:58
1

450MB is not much for a root+boot partition on a modern amd64 system. If you want to install multiple kernels, you're going to have to reorganize your partitions. Even if you don't, it's pretty tight.

Given the partitions you have now, I suggest moving the root partition to what is now /var. Since you're going to move the root partition, boot from rescue media (e.g. SystemRescueCD). Mount /dev/sda6 and /dev/sda8, say to /media/sda6 and /media/sda8. Then:

  1. Create a /var directory: mkdir /media/sda8/var
  2. Move everything in the old /var partition to this new subdirectory: mv /media/sda8/* /media/sda8/var (/var itself will be skipped)
  3. Move everything except /boot from the old root partition to the old var partition: mv /media/sda6/[^bv]* /media/sda6/bin /media/sda8/
  4. There should only be /boot and an empty /var on the old root partition. Move everything from /boot to the root of the partition: mv /media/sda6/boot/* /media/sda6
  5. Remove the spurious directories: rmdir /media/sda6/boot /media/sda6/var and create one that's now needed: mkdir /media/sda8/boot
  6. Edit the fstab file (now in /media/sda8/etc/fstab), remove the entry for /var, add one for /boot, and correct the entry for / if necessary.
  7. Update the bootloader configuration. The easy way to get it right is to run both update-grub script (to regenerate grub.cfg) and grub-install (to regenerate the first-stage bootloader so that it knows where to find the rest, including grub.cfg). But to do that, you need to present it the right directory tree.

    mount --rbind /dev /media/sda8/dev
    mount --rbind /proc /media/sda8/proc
    mount --rbind /sys /media/sda8/sys
    mount --bind /media/sda6 /media/sda8/boot
    chroot /media/sda8
    mount /usr
    update-grub
    grub-install /dev/sda
    

Now reboot.

Alternatively, you could move /boot to /var; but it's a less common configuration, so you may have to tweak some bootloader configuration files.

These days, separating /usr from / is pretty pointless. Separating /var from / has never been really useful (they both need to be mounted read-write on most setups).

In the future, I recommend using LVM for Linux partitions. It's a lot more flexible.

  • I followed those steps and after reboot I've got error: file '/boot/grub/x86_64-efi/normal.mod' not found. Entering rescue mode... which is probably result of wrong /etc/fstab. I've changed 2 lines of /etc/fstab - one for /dev/sda8 (which used to be mounted as /var) and one for /dev/sda6 (which used to be mounted as /). Before: UUID=SDA8_UUID_HERE /var ext4 defaults 0 2, UUID=SDA6_UUID_HERE / ext4 errors=remount-ro 0 1. After: UUID=SDA8_UUID_HERE / ext4 errors=remount-ro 0 1, UUID=SDA6_UUID_HERE /boot vfat defaults 0 1. Any idea what's wrong? – patryk.beza Jan 31 '16 at 20:38
  • 1
    @patryk.beza Grub is looking for a file in /boot, but if /boot is in a separate partition, then the path should be /grub/x86_64-efi/normal.mod. I think the prefix setting is wrong, it should be something like (hd0,0)/grub/grub.cfg. Normally running grub-install should take care of setting it correctly so that you don't need to set it in grub.cfg. In fact setting it in grub.cfg is too late since that's where Grub looks for grub.cfg. My bad, I forgot to mention this: I think you need to rerun grub-install /dev/sda. Could you try this and report back? – Gilles Jan 31 '16 at 20:48
  • It worked! I really appreciate your help @Gilles. A few notes: I needed to run chroot /media/sda8 /bin/bash because by default it tried to use /bin/zsh; I needed to mount /boot with ext4, not vfat (as I wrongly suggested above); don't know why, but grub-install wiped out Windows' dual boot options - I probably need to add them manually. BTW: SystemRescueCD is great tool. – patryk.beza Jan 31 '16 at 21:29

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.