On /boot
partition there are installed kernels. When you make system update if there is new kernel it is downloaded and placed in /boot
. After that system creates new initrd image for this kernel and also place it in /boot
.
Old kernels are not removed, so after few updates there could be few kernels and initrd images in /boot
.
To clean it up check what kernel you are using (uname -a
), and remove old kernels using package manager. This should remove unused kernels and initrd images, but you can check it manually.
I don't think that separate /boot
partition is necessary unless you are using some weird filesystem on /
other than:
The currently supported filesystem types are Amiga Fast FileSystem
(AFFS), AtheOS fs, BeFS, cpio, Linux ext2/ext3/ext4, DOS
FAT12/FAT16/FAT32, HFS, HFS+, ISO9660, JFS, Minix fs, nilfs2, NTFS,
ReiserFS, Amiga Smart FileSystem (SFS), tar, UDF, BSD UFS/UFS2, and
XFS.
Source: GNU GRUB Manual 1.99
Short answer -- there is as far as I know no out of the box working solution for your specific requirements. You will have to adjust each initramfs of each distribution to support your specific needs.
Long answer -- yes it is possible. Nowadays most Linux distributions use an initramfs which will be loaded into memory by the bootloader and then unpacked by the kernel. There it will run /sbin/init
which is responsible for setting up the early userspace (running udev, loading modules, starting plymouth, asking for crypto passphrase, setting up the network for network mounts, … you name it). As you can run your own scripts and evaluate custom boot parmaters.
Example for Debian
If you are using Debian (should be the same with Ubuntu) you should be able to place a script in /etc/initramfs-tools/scripts/init-bottom/
which will be executded before init is started. For more information about the script, the different directories and the layout have a look at man initramfs-tools. You will have to adjust rootmnt
and add the target directory.
Sample (untested) script which should be installed either as /etc/initramfs-tools/scripts/local-bottom/00-myroot
or /usr/share/initramfs-tools/scripts/init-top/00-myroot
:
#!/bin/sh -e
PREREQS=""
prereqs() { echo "$PREREQS"; }
case "$1" in
prereqs)
prereqs
exit 0
;;
esac
for opt in $(cat /proc/cmdline); do
case $opt in
rootdir=*)
new_mntdir="${opt#rootdir=}"
;;
esac
done
if [ -n "$new_mntdir" ] ; then
echo rootmnt="$rootmnt/$new_mntdir" >> /conf/param.conf
fi
The idea is to adjust rootmnt
which is used in the initramfs init
script to start/execute the real init. As the root device is already mounted in the init-bootom
stage you can just adjust/alter the target directory.
To use this script just add a new boot parameter, copy the script, make it executable, regenerate your initramfs and add a boot parameter for your Linux distribution, e.g. rootdir=/Ubuntu_Precise
.
Best Answer
You can shrink your existing filesystem and partition to make room for other partitions, then copy your files. Most filesystems can't be shrunk while they're mounted, so do it from a live CD/USB such as your distribution's or the GParted live CD (live CD dedicated to partitioning) or SystemRescueCD (general system administration and rescue live CD).
I do not, however, recommend making
/boot
a separate partition. Making/boot
separate is only useful if your boot system can't manage to load a kernel from your root partition. The typical circumstances in which this happens areIf your system can already boot with the kernel on the root partition, there's nothing to be gained by creating a separate boot partition.
If you do decide to create a separate boot partition — or, for that matter, if you merge an existing boot partition onto your root partition, there's a bit more to it than just copying the files. When a PC boots, the BIOS loads the boot sector (the first 512 bytes of the boot disk) into memory. There isn't enough room in there to put a whole filesystem driver, so what that code does is to load more code from a location that's stored in the boot sector. If you move that code around to a different partition, you need to update that location. You may need to update your bootloader's configuration file as well.
update-grub
(e.g. Debian or Ubuntu), run it. Otherwise, edit the configuration file (/boot/grub/menu.lst
for Grub 1 or/boot/grub/grub.cfg
for Grub 2) and update the device from which Grub will find the kernel. (With Grub 2, you may have nothing to do as it can find the kernel automatically at run time.) In either case, also rungrub-install /dev/sda
.lilo
.