HOWTO: Move /boot to its own partition

Having /boot on its own partition is useful if you use many linux distributions, especially on different hard disks. Besides, if your root filesystem gets corrupted, you’ll still be able to boot if your /boot is separate.

Let’s get started.. first of all we need to create a new ext3 partition which will be our new /boot. In order to decide how big it should be, let’s see how much space our current /boot is taking up. A value of 100Mb should suffice for most needs (unless you’re a kernel hacker with lots of images in /boot):

$ du -h /boot

Once we have an idea about the size, go ahead and create the partition. You can use GParted… or if you prefer the command line, use mkfs:

# mkfs -t ext3 /dev/hda#

Now let’s assume that the partition you just created is /dev/hdaX (replace X with the actual digit). We’ll proceed as follows (prepend sudo before each command, or relogin as root):

1. # mkdir /mnt/newboot
2. # mount /dev/hdaX /mnt/newboot
3. # cp -dpR /boot/* /mnt/newboot/
4. # mv /boot /oldboot
5. # mkdir /boot
6. # nano -w /etc/fstab

and modify the /boot line to:
/dev/hdaX /boot ext3 ro 0 0

Note that we want /boot to be mounted read-only after the OS boot process. You can also delete the whole entry altogether to prevent /boot from being mounted.

7. # umount /mnt/newboot
8. # mount /dev/hdaX /boot
9. # nano -w /boot/grub/menu.lst

Now change the entries corresponding to your old root partition to /dev/hdaX. In grub’s terms, that translates to (hd0,X-1) if it’s the first hard drive. For eg, /dev/hda8 is (hd0,7). Note that you also need to change /boot/xxx.x entries to /xxx.x since the /boot partition is itself the root partition in grub’s eyes. For eg, /boot/grub becomes /grub. Finally, install grub onto the MBR. Issue:

10. # grub-install /dev/hda

(Replace /dev/hda with the /dev/… entry of the hard disk where you want to install Grub to).
Warning: DO NOT run grub-install on /dev/hda1 if you have windows installed there. You won’t be able to boot into it.. if you commit this mistake, take a look here.

All done! Now reboot.

P.S: Any time you want to write to /boot, do a:
$ sudo mount -o remount,rw /boot

in order to remove the read-only flag..