个人工具

UbuntuHelp:CreateBootPartitionAfterInstall

来自Ubuntu中文

Wikibot讨论 | 贡献2010年5月19日 (三) 21:57的版本

(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航, 搜索
  1. title Create boot partition after install
    This is not finished (but then isn't this the nature of the web?)
    These procedures could damage the information on your computer. Make backups first.
    Be careful. Read the documentation, again. You have been warned. Twice.
    !!! All device names (like /dev/sda1 and hd0,1) 
    used in the tutorial need not to apply on your situation,
    do some research of your device names first and don't 
    blindly copy every command from this tutorial !!!

This tutorial covers how to create a boot partition for an Ubuntu 8.04 install after installing the system without a boot partition. Why may you want to do this?

  • If you get this error message after updating your linux kernel:

Error 18: Selected cylinder exceeds maximum supported by BIOS Needed for this tutorial are

Preparations

Booting the Ubuntu Live CD

Boot from the Ubuntu Live CD as you would normally, select your language and choose the 'try Ubuntu' option

Creating a partition for /boot

Once your system has booted from the live CD open GParted this is in 'System -> Administration -> Partition Editor' Resize your main partition by adding 100 MB of free space before this, turn this created free space in a partition as well. If you don't know how, read this: HowtoPartition We now have 2 partitions on the main drive, in my case /dev/sda

  • /dev/sda2 - 100 MB new partition
  • /dev/sda1 - 3.65 GB linux installation partition

Disable the bootflag on /dev/sda1 and enable it on /dev/sda2 using the right-click menu in GParted Q: Is this really necessary? GRUB and LILO are supposed to ignore the bootable flag A: In rare cases, the motherboard BIOS requires a partition with a bootable flag in order to boot from the hard drive. I have personal experience with this. In these cases, GRUB or LILO are not given control even if installed in the MBR. The partition order can be fixed so that /dev/sda1 comes before /dev/sda2 in fdisk using the advanced options "f fix partition order"

Moving files from existing /boot to new location

Now let's start a console in the console type sudo su to become root, like this you can do all the root task without having to use 'sudo' all the time.

Mount drives

next is to make a directory to mount the two drives in.

mkdir /mnt/boot
mkdir /mnt/root

and mount the two drives in here

mount /dev/sda2 /mnt/boot
mount /dev/sda1 /mnt/root

Copy files

cp -r /mnt/root/boot/* /mnt/boot/

Remount the boot partition

Now we are remounting the boot partition to be where /boot is, we need this for later to re-install grub

umount /dev/sda2
mount /dev/sda2 /boot

Editing the files from your Ubuntu install

Add /boot to your /etc/fstab

in the console write

gedit /mnt/root/etc/fstab

to edit the fstab file in your Ubuntu install and add the line

/dev/sda2    /boot     ext2     defaults    0  0

or if you want to find out the UUID of the drive and use that in the fstab file, in the console type

blkid

in the output there will be

/dev/sda2:  UUID="<some uid>" TYPE="ext2"

the line to add in /etc/fstab would now be

UUID=<uid found with blkid> /boot   ext2   defaults  0  0

The UUID will be the same in the live cd environment as in your normal Ubuntu, so it's completely save to copy this value

Setting up GRUB

Edit /boot/grub/menu.lst

in the console write

gedit /boot/grub/menu.lst

gedit opens with the menu.lst file, find the part that says:

# groot=(hd0,0)

and change the line

# groot=(hd0,0)

to

# groot=(hd0,1)

Next, update the boot entries at the end of the file. Since you now have a /boot partition, all kernel and initrd paths are relative to /boot/ instead, eg.

title           Ubuntu 8.04.1, kernel 2.6.24-21-generic
root            (hd0,1)
kernel          /vmlinuz-2.6.24-21-generic root=UUID=41f24518-160e-48a1-9bb1-295213e94a67 ro quiet splash
initrd          /initrd.img-2.6.24-21-generic
quiet

Update root to match that of groot above and remove /boot from the kernel and initrd paths in all the entries.

Reinstall grub

run:

sudo grub
grub> root (hd0,1)
grub> setup (hd0)

remember in the setup command do not use hd0,1 as you need to install grub in the master boot record not in this specific partition boot record.

Reboot

reboot your system by typing reboot. Take out the ubuntu live cd, and boot back to your normal system voila, you now have a working /boot partition

Final Cleanup

You are now booted using your new /boot partition, but in the old /boot dir on the / (root) filesystem there are still the files used for booting before you had a separate partition for that. To clean this up, open up a console and type the following commands

umount /boot
rm -rf /boot
mkdir /boot
mount /boot

You have now unmounted the boot partition,<
> deleted all the files from /boot in the / (root) filesystem.<
> recreated the /boot dir as empty dir.<
> remounted the boot partition.

Maintenance

Remember when your install new linux kernel next time, you may need to reinstall grub after mounting your boot partition over /boot in the live-CD root as shown above.