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..


11 thoughts on “HOWTO: Move /boot to its own partition

  1. I believe the line

    3. cp -dpR /boot /mnt/newboot

    should instead read:

    3. cp -dpR /boot/* /mnt/newboot

    You want to copy the *contents* of /boot, not the folder itself, to the newboot. Otherwise you will end up with a ‘boot’ folder inside /boot, which will not agree with the kernel path in Step 9.

  2. I believe the 6th step does exactly that. Afaik /boot needn’t be mounted as long as we tell Grub what’s going on.. So you can skip that step if you want..

  3. You mean during a kernel upgrade? Well, we can just mount it manually, right? But yea, if you have automatic updates (which I don’t usually enable) then it makes sense to mount it R/W.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s