ze blog of ankur banerjee

needlessly messianic articles written by ankur banerjee on anything that catches his fancy, which is quite a lot indeed - stuff like tech, quizzing, h2g2 - and cups of filthy liquid almost, but not quite, entirely unlike tea


Psst! Now you can get updates on articles posted to this blog through email.

$7.49 .com banner

Solving Ubuntu USB Disk Install Error

Filed Under (Linux Rules, Tech Takes) by Ankur on 19-11-2008

Ubuntu 8.10 Intrepid Ibex + Asus eeePC 1000H
Creative Commons License photo credit: CrackVan

Ubuntu’s latest release - Interpid Ibex 8.10 - ships with a new feature that allows to install itself to a USB drive. This by no means is revolutionary since you could have done this earlier using software like Ubnetbootin, but bundling this feature with the distro itself adds a new dimension of ease to those who’re just trying out Ubuntu and might want to carry a secondary operating system in their USB drive. ‘Ease of use’ since unlike Unetbootin, you don’t have to download a distro or keep / create an ISO file; you can simply use any Ubuntu Live CD you already have. You can access this feature from System > Administration > Create USB startup disk. There is really nothing much you need to do, except plug-in your USB drive BEFORE you start this utility. Ideally, you should do this install on a formatted (clean) pen drive.

In the utility, you’ll find an option on how much disk space you want to allot for documents created in the USB disk session. I would suggest that you keep this amount to the minimum, because no matter whether the documents are there are not that much amount of specified space will always be occupied. Ubuntu makes a ‘persistence’ file called casper-rw with filesize equal to the amount you specify you want to reserve. I won’t get into the technical details, but the moot point is that without reinstalling Ubuntu you won’t be able to change this. You probably won’t create THAT much documents in a USB disk session to fill up the whole minimum amount. You should note, however, that the extra space after installing Ubuntu on your USB drive will NOT be available if you’re running in a USB Ubuntu session - but you can use the pen drive normally if you’re running Windows and / or Linux from hard disk / Live CD. Furthermore, any files that you create and store in the Ubuntu session will be stored in the casper-rw persistence file, and thus not available from Windows. (You can, however, save the files you create to the hard disk of the computer you’re using and retrieve it later using the USB drive.)

With the new USB install procedure you might run into some problems. First you need to ensure that you’re BIOS supports booting from USB drive, and that the boot priority for USB disk is set to higher than hard disk in your BIOS settings. I can’t give instructions for BIOS because it’s different for different manufacturers / makes, but I’m sure you’ll figure that out. The other (more ‘disturbing’) problem that you might encounter is after booting from the USB drive, your computer might throw up this error:

Invalid or damaged Bootable partition

This happens on only certain makes of BIOS and hardware, and isn’t actually anything scary. The solution for this is pretty simple:

  1. When you encounter the error message, force a shutdown by pressing down the power button.
  2. Power up, and pop the Ubuntu Live CD into your CD tray. Boot into the Live CD session.
  3. Plug-in your USB drive. Wait for it to be detected. If the system prompts you to auto-run the USB drive, press Cancel.
  4. Go to System > Administrator > Partition Editor. Wait for it to scan available media. When it does, switch the media to your USB disk from the dropdown box at the top right corner.
  5. Right click on the USB disk partition which shows up and choose Unmount. (I’m assuming that the disk is mounted; if it’s not you may skip this step.)
  6. After it has been unmounted, right click again on the partition and choose the option Flags. In the dialog box that open, boot would already be checked. Let that be, and check the box next to lba. Click OK.
  7. Apply any pending changes (if needed) by clicking the Apply button on top and close Partition Editor.
  8. You can now shutdown / reboot the Live CD session. Note about Ubuntu 8.10 live CD session: On some system configs, shutdown / reboot might not work properly. If you reach a screen with a blinking cursor at the top only, eject CD / unplug pen drive. Software already loaded onto RAM will encounter an error and then proceed with shutdown. This does not harm your system in any way.

Try booting from USB disk next time. It should work now. This is a bug in the USB creator in Ubuntu which doesn’t add the LBA (logical block addressing) flag - which is needed for bootable partitions of size more than 500 MB. A small error, but one which can scare the wits out of some newcomer to Linux who’s trying out stuff.

Everything else remains in the USB disk sessions runs pretty much like booting into a live CD, except that if you chose to keep the persistence file then any settings changes you make are also retained. I seriously suggest everyone to go ahead and create a USB startup like this. It can be very handy in recovering your precious data if your operating system crashes. Also a good idea to use a USB disk when you’re accessing the Internet / working on a public computer (say, a cyber cafe or library) for greater security.

Yodel Anecdotal » Stepping down

Filed Under (Stop The Press, Tech Takes, Yahoo-niverse) by Ankur on 19-11-2008

Yodel Anecdotal » Stepping down.

Jerry Yang has announced that he’ll be stepping down as the CEO of Yahoo! and going back to his role as…Chief Yahoo!. He sure did make Yahoo! more…purple. Moreover, a lot of cool stuff has been brought in by him on the technology front. It’s probably right for him to step down because what he does best is technology - which he has given to Yahoo! What Yahoo! sorely needs now is someone who can market all this brilliant stuff to the masses.

Reseting Post and Comment Count in WordPress

Filed Under (Tech Takes, Web Dee) by Ankur on 16-11-2008

I had faced a problem a few weeks back when I had tried to upgrade my WordPress install from 2.6.1 to 2.6.2. I was using the WP Automatic Upgrade plugin to upgrade my install, and it failed. Screwed up my database. Restoring from an SQL backup didn’t work either, strangely. Spent a few agonizing hours on the WordPress IRC channel and trying the stuff the helpful people there were suggesting but in the end it boiled down to this - short of doing a clean install there seemed no way out.

Thankfully I had also exported a WordPress Extended RSS (WXR) backup file (along with the SQL backup) before starting the upgrade process, so I was able to manually do a clean install of WordPress and then use WXR XML file to restore my blog. Before removing the old install I had already kept a copy of the wp-content directory on my host, so that when the XML import process was done recreating the file structure I could simply replace that with the copy I had moved to another folder. I learned a valuable lesson too - using the WP-AU might save you some time, but the consequences if something goes wrong are far-reaching and potentially ‘devastating’. My advice to fellow WP users is to use the manual update procedure no matter what. I shudder to think if the auto-upgrade functionality the developers intend to include in WordPress 2.7 fails, then a lot more users will be affected. (Since the feature will be available in the core install from now on, possibly a much greater number of users will be using it and will be at risk of something going wrong.)

Anyway, after doing the import I noticed that a few things were amiss. The first thing was that the category count for all posts was showing up as zero (and neither did the post management page show the categories under which a post was filed). This can be particularly irritating if you use a template (like mine) which displays the number of posts in a category in the sidebar. The solution for this is simple: create a post and file it under every category you have and publish it. This ‘forces’ WordPress to do a recount of the number of posts in for each category and the count is updated. You can then delete that post. Maybe ‘forces’ would be a strong word; WordPress counts the number of posts under a category any time you make a post.

Another note regarding post categories after importing from an WXR file it that if you were using a custom name for your ‘Uncategorized’ category, then you need to delete the custom category name (which will show up separately) and then rename the ‘Uncategorized’ category to whatever custom name you want.

The biggest problem I faced after the import was the fact that the comment count for each post was showing up as zero. Now you could do this the ‘hard way’ - similar to the post category update, you could go and make a new comment on each and every post you have (which would trigger WordPress to do a recount), and then delete those comments. Admittedly that would be stupid and time-consuming especially if you have a blog like mine which has hundreds of posts. So for this, here’s what you need to do:

  1. Save the script below as a *.php file using a text editor. Name it something like filename.php or whatever you feel like; just keep in mind NOT to give it a filename same as already-existing WordPress files on your host.
  2. Upload the PHP file to the root folder of your WordPress install.
  3. Navigate to the file at yourblogname.com/filename.php using your web browser (using your own blog and file name).
  4. Remember to remove the file after you’re done.

So use the comment count update script below to automate the comment count updation process. If the comment doesn’t seem to work then your text editor is probably breaking something. Remove all newline characters manually.


<?php

/* This program is free software: you can redistribute it and / or modify it under the terms of the GNU General Public License as published by the Free Software Foundation version 3 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. For a copy of the GNU General Public License see http://www.gnu.org/licenses/gpl.html */

/* Script to recount number of comments in WordPress install. This script has been tested with WordPress 2.6.x. Note that script may fail to run the update for all posts in case the script runs longer than the timeout period specified in your settings. In case that happens, try increasing the timeout limit by editing the php.ini file on your webhost. If you are unable to modify the php.ini file and / or don't have access to it then just say a quick prayer and hit the 'Reload' button on your web browser. */

include('wp-config.php'); // Needed for login details to WordPress database to make necessary changes

function updateCount()
    {
        $posts = mysql_fetch_row(mysql_query("SELECT ID FROM wp_posts ORDER BY ID DESC LIMIT 1")); // Fetch row in WordPress database containing information about post data
        for ($i = 1; $i < ($posts[0] + 1); $i++)
        {
      
     $comments = mysql_query("SELECT SQL_CALC_FOUND_ROWS comment_ID FROM wp_comments WHERE comment_post_ID = '$i' AND comment_approved = 1;") or die("Failed to calculate number of approved comments"); // Calculate the number of approved comments for a post and store in a variable. If unsuccessful, end program.
      
     mysql_query("UPDATE wp_posts SET comment_count = '".mysql_num_rows($comments)."' WHERE id = '$i';") or die("Failed to update the number of comments calculated"); // Update the comment count using the comment number fetched earlier. If unsuccessful, end program
      
     echo "Updated Post #$i - ".mysql_num_rows($comments)." comments <br />"; // Display message to user for each post comment count successfully updated
        }
    }

updateCount();
?>
Subscribe to Rss Feed : Rss