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:

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
  5. SystemRescueCd - I prefer this rescue CD as it comes with gparted utility

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

Step 2: Create new partition

shell> mkdir ~/ubuntu
shell> mount /dev/sdZY ~/ubuntu
or
shell> mount /dev/hdZY ~/ubuntu
# where ZY is your ubuntu partition's block device name (you can find this from gparted window)
shell> cd ~/ubuntu

shell> umount ~/ubuntu

Step 3: Clone Ubuntu partition to new location

Step 4: Generate and update UUID

shell> blkid

shell> tune2fs -U random /dev/sdZY
or
shell> tune2fs -U random /dev/hdZY
# where ZY is your new partition's block device name (you can obtain this from gparted window)

shell> blkid

Step 5: Update grub and fstab

shell> gksu gedit /media/<new partition uuid>/boot/grub/grub.cfg &

shell> gksu gedit /media/<new partition uuid>/etc/fstab &

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

shell> sudo dd if=/dev/sdZ of=~/sdZ.img bs=1 count=512
or
shell> sudo dd if=/dev/hdZ of=~/sdZ.img bs=1 count=512
# where Z is your old Ubuntu partition's block device name
# note that device name is without 'Y'; without partition id.
  • Mount the partition via gnome -> Places option (if is not mounted)

  • Run grub setup for new partition

shell> sudo grub-install -d /media/<new partition uuid>/usr/lib/grub/[instance] /dev/sda

Where [instance] is the version you want to make bootable

  • Update new ubuntu partition as bootable

gnome> Run the "Disks" application
  • 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.

1) UBUNTU...

  • Finally, once rebooted successfully on new Ubuntu partition.
  • Refresh the GRUB 2 menu

sudo update-grub
  • 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.

shell> sudo dd if=~/sdZ.img of=/dev/sdZ bs=1 count=512
or
shell> sudo dd if=~/sdZ.img of=/dev/hdZ bs=1 count=512
# where Z is your old Ubuntu partition's block device name
# note that device name is without 'Y'; without partition id.

See Also

External Links


CategorySystem

MovingLinuxPartition (last edited 2020-03-23 10:04:38 by rs2009)