Linux move boot partition

Ubuntu Documentation

This tutorial covers how to move the boot partition for an Ubuntu 10.04 install after installing the system without a separate boot partition.

» height=»16″ src=»/moin_static198/light/img/icon_cool.png» title=»Info » width=»16″/> Commands executed improperly can lead to an unbootable condition. If this happens, the user can use the Ubuntu installation CD to repair the installation to a working condition.

» height=»16″ src=»/moin_static198/light/img/icon_cool.png» title=»Info » width=»16″/> All device names (like /dev/sda1 and hd0,1) used in the tutorial must be adjusted to match the partitions on the user’s specific system. Do not copy commands in this tutorial without adjusting the drive/partition designations when appropriate!

Why may you want to do this?

Grub 2 error: no such partition.

  • BIOS limitations prevent the system from seeing the /boot partition files before an Operating System is loaded.
  • The user is using an OS filesystem format not compatible with the boot loader and must create a compatible ext2/3/4 partition for booting purposes.
  • What other options are there?

    • If an older BIOS doesn’t recognise the full hard drive size, enable the ‘large file’ option (such as enabling LBA) in the BIOS settings; obtain a BIOS update from the manufacturer; or move the entire Ubuntu installation to the first part of the hard drive.

    Needed for this tutorial are

      An Ubuntu live CD

    Basic knowledge of partitioning using GParted

  • Some understanding of how to use the terminal and command line
  • 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 via the ‘System -> Administration -> Gparted Partition Editor’ menu.

    Unmount the swap partition: Highlight it, then Partition -> Swapoff

    Create a partition of at least 200 MB of free space. This partition can be created from existing unallocated space, or by shrinking another partition and using the newly-created free space.

    • On older systems or very large drives, ensure the boot partition is within the area recognised by the BIOS. Check the BIOS settings for the reported disk size. It may be necessary to place the new boot partition before the Linux/Ubuntu partition in order for the BIOS to see it.

    For guidance on creating partitions read this: HowtoPartition

    For this guide, actions will be taken on a main Ubuntu installation partition and a new boot partition. These partitions will be designated as:

    • /dev/sda2 — 200 MB (minimum) new boot partition
    • /dev/sda1 — 10 GB linux installation partition

    » height=»16″ src=»/moin_static198/light/img/icon_cool.png» title=»Info » width=»16″/> Remember to change the designations to match those on your system. The current partitioning setup can be viewed with the sudo fdisk -l (lowercase L) command.

    If the boot flag is currently on your Ubuntu partition, move it to the new boot partition. This can be done with Gparted or the Disk Utility application.

    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. In these cases, GRUB or LILO are not given control even if installed in the MBR.

    Читайте также:  Kes для linux настройка

    The partition order can be changed so that /dev/sda1 comes before /dev/sda2 when using the fdisk command using the advanced options.

    » height=»16″ src=»/moin_static198/light/img/icon_cool.png» title=»Info » width=»16″/> Changing these designations may affect system files which still identify partitions by device name rather than UUID.

    Moving files from existing /boot to new location

    Open a terminal via Applications -> Accessories -> Terminal To run commands as ‘root’ for the commands in this guide without using ‘sudo’: sudo su

    Mount drives

    Make the mount points. In this guide, we will mount the main Ubuntu partition on /mnt/main, and the new boot partition on /mnt/boot

    Mount the two partitions:

    Copy /boot files

    Remount the boot partition

    Unmount the boot partition from /mnt and remount to /boot:

    Editing the files from your Ubuntu install

    Add /boot to your /etc/fstab

    If you want to find out the UUID and confirm the format of the /boot partition type:

    The output should look similar to:

    Open /etc/fstab for editing:

    » height=»16″ src=»/moin_static198/light/img/icon_cool.png» title=»Info » width=»16″/> Note the format in fstab should match the format reported by the blkid command (ext2, ext3, ext4, etc). Add this line.

    or to use the preferred UUID designation:

    Setting up GRUB 2

    Using the same mounting procedures as previously executed, from the LiveCD:

    Continue at the Reboot section.

    Setting up GRUB Legacy

    Edit /boot/grub/menu.lst

    in the console write

    gedit opens with the menu.lst file,

    and change the line

    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.

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

    Reinstall grub

    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 You will be asked to remove the CD and press «ENTER» before the system will reboot.

    Final Cleanup

    You are now booted using your new /boot partition but in the old /boot folder and files still exist on the / (root) filesystem.

    To clean this up, open up a terminal and type the following commands to unmount the /boot partition, make a backup copy and then delete the old /boot folder*, recreate the /boot folder, and remount the new boot partition:

    » height=»16″ src=»/moin_static198/light/img/icon_cool.png» title=»Info » width=»16″/> The ‘rm -rf’ command, if executed improperly, can delete your entire installation. Ensure you have unmounted the new /boot partition with the ‘umount’ command and confirm you have typed or copied the «rm» command exactly before executing it! A backup copy of the old boot folder will be placed in /root/Desktop

    Maintenance

    If using Grub legacy (not Grub 2), when you install a new linux kernel you may need to reinstall grub after mounting your boot partition over /boot in the live-CD root as shown above.

    CreateBootPartitionAfterInstall (последним исправлял пользователь yannubuntu 2012-09-03 14:19:01)

    The material on this wiki is available under a free license, see Copyright / License for details
    You can contribute to this wiki, see Wiki Guide for details

    Источник

    How to move boot and root partitions to another drive

    I have two drives on my computer that have the following configuration:

    Unfortunately, drive 2 seems to be dying, because trying to write to it is giving me errors, and checking out the SMART settings shows a sad state of affairs.

    I have plenty of space on Drive 1, so what I’d like to do is move the / and /boot partitions to it, remove Drive 2 from the system, replace Drive 2 with a new drive, then reverse the process.

    Читайте также:  Как удалить установочный файл mac os catalina

    I imagine I need to do some updating to grub, and I need to move some things around, but I’m pretty baffled how to exactly go about this. Since this is my main computer, I want to be careful not to mess things up so I can’t boot.

    3 Answers 3

    You’ll need to boot from a live cd. Add partitions for them to disk 1, copy all the contents over, and then use sudo blkid to get the UUID of each partition. On disk 1’s new /, edit the /etc/fstab to use the new UUIDs you just looked up.

    Updating GRUB depends on whether it’s GRUB1 or GRUB2. If GRUB1, you need to edit /boot/grub/device.map

    If GRUB2, I think you need to mount your partitions as they would be in a real situation. For example:

    (Filling in whatever the actual partitions are that you copied things to, of course)

    Then bind mount /proc and /dev in the /media/root:

    Now chroot into the drive so you can force GRUB to update itself according to the new layout:

    The second command will make one complaint (I forget what it is though. ), but that’s ok to ignore.

    Test it by removing the bad drive. If it doesn’t work, the bad drive should still be able to boot the system, but I believe these are all the necessary steps.

    If you replace the drive right away you can use dd (tried it on my server some months ago, and it worked like a charm).

    You’ll need a boot-CD for this as well.

    1. Start boot-CD
    2. Only mount Drive 1
    3. Run dd if=/dev/sdb1 of=/media/drive1/backuproot.img — sdb1 being your root ( / ) partition. This will save the whole partition in a file.
      • same for /boot
    4. Power off, replace disk, power on
    5. Run dd if=/media/drive1/backuproot.img of=/dev/sdb1 — write it back.
      • same for /boot

    The above will create 2 partitions with the exact same size as they had before. You might need to adjust grub (check macos post).

    If you want to resize your partitions (as i did):

    Источник

    Ubuntu Documentation

    The purpose of this how-to is to describe how to move your Ubuntu Linux partition to a different partition either in same hard-disk or different hard-disk.

    Many other article of same subject in Internet seems to be outdated on following parts:

    1. Grub2 (Ubuntu 9.10 and later)
    2. UUID for partition identification (Ubuntu 6.10 and later)

    Hence, the main purpose of this article to fill in the gap as well as one stop reference for the entire steps.

    Following are outlines of steps involved:

    • Create new target partition
    • Clone current Linux partition to target partition
    • Generate and update UUID for target partition
    • Update grub and fstab
    • Update MBR to point the new grub.

    Few assumptions I make are:

    1. Your Ubuntu is 9.10 or later
    2. Your Ubuntu is on ext4 partition (gparted should be to copy/paste any other file-system as well, however these steps were tested on ext4)
    3. Your Ubuntu configuration is of standard (not too customized)
    4. Grub2 is your boot loader

    SystemRescueCd — I prefer this rescue CD as it comes with gparted utility

  • You are not changing swap partition
  • If any of above assumptions do not apply to your system, then you will need to execute following steps with cautions.

    Step 1: Booting through Rescue CD

    A copy of SystemRescueCd can be obtain from here.

  • Burn this to a CD
  • And reboot the machine to boot from the rescue CD
    • You may need to change configuration in your bios to enable boot up from CD
  • Choose default booting option and type «wizard» once it goes to prompt
  • Now you should have X desktop loaded.
  • Step 2: Create new partition

    • Launch gparted from start menu
    • Using gparted create a new partition on your target hard-disk.

      Make sure the size new partition is same or bigger than your current Ubuntu partition used space.

    • You may also mount current Ubuntu partition to clean up unnecessary files in the partition to reduce the size.
    • And once you are done, make sure to unmount

    Step 3: Clone Ubuntu partition to new location

    • On gparted window, right-click on Ubuntu partition and select «Copy»
    • Then right-click on the new partition you have just created and select «Paste»
      • gparted will start step-by-step copy process. This may take a while.
      • You may also opt to use dd for the same purpose, but I prefer gparted because
        • It does calculate optimal way to copy over the data (block size)
        • It able to verbose current progress status

    Step 4: Generate and update UUID

    • Since step 3 copy and paste produce the new partition with exact same UUID, this will conflict and grub not able to tell the partitions apart. Hence we need to update UUID information on new partition.
    • Following is to check current UUID (You should notice duplicate UUID)
    • And following is to generate and update UUID.
    • Verify UUID (All UUIDs should be unique now)

    Step 5: Update grub and fstab

      Reboot your system from Rescue system back to normal Ubuntu

    Once you have booted to your original Ubuntu, mount the partition via gnome -> Places option

  • Edit grub.cfg file from new partition.
  • Note that you should edit grub.cfg from new partition and not from «/boot/grub/grub.cfg»

    • Using gedit, find and replace every «(hdX,Y)» appropriately
      • X and Y should be replaced based on your new partition’s /dev/sdZY or /dev/hdZY, if Z is ‘a’ then X should be ‘0’, if Z is ‘b’ then X should be ‘1’ and so on.

      Using gedit, find and replace every «—fs-uuid —set » based on new generated UUID.

    • Also still within the same file, find and replace every ‘menuentry ‘Ubuntu. » to «menuentry ‘UBUNTU. «. This is just to verify which grub is used for main boot menu. This will be overwritten by grub-update later.
    • Edit fstab file from new partition

    Note that you should edit grub.cfg from new partition and not from «/etc/fstab»

      Using gedit, find and replace root mount point’s (line with «/») based on new generated UUID.

    Step 6: Update MBR to point the new grub

    • By now, you have 2 proper bootable Ubuntu in your system, and the idea now is to make the new Ubuntu partition self bootable without any dependencies to old Ubuntu partition. And to get ride the old Ubuntu partition eventually.
    • Before updating MBR, backup current MBR data

    Mount the partition via gnome -> Places option (if is not mounted)

  • Run grub setup for new partition
  • Where [instance] is the version you want to make bootable

    • Update new ubuntu partition as bootable
    • Find and select your old Ubuntu partition to highlight the partition
    • Click the «Settings» gear button and select «Edit Mount Options»
    • Uncheck «Mount at Startup» and click «OK»
    • Find and select your new Ubuntu partition to highlight the partition
    • Click the «Settings» gear button and select «Edit Mount Options»
    • Set «Automatic Mount Options» to OFF
    • Check «Mount at startup»
    • «Show in user interface» and «Require additional authorization to mount» should NOT be checked
    • Mount options should be «errors=remount-ro»
    • Mount point should be «/»
    • Click «OK»
    • Reboot you machine again
    • On booting, make sure new partition’s grub menu is displayed as.
    • Finally, once rebooted successfully on new Ubuntu partition.
    • Refresh the GRUB 2 menu
    • Make sure Ubuntu from new partition is perfectly fine before deleting the old Ubuntu partition.
    • In case to revert back to old Ubuntu partition, all you need to do is restore the backed-up MBR image.

    Источник

    Читайте также:  Etoken driver linux alladin
    Оцените статью