'Secrets of PowerShell Remoting' is the title of an eBook that can be downloaded from PowerShellBooks.com. It's written by PowerShell MVP Don Jones and Dr. Tobias Weltner and is the most detailed of any documentation I have ever seen about the subject.
In a standard domain environment where http is used as the default remoting protocol, it may come down to a simple command that should be run in administrator PowerShell console session: `enable-psremoting`, yet it's dizzying to look at the number of scenarios and steps in the eBook, especially if you want to use https.
Don Jones mentioned that newer versions of the book will be hosted on PowerShell.org.
Taking mental notes does not help anyone else, bloggin' it might...
2012-09-12
2012-09-08
Copying recent files with PowerShell
I saw an interesting question in 'Scripting Guys' Facebook group today:
"I want to check which photos have changed or were added after a specific date on my disk, and copy those to the same path on my backup disk.
I managed to filter:
Get-ChildItem -Recurse | ? {$_.LastWriteTime -gt (get-date).adddays(-180)}
but I don't know how to pick each item's folder path and copy.
e.g.:
PS E:\fotos> Get-ChildItem Hornet01.jpg | fl *
...
And this file should be copied to L:\fotos\Hornet01.jpg"
Before I go about how I would solve this problem, I will explain a bit about how I store my pics and how I would copy them to a different drive.
I keep my pics in a network drive that's mapped as Z:, structure goes like this
Z:\Family\Pictures\{Year}\{Year.Month}\{Event or Place}\*.jpg
Note that Z:\Family\Pictures does not change, so we can think it of as the 'root'. Now, say, I wanted to find all the pictures in the last 6 months and copy them to a different drive maintaining the same structure like
Y:\MyPics\{Year}\{Year.Month}\{Event or Place}\*.jpg
For this, I need to do followings:
Well, I will talk about how this can be shortened to two steps but stick with me for the time being...
#1 has already been solved:
Of course, we could have filtered these if really wanted just pictures using "-filter" option but let's not bother with that for the moment.
#2 Now, we need to get unique directory names:
Note that we ended up with a "System.String" type that we are going to manipulate
#3 We need to replace the first part (ie.z:\family\pictures with y:\mypics):
Interestingly, you have to escape backslashes with Powershell's escape character, which happens to be backslash as the first part of replace operator needs a 'regular expression' but not the destination.
#4 Create the destination directories.
If destination directories do not exist, copy operation will fail. And I am not aware of any parameters that would tell copy to create the directories in the way. This is why we are creating them first.
#5 We are almost ready to copy.
We have the source file list, and we know that destination directories are created now but we need destination paths. We could use the techniques above to get the destination paths.
I know, repeating code is just ugly, could not we combine the steps? Sure, above steps helps clarify the action items but it could be shortened to this:
Couple of Notes:
"I want to check which photos have changed or were added after a specific date on my disk, and copy those to the same path on my backup disk.
I managed to filter:
Get-ChildItem -Recurse | ? {$_.LastWriteTime -gt (get-date).adddays(-180)}
but I don't know how to pick each item's folder path and copy.
e.g.:
PS E:\fotos> Get-ChildItem Hornet01.jpg | fl *
...
And this file should be copied to L:\fotos\Hornet01.jpg"
Before I go about how I would solve this problem, I will explain a bit about how I store my pics and how I would copy them to a different drive.
I keep my pics in a network drive that's mapped as Z:, structure goes like this
Z:\Family\Pictures\{Year}\{Year.Month}\{Event or Place}\*.jpg
Note that Z:\Family\Pictures does not change, so we can think it of as the 'root'. Now, say, I wanted to find all the pictures in the last 6 months and copy them to a different drive maintaining the same structure like
Y:\MyPics\{Year}\{Year.Month}\{Event or Place}\*.jpg
For this, I need to do followings:
- Find all pictures that have changed in the last 6 months.
- Get the 'unique' parent directory names of those pictures
- Replace those directory names with the new ones
- Create the destination directories
- Copy the files to new destinations
Well, I will talk about how this can be shortened to two steps but stick with me for the time being...
#1 has already been solved:
$recent_files=Get-ChildItem -Recurse | ? {$_.LastWriteTime -gt (get-date).adddays(-180)}
Of course, we could have filtered these if really wanted just pictures using "-filter" option but let's not bother with that for the moment.
#2 Now, we need to get unique directory names:
$unique_sourcedirs = $recent_files | %{ ($_.directory).fullname } |unique
Note that we ended up with a "System.String" type that we are going to manipulate
#3 We need to replace the first part (ie.z:\family\pictures with y:\mypics):
$dest_dirs=$unique_sourcedirs | %{$_ -replace 'Z:\\family\\Pictures','Y:\MyPics'}
Interestingly, you have to escape backslashes with Powershell's escape character, which happens to be backslash as the first part of replace operator needs a 'regular expression' but not the destination.
#4 Create the destination directories.
If destination directories do not exist, copy operation will fail. And I am not aware of any parameters that would tell copy to create the directories in the way. This is why we are creating them first.
$dest_dirs | % { if (! (test-path $_)) { new-item -itemtype directory -path $_ }}
#5 We are almost ready to copy.
We have the source file list, and we know that destination directories are created now but we need destination paths. We could use the techniques above to get the destination paths.
$recent_files | %{
$target = ($_.directory).fullname -replace 'Z:\\family\\Pictures','Y:\MyPics';
copy-item ($_.fullname) $target}
I know, repeating code is just ugly, could not we combine the steps? Sure, above steps helps clarify the action items but it could be shortened to this:
- Find all pictures that have changed in the last 6 months
- For each file, determine the target directory name by replacing the parent directory name with the new name; create the destination directory if it does not exist; copy the file to new destination.
$recent_files | % {
$target = ($_.directory).fullname -replace 'Z:\\family\\pictures','Y:\MyPics';
if (!(test-path $target)){ new-item -itemtype directory -path $target };
copy-item -path ($_.fullname) -destination $target -force -whatif
}
Couple of Notes:
- All of the above code-snippet is actually a single line if you are typing it in command line, I introduced line-breaks for better readability.
- Parameter -whatif is only to see what will happen. You should remove it when executing the command
- Parameter -force is not necessary if there are no files in destination directory.
2012-08-22
OS X 10.8 App Installation and Gatekeeper
OS X 10.8 Mountain Lion is here with us and so is a new security feature called Gatekeeper, which allows a user to only install applications that came from Mac App Store or from sources that have a certificate from Apple.
Gatekeeper options can be displayed by heading over to Settings > Security and Privacy
App Store is great but not so much for Enterprise as it is not realistic to expect in-house developed code to go through Apple every time. So, Developers who signed up with Apple get a Developer ID Certificate that can be used to sign the installation packages. Details of this process are explained here on the Official Apple pages and also here on 'unreleased notes' in layman terms.
If an application is not signed and is not available in the App Store, then Gatekeeper 'may' get in the way in its default form (Mac App Store + identified developers) but there are 'gotchas'.
Should I disable Gatekeeper?
You may be tempted to select 'Anywhere' option in Gatekeeper to avoid the hassle but consider this
Gatekeeper will "only" block the installation of applications downloaded from web.
You will still be allowed the installation of unsigned, non-flat packages:
Quarantine attribute on Downloaded Applications:
When you download any install package from Web with, let's say, Safari, a hidden 'com.apple.quarantine' attribute will be added to it. You can use `ls -l@` to display those attributes. When you try to install such files, Gatekeeper will block the application!
You can use the following command to remove the quarantine attribute:
'xattr -d -r com.apple.quarantine /path/to/downloaded/package'
This will stop the prompts that tells you what you may already know: "ApplicationName" is from an unidentified developer. Are you sure you want to open it?
Gatekeeper options can be displayed by heading over to Settings > Security and Privacy
App Store is great but not so much for Enterprise as it is not realistic to expect in-house developed code to go through Apple every time. So, Developers who signed up with Apple get a Developer ID Certificate that can be used to sign the installation packages. Details of this process are explained here on the Official Apple pages and also here on 'unreleased notes' in layman terms.
If an application is not signed and is not available in the App Store, then Gatekeeper 'may' get in the way in its default form (Mac App Store + identified developers) but there are 'gotchas'.
Should I disable Gatekeeper?
You may be tempted to select 'Anywhere' option in Gatekeeper to avoid the hassle but consider this
Gatekeeper will "only" block the installation of applications downloaded from web.
You will still be allowed the installation of unsigned, non-flat packages:
- if you already have a package repository on a network or USB etc. and copying from there
- if you use tools like curl that does not set 'quarantine' flag (see below)
- if you control click and choose open in Finder.
- If you launch Installer App (`sudo /System/Library/CoreServices/Installer.app/`) and browse to the downloaded application
- If you use command line as in `sudo installer -pkg /path/to/package -target /`
So, there are plenty of ways to let Gatekeeper work for you without disabling it.
Quarantine attribute on Downloaded Applications:
When you download any install package from Web with, let's say, Safari, a hidden 'com.apple.quarantine' attribute will be added to it. You can use `ls -l@` to display those attributes. When you try to install such files, Gatekeeper will block the application!
You can use the following command to remove the quarantine attribute:
'xattr -d -r com.apple.quarantine /path/to/downloaded/package'
This will stop the prompts that tells you what you may already know: "ApplicationName" is from an unidentified developer. Are you sure you want to open it?
2012-08-17
Must watch this!
I had a blog post about time-less articles that I came across on Internet. TED is full of incredibly powerful speeches. Today, I watched some of them and decided to post the links here. This post will serve as a place holder for future video links.
Jill Bolte Taylor talks about 'brain'. It's very moving and enlightning
http://www.ted.com/talks/jill_bolte_taylor_s_powerful_stroke_of_insight.html
Alain de Botton talks about 'success'. What we mean by it now and realities of western-life
http://www.ted.com/talks/alain_de_botton_a_kinder_gentler_philosophy_of_success.html
Alain de Bottom discusses shortcomings of secular life and what it can borrow from religion
http://www.ted.com/talks/lang/en/alain_de_botton_atheism_2_0.html
Jill Bolte Taylor talks about 'brain'. It's very moving and enlightning
http://www.ted.com/talks/jill_bolte_taylor_s_powerful_stroke_of_insight.html
Alain de Botton talks about 'success'. What we mean by it now and realities of western-life
http://www.ted.com/talks/alain_de_botton_a_kinder_gentler_philosophy_of_success.html
Alain de Bottom discusses shortcomings of secular life and what it can borrow from religion
http://www.ted.com/talks/lang/en/alain_de_botton_atheism_2_0.html
2012-08-12
Using Mac as the primary machine and fixing Synergy
So, I swapped my Mac and PC. Now, my mac is connected solely to the primary screen in front of me (Samsung SyncMaster 245BW at 1980x1200) with a displayPort to DVI adapter. Unfortunately, that meant that my PC had to be connected using a VGA as that was the only other input.
My PC is also connected to the 20" ViewSonic VP2030b (1600x1200) on my right via DVI. I have dual ATI Radeon HD 5700 in CrossFire setup (4xDVI out), so I would like to get a monitor that supports dual DVI input but there does not seem to be many options out there that I like. In fact, I like Dell UltraSharp U2412 the most at this point but still trying to decide.
Anyway, I did not want to use multiple keyboards and mouses anymore, so I wanted to try the latest version of Synergy (v1.4.9 as of this writing). I used Synergy at work on 10.7 for some time but quickly had to give up on it when I upgraded one of my Macs to 10.8.
I set it up so that My Windows 7 x64 would be the 'server' and Mac OS X 10.8 Mountain Lion as the 'client'. Setting it up is not really difficult, there is a single synergy.conf file that has to be common to both client and server (see mine below).
The biggest trouble was that back and forward buttons of my mouse stopped working on Mac side. That was really annoying when browsing web sites and after some google'ing I found out that this was an issue that has been experienced by several others.
Some posts in that google code link put me into the right direction and after some trial and error, I figured out that using 'Windows + [' key was like hitting back button key, and 'Windows + ]' key was acting as forward key.
I solved the problem by mapping mousebutton(4) to keystroke(Meta+BracketL) and mouse(button5) to keystroke(Meta+BracketR). The whole config file is shown below:
section: screens
AHPC:
halfDuplexCapsLock = false
halfDuplexNumLock = false
halfDuplexScrollLock = false
xtestIsXineramaUnaware = false
switchCorners = none
switchCornerSize = 0
AHMac:
halfDuplexCapsLock = false
halfDuplexNumLock = false
halfDuplexScrollLock = false
xtestIsXineramaUnaware = false
switchCorners = none
switchCornerSize = 0
end
section: aliases
end
section: links
AHPC:
right = AHMac
AHMac:
left = AHPC
end
section: options
mousebutton(4)=keystroke(Meta+BracketL)
mousebutton(5)=keystroke(Meta+BracketR)
relativeMouseMoves = false
screenSaverSync = false
win32KeepForeground = true
switchCorners = none
switchCornerSize = 0
end
2012-08-05
There be dragons
Here is a good one... I happened to be checking one of my yahoo addresses which I rarely use and noticed the following message from 'Blizzard'.
Language is off. You can tell from the first sentence that message is suspicious. Plus, I had never given my yahoo address to Blizzard, so clearly this was a scam. If you hover over the first link, it really points to the Blizzard but the second one was pointing a phishing site they want the person to go. Chrome actually recognizes the site as warns you about it.
Here is the lesson: NEVER click any link without checking the actual URL it's pointing to by looking at the status bar.
Greetings!
We have already noted that you are trying to sell your personal World of Warcraft account (s).
Terms of Use
http://us.blizzard.com/en-us/company/legal/wow_tou.html
It will be ongoing for further investigation by Blizzard Entertainment's employees.
If you wish to not get your account suspended you should immediately verify your account ownership. You must complete the steps below to secure the account and your computer.
STEP 1: ACCOUNT INVESTIGATION
We now provide a secure website for you to verify that you have taken the appropriate steps to secure the account, your computer, and your email address. Please go to this site and follow the instructions:
http://us.blizzard.com/support/article/securitywebform (points to the site in the picture. Link removed)
STEP 2: VERIFY YOUR SUBMISSION WAS RECEIVED
We will contact you with further instructions once we have received and processed your submission. If you do not receive a reply within 48 hours of submitting this form, please resend it from the address listed above.
Please be aware that if unauthorized access to this account, it may lead to further action against the account.
Regards,
Game Master Dunarthra
Customer Services
Blizzard Entertainment
http://us.battle.net/support/en/
Update: I actually saw at least 5 different variations in my e-mail box all trying to entice me to phishing sites. Some of the subjects are below:
Mists of Pandaria Beta Test Invitation WoW MoP Beta
Mists of Pandaria Beta Test Invitation
World of Warcraft Mount: Heart of the Aspects (lol on this one)
Fixing pepper flash issue(?) on latest chrome
Problem:
The latest version of Chrome (v22.0.1221.0 - I am on dev-m channel) causes some playback issues with flash videos on my pc. Top part of the video is cut diagonally and keeps on flickering. Here is the link to my bug report.
Screenshot shows how it looks on my screen.
Possible Cause:
The new 'Pepper Flash', result of collaboration between Adobe and Google is supposed to be more secure. Latest release of Chrome has it set as the default flash player on my Windows 7 machines and it seems to be the cause of this issue.
Workaround:
Until a fix is available, disabling Pepper Flash seems to be an easy solution.
In my case, typing chrome://plugins showed that I had 3 Flash plug-ins:
- The new Pepper Flash plug-in
- The built-in Flash plug-in that comes with Chrome
- And the Flash plug-in installed separately for IE and other browsers.
Clicking the details on the right side of the screen and checking the "disable" link under Pepper Flash seems to have fixed the issue for me.
Note: I still see the same diagonal line if I hover over a link item on the page that would normally overlay a menu, so I am actually not so convinced that this is a PepperFlash issue as I originally suspected. See Chromium discussions for further details (link above).
2012-07-20
Upgrading Android Nexus S to Jelly Bean 4.1.1
It's been quite a while since I embarked on getting my Nexus S upgrade to ICS early. I blogged that journey here. For the last 1.5 months I am carrying both my Nexus S and an iPhone 4S, and frankly I prefer using iPhone for battery life if not for anything else. My favorite activity on Nexus S is tethering my iPad Wi-Fi during my work commute. Anyway, iPhone 4S vs Android 4.x Nexus S discussion is for another day.
Today, Google released 4.1.1 for Nexus S (T-Mobile) and it's officially available if you want to download the binaries: http://android.clients.google.com/packages/ota/google_crespo/9ZGgDXDi.zip
I downloaded the zip file and renamed it to update.zip (renaming is optional)
Then connected phone to my pc and transferred the update.zip to SD Card
Powered off the phone
Pressed Power + Volume Up keys to bring the boot menu
Selected recovery
...and wait for it...
No cigar! I got the infamous red triangle with a black exclamation mark on a green Android picture.
Apparently, one of the updates from 4.0 to 4.0.4 changed the boot files I had for custom booting before.
Interestingly, I found out that I was able to bypass this screen if I keep on trying to press Power + Volume UP key a couple of times (usually the 3rd was the charm).
I then got into the recovery mode where I was presented with the option I was looking for:
"apply update from /sdcard" (to select the option use Power button. Volume up/down to go up/down)
After selecting update.zip, install started and ...
-- Install /sdcard ...
Finding update package...
Opening update package...
Verifying update package...
Installing update...
Verifying current system...
assert failed: apply_patch_space(16570800)
E:Error in /tmp/sideload/package.zip
(Status 7)
Installation aborted.
failed :(
At this point, I thought I might be low on sdcard space and perhaps that was causing this issue. I did some clean up and free space jumped up from 700MB to 5GB. Unfortunately, the next attempt did not result in anything different.
So tried a couple of other options, all failed:
At this point, I started looking at Nexus S XDA forums. People suggested using ClockWorkMod to patch. I used it before, it's a great tool but instead I chose to use this trick to get official OTA update from Google. Steps (I changed the order a bit) are as follows:
After the second try I got offered the update. Rest, as they say, is history:
I am dying to try this trick, which is clearly quite harmless, on my wife's nexus S but she explicitly prohibited me from installing Jelly Bean / 4.1.1 until I confirm that it had been working without any hiccups on my phone for about a week :)
Now it's time check out Highlights and read what's new?
Today, Google released 4.1.1 for Nexus S (T-Mobile) and it's officially available if you want to download the binaries: http://android.clients.google.com/packages/ota/google_crespo/9ZGgDXDi.zip
I downloaded the zip file and renamed it to update.zip (renaming is optional)
Then connected phone to my pc and transferred the update.zip to SD Card
Powered off the phone
Pressed Power + Volume Up keys to bring the boot menu
Selected recovery
...and wait for it...
Apparently, one of the updates from 4.0 to 4.0.4 changed the boot files I had for custom booting before.
Interestingly, I found out that I was able to bypass this screen if I keep on trying to press Power + Volume UP key a couple of times (usually the 3rd was the charm).
I then got into the recovery mode where I was presented with the option I was looking for:
"apply update from /sdcard" (to select the option use Power button. Volume up/down to go up/down)
After selecting update.zip, install started and ...
-- Install /sdcard ...
Finding update package...
Opening update package...
Verifying update package...
Installing update...
Verifying current system...
assert failed: apply_patch_space(16570800)
E:Error in /tmp/sideload/package.zip
(Status 7)
Installation aborted.
failed :(
At this point, I thought I might be low on sdcard space and perhaps that was causing this issue. I did some clean up and free space jumped up from 700MB to 5GB. Unfortunately, the next attempt did not result in anything different.
So tried a couple of other options, all failed:
- Wiped cache partition...
- Wiped cache partition + Wiped data/factory reset (which means you lose everything on the phone!)...
- Wiped SDCard...
At this point, I started looking at Nexus S XDA forums. People suggested using ClockWorkMod to patch. I used it before, it's a great tool but instead I chose to use this trick to get official OTA update from Google. Steps (I changed the order a bit) are as follows:
- System settings
- Apps > All (If "all" is not displayed, pull the top bar that reads "running" to the left)
- Google-Service-Framework
- Force stop
- Clear Data
- Go to Homescreen
- System settings
- About Phone
- System updates (last time of update checking should be before 1970)
- Check now
- if you do not get the update, go to step 1.
After the second try I got offered the update. Rest, as they say, is history:
Now it's time check out Highlights and read what's new?
2012-07-07
New Features in PowerShell 3.0
MS PowerShell Team blogged about some of the upcoming features in PowerShell 3.0 here.
I think there are some terrific improvements in the syntax that will make PowerShell more consistent or less unpredictable, if you prefer.
In my tests, some of the features are not yet fully working on Windows 7 but once the final release is out, current issues should go away.
Improved Custom PSObject Creation
One of the cool changes is about creating a custom object. It was already improved in Version 2.0 and now it got even better. Here is a common way of creating one:
Powershell 1.0
PowerShell 2.0
PowerShell 3.0
So basically you are now simply casting 'PsCustomObject' type like any other.
Local Variables with $using
Another feature I liked seeing is about using local variables. I had written a function a while ago to remove an application given its uninstall string. I needed that to remove unwanted VNC installations from an environment.
It goes something like this:
You see that invoke-command line over there? I had to use $UninstallString 3 times in that command to pass it to the remove machine. This got much simpler with PowerShell 3.0 with the addition of "$using:" :
By the way, I used that function together with another here that returned a list of uninstall strings from the registry:
Count and Length
With PowerShell 3.0 "count" and "length" properties are also becoming universal. I.e. even if an object does not have these properties currently, you will be able to use them in the new version.
Indexing
Similarly, every object is getting 'indexing'. So, using the custom object example above, it will be possible to use the following syntax:
It does not look useful really but it does improve the consistency!
I think there are some terrific improvements in the syntax that will make PowerShell more consistent or less unpredictable, if you prefer.
In my tests, some of the features are not yet fully working on Windows 7 but once the final release is out, current issues should go away.
Improved Custom PSObject Creation
One of the cool changes is about creating a custom object. It was already improved in Version 2.0 and now it got even better. Here is a common way of creating one:
Powershell 1.0
$MyCustomObject = New Object PSObject $MyCustomObject | add-member NoteProperty name "Adil" $MyCustomObject | add-member NoteProperty lastname "Hindistan"
PowerShell 2.0
$MyCustomObject = new-object PSObject -Property @{name="Adil";lastname="Hindistan"}
PowerShell 3.0
$MyCustomObject = [PsCustomObject]@{name="Adil";lastname="Hindistan"}
So basically you are now simply casting 'PsCustomObject' type like any other.
Local Variables with $using
Another feature I liked seeing is about using local variables. I had written a function a while ago to remove an application given its uninstall string. I needed that to remove unwanted VNC installations from an environment.
It goes something like this:
function remove-app {
## E.g. $vnc |%{ remove-app $_ '"C:\Program Files\RealVNC\VNC4\unins000.exe" /SILENT' }, where $vnc holds list of machines
param ($computer="$env:ComputerName",
[string]$UninstallString ## Use QuietUninstallString when possible
)
$result="Encountered an error, sorry!"
if (test-connection $computer -count 1) {
"Pinging $computer successful"
if ($UninstallString) {
## we have to use param and argumentlist in the script block to pass variable to the remote computers
$result = invoke-command -computer $computer { param($UninstallString);&cmd /c $UninstallString} -ArgumentList $UninstallString
## New in PowerShell 3.0:
## $result = invoke-command -computer $computer { &cmd /c $using:$UninstallString}
"...Done"
}
} else { "Pinging $computer failed"}
$result
}
You see that invoke-command line over there? I had to use $UninstallString 3 times in that command to pass it to the remove machine. This got much simpler with PowerShell 3.0 with the addition of "$using:" :
$result = invoke-command -computer $computer { &cmd /c $using:$UninstallString}
By the way, I used that function together with another here that returned a list of uninstall strings from the registry:
function get-appsreg {
param ($computer="$env:ComputerName",
[string]$product
)
$result="Encountered an error, sorry!"
if (test-connection $computer -count 1) {
if ($product) {
## we have to use param and argumentlist in the script block to pass variable to the remote computers
$result = invoke-command -computer $computer { param($product);get-itemproperty hklm:\software\microsoft\windows\currentversion\uninstall\* |?{$_.DisplayName -match $product}|Select DisplayName,UninstallString,QuietUninstallString } -ArgumentList $product
} else {
$result = invoke-command -computer $computer { get-itemproperty hklm:\software\microsoft\windows\currentversion\uninstall\*,hklm:\software\wow6432node\microsoft\windows\currentversion\uninstall\* |Select DisplayName,UninstallString,QuietUninstallString } -erroraction silentlycontinue
}
}
$result
}
Count and Length
With PowerShell 3.0 "count" and "length" properties are also becoming universal. I.e. even if an object does not have these properties currently, you will be able to use them in the new version.
Indexing
Similarly, every object is getting 'indexing'. So, using the custom object example above, it will be possible to use the following syntax:
$MyCustomObject[0] ## returns the object itself. Other indexes return nothing
It does not look useful really but it does improve the consistency!
2012-06-26
Must Read This!
Internet is a beautiful place. Sometimes, you hit an old article that makes you feel like you found a treasure, it may teach you a great life lesson.
For me, the best way to get back to them is simply link to them in this blog. Here are a few and I intent to update this post with such findings in the future:
For me, the best way to get back to them is simply link to them in this blog. Here are a few and I intent to update this post with such findings in the future:
- Submarine - Paul Graham [2005]: This article is about PR firms and how 'news' get planted.
- Nastiness - Tim Bray [2009]: I admired Tim Bray ever since reading up his take on XML specification, which he co-edited. Here, he tells a story about some nastiness that went on in a Ruby conference, which is totally insignificant, and gives us his recommendation on when to apologize, which is golden!
2012-05-28
Do typos bother you?

Typos do bother me. I guess that's because when I am reading something, they hit (and hurt) my eyes pretty quickly (so if you are seeing typos on this blog, you know why: I do not read my own blog :) and it sort of gives the impression that the person who was writing it may not have paid enough attention to the piece, somewhat decreasing the over all value of it.
Anyway, today I was looking at my Google Reader RSS subscriptions and noticed a new article from Microsoft KB here: "Configuring WinRM for HTTPS" (click on pic above to see the actual page).
There is nothing special about this KB other than that it is on its 8th revision (wow!) as of May 17, 2012, yet apparently information was printed without going through a spell-checker. In fact, there is a note at the bottom of the article which prepares us for such typos:
Note This is a "FAST PUBLISH" article created directly from within the Microsoft support organization. The information contained herein is provided as-is in response to emerging issues. As a result of the speed in making it available, the materials may include typographical errors and may be revised at any time without notice.
I sent a message to them using the feedback system at the bottom. I wonder how long it will take them to correct it.
Update: 2012-06-29
Almost the same story but this time, it's about an Apple Knowledge Base article. Here is a very common typo in article about 'Apple Thunderbolt to Gigabit Ethernet Adapter: FAQ' (HT5309) that was last modified 10 days ago (click on picture to see the actual page).
Oh, Microsoft page is still not corrected. I guess they are not reading the feedback.
2012-02-06
Uninstalling Microsoft Security Essentials from Command Line
Recently, I came across a situation where I wanted to replace Microsoft Security Essentials on a couple of computers. The first question was how to uninstall Microsoft Security Essentials from command line.
So, I looked for an Uninstall String in the registry:
First one was promising. So, I started the PowerShell from an elevated command prompt to avoid UAC, and typed the following:
Followed by:
I did not yet pass a computer list with -computer parameter. This command did start the uninstall "wizard". I did not want to baby-sit the installation, in other words, I wanted to run the uninstall silently, so I started looking at other parameters that would do it and found out that, "/s" is the parameter I was looking for. The command below took care of the uninstalls silently:
Where computers.txt contains the list of machines.
Update - 2012-08-08: PowerShell 3.0 has an updated syntax, that simplifies this code greatly. See this post: http://www.adilhindistan.com/2012/07/new-features-in-powershell-30.html
PS Z:\> gp HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\* |? {$_.DisplayName -match "security" } | select DisplayName,UninstallString |ft -auto
DisplayName UninstallString
----------- ---------------
Microsoft Security Essentials C:\Program Files\Microsoft Security Client\Setup.exe /x
Microsoft Baseline Security Analyzer 2.2 MsiExec.exe /I{08C3441C-4FAF-48D3-A551-70DD6031734F}
Microsoft Security Client MsiExec.exe /I{42738DB0-FC3E-4672-A99B-9372F5696E30}
First one was promising. So, I started the PowerShell from an elevated command prompt to avoid UAC, and typed the following:
PS Z:\>$UninstallString='"C:\Program Files\Microsoft Security Client\Setup.exe" /x'
Followed by:
PS Z:\>Invoke-Command { param($UninstallString);&cmd /c $UninstallString } -ArgumentList $UninstallString
I did not yet pass a computer list with -computer parameter. This command did start the uninstall "wizard". I did not want to baby-sit the installation, in other words, I wanted to run the uninstall silently, so I started looking at other parameters that would do it and found out that, "/s" is the parameter I was looking for. The command below took care of the uninstalls silently:
PS Z:\>$UninstallString='"C:\Program Files\Microsoft Security Client\Setup.exe" /x /s'
PS Z:\>Invoke-Command -computer (gc .\computers.txt) { param($UninstallString);&cmd /c $UninstallString } -ArgumentList $UninstallString
Where computers.txt contains the list of machines.
Update - 2012-08-08: PowerShell 3.0 has an updated syntax, that simplifies this code greatly. See this post: http://www.adilhindistan.com/2012/07/new-features-in-powershell-30.html
2012-01-22
More funny comments...from Microsoft
After discovering some funny comments from Dell folks (see previous post), I looked at some other folders in the CD and came across what seemed to be manifest files used possibly used by Microsoft upgrade scripts, User State Migration Tool (USMT) and Migration Wizard (MigWiz).
These files reside in the Dell's Windows 7 Pro CD that came with Dell Vostro CD. Specifically, under \sources\dlmanifests folder:
OK, that's a confession there! And why would not you uninstall reg keys cleanly?
I am just wondering who is (s)he talking to here...
Hmm, so who is this mollybro? I see a 'mollybro' profile in MSDN, with a reference to an SMB related resource. Same person?
OK, enough with this Saturday-Night Geek Entertainment. Here is the last one:
Nobody can say (s)he is not honest!
These files reside in the Dell's Windows 7 Pro CD that came with Dell Vostro CD. Specifically, under \sources\dlmanifests folder:
OK, that's a confession there! And why would not you uninstall reg keys cleanly?
I am just wondering who is (s)he talking to here...
Hmm, so who is this mollybro? I see a 'mollybro' profile in MSDN, with a reference to an SMB related resource. Same person?
OK, enough with this Saturday-Night Geek Entertainment. Here is the last one:
Nobody can say (s)he is not honest!
2012-01-21
Funny Comments in Dell's IE Branding Script
I was looking at the contents of a CD that came with a new Dell Vostro PC (oh, don't even ask why).
The following folder initially seemed interesting:
\sources\$OEM$\$$\system32\OEM
But there was not much in there other than what seemed like an Internet Explorer branding script:
I was about to check the other folders, but wanted to checkout TextAppend.vbs and then noticed some interesting comments:
I like the --fail comments. Blogging for entertainment value :)
The following folder initially seemed interesting:
\sources\$OEM$\$$\system32\OEM
But there was not much in there other than what seemed like an Internet Explorer branding script:
I was about to check the other folders, but wanted to checkout TextAppend.vbs and then noticed some interesting comments:
I like the --fail comments. Blogging for entertainment value :)
2011-12-03
PowerShell 3 Community Technology Preview 2
PowerShell architect Jeffrey Snover (@jsnover) announced availability of PowerShell v3 CTP 2 today in a twitter post. I installed the 64bit version. It required a reboot.
I have not yet have a chance to look into the goodies but right out of the bat I noticed two changes.
1) While my profile was loading, I got an error message, where PowerShell 3 complained about a line in my profile which goes something like this:
PowerShell v2 never complained about that line but I like the fact that PowerShell message is clear and suggests a way to fix it. Both of the following works
2) PowerShell now auto-completes function names in my $profile when I hit "tab". From release notes, I see that some work went into "tabbing" and if you tab in the middle of a line, it does not delete the rest of the line anymore. This is a welcome usability change.
I have not yet have a chance to look into the goodies but right out of the bat I noticed two changes.
1) While my profile was loading, I got an error message, where PowerShell 3 complained about a line in my profile which goes something like this:
write-host "$mounted_drive: could not be found"
At C:\Users\Adil\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1:56 char:15
+ write-host "$mounted_drive: could not be found."
+ ~~~~~~~~~~~~~~~
Invalid variable reference. ':' was not followed by a valid variable name character. Consider using ${} to delimit the name.
+ CategoryInfo : ParserError: (:) [], ParseException
+ FullyQualifiedErrorId : InvalidVariableReferenceWithDrive
PowerShell v2 never complained about that line but I like the fact that PowerShell message is clear and suggests a way to fix it. Both of the following works
write-host "$mounted_drive : could not be found" ## add a space
write-host "${mounted_drive}: could not be found" ## avoid ambiguity
2) PowerShell now auto-completes function names in my $profile when I hit "tab". From release notes, I see that some work went into "tabbing" and if you tab in the middle of a line, it does not delete the rest of the line anymore. This is a welcome usability change.
2011-11-13
Using your own domain name with blogger
Using your own domain name instead of generic blahblah.blogspot.com is a pretty easy change.
Login to blogger.com and select the blog (in case you have more than one)
Click "Settings" > "Basic"
Scroll down a bit until you see "Publishing" section
Click "Add a custom domain"
If you already have a domain, you can use that:
- Click "Switch to advanced settings"
- Enter your domain name under Advanced settings
- Click "Save"
If not, you can buy one through blogger as described here. Or the other option is to buy through Google Apps by following the wizard here. I chose to use Google Apps to buy the new domain. It takes about 10mins to get your new domain up and running. All DNS records are automatically pointed to Google's ghs.google.com name servers.
After this was done, I went back to Blogger and and wanted to use my new domain name. I got an error:
"Another blog or Google Site is already using this address".
Reason is pretty straightforward, but solution is a bit tricky. I was getting this message because Google Sites are part of Google Apps and when you type "www.yourdomainname.com", you are redirected to Google Sites. In other words, DNS record for "www" is mapped to Google Sites address.
Problem is that Blogger needs to use this address to be able to serve your blog when someone requests your site. Uninstalling Google Sites should have fixed this:
- Logon to Google Apps (http://www.google.com/a/yourdomainname)
- Click Settings on the top menu bar
- Click Sites on the left
- Click "Uninstall Sites" (Do not do this yet, keep on reading)
This, however, did NOT fix the problem because to my surprise it seems that this process does not remove 'www' record.
Following is the correct procedure:
- Logon to Google Apps (http://www.google.com/a/yourdomainname)
- Click "Settings" on the top menu bar
- Click "Sites" on the left
- Click "Web Address Mapping"
- Delete "www" mapping
- Click "General" > "Uninstall Sites" (Optional)
If you, have already uninstalled "Google Sites", you can add it back:
- "Dashboard" > "Service Settings" near the bottom > "Add more services"
That way you can get access to the Sites menu to complete the procedure above. Once done, simply head over to blogger.com and add your domain. That's all there is to it.
2011-11-08
Installing Android 4.0 on Nexus S
The latest version of Android, Ice Cream Sandwich (ICS), is not officially available for Nexus S yet. However, there are some talented developers who managed to use available SDK and some dump data to port ICS to Nexus S. For this post, I used Drew Garen's Beta v10 port (no longer available - 11/30/2011. See updates at the bottom of the post).
As I explained in my "On Rooting Android" post, I spent the last few days to understand a bit more about inner-workings of Android and rooting landscape. As I now have a good backup of everything I have and I tested that I can restore everything back to that point, it is time to test ICS.
ICS Installation for Nexus S is quite simple but make sure you have read the previous article and have Pre-reqs as described there:
If all goes well, you should have ICS up and running on your Nexus S in 5 mins!
This is the new boot screen. It takes about the same time it used to boot. If there is an improvement, I did not notice it. In fact, it's great that this 'beta' version is able to match Stock 2.3.6 speeds.
Once boot process finishes, you will see a welcome screen. Simply Tap "Start" to kick off Google initialization process.
Then, you can allow or disallow Google location services. Tap "Next" to continue.
At his point , you can either sign in with your Google account or create a new one.
Once the wizard is done, you are going to notice that your apps will start coming down from Android Market. As far as I can tell most of the apps came down just fine. I was however missing the apps that I had installed from Amazon Market. This of course makes sense.
The only surprise I had was about the Google Authenticator App. It did not come down and I had to download and log into it by generating an Application-Specific Password in Two-factor Authentication page.
If you are using two-factor authentication, you might want to make sure your recovery methods for two-factor authentication are still valid before diving into this process.
I've been using ICS Beta Port for a day now and apart from known issues like GPS, the only issue I noticed was the battery killing Google+ app. See the screenshot.
It basically drained the battery to half in only 5hrs. I have not yet looked into what exactly in Google+ is causing this and have not seen any other reports from testers in the related xda-developer forum.
Update: 11/30/2011
After Google released ICS source code, devs at XDA forums started working on it and porting it to different phones. Koushing Dutta, who also owns other popular apps like ClockworkMod Recovery and ROM Manager, was one of the first who came up with a build for Nexus S.
There are several ICS ports right now and many other tweaked the works of rom developers or came up with mixes of those. There are also several kernel releases at this point all available from Nexus S XDA forums here (usually under Development).
Drew Garen has also used Koushik and other's work adding his own stuff on top and his work is available from his new (blogger) site.
By the way, a few times I got "Random Offset {some number}" when flashing roms but apparently this is NOT an error but related to a new security feature "Address Space Layout Randomization" as mentioned here.
As I explained in my "On Rooting Android" post, I spent the last few days to understand a bit more about inner-workings of Android and rooting landscape. As I now have a good backup of everything I have and I tested that I can restore everything back to that point, it is time to test ICS.
ICS Installation for Nexus S is quite simple but make sure you have read the previous article and have Pre-reqs as described there:
- Android SDK
- Root via DooMLoRD's Easy Rooting Toolkit v1.0
- Install ROM Manager
- Install "ClockworkMod Recovery" and make sure it will stick.
- Take a full system backup
- Download the latest Beta from Drew's site.
- Rename the downloaded zip file to update.zip (Optional)
- Connect Your android via USB in USB Mass Storage Mode and copy update.zip to the root.
- Disconnect USB Storage Mode
- Launch ROM Manager
- Boot into Recovery Mode
- Wipe Dalvik Cache in Advanced Mode
- Wipe Data/Factory Reset
- Wipe Cache
- Select Install from zip file and point to /sdcard/update.zip
- Watch it do its magic.
If all goes well, you should have ICS up and running on your Nexus S in 5 mins!
This is the new boot screen. It takes about the same time it used to boot. If there is an improvement, I did not notice it. In fact, it's great that this 'beta' version is able to match Stock 2.3.6 speeds.
Once boot process finishes, you will see a welcome screen. Simply Tap "Start" to kick off Google initialization process.
Then, you can allow or disallow Google location services. Tap "Next" to continue.
At his point , you can either sign in with your Google account or create a new one.
Once the wizard is done, you are going to notice that your apps will start coming down from Android Market. As far as I can tell most of the apps came down just fine. I was however missing the apps that I had installed from Amazon Market. This of course makes sense.
The only surprise I had was about the Google Authenticator App. It did not come down and I had to download and log into it by generating an Application-Specific Password in Two-factor Authentication page.
If you are using two-factor authentication, you might want to make sure your recovery methods for two-factor authentication are still valid before diving into this process.
I've been using ICS Beta Port for a day now and apart from known issues like GPS, the only issue I noticed was the battery killing Google+ app. See the screenshot.
It basically drained the battery to half in only 5hrs. I have not yet looked into what exactly in Google+ is causing this and have not seen any other reports from testers in the related xda-developer forum.
Update: 11/30/2011
After Google released ICS source code, devs at XDA forums started working on it and porting it to different phones. Koushing Dutta, who also owns other popular apps like ClockworkMod Recovery and ROM Manager, was one of the first who came up with a build for Nexus S.
There are several ICS ports right now and many other tweaked the works of rom developers or came up with mixes of those. There are also several kernel releases at this point all available from Nexus S XDA forums here (usually under Development).
Drew Garen has also used Koushik and other's work adding his own stuff on top and his work is available from his new (blogger) site.
By the way, a few times I got "Random Offset {some number}" when flashing roms but apparently this is NOT an error but related to a new security feature "Address Space Layout Randomization" as mentioned here.
2011-11-06
On Rooting Android
When I got my iPod Touch, I immediately started looking for methods to root it, but never felt the need on my Android Nexus S, as I was already able to do pretty much anything including free-of-charge tethering (thank you T-mobile).
The newest Android version (v4 or Ice Cream Sandwich, a.k.a ICS), has been announced a few weeks back and smart folks at xda forums have already managed to port the SDK version for my phone. Of course, phone needs to be rooted to flash the new rom.
Although you probably have lots of your data like your contacts backed up to Google Cloud, there is no way you can keep 'all' your data backed up at this point and rooting wipes out your device.
A couple of funny thing happened when I looked at rooting instructions. All of them tell you to make a full back up of your system, but you will be lucky if you find any instructions on what exactly to back up and how? Most of the tools mentioned want you to be rooted to begin with. It maybe possible to use Astro File Manager or 'adb pull' commands from Android SDK but the things you can do are limited 'before' you root. In fact, this is one of the reasons people root their phones because they would like to keep their 'data' when they buy a new phone (e.g. high scores in a game, or play lists in a music app...).
At this point, applications may write their data anywhere as there is no 'designated' location to keep app data and therefore there is no easy way to back that data up even if it was possible for a user to access /data folder, which is 'usually' where apps write. There is a feature request on this but as of now, no solution.
Anyway, the other funny bit is about an SDK tool named 'fastboot'. There are tons of material on web that tell you how to use it, problem is that latest SDKs do not have this tool. If you head over to Android SDK download page, you will notice that there is only a link to android-sdk_r15-windows.zip (i.e. revision 15). The last revision that had the 'fastboot' was r13 and there is no link to it.
If you are a developer, you probably know how to get older versions of SDK using SDK manager but mere mortals do not need to despair either! Here is what you can do:
Hover over the r15 link, you will notice that it is pointing to http://dl.google.com/android/android-sdk_r15-windows.zip So, to download r13, simply replace 'r15' with 'r13' in the link and you should be able to download the r13 version. Once you download it, you can extract the fastboot.exe from 'tools' folder. In the current revision, Google has moved adb.exe from 'tools' folder to 'platform-tools' folder. You might want to put this one there too.
One more thing. You need to install USB drivers on your machine. When you download SDK, you will be able to get the Google USB drivers for your device. The catch is that it won't work when you are in 'fastboot' mode (at least for Nexus S) if your windows is 64bit. You will then need to install PDANet drivers so that your Nexus S is detected. You can find those links here. Good luck!
Btw, what do you get out of all this hassle? Here is a pretty good video from NexusHacks.
Update: 2011-11-06 - Root-ed
I finally found an easy to use hack to root my Nexus S without destroying/wiping any data (i.e. without unlocking the bootloader). I would like to emphasize this again, because I have read tons of so called 'guides' which seems to use 'rooting' and 'bootloader unlocking' interchangeably.
If you are like me, you may want to understand why do you need to do these things mentioned in the 'guides' instead of blindly following them. There is a lot of mumbo-jumbo to confuse the hell out of a regular user like myself. So, I had to look deeper into whole Android boot process and architecture to make sense of it. Hope this helps others as well.
Root - Super User
As in any other unix/linux variant, your purpose is to become the most powerful user with no restrictions on your Android. I.e. you want to become 'root' or 'super user'. That way you can install any application or even a totally new Android system (e.g. CyanogenMod). It's your device, your do whatever you like with it.
Well, you wish! Android will not just allow a regular user to become root. From a security perspective, you really would not want that anyway. Imagine any software messing with your device? Yep, that would be malware.
But you own the device and "you" want to become root! Well, you have two options:
1) You will need to find an exploit, as malware does. A hack, that elevates your privileges to become root. This is exactly what the 'zergRush Exploit' mentioned below does.
2) If there is no known hack, the other option is to go through steps in those rooting guides. Most of them will tell you that you will need to "unlock your boot loader".
Why unlock your boot loader?
Well, you are trying to become root in the Android Operating System but it does not allow you and boot loader is the software that comes "before" the (Android) Operating System. In other words, it's the initialization code that loads the (Android) OS and if you can mess with it, you can hack into that Android OS or replace it all together with a modified version perhaps.
Bootloader has two stages. The first stage of the bootloader (also referred as 'IPL' or "Initial Program Load") provides support for loading recovery images to the flash memory of the device.
If boot loader detects certain keypress (in Nexus S this would be Power button + Volume up), it goes in to a special mode called 'fastboot mode' where you can use 'recovery' option to flash a new (or old) image. From this point on you are on the second phase of the boot process. You may see acronyms like 'SPL', which means 'Secondary Program Loader' and refers to this second phase.
This is also why you usually see instructions for manually installing OTA (Over The Air) update files where you are told to drop the update.zip file in the root of sdcard, and then turn your device on while pressing 'special keys' for your phone and choose 'recovery' option. Upgrading your firmware is basically flashing a new (firmware) image.
However, we have a problem there. Usually, the boot-loader is "locked" so that it will load only recovery images that are signed by a certain authority. This might be Google or your wireless carrier.
So, if we can unlock the boot loader, then we can use a 'custom recovery image' like ClockworkMod Recovery, which allows us to install a 'custom firmware' like CyanogenMod (a.k.a CyanogenMod ROM). As these ROMs may include not only Android OS but IPL/SPL as well, there is a risk of making your phone unusable, commonly referred as 'bricking' the phone in case there is a bug in the IPL/SPL code.
Phones like my Nexus S are pure Android Devices. Wireless carrier does not install any customized software on it, it does not cripple any of the abilities and Google allows us to 'unlock' the bootloader by running a simple command:
"fastboot oem unlock"
I explained above how to get fastboot.exe. So you get that and other pre-reqs and then issue the command to unlock your boot-loader, which apparently voids your warranty and "WIPES YOUR DEVICE" including your SDCard.
In my case, I did not want that to happen without taking a full back up of the system, which was not really possible because I did not have root access. A bit of a chicken and egg problem...
Solution: Exploit to become Root
This method depends on DooMLoRD's Easy Rooting Toolkit v1.0, which is using what's called "zergRush Exploit".
The whole process took me less than a minute:
At the end of this, you get SuperUser v3.0.5(39) installed on your Nexus S. This exploit seems to be working with many other Android phones. There is a growing list in the forum linked above. It's also easy to go back if you want to unroot.
I launched SuperUser, clicked "Preferences" and tapped "Su binary v3.0" to update it to the latest version (3.0.3 as of now). I also set "Automatic Response" to "Allow". To test:
* Install Backup Software: Now that I have 'root' access, I can now install all these 'backup software' mentioned on all those rooting sites. I installed 'Titanium Backup'. Then I took a full back up of the system to my sdcard, and then mounted the phone via usb to take back up of everything on my sdcard to my hard drive.
* Install Rom Manager: This is to be able to 'flash custom ROMs (i.e. install customized Android versions). I installed 'Rom Manager' but have not done anything else yet.
One last thing tonight... Once I became root, I was able to get more information about my system and manually create backup images as shown below
Then connected phone to my pc using 'USB mass storage' mode and backed up these two images to my hard drive:
where l: refers to sdcard drive
z: is where in hard drive I backed it up to
and /mir makes a mirror copy of everything in the sdcard (be careful with this option, if you use it incorrectly by specifying wrong target, you may wipe out the target).
I am, however, not sure if these will be enough to get things back. See the update below for proper Backup/Restore procedures.
Update 2011-11-07 More on Back up and Rom Management
Revenge of Stock ROM
Stock ROM is the original Android Image. Below, you will find how it tries to keep its integrity.
Today I wanted to use "ROM Manager" app to take a backup. To my surprise,
"ROM Manager" > "Backup Current ROM"
got me into a black screen with a yellow exclamation mark and an android icon underneath. Apparently, "ClockworkMode Recovery" (CWM) was overridden by Stock ROM after the reboot. Boot loader had detected that it was tempered with and had restored previous version.
Reinstalling ClockworkMod Recovery
This is pretty straight forward as I still have root access on my Nexus S.
Once done, you get a message that says "Successfully flashed ClockworkMod Recovery". This solution is temporary. One suggested solution is to rename the file that's causing this as follows:
Unfortunately, you get an error back. The reason is that /system partition is mounted as read-only (ro) and before you can make any changes to files under it, you will need to mount it as read-write (rw).
First, we have to find out where the /system is mounted:
What does this mean:
With this knowledge we will use mount command to remount /system to the same location but this time with 'rw' parameter to be able to modify its content
Now we can go ahead and make the change.
Then, we should go back to Rom Manager and flash ClockworkMod Recovery one last time and it should stick around between reboots.
Using ClockworkMod Recovery for Backup
There is a long guide here explaining various options with screenshots but it's pretty basic.
1) Manual Backup
Select "ROM Manager" > "Reboot into Recovery" (for manual management). Phone will boot into ClockworkMod Recovery console.
Use "Volume down/up" buttons to move up or down and "Power" button to select an option.
As we wanted to take a full back up, we want to choose the option that says "backup and restore"
We then choose backup option and let the tool work its magic.
In my phone, the process took about 10 minutes. There is a progress bar that gives some visual feedback and when all is done you get "Backup complete!" message at the bottom.
2) Backup via ROM Manager
This is quite straightforward as it is an option in the "ROM Manager" application.
Select "ROM Manager" > "Backup Current ROM"
Enter a backup name, or tap "OK" to accept the suggested name.
Phone boots into recovery mode and starts the back up process.
After the backup is finished, phone boots back up.
Backed up files reside under /sdcard/clockworkmod/backup/{backup_name} folder. Below is the list of files after a backup
Testing Restore from Backup
At the end of the day, all this effort is to be able to restore from a backup to get Android back to the original (Stock) state.
So, I booted into ClockworkMod Recovery mode and
wiped cache,
wiped dalvik cache,
wiped data/factory-reset...
After the reboot, Nexus S came up and kicked off Google's Welcome Wizard. I skipped it and there it was. My Nexus S as if I just bought it. The only difference was that SuperUser app was still there.
To restore everything back:
Update: - 12/02/2011
Here is a very detailed, thoughtful article from security researcher Dan Rosenberg on "Rooting and Plagiarism". It helps put things into context.
The newest Android version (v4 or Ice Cream Sandwich, a.k.a ICS), has been announced a few weeks back and smart folks at xda forums have already managed to port the SDK version for my phone. Of course, phone needs to be rooted to flash the new rom.
Although you probably have lots of your data like your contacts backed up to Google Cloud, there is no way you can keep 'all' your data backed up at this point and rooting wipes out your device.
A couple of funny thing happened when I looked at rooting instructions. All of them tell you to make a full back up of your system, but you will be lucky if you find any instructions on what exactly to back up and how? Most of the tools mentioned want you to be rooted to begin with. It maybe possible to use Astro File Manager or 'adb pull' commands from Android SDK but the things you can do are limited 'before' you root. In fact, this is one of the reasons people root their phones because they would like to keep their 'data' when they buy a new phone (e.g. high scores in a game, or play lists in a music app...).
At this point, applications may write their data anywhere as there is no 'designated' location to keep app data and therefore there is no easy way to back that data up even if it was possible for a user to access /data folder, which is 'usually' where apps write. There is a feature request on this but as of now, no solution.
Anyway, the other funny bit is about an SDK tool named 'fastboot'. There are tons of material on web that tell you how to use it, problem is that latest SDKs do not have this tool. If you head over to Android SDK download page, you will notice that there is only a link to android-sdk_r15-windows.zip (i.e. revision 15). The last revision that had the 'fastboot' was r13 and there is no link to it.
If you are a developer, you probably know how to get older versions of SDK using SDK manager but mere mortals do not need to despair either! Here is what you can do:
Hover over the r15 link, you will notice that it is pointing to http://dl.google.com/android/android-sdk_r15-windows.zip So, to download r13, simply replace 'r15' with 'r13' in the link and you should be able to download the r13 version. Once you download it, you can extract the fastboot.exe from 'tools' folder. In the current revision, Google has moved adb.exe from 'tools' folder to 'platform-tools' folder. You might want to put this one there too.
One more thing. You need to install USB drivers on your machine. When you download SDK, you will be able to get the Google USB drivers for your device. The catch is that it won't work when you are in 'fastboot' mode (at least for Nexus S) if your windows is 64bit. You will then need to install PDANet drivers so that your Nexus S is detected. You can find those links here. Good luck!
Btw, what do you get out of all this hassle? Here is a pretty good video from NexusHacks.
Update: 2011-11-06 - Root-ed
I finally found an easy to use hack to root my Nexus S without destroying/wiping any data (i.e. without unlocking the bootloader). I would like to emphasize this again, because I have read tons of so called 'guides' which seems to use 'rooting' and 'bootloader unlocking' interchangeably.
If you are like me, you may want to understand why do you need to do these things mentioned in the 'guides' instead of blindly following them. There is a lot of mumbo-jumbo to confuse the hell out of a regular user like myself. So, I had to look deeper into whole Android boot process and architecture to make sense of it. Hope this helps others as well.
Root - Super User
As in any other unix/linux variant, your purpose is to become the most powerful user with no restrictions on your Android. I.e. you want to become 'root' or 'super user'. That way you can install any application or even a totally new Android system (e.g. CyanogenMod). It's your device, your do whatever you like with it.
Well, you wish! Android will not just allow a regular user to become root. From a security perspective, you really would not want that anyway. Imagine any software messing with your device? Yep, that would be malware.
But you own the device and "you" want to become root! Well, you have two options:
1) You will need to find an exploit, as malware does. A hack, that elevates your privileges to become root. This is exactly what the 'zergRush Exploit' mentioned below does.
2) If there is no known hack, the other option is to go through steps in those rooting guides. Most of them will tell you that you will need to "unlock your boot loader".
Why unlock your boot loader?
Well, you are trying to become root in the Android Operating System but it does not allow you and boot loader is the software that comes "before" the (Android) Operating System. In other words, it's the initialization code that loads the (Android) OS and if you can mess with it, you can hack into that Android OS or replace it all together with a modified version perhaps.
Bootloader has two stages. The first stage of the bootloader (also referred as 'IPL' or "Initial Program Load") provides support for loading recovery images to the flash memory of the device.
If boot loader detects certain keypress (in Nexus S this would be Power button + Volume up), it goes in to a special mode called 'fastboot mode' where you can use 'recovery' option to flash a new (or old) image. From this point on you are on the second phase of the boot process. You may see acronyms like 'SPL', which means 'Secondary Program Loader' and refers to this second phase.
This is also why you usually see instructions for manually installing OTA (Over The Air) update files where you are told to drop the update.zip file in the root of sdcard, and then turn your device on while pressing 'special keys' for your phone and choose 'recovery' option. Upgrading your firmware is basically flashing a new (firmware) image.
However, we have a problem there. Usually, the boot-loader is "locked" so that it will load only recovery images that are signed by a certain authority. This might be Google or your wireless carrier.
So, if we can unlock the boot loader, then we can use a 'custom recovery image' like ClockworkMod Recovery, which allows us to install a 'custom firmware' like CyanogenMod (a.k.a CyanogenMod ROM). As these ROMs may include not only Android OS but IPL/SPL as well, there is a risk of making your phone unusable, commonly referred as 'bricking' the phone in case there is a bug in the IPL/SPL code.
Phones like my Nexus S are pure Android Devices. Wireless carrier does not install any customized software on it, it does not cripple any of the abilities and Google allows us to 'unlock' the bootloader by running a simple command:
"fastboot oem unlock"
I explained above how to get fastboot.exe. So you get that and other pre-reqs and then issue the command to unlock your boot-loader, which apparently voids your warranty and "WIPES YOUR DEVICE" including your SDCard.
In my case, I did not want that to happen without taking a full back up of the system, which was not really possible because I did not have root access. A bit of a chicken and egg problem...
Solution: Exploit to become Root
This method depends on DooMLoRD's Easy Rooting Toolkit v1.0, which is using what's called "zergRush Exploit".
The whole process took me less than a minute:
--------------------------------------------------------------- Easy rooting toolkit (v1.0) created by DooMLoRD using exploit zergRush (Revolutionary Team) Credits go to all those involved in making this possible! --------------------------------------------------------------- [*] This script will: (1) root ur device using zergRush exploit (2) install Busybox (1.18.4) (3) install SU files (3.0.5) [*] Before u begin: (1) make sure u have installed adb drivers for ur device (2) enable "USB DEBUGGING" from (Menu\Settings\Applications\Development) (3) enable "UNKNOWN SOURCES" from (Menu\Settings\Applications) (4) [OPTIONAL] increase screen timeout to 10 minutes (5) connect USB cable to PHONE and then connect to PC (6) skip "PC Companion Software" prompt on device --------------------------------------------------------------- CONFIRM ALL THE ABOVE THEN Press any key to continue . . . --- STARTING ---- --- WAITING FOR DEVICE adb server is out of date. killing... * daemon started successfully * --- cleaning --- pushing zergRush" 3215 KB/s (23052 bytes in 0.007s) --- correcting permissions --- executing zergRush [**] Zerg rush - Android 2.2/2.3 local root [**] (C) 2011 Revolutionary. All rights reserved. [**] Parts of code from Gingerbreak, (C) 2010-2011 The Android Exploid Crew. [+] Found a GingerBread ! 0x00015118 [*] Scooting ... [*] Sending 149 zerglings ... [+] Zerglings found a way to enter ! 0x10 [+] Overseer found a path ! 0x000151e0 [*] Sending 149 zerglings ... [+] Zerglings caused crash (good news): 0x40119cd4 0x0054 [*] Researching Metabolic Boost ... [+] Speedlings on the go ! 0xafd255dd 0xafd3908f [*] Popping 24 more zerglings [*] Sending 173 zerglings ... [+] Rush did it ! It's a GG, man ! [+] Killing ADB and restarting as root... enjoy! --- WAITING FOR DEVICE TO RECONNECT if it gets stuck over here for a long time then try: disconnect usb cable and reconnect it toggle "USB DEBUGGING" (first disable it then enable it) --- DEVICE FOUND --- pushing busybox 4149 KB/s (1075144 bytes in 0.253s) --- correcting permissions --- remounting /system --- copying busybox to /system/xbin/ 2099+1 records in 2099+1 records out 1075144 bytes transferred in 0.097 secs (11083958 bytes/sec) --- correcting ownership --- correcting permissions --- installing busybox --- pushing SU binary 1276 KB/s (22228 bytes in 0.017s) --- correcting ownership --- correcting permissions --- correcting symlinks --- pushing Superuser app 4739 KB/s (762010 bytes in 0.157s) --- cleaning --- rebooting ALL DONE!!! Press any key to continue . . .
I launched SuperUser, clicked "Preferences" and tapped "Su binary v3.0" to update it to the latest version (3.0.3 as of now). I also set "Automatic Response" to "Allow". To test:
$ PS Z:\adil\scripts\powershell> adb shell $ su su # whoami whoami whoami: unknown uid 0This means I have root access on my Nexus S and my bootloader is still locked! What's next?
* Install Backup Software: Now that I have 'root' access, I can now install all these 'backup software' mentioned on all those rooting sites. I installed 'Titanium Backup'. Then I took a full back up of the system to my sdcard, and then mounted the phone via usb to take back up of everything on my sdcard to my hard drive.
* Install Rom Manager: This is to be able to 'flash custom ROMs (i.e. install customized Android versions). I installed 'Rom Manager' but have not done anything else yet.
One last thing tonight... Once I became root, I was able to get more information about my system and manually create backup images as shown below
$ adb shell $ su # cat /proc/mtd dev: size erasesize name mtd0: 00200000 00040000 "bootloader" mtd1: 00140000 00040000 "misc" mtd2: 00800000 00040000 "boot" mtd3: 00800000 00040000 "recovery" mtd4: 1d580000 00040000 "cache" mtd5: 00d80000 00040000 "radio" mtd6: 006c0000 00040000 "efs" # cat /dev/mtd/mtd2 > /sdcard/mtd2.img ## Boot image # cat /dev/mtd/mtd3 > /sdcard/mtd3.img ## Recovery image
Then connected phone to my pc using 'USB mass storage' mode and backed up these two images to my hard drive:
robocopy /mir l:\ z:\adil\Backup\Android\sdcard\
where l: refers to sdcard drive
z: is where in hard drive I backed it up to
and /mir makes a mirror copy of everything in the sdcard (be careful with this option, if you use it incorrectly by specifying wrong target, you may wipe out the target).
I am, however, not sure if these will be enough to get things back. See the update below for proper Backup/Restore procedures.
Update 2011-11-07 More on Back up and Rom Management
Revenge of Stock ROM
Stock ROM is the original Android Image. Below, you will find how it tries to keep its integrity.
Today I wanted to use "ROM Manager" app to take a backup. To my surprise,
"ROM Manager" > "Backup Current ROM"
got me into a black screen with a yellow exclamation mark and an android icon underneath. Apparently, "ClockworkMode Recovery" (CWM) was overridden by Stock ROM after the reboot. Boot loader had detected that it was tempered with and had restored previous version.
Reinstalling ClockworkMod Recovery
This is pretty straight forward as I still have root access on my Nexus S.
- Launch "ROM Manager"
- Tap "Flash ClockworkMod Recovery"
- Select "Google Nexus S"
Once done, you get a message that says "Successfully flashed ClockworkMod Recovery". This solution is temporary. One suggested solution is to rename the file that's causing this as follows:
$ adb shell ## Use adb Android SDK tool to open a shell (see above) $ su ## Become root # mv /system/etc/install-recovery.sh /system/etc/donot_install-recovery.sh ## rename the file failed on '/system/etc/install-recovery.sh' - Read-only file system
Unfortunately, you get an error back. The reason is that /system partition is mounted as read-only (ro) and before you can make any changes to files under it, you will need to mount it as read-write (rw).
First, we have to find out where the /system is mounted:
# mount |grep system /dev/block/platform/s3c-sdhci.0/by-name/system /system ext4 ro,relatime,barrier=1,data=ordered 0 0
What does this mean:
- First block is telling us about the actual directory under which /system partion will show its data
- Second block is what we are mounting (/system)
- Third block is the filesystem. This used to be yaffs2 but now we see it is 'ext4'
- Fifth block are the options and what matters for us is the 'ro' parameter telling us mount is read-only
For further reading on Android partitions, take a look at this post.
With this knowledge we will use mount command to remount /system to the same location but this time with 'rw' parameter to be able to modify its content
# mount -o remount,rw -t ext4 /dev/block/platform/s3c-sdhci.0/by-name/system /system
Now we can go ahead and make the change.
# mv /system/etc/install-recovery.sh /system/etc/donot_install-recovery.sh
# ls -l /system/etc -rw-r--r-- root root 58357 2011-09-30 09:06 NOTICE.html.gz -rw-r--r-- root root 236823 2011-09-30 09:06 apns-conf.xml drwxr-xr-x root root 2010-11-24 16:42 bluetooth -rw-r--r-- root root 682 2010-11-24 16:42 contributors.css -r--r----- bluetooth bluetooth 935 2010-11-24 16:42 dbus.conf drwxr-xr-x root root 2010-11-24 16:42 dhcpcd -rw-r--r-- root root 11865 2011-04-29 12:18 event-log-tags -rw-r--r-- root root 238 2010-11-24 16:42 gps.conf -rw-r--r-- root root 25 2010-11-24 16:42 hosts -r-xr-x--- root shell 1200 2010-11-24 16:42 init.goldfish.sh -rw-r--r-- root root 7696 2010-11-24 16:42 media_profiles.xml drwxr-xr-x root root 2011-09-30 09:06 permissions drwxr-xr-x root root 2010-11-24 16:42 ppp -rw-r--r-- root root 104 2010-11-24 16:42 secomxregistry drwxr-xr-x root root 2011-09-30 09:06 security drwxr-xr-x root root 2011-04-29 12:18 updatecmds -rw-r--r-- root root 531 2010-11-24 16:42 vold.fstab drwxr-xr-x root root 2010-11-24 16:42 wifi -r-xr--r-- root root 415 2008-08-01 08:00 donot_install-recovery.sh
Then, we should go back to Rom Manager and flash ClockworkMod Recovery one last time and it should stick around between reboots.
Using ClockworkMod Recovery for Backup
There is a long guide here explaining various options with screenshots but it's pretty basic.
Select "ROM Manager" > "Reboot into Recovery" (for manual management). Phone will boot into ClockworkMod Recovery console.
Use "Volume down/up" buttons to move up or down and "Power" button to select an option.
As we wanted to take a full back up, we want to choose the option that says "backup and restore"
We then choose backup option and let the tool work its magic.
In my phone, the process took about 10 minutes. There is a progress bar that gives some visual feedback and when all is done you get "Backup complete!" message at the bottom.
2) Backup via ROM Manager
This is quite straightforward as it is an option in the "ROM Manager" application.
Select "ROM Manager" > "Backup Current ROM"
Enter a backup name, or tap "OK" to accept the suggested name.
Phone boots into recovery mode and starts the back up process.
After the backup is finished, phone boots back up.
Backed up files reside under /sdcard/clockworkmod/backup/{backup_name} folder. Below is the list of files after a backup
l:\clockworkmod\backup\2011-11-07-19.41.58\ 183.4 m .android_secure.vfat.tar 8.0 m boot.img 12672 cache.yaffs2.img 478.3 m data.ext4.tar 298 nandroid.md5 8.0 m recovery.img 174.8 m system.ext4.tar
Testing Restore from Backup
At the end of the day, all this effort is to be able to restore from a backup to get Android back to the original (Stock) state.
So, I booted into ClockworkMod Recovery mode and
wiped cache,
wiped dalvik cache,
wiped data/factory-reset...
After the reboot, Nexus S came up and kicked off Google's Welcome Wizard. I skipped it and there it was. My Nexus S as if I just bought it. The only difference was that SuperUser app was still there.
To restore everything back:
- I installed ROM Manager from Market
- Flashed ClockworkMod Recovery
- Tapped "Manage and Restore Backups"
- Selected the latest backup (the one above)
- Phone went into Recovery Mode and recovery started
- After about 5 minutes, phone rebooted again
- Android came up and everything was restored successfully as if I never wiped my phone!
Update: - 12/02/2011
Here is a very detailed, thoughtful article from security researcher Dan Rosenberg on "Rooting and Plagiarism". It helps put things into context.
Subscribe to:
Posts (Atom)






















