Sunday, January 2, 2011

Labels: , , , ,


After ubuntu released wubi for people who were "afraid" to touch their hard disk partitions, but wanted linux, many had tried ubuntu installing it inside windows. Once they are comfortable with ubuntu, they start thinking of moving ubuntu to a seperate partition. But, how can it be done without losing all their information and data in the current ubuntu installation? 
That is answered here..

These are the steps required to migrate a wubi 9.10, 10.04 or 10.10 install to partition (grub2 only). The first part shows how to do a manual migration, and the second how to use the attached script to do an automated migration.

The partition(s) must be created already - there are plenty of guides on how to do this.

Manual migration (see below for automated migration)

This example assumes the new install will be on /dev/sda5 and that there will be a swap on /dev/sda6. If there is no swap, just ignore lines containing /dev/sda6. If there is a swap partition it must be of type 'swap'. Change the device names as appropriate.

1. Do this all as root
Code:
sudo -i
1.a. Ensure you do not have grub-legacy. If the output of the following shows version 0.97 then please do not continue. These instructions only work with grub versions 1.96 and greater.
Code:
grub-install --version
2. Format new partition if not done so already - make sure it's empty, large enough and unmounted
WARNING -- the next command will wipe all existing data on /dev/sda5
Code:
mkfs.ext4 /dev/sda5
3. Mount new partition and copy files. 
Code:
mkdir /tmp/wubimove
mount /dev/sda5 /tmp/wubimove
rsync -av --exclude=/host --exclude=/mnt/* --exclude=/home/*/.gvfs --exclude=/media/*/* --exclude=/tmp/* --exclude=/proc/* --exclude=/sys/* / /tmp/wubimove
chmod -x /tmp/wubimove/etc/grub.d/10_lupin
4. Setup swap partition and enable hibernation (swap must be at least as big as RAM to hibernate)
Code:
mkswap /dev/sda6
echo "RESUME=UUID=$(blkid -o value -s UUID /dev/sda6)" > /tmp/wubimove/etc/initramfs-tools/conf.d/resume
5. Edit fstab (blank out wubi mounts with sed and add new partitions)
Code:
sed -i 's:/.*[\.]disk .*::' /tmp/wubimove/etc/fstab    
echo "UUID=$(blkid -o value -s UUID /dev/sda5)    /    ext4    errors=remount-ro    0    1" >> /tmp/wubimove/etc/fstab
echo "UUID=$(blkid -o value -s UUID /dev/sda6)    none    swap    sw    0    0" >> /tmp/wubimove/etc/fstab
6. Remove lupin support and update grub (all in chroot). Note that this step installs the grub bootloader to /dev/sda and will replace your windows bootloader (the line 'grub-install /dev/sda') -- see note below
Code:
mkdir /tmp/wubimove/host
for i in dev proc sys dev/pts host; do mount --bind /$i /tmp/wubimove/$i; done
chroot /tmp/wubimove
dpkg-divert --local --rename --add /sbin/initctl
ln -s /bin/true /sbin/initctl
apt-get -y remove lupin-support
update-grub
grub-install /dev/sda
rm /sbin/initctl
dpkg-divert --local --rename --remove /sbin/initctl
exit
for i in host dev/pts dev proc sys; do umount /tmp/wubimove/$i; done
rmdir /tmp/wubimove/host
umount /dev/sda5
7. Update wubi grub menu to pick up new install and exit sudo
Code:
update-grub
exit
You're done. When you reboot, you should see a grub menu instead of the windows boot menu. Select the first entry. If you didn't run 'grub-install' you can boot from the wubi menu, select your new install from the bottom after the Windows entry.

NOTE on installing the grub bootloader: you can try out the new installation by booting it from the wubi grub menu first - if you want to make sure everything is working before replacing the windows bootloader. To do this, bypass the line 'grub-install /dev/sda' (in step 6.). You can then install the grub2 bootloader manually later after booting into the new install.
I also recommend updating the grub menu after booting into the target partition
Code:
sudo update-grub
Automated migration

I have attached a parameter driven script that does the above with additional validation e.g. checks the target partition is big enough and empty etc.

Usage instructions:
Code:
bash wubi-move.sh --help
To migrate wubi to /dev/sda5 without swap
Code:
sudo bash wubi-move.sh /dev/sda5
To migrate wubi to /dev/sda5 with swap on /dev/sda6
Code:
sudo bash wubi-move.sh /dev/sda5 /dev/sda6
If you don't want to install the grub bootloader i.e. you want to leave the windows bootloader in place, use the --no-bootloader option. In this case, you can boot the new install using the wubi menu, and will have to manually install the grub bootloader later.
Code:
sudo bash wubi-move.sh --no-bootloader /dev/sda5 /dev/sda6

Warning - while I have tested this numerous times and every attempt has been made to ensure there are no bugs, use it at your own risk.

Please note - it takes some time to copy all the data from wubi to the target partition. e.g. on my computer it takes about 5-10 minutes for a small install (5GB).

Known issues:
1. For some reason, running "update-grub" in the chroot doesn't pick up other linux installations on the same drive (same running the script or manual commands listed above). This is unlikely an issue for wubi users. Run sudo update-grub after booting the new install for the first time.
Attached Files
File Type: shwubi-move.sh (12.9 KB, 296 views)

0 Responses to :