11/21/13

Convert from Ubuntu to Debian LIVE

Convert from Ubuntu to Debian LIVE


The following will walk you through setting up a chroot on your live system, updating it to include the software you need to replace your live system, overwriting your live system, and rebooting into your new Debian based system.


The debian base debian system will be set up via debootstrap.


export $CHROOT=/path_to_chrootapt-get install debootstrap


You are ready to run debootstrap This command will take a while as it is downloading and installing a base system. Sit back and relax.

Installing the chroot with debootstrap


sudo debootstrap --arch amd64 sid $CHROOT http://http.debian.net/debian/


You will need to determine what your systems architecture is, you can do this by executing uname -p


Entering the chroot

In this section mount points will be set up to refer to similar places on your current live system. These are mainly pseudo filesystems like proc, sysfs, etc. Instead of mounting them manually inside of the chroot a mount bind is used for persistence.

Perform the following as root.
sudo mount --bind /proc $CHROOT/proc
sudo mount --bind /sys $CHROOT/sys 
sudo mount --bind /dev $CHROOT/dev 
sudo mount --bind /dev/pts $CHROOT/dev/pts 
sudo mkdir $CHROOT/old_root 
sudo mount --bind / $CHROOT/old_root 
# Copy files over to the chroot 
sudo cp /etc/resolv.conf $CHROOT/etc/resolv.conf 
sudo cp /etc/fstab $CHROOT/etc/


Get the packages from your old system and install them on your "new" install
sudo dpkg --get-selections | sudo tee $CHROOT/packages


Enter the chroot
sudo chroot $CHROOT

Installing and setting up the new system

This section walks you through updating your system to look as similar as possible to the previous system you had set up. This can be skipped if you arrived here looking for a way to overwrite your live system using any sort of chroot (stage3 gentoo, fedora chroot etc), you may skip this section.


*At this stage you should be inside the CHROOT.


Install dselect and initialize its database
apt-get install dselect 
dselect update


Now, take a moment to look at the packages file we created in the root of your sysroot /packages. Packages that no longer are necessary or undesired can be removed from this file.


Ubuntu uses a different init system, upstart, than Debian, sysvinit. To ensure that upstart does not remove sysvinit find the line in packages that says:

upstart                     install


Remove it.


After saving any modifications to packages, it is time to use the package file to set packages to install.


Still in the CHROOT
dpkg --set-selections < packages 2> dead_packages


dead_packages are packages that did not match up with any of the available packages in debian.


They are identified by lines like:
dpkg: warning: package not in database at line 653: libppl-c2
These are packages worth noting for later so they can be installed by hand.


Run the dselect upgrade command and wait for all the packages to be installed:
apt-get dselect-upgrade

Daemons not starting


After the dselect-upgrade has completed a number of daemons will most likely not be able to start. You have two options, remove the daemons for now or iteratively disable the daemons on the currently live system so the ports are available for the newly installed ones to start.


To iterate over the items that need repair use apt-get -f install. The process is more or less.
  1. Find daemon with a problem (mysql)
  2. Stop daemon on live system (/etc/init.d/mysqld stop)
  3. Continue apt upgrade process in chroot (apt-get -f install)


Example of what this may look like:
Errors were encountered while processing:
mysql-server-5.5
mpd
mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

Configuring your Chroot

In order to be able to use the newly created live system a few things will need to be set up properly.
  1. A kernel and bootloader need to be present
  2. Networking needs to be set up
  3. User account/root password


Install a kernel and a bootloader


If you used the dselect upgrade method above a bootloader is most likely already installed, however, chances are low that a kernel is installed.


apt-get install linux-image-amd64 grub
Notice the amd64, again pay attention to the architecture you want to install.

Setup a root password/Addusers

Users need to be set up so that the new debian system is accessible once booted. It is not necessary to add users now but at the very least a root password needs to be set.
In the chroot the default user is ‘root’ run passwd to set up a password


To add users use adduser <username>


Setting up networking

debootstrap by default will not setup networking and a server without networking is of little help when the machine is remote.


Add the following to /etc/network/interfaces


auto eth0 allow-hotplug eth0  
iface eth0 inet dhcp


If the default ethernet device is not eth0 replace it with the proper device. If you are unsure run ifconfig or ip link show on the current system and look for your current IP Address.


***Make sure openssh-server is installed on the system.


Taking over the live system

The majority of distros are not exactly binary compatible so it is not possible to simply move part of the sysroot out of the way. All of this has to be done at the same time via the chroot.


Remember the old system is mounted in the chroot under $CHROOT/old_system, this was performed above in the Entering the Chroot section.


Once these steps are started it is difficult to turn back.
mkdir old_root/old && cd old_root && mv * old

The above mv command will not complete without a few failures or warnings like
mv: cannot move 'sys' to 'old/sys': Device or resource busy, this is OK. The directories are used by the new system and it is due to a FS or PseudoFS being mounted on that location.


Now copy the new system over, this is still within the chroot!
cd / ; rsync -a bin boot debian dead_packages etc initrd.img lib lib32 libx32 lib64 media mnt opt packages root sbin var vmlinuz run usr var vmlinuz old_root/

*Note: You may see errors about rsync not being able to link_stat some files. This can safely be ignored.

Finalizing

Make sure your fstab points at the proper system.
install grub on your device
/usr/bin/grub-install /dev/sda
Regenerate grub’s config 
/usr/sbin/update-grub


That’s it, reboot your system and hope for the best. If you get stuck somewhere post a comment and I’ll help where I can.


Potential problems

Q. When entering the chroot the old_root was not available?
If this happens you can mount the root device within the chroot as if it is a normal block device
mount /dev/sda1 /old_root

Where /dev/sda1 is the root device from your currently booted system. 


References


8/1/12

Cyanogenmod 10 on the Nexus 7

This is a quick guide to walk you through putting cm10 on your Nexus 7.

There are quite a few of these guides out there but all the ones I found had pitfalls or were one click options for Windows only user. This will work on Mac, Windows, and Linux.


  • download adb/fastboot pack.
    • contains binaries and supporting files for Linux, Mac, and Windows.
    • For Linux you will need to install lib32stdc++6 and lib32ncurses5. If you are not on a 64bit machine drop the 32 from the package name. If you can't get it ask in the comments.
  • download Team Win's open recovery
  • download cm10
  • download gapps

Unlock your bootloader
Turn off your device.  Turn on the device and keep holding volume down until a menu shows up.  The device will now be in fastboot mode. Plug the device into your computer. 

If you do not have the proper drivers for windows the device will not be recognized. You need to go to Google's page and get the USB Drivers

If you device is already working with adb you can boot it into the boatloader mode without dealing with the whole volume holding procedure by running adb with the following options.

adb reboot bootloader

Once the bootloader boots you should be a big START button in green with an android's front showing a touch pad of sorts.

*The next step will WIPE everything on your device.

Run fast boot to unlock the bootloader.

fastboot oem unlock
You will be prompted on the device to confirm. Once you have done this move on to flashing a new recovery
*Stay in the bootloader.

Flashing a the Team Win open recovery
I went with Team Win's recovery over Clockwork Mod's because Clockwork Mod's recovery did not work. It would error out with "Unable to mount /sdcard" whenever I tried to install the zip files.

Flash the Team Win recovery with the following command line.
fastboot flash recovery openrecovery-twrp-2.2.1-grouper.img
You should see output like:

sending 'recovery' (6616 KB)... OKAY
writing 'recovery'... OKAY
Once that is done push the volume up button until you see Recovery Mode in red letters.
Press the power button to select recovery.

Flashing Cyanogenmod 10 and Google Apps
You should now be in the recovery with two rows of buttons.

The first thing we have to do is get the files you want to install in the right path.

Transfer both files that were downloaded from above to your device:

adb push cm-10-20120727-EXPERIMENTAL-grouper-nemith.zip /sdcard/
adb push gapps-jb-20120726-signed.zip /sdcard

After both of those have completed transferring (It will take a bit of time this since the files are quite large) move on to installing.
  • Click the install button in the upper left corner. You should already be in path /sdcard, if not navigate there.
You will see both of your files.

First install cm-10-20120727-EXPERIMENTAL-grouper-nemith.zip then install gapps-jb-20120726-signed.zip.

Navigate out and just to be sure do a full system wipe (At times, if you don't do this you will get weird behavior.)
  • Touch wipe in the upper right corner and select factory reset.
Click the back boot and then reboot.  That is it you should now have CM10 on your Nexus 7.