Ubuntu: How to copy /sda3 to /sda1? UUID's can't be similar



Question:

/dev/sda is a 400 gig drive. It's partitions WERE: /sda1 - Windows boot partition (100 meg); /sda2 Windows "C:\" (68 gig); /sda3 is Linux boot partition; /sda5 is /home partition; /sda6 is linux-swap.

/sda1 and /sda2 have been deleted and /sda2 expanded into /sda1.

I want to clone /sda3 to /sda1 AND have the 12.04 (precise pangolin) know to boot from /sda1 and not from /sda3.

How do I edit both /etc/fstab and GRUB2 to have proper (I have no idea how to use words to express this idea) UUID? I know that using GParted to "copy" /sda3 to /sda1 requires editing to make the copied partition have a UUID that is not a match (or the same UUID number as) the original partition (/sda3). What other steps must I take to not confuse GRUB2 and the fstab so that they work harmoniously and I don't harm the OS/data/other stuff on the hard drive?

Next, I want to shrink /sda1 to 25 gig (currently 68 gig), and continue /sda1 as boot. Then I want to use 43 gig from shrinking /sda1, and add it to the (to be) unused /sda3 and then to expand /sda5 into the expanded /sda3

I cannot post a screenshot of gparted, so here is fdisk -l in stead:

mark@Lexington-19:~$ sudo fdisk -l  [sudo] password for mark:     Disk /dev/sda: 400.1 GB, 400088457216 bytes  255 heads, 63 sectors/track, 48641 cylinders, total 781422768 sectors  Units = sectors of 1 * 512 = 512 bytes  Sector size (logical/physical): 512 bytes / 512 bytes  I/O size (minimum/optimal): 512 bytes / 512 bytes  Disk identifier: 0xf3e1e104         Device Boot      Start         End      Blocks   Id  System    /dev/sda1            2048   143570943    71784448   83  Linux    /dev/sda3   *   143572905   174176729    15301912+  83  Linux    /dev/sda4       174176791   781417664   303620437    5  Extended    /dev/sda5       174176793   764420894   295122051   83  Linux    /dev/sda6       764420958   781417664     8498353+  82  Linux swap / Solaris  


Solution:1

The easy way, IMO, is to boot the Ubuntu desktop CD. You can then use gparted to copy-paste your partitions.

The only trick with gparted is that you have to apply the changes one setp at a time.

Delete sda1 -> apply changes -> copy sda3 -> paste -> apply changes.

gparted

Once you have copied the partition you can also use gparted to create a new UUID

Select the partition â†' New UUID

Mount the partition at /mnt

sudo mount /dev/sda1 /mnt  

Edit fstab, enter the new UUID under the entry for the root file system.

List the UUID, if needed, with blkid

blkid    gksu gedit /mnt/etc/fstab  

Re-install / update grub

sudo grub-install --boot-directory=/mnt/boot /dev/sda  

See also:


Solution:2

Is there a specific reason why you want to move the Linux partition from 3 to 1? Do you aim for a performance gain or is it just out of habit?

The easy way

  1. Shrink the Linux partition from within a Live CD
  2. Delete partition sda1
  3. Move partition sda2 to the very beginning of your hard drive and sda3 right behind
  4. Extend the extended partition that holds sda5 and sda6

The proper way

  1. Shrink the Linux partition to minimum from within a Live CD
  2. Move partitions sda2 and sda3 as far to the end as possible
  3. Resize and format sda1
  4. Copy everything from sda3 to sda1 with rsync --progress -av, modyfiy fstab accordingly on sda1
  5. Reinstall grub with grub-install --boot-directory=/path/to/mounted/sda1 sda
  6. Delete partition sda1
  7. Extend the extended partition that holds sda5 and sda6

Pro: Linux partition is physically in first place (and also defragmented Linux partition)

Con: Involves reinstalling boot loader

The dirty way

  1. Dump partition /dev/sda2 (the device) with dd to a file (like an external hard drive), note down the exact size of the partition an delete it as well as sda1
  2. Resize sda3 to desired size and move it to the very beginning of your hard drive
  3. Recreate the Windows partition and write the dump back to the partition (switch input and output files/devices)
  4. Extend the extended partition that holds sda5 and sda6

Pro: Linux partition is physically in first place, no need to reinstall bootloader

Con: sda3 is still sda3 and what has been sda2 could be sda1, be careful not to write to the wrong partition with dd, dumping takes more time as it copies everything (even files and fragments of files that do no longer exist)

Recommendation

Go the easy way. If performance matters buy a SSD. (I know that this is the most overused phrase these days, but measurably worth the effort.)


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »