1

I'm running a box under Gentoo. Said box is a server (no GUI, only SSH).

Since I used genkernel to generate my kernel, I've seen that it creates several images (System.map, initramfs, kernel) that takes some place:

$ du -ahd1|sort -k1h
0       ./boot
0       ./.keep
12K     ./lost+found
1.4M    ./memtest86plus
2.4M    ./System.map-genkernel-x86_64-4.9.34-gentoo
2.7M    ./System.map-genkernel-x86_64-4.12.5-gentoo
3.7M    ./kernel-genkernel-x86_64-4.9.34-gentoo
4.2M    ./initramfs-genkernel-x86_64-4.9.34-gentoo
8.1M    ./grub
8.3M    ./kernel-genkernel-x86_64-4.12.5-gentoo
31M

Indeed, my /boot partition is only 32M large and I'd like to change its size to some size that better accommodate this (like 256M).

My /dev/sda is as follow; for reference, it is an Intel SSD (although it is an old model).

$ lsblk /dev/sda
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0 37.3G  0 disk
├─sda2   8:2    0 37.2G  0 part /
└─sda1   8:1    0   32M  0 part /boot

I know I can grow a partition on some condition (end of disk, etc) and shrink it. I also know it is risky and I'm not enough confident to do it without using a good GUI.

Can I do that:

  • shrink /dev/sda2 to get some space
  • create and mount /dev/sd3 as /new_boot
  • copy whole /boot to /new_boot (either threw a simple copy, either threw dd ?)
  • swap /boot and /new_boot
  • drop /dev/sda1 and resize /dev/sda2

Or is there a better solution ? (I have physical access to the server)

  • 1
    Is a separate /boot partition really necessary? Is your root FS encrypted, on LVM or something like this? – xhienne Aug 14 '17 at 22:43
  • Nothing complicated like that. The /boot was separated because It was like that in the gentoo manual when I installed it. -> wiki.gentoo.org/wiki/Handbook:AMD64/Installation/… I had the "good" idea to use 32M. – NoDataFound Aug 14 '17 at 23:16
  • You don't usually need the System.map files. Actually, they can pose a security risk if they're globally readable as they present an attacker the kernel memory layout. – L29Ah Aug 14 '17 at 23:31
  • @L29Ah On my Linux Mint /boot/vmlinuz* (i.e. the kernel) and /boot/System.map* permissions are 700. Strangely, on Debian, they are readable by everyone. – xhienne Aug 15 '17 at 0:07
3

Just use your root partition to store the content of /boot:

  • mount --move /boot /elsewhere or umount /boot it and mount it on /elsewhere
  • copy the content of /elsewhere into the now (probably) empty /boot while preserving the rights and owners of everything (cp -a /elsewhere/. /boot)
  • umount /elsewhere
  • remove /boot from /etc/fstab
  • update grub (grub-install probably, or your Gentoo wrapper if any)
  • reboot

Ensure that everything is fine and that you are not using anything from your old /boot partition before emptying it or recycling it (personnally I would not take any risk for 32M)

  • You spoke about security risks, but the /boot partition is only mounted by the root whenever is needed (eg: kernel upgrade). Don't I risk the same problem if I let my /boot folder in the / partition ? – NoDataFound Aug 14 '17 at 23:50
  • I didn't mention anything about security risks. The /boot directory rights, as well as the rights and owner of its content, must be preserved, that's all what matters. I'm going to add something about this in the answer. – xhienne Aug 14 '17 at 23:56
  • I've seen. In fact that was L29Ah who mentioned the security risk. – NoDataFound Aug 15 '17 at 0:20
  • Before I try that tonight: does grub needs to be the first partition ? If I can move /boot elsewhere, then I can probably create a partition at end of /dev/sda and keep the "don't mount /boot" idiom ? – NoDataFound Aug 16 '17 at 11:51
  • @NoDataFound Personally I put grub at the start of the disk, when not using UEFI. Of course, since /boot is going to be eventually removed, grub should not be put on that partition. Apart from that, as said in my answer, you should not do anything on /boot unless you are sure that everything works without it. – xhienne Aug 16 '17 at 13:23

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.