Shakes Home

How To's

How to Use Linux Commands in Windows with Cygwin

posted Jan 25, 2011, 6:33 AM by Ahmed El-Sharkasy

Windows command-line tools have advanced a lot with PowerShell, but Linux has had a much more usable terminal for many years. Here’s how you can get the best of both worlds with Cygwin, a ‘nix-style terminal for Windows PCs.

In today’s lesson, we’ll explain how to get Cygwin running, but stay tuned for future articles where we’ll explain how to use it for all sorts of different things.

Install Cygwin

Cygwin comes with a normal setup.exe to install in Windows, but there are a couple steps you will need to pay attention to, so we will walk you through the installation.

To keep the installation small while saving bandwidth for you and Cygwin, the default installer will download only the files you need from the internet.

The default install path is C:\Cygwin but if you don’t like to have programs installed on the root of your C: drive you can change the path or make a symbolic link from C:\Cygwin to your program files.

Click next until you come to a download mirror selection. Unfortunately, the installer does not say where the mirrors are located so in most cases you might as well just guess which mirror works best.

After you have selected a mirror, the installer will download a list of available packages for you to install. Here is where things get a bit more intimidating.

There will be hundreds of packages available separated by multiple different categories. If you don’t know what the package is you can leave the default selection and install additional packages later by running the installer again.

If you know what package you need, you can search for it and the results will be automatically filtered.

Once you click next, it will take a little while to download all the selected tools and then finish the installation.

Add Cygwin Path to Windows Environment Variable

After the installation you will have a Cygwin icon on your desktop that you can launch to open the Cygwin terminal.

This terminal starts in the C:\Cygwin\home\<user> folder but that isn’t particularly useful because you probably don’t have any files stored there. You can use all of the basic Linux commands but if you want to get back to your C: drive you have to change directory to /cygdrive/c.

To make Cygwin work in your normal Windows command prompt you need to add Cygwin to your Windows Environment Variables.

Start by opening your system properties with either Win+Pause/Break or right click on computer and select properties.

In the left column click on advanced system settings to open the system properties window we are looking for.

From the advanced tab, click on environment variables at the bottom.

Then in the system variables, locate the path variable and click edit.

At the end of the variable value option, add the Cygwin bin location like so.

;C:\Cygwin\bin

Note: Make sure you add a semicolon to separate it from the other values.

Click OK to close out of the window and then open a command prompt to test out a few Linux commands.

As you can see from the below picture both pwd and ls work in the normal Windows command prompt. You can also see that /cygdrive/c is automatically added to the location.

There is a lot more you can do with Cygwin installed and we will show you some more of the useful tools in future articles.

Cygwin homepage

Security Tips - Let's Make a Computer Virus ... But Only For Testing AntiVirus

posted Jan 22, 2011, 8:00 PM by Ahmed El-Sharkasy

 www.shoutwhisper.com This is an interesting tips. We will test antivirus program running on computer whether it works well or not, but using quite a unique way, namely we will create a file containing the virus codes, so that when it runs, the antivirus program should be able to detect and remove it. But you all no need to fear, because we will create a virus that will not disrupt or damage the computer system even though antivirus program can not detect it. So this is just a kind of AV tester. These virus codes were developed by those who joined in the EICAR, which stands for European Institute for Computer Anti-Virus Research, having website at http://www.eicar.org/. Here are the steps to make this tester virus: 1. First step, run Notepad. This virus can be made just using Notepad. 2. Copy the codes below, and then paste them into Notepad. X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H* 3. Save the file with filename: EICAR.COM. How: on Notepad, click File > Save As. On the Save As dialog box, choose folder to save this file in, then choose option Save As Type, next select All Files, and then type eicar.com for its filename. Finish it by clicking the Save button. It's done. 4. Now open the Windows Explorer (press Windows + E), go to folder containing the virus file you've created, and then run then virus file by double-clicking it. If  antivirus installed has real time guard, it shoud have detected the virus usually by displaying a dialog box containing information about detected threat. If your antivirus doesn't have real time guard (maybe you're using a light weight free AV :-)  => not recommended  ), run it and do scan for folder which the virus located. I myself try this on a computer using AVG Antivirus, and it can detect the virus and displaying this message: Notes: Once attention again, the virus we will create is not a real virus, but just a tester virus. Even though your antivirus program can not detect and remove it, it will NOT harm your computer. For more information about this virus, please go to http://www.eicar.org/.

How to Reset/Restore MySQL's root password

posted Jan 21, 2011, 4:02 AM by Ahmed El-Sharkasy

http://blog.ezzarghili.info/

If you set previously a root password for you MySQL server instance but have lost/forgotten it, don't worry that happens to everyone.

In this post I will explain the procedure to reset the password as there is no way to restore it, the following procedure applies to any platform (Unix, Windows,Mac OSX, Linux).

first let's look at the steps:

1. Stop mysqld
2. Restart mysqld
3. Connect to MySQL server
5. stop and restart mysqld normally

Now let's look at each step in details

1- Stop mysqld

a) On windows platform

If the the mysqld is running as a service you need to stop the mysql service in #Start menu > Control Panel > Administrative Tools > Services. or use the command:

 cmd> net stop MYSQL

where MYSQL is the name of the service

If that is not the case you may use the script provided with your install or just force stop it using the Task Manager

b) On *nix platforms

you may stop mysql daemon using

 shell> kill 'pid'

where 'pid' corresponds to processes of mysqld which you can get with the command

 shell> ps -ef | grep mysql

or you may also use something like:

 shell> /etc/init.d/mysqld stop

in some distros you may use the command

 shell> service mysql stop

2- Restart mysqld

a) On windows

you need to start mysqld with --skip-grant-tables and optionaly –skip-networking option from the bin directory of your mysql installation folder or by typing mysqld directly if you have added mysql bin directory to the %PATH% environment variable.

 cmd> mysqld --skip-grant-tables –skip-networking

or something like

 cmd> c:\path\to\mysql\bin\mysqld --skip-grant-tables –skip-networking
b) On *nix

use the command:

 shell> mysqld --skip-grant-tables –skip-networking &

Note: as noted above –skip-networking is optional but strongly recommended if your MySQl instance is accessible through insecure network (Internet, wi-fi...) as omitting this option is like allowing anyone in the network to mess with your server.

3- connect to mysql

Connect to mysql on Windows using the command:

 cmd> c:\path\to\mysql\bin\mysql

or if the bin directory of your mysql install is included the %PATH% environment variable just type

 cmd> mysql

and the same goes for *unix issue the command:

 shell> mysql

this step will get you to the mysql command prompt

4- Restore / reset root password

You need now to update the old password by issueing two sql statements:

 mysql> UPDATE mysql.user    -> SET Password=PASSWORD('newPasswordHere')    -> WHERE User='root';mysql> FLUSH PRIVILEGES;

The FLUSH PRIVILEGES statement allows mysql to notice the password change.

5- Restart your MySQL server normally

Were're done all you need now to do is restarting the server without the --skip-grant-tables and –skip-networking options.

with these steps you're now able to reset/restore mysql root password, If you still can't connect to your server, just have a suggestion or addotion; your feedback is most welcome.

What’s the Difference Between JPG, PNG, and GIF?

posted Dec 27, 2010, 6:12 AM by Ahmed El-Sharkasy

As we keep building on old image technology, types of file formats keep piling up, each with their own nuances and uses. JPG, PNG, and GIF have become the most common, but what sets them apart from each other?

These formats have become the most popular because of their compatibility with modern browsers, broadband speeds, and the needs of average users. Join us as we take a detailed look at each format, and cover the strengths and weaknesses of each.

JPG (Joint Photographic Experts Group)

JPG was a filetype developed by the Joint Photographic Experts Group (JPEG) to be a standard for professional photographers. Like the method ZIP files use to find redundancies in files to compress data, JPGs compress image data by reducing sections of images to blocks of pixels or “tiles.” JPG compression has the unfortunate side effect of being permanent, however, as the technology for the file was created for storing large photographic image files in surprisingly small spaces, and not for photo editing.

JPGs have become the de facto standard image of the internet because they can be compressed so much. A typical JPG can be compressed at a ratio of anywhere from 2:1 to as high as 100:1, depending on your settings. Particularly back in the days of dial-up internet, JPGs were the only viable way to send image information.

However, because of the lossy nature of JPG, it is not an ideal way to store art files. Even the highest quality setting for JPG is compressed, and will change the look of your image, if only slightly. JPG is also not an ideal medium for typography, crisp lines, or even photographs with sharp edges, as they are often blurred or smeared out by anti-aliasing. What is potentially worse, is that this loss can accumulate—saving multiple versions of artwork can cause degradation with every save. Even so, it is common to see these things saved as JPG, simply because the filetype is so ubiquitous.

Close up of a high quality JPG.

Close up of a very lossy JPG.

The Joint Photographic Experts Group developed lossless JPG technology to combat this serious problem of quality degradation. However, because of dial-up speeds and general lack of interest in high quality non-degrading files, the JPG-LS standard never caught on.

It is possible to download plugins that allow users to open and save the lossless JPG2000, and some programs, like Apple’s Preview application, can read and save JPG2000 directly out of the box.

JPGs support 24-bit RGB and CMYK, as well as 8-bit Grayscale. I personally do not recommend using CMYK color spaces in JPGs. It’s also important to note that Grayscale JPGs do not compress nearly as much as color ones do.

GIF (Graphics Interchange Format)

GIF, like JPG, is an older filetype, and one generally associated with the internet as opposed to photography. GIF stands for “Graphics Interchange Format” and employs the same lossless LZW compression that TIFF images use. This technology was once controversial (for patent enforcement issues) but has become an accepted format since all patents have expired.

Close up of an 8-bit color GIF.

GIF is by nature an 8-bit color file, meaning they are limited to a palette of 256 colors, which can be picked from the RGB color model and saved to a Color Look Up Table (CLUT), or simply “Color Table.” There are, however, standard color palettes, like the “Web Safe” palette. An important note is that Grayscale images are by nature an 8-bit palette, so saving them as GIF is fairly ideal.

Apart from support for transparency, GIF also is supports animations, limiting every frame to 256 preselected colors.

While GIF is not lossy like JPG, conversion to 8-bit color distorts many images, using dither filters to optically blend, or “diffuse,” colors, similar to halftone dots or pointilism. This can radically alter an image for the worse, or, in some cases, be used to create an interesting effect.

Because of this non-lossy format, GIF can be used to keep tight lines on typography and geometric shapes, although these things are better suited to vector graphic files like SVG or the Adobe Illustrator native format, AI.

GIF is not ideal for modern photography, nor image storage. At small sizes with very limited color tables, GIF images can be smaller than JPG files. But at most ordinary sizes, JPG compression will create a smaller image. They are largely out of date, useful only to create dancing babies or to sometimes create rough transparencies.

PNG (Portable Network Graphics)

PNG stands for Portable Network Graphics (or, depending on whom you ask, the recursive “PNG-Not-GIF”). It was developed as an open alternative to GIF, which used the proprietary LZW compression algorithm discussed earlier. PNG is an excellent filetype for internet graphics, as it supports transparency in browsers with an elegance that GIF does not possess. Notice how the transparent color changes and blends with the background. Right-click the image to see. This is actually one image that is on four different background colors.

PNG supports 8-bit color like GIF, but also supports 24-bit color RGB, like JPG does. They are also non-lossy files, compressing photographic images without degrading image quality. PNG tends to be the biggest of the three filetypes and isn’t supported by some (usually older) browsers.

In addition to being an excellent format for transparency, the non-lossy nature of 24-bit PNG is ideal for screenshot software, allowing pixel for pixel reproduction of your desktop environment.

Which to use?

From left to right, these files are: 24-bit JPG Compressed, 8-bit GIF, 8-bit PNG, Full Quality 24-bit JPG, and 24-bit PNG. Note that the file sizes increase in this same direction.

PNG is the largest image type for bigger images, often containing information you may or may not find useful, depending on your needs. 8-bit PNG is an option, but GIF is smaller. Neither are optimal options for photography, as JPG is much smaller than lossless PNG with only minimal loss of quality. And for storage of high resolution files, JPG compresses to tiny proportions, with quality loss only visible on close inspection.

In short:

• PNG is good option for transparency and non-lossy, smaller files. Larger files, not so much, unless you demand non-lossy images.
• GIF is largely a novelty and only useful for animation, but can produce small 8-bit images.
• JPG is still the king for photographs and photo-like images on the internet, but be careful, as your file can degrade with every save.

imgscalr – Java Image Scaling Library

posted Dec 27, 2010, 3:45 AM by Ahmed El-Sharkasy

Description

imgscalr is an very simple and efficient “best-practices” image-scaling library implemented in pure Java.

This library makes  uses of efficient Java2D scaling techniques advocated by the Java2D team which provides hardware accelerated operations on most platforms. This library also implements the optimized incremental scaling algorithm proposed by Chris Campbell with some minor enhancements for good-looking (and quick) thumbnail generation (previously only possible with the discouraged Image.getScaledInstance method using the much slower SCALE_AREA_AVERAGE algorithm).

What Problem Does this Solve?

If you have ever wanted to quickly rescale an image in Java you have probably noticed the following confusing things:

Usage

The simplest use-case of the library is a simple, single 2-argument method call:

BufferedImage srcImage = ...

// Scale the image using the imgscalr library
BufferedImage scaledImage = Scalr.resize(srcImage, 150);

In this use-case we pass the library our image and ask it to fit the image (while maintaing its original proportions) within a width and height of 150 pixels.

Alternatives, if we wanted to use the full-argument method call and print out some debugging and performance information from the library, we could do this:

BufferedImage srcImage = ...

// Scale the image using the imgscalr library
BufferedImage scaledImage =
Scalr.resize(srcImage, Scalr.Method.AUTOMATIC, 150, 100, true, true);

Here we are explicitly telling the library to use the AUTOMATIC method when deciding between QUALITY or SPEED for the scaling operation. We are also telling the library to fit our image (while maintaing its proportions) within a max width of 150 pixels and max height of 100 pixels while printing out debugging and performance metrics.

NOTE: If a width and height are provided that violate the image’s proportions (e.g. attempt to resize an 800×600 image to a 150×150 square) the library will select the smallest (most constrained) dimension and then re-calculate the correct size for the other dimension based on that. So the given targetWidth and targetHeight arguments are used as upper bounds when scaling an image, not absolutes. This was done intentionally as a correctly proportional image was determined to be a better default behavior (more expected by users) than cropping the image or forcibly rescaling it to the given dimensions, possibly skewing it.

Intended Audience

This library is intended for developers needing to quickly scale images (using the correct or most optimized methods available in native Java) and move one with their lives.

imgscalr is general purpose and will work on any platform providing the base Java2D classes it uses. imgscalr was also written with web application’s in mind, possibly needing to generate thousands of thumbnails or previews from larger uploaded images.

This library is not a comprehensive image processing (e.g. blur, sharpen, saturate, etc.) library for Java.

The Beginner’s Guide to Managing Users and Groups in Linux

posted Dec 10, 2010, 2:30 PM by Ahmed El-Sharkasy

Ubuntu Linux uses groups to help you manage users, set permissions on those users, and even monitor how much time they are spending in front of the PC. Here’s a beginner’s guide to how it all works.

Users and Groups

Ubuntu is set up for a single person to use when you installed it in your system, but if more than one person will use the computer, it is best for each person to have their own user account. This way each person can have separate settings and documents, and files can be protected from being viewed by the other users on the same PC.

Normally Linux computers have two user accounts—your own user account, and the root account, which is the super user that can access everything on the PC, make system changes, and administer other users. Ubuntu works a little differently, though—you can’t login directly as root by default, and you use the sudo command to switch to root-level access when you need to make a change.

Linux stores a list of all users in the ‘/etc/groups’ file. You can run this command in the Terminal to to view and edit the groups and users in your system:

sudo vigr /etc/groups

Creating User Accounts

To create a new user, you can head to System –> Administration -> User and Groups, and click the “Add” button to add a new user.

Give the appropriate name that identifies the other user and tick the “encrypt” checkbox to secure their home folder.

Click the “Advanced Settings” button to configure the user’s privileges.

The user management module lists Anna’s privileges under the “User Privileges” tab.

We recommend that you remove the “Administer System” privilege from other user accounts. This is to make sure that other users cannot easily change critical system settings that may jeopardize your Linux box.

Linux File and Folder Permissions

Each file in Linux has a set of user and group permissions, and you can use the ls -l command to show the full set of permissions and attributes from the terminal.

Reading from left to right, each item in the list means:

<permissions> 1 <file owner> <file group> <file size> <file date> <file name>

For instance, in the example showing a file named anki, the permissions are rwxr-xr-x, the file is owned by the root user and belongs to the root group, and it’s 159 bytes.

The permission flag has four components, the first character being the flag, usually used to indicate whether it’s a directory or a file—a directory would show a “d” and a regular file will show a “-“. The next 9 characters are broken up into sets of 3 characters, which indicate user, group, and everyone permissions.

<flag><user permissions><group permissions><everyone permissions>

In this particular example, we’ve got rwxr-xr-x, which can be broken up like this:

<flag><user permissions = rwx><group permissions = r-x><everyone permissions = r-x>

The permissions correspond to the following values:

• w = write permission
• x = execute permission

This means that for the file in question, everybody has read and execute permissions, but only root has access to write to the file.

Changing Group Ownership of Files and Directories

Anna is a 7th grader and her brother Peter just enrolled in a programming course in a university. Anna will be more interested to use the educational software for her mathematics or geography homework, compared to Peter who is more interested to use software development tools.

We can configure Anna’s and Peter’s access to these applications by assigning them to the appropriate groups from the “Manage Groups” module.

Let’s create two user groups, a K-12 student group, a University student group, and assign the appropriate user accounts to each group.

We should give the K-12 students the privileges to run the educational software.

Linux stores most of the executables under /usr/bin, for example, Linux stores Anki under /usr/bin/anki. If you’re not sure where a file is located, the which command is a convenient way to find out the location from the terminal:

which anki

Let’s assign Anki and Kig to the k12 group using the chown command, which uses the following format:

sudo chown :[group name] [files list]

You can also revoke the read and execute access from other user groups using the chmod command.

sudo chown :[group name] [files list]

This command gives the member of K12 group access to Anki and Kig. We should restrict the access rights of the university group from Anki and Kig by removing the read and execute permission from the “Other” groups. The format of the command is:

chmod [ugoa][+-=][rwxXst] fileORdirectoryName

The first command that we executed in the command line removes the read (r) and execute (x) privilege from the “Other” group. The “O” option indicates that we are modifying the access right of the Other group. The ‘-’ option means that we want to remove certain file permissions specified in the parameters that follow the ‘-’ option. The man page of chmod gives a detailed explanation of these options.

man chmod

Monitoring Computer Usage

Timekpr allows us to set give each user a limited amount of computing time, and you’ll need to add the following PPA to your software sources so that you can install Timekpr from the Ubuntu Software Center.

deb http://ppa.launchpad.net/timekpr-maintainers/ppa/ubuntu lucid main deb-src http://ppa.launchpad.net/timekpr-maintainers/ppa/ubuntu lucid main

Ubuntu Software Center is the easiest way to install Timekpr—just use the search box and it should come right up.

Timekpr allows us to limit the computer usage time by a certain time frame on each day of the month. For example, we can specify the computer time usage for 300 minutes on Sunday and 60 minutes on Monday.

Timekpr will appear on the user’s task bar and lock the desktop when the computing time of the user is up.

The 50 Best Registry Hacks that Make Windows Better

posted Dec 10, 2010, 2:22 PM by Ahmed El-Sharkasy   [ updated Dec 11, 2010, 10:48 AM ]

We’re big fans of hacking the Windows Registry around here, and we’ve got one of the biggest collections of registry hacks you’ll find. Don’t believe us? Here’s a list of the top 50 registry hacks that we’ve covered.

It’s important to note that you should never hack the registry if you don’t know what you’re doing, because your computer will light on fire and some squirrels may be injured. Also, you should create a System Restore point before doing so. Otherwise, keep reading.

Prevent Windows Update from Forcibly Rebooting Your Computer

We’ve all been at our computer when the Windows Update dialog pops up and tells us to reboot our computer. I’ve become convinced that this dialog has been designed to detect when we are most busy and only prompt us at that moment.

There’s a couple of ways that we can disable this behavior, however. You’ll still get the prompt, but it won’t force you to shut down. Here’s how to do it.

Prevent Windows Update from Forcibly Rebooting Your Computer

One of the most irritating things about Windows is the context menu clutter that you have to deal with once you install a bunch of applications. It seems like every application is fighting for a piece of your context menu, and it’s not like you even use half of them.

Today we’ll explain where these menu items are hiding in your registry, how to disable them the geeky way, and an easier cleanup method for non-geeks as well.

Stop Windows Update from Hijacking the Sleep/Shutdown Button

As an avid user of the Sleep function on my laptop, I’ve been more than irritated with Windows 7 or Vista’s habit of changing the Sleep/Shutdown button into an “Install Updates and Shut Down” button whenever there are updates from Windows Update.

After the last time I accidentally clicked this stupid button when I just wanted to enter sleep mode, I decided to look for a solution.

Stop Windows Update from Hijacking the Sleep/Shutdown Button

Add “Take Ownership” to Explorer Right-Click Menu in Win 7 or Vista

Taking ownership of system files or folders in Windows 7 or Vista is not a simple task. Whether you use the GUI or the command line, it takes far too many steps.

Here’s a registry hack that adds an item to the menu that will let you take ownership of the files in a single step, so you can delete, move, or otherwise modify the file.

Add “Take Ownership” to Explorer Right-Click Menu in Win 7 or Vista

Disable Aero Shake in Windows 7

One of the interesting new features in Windows 7 is the way you can grab a window by the title bar and “shake” it back and forth to minimize everything else. It’s a fun feature, but just in case you want to disable it we’ve got the solution for you.

All you’ll have to do is apply a simple registry hack, and that

Disable Aero Shake in Windows 7

The default method of opening unknown files forces you to go through a list of known applications and is generally a pain to deal with.

That’s why I like to have a context menu option for “Open with Notepad” so that I can quickly open up files without having to go through a lot of trouble.

Disable All Notification Balloons in Windows 7 or Vista

If you find the popup notification balloons in the Windows system tray to be too annoying, you might be interested to know that you can completely disable them. This would be an extreme option, of course… typically you can just turn them off in any offending applications, but if you want to disable them across the board, this is the solution.

Disable All Notification Balloons in Windows 7 or Vista

Change the Registered Owner in Windows

If you’ve ever wondered how to change the name of the person that Windows is registered to, this is the quick tip for you. It’s not all that useful for most people, but it might come in handy if you got a computer from somebody else.

To show off the new changes, just type winver.exe into the start menu search box to see the About Windows box.

Quick Tip: Change the Registered Owner in Windows

Kill Windows with the Blue Screen of Death in 3 Keystrokes

Have you ever wanted to show off your keyboard ninja skills by taking down Windows with just a couple of keystrokes? All you have to do is add one registry key, and then you can impress your friends… or use it to convince people to switch to Linux.

This isn’t a bug, it’s a “feature” in Windows that is designed to let users trigger a crash dump for testing purposes. Note: this one doesn’t work in Windows 7 anymore. Also, it clearly doesn’t make Windows better, but we included it because it’s lots of fun.

Keyboard Ninja: Kill Windows with the Blue Screen of Death in 3 Keystrokes

If you want really quick access to launch a frequently used application without putting extra icons on your desktop, you can add that application to the context menu for the desktop with a simple registry hack. Here’s how to do it.

We’ve already shown you how to create shortcuts to create new Google Docs easily, but what if you want total Windows integration? Here’s how to add them to the Windows Explorer “New” menu for easier access.

This should work for all versions of Windows, and you can modify it to work with Google Apps for your Domain as well. Keep reading for the full instructions.

How to Add Registry Editor to Control Panel

It’s always struck me as odd that system tweakers use the registry editor all the time to fix annoyances in Windows, but nobody has created a tweak to add the registry editor to the control panel… until now.

I’ve created a registry hack to add the registry editor as another option in the Control Panel in any version of Windows.

Remove “Shortcut” Text From New Shortcuts in Windows 7 or Vista

A source of annoyance for many Windows users is the ” – Shortcut” text that is added to the name of newly created shortcuts, and every time you have to manually edit the shortcut and remove that text. Wouldn’t it be great if there was a registry hack for this?

Most long-time geeks will remember that there was a hack for Windows XP, and probably already know that the same hack works in Windows 7 or Vista as well.

Disable Win+X Shortcut Keys on Windows 7 or Vista

Windows 7 and Vista have all the same Windows+X shortcut keys as other versions of Windows, such as Win+E for explorer and Win+D for the desktop, but adds in all of the Win+<num> keys to launch the shortcuts in the Vista Quick Launch menu (or switch to apps in Windows 7), as well as Win+X for mobility center, etc.

But what if you want to disable all these extra keys?

Stupid Geek Tricks: Enable the Secret “How-To Geek” Mode in Windows 7

We haven’t told anybody before, but Windows has a hidden “How-To Geek Mode” that you can enable which gives you access to every Control Panel tool on a single page—and we’ve documented the secret method for you here.

NOTE: Do not use this on Vista or XP: things will break.

Disable Windows Mobility Center in Windows 7 or Vista

Windows Mobility Center is a fairly useful tool for those of us using Windows 7 or Vista on a laptop computer, but might not be for everybody, especially since it takes over the Win+X keyboard shortcut.

If you would rather disable Windows Mobility Center, all it takes is a single registry tweak.

Hide Drives from Your Computer in Windows 7 or Vista

If you’ve got drives in My Computer that you never access, such as a USB Flash drive that you are using solely for ReadyBoost, a floppy drive, or a network drive only used for a particular piece of software, then you might want to simply hide the drive from your computer.

This tip will only hide the drive from being displayed, applications and the command prompt will still have access to it, and you can still manually browse to the folder if you type in the path.

How to Put a Real Libraries Icon On Your Windows 7 Desktop

We’re big fans of hidden registry hacks around here, so when our friend Justin showed how to put a real, working Libraries icon on the desktop, we figured it would make a perfect article for for a few extra geek points.

Yeah, you can always create a shortcut icon for anything on the desktop, but this one is the actual icon without the shortcut overlay. Plus it’s a geeky hidden trick—what’s not to like?

How to Restore Previous Versions of the Registry in Windows 7

If you want to manually restore a specific section of the registry from a previous System Restore snapshot, or access some specific keys from an older version of the registry, you can do so by getting access to those files and then exporting sections from them. Here’s how to do it in Windows 7 or Vista.

Remove or Hide Unwanted Items From the Control Panel in Windows 7

Have you ever opened the Control Panel in Windows 7 and thought there is no reason to have some of the icons listed? Today we take a look at how to remove unwanted or unneeded items from Control Panel in Windows 7.

For some items you won’t be able to easily delete the CPL file if it’s a Windows system file or in use. You could use a program like Unlocker, but we can tweak the Registry to hide items in Control Panel.

Make the Taskbar Buttons Switch to the Last Active Window in Windows 7

The new Windows 7 taskbar’s Aero Peek feature, with the live thumbnails of every window, is awesome… but sometimes you just want to be able to click the taskbar button and have the last open window show up instead. Here’s a quick hack to make it work better.

Make Aero Peek Display Instantly (or Disable it) in Windows 7

Aero Peek is one of the more useful new features in Windows 7… just move your mouse to the taskbar for half a second, and everything else hides so you can see the desktop or application window. But why does it take half a second?

There’s a simple little registry hack that will change the amount of time between hovering your mouse over the show desktop button in the lower right-hand corner, and the Aero Peek display showing up. The same thing should work for when you hover over an application window on the taskbar.

Why Doesn’t Disk Cleanup Delete Everything from the Temp Folder?

After you’ve used Disk Cleanup, you probably expect every temporary file to be completely deleted, but that’s not actually the case. Files are only deleted if they are older than 7 days old, but you can tweak that number to something else.

Why Doesn’t Disk Cleanup Delete Everything from the Temp Folder?

Remove “Troubleshoot Compatibility” from the Windows Context Menu

Reader Jeevus wrote in asking how to remove the “Troubleshoot Compatibility” item from the Windows context menu whenever you right-click on an application—naturally, we were happy to explain how to do it, and share with the rest of you.

You’ll want to note that we’re not necessarily recommending that you remove this item, since it could be useful if you’re having compatibility issues with an application, but we’re fans of showing how to do something—also, we just like tinkering in the registry.

Show the Classic “All Programs” Menu in the Start Menu in Windows 7

There are a lot of new users to Windows 7 who are not happy with the new Start Menu and wish they could revert to the Classic menu. Here is how to at least get back the Classic “All Programs” Menu.

While it’s not quite the same as the good old XP days, if you’re looking to get the All Programs Menu back, this Registry hack will do the trick without installing 3rd party software.

How To Add Recycle Bin to “My Computer” in Windows 7 or Vista

Have you ever wanted to add the Recycle Bin to your My Computer screen? Yeah, it’s probably not the most common request, but here’s how to do it anyway with a simple registry hack.

To make this tweak, we’ll be doing a quick registry hack, but there’s a downloadable version provided as well.

One of the first things you might notice in Windows 7 is the addition of the new Gadgets and Screen Resolution items to the context menu. The only problem is that you might not really want them there—so we’ll explain how to get rid of them.

No clue what we’re talking about? If you are using Windows 7 and you right-click on the desktop, you’ll see a bunch of new items at the bottom:

Stupid Geek Tricks: Enable More Fonts for the Windows Command Prompt

Have you ever noticed that there are only two fonts to choose from in the Command prompt properties window? What you might not know is that you can use a simple registry hack to enable alternate fonts, including a very readable font that comes with Windows 7, Vista, or Office 2007.

But that’s not all… you can enable a number of fixed width fonts if you really want to. We’ll cover how this works, as well as one of my favorite “interesting” fonts for the command prompt.

Remove ATI Catalyst Control Center from the Desktop Right-Click Menu

Have you ever wondered how to remove the “Catalyst(TM) Control Center” item from the desktop context menu? Here’s the simple registry hack to remove it.

Remove NVIDIA Control Panel from Desktop Right-Click Menu

Have you ever wondered how to remove the “NVIDIA Control Panel” item from the desktop context menu? If so, you probably didn’t realize that it’s trivially easy to remove.

Make “Command Prompt Here” Always Display for Folders in Windows

We’ve previously explained how you can open a command prompt by holding down the Shift key and right-clicking on a folder or the desktop… but how do you make that item show up without having to hold down the shift key?

There’s a simple registry hack you can do that will enable “Open Command Window Here” item without holding down the shift key:

Add Encrypt / Decrypt Options to Windows 7 / Vista Right-Click Menu

If you use the built-in file encryption in Windows 7 or Vista, you might be interested in adding an option to the right-click menu to more easily encrypt and decrypt your files, rather than having to use the file properties dialog.

Adding this to the menu couldn’t be simpler – there’s only a single registry key to add.

Customize the Default Screensavers in Windows 7 and Vista

Windows 7 and Vista include a nice set of backgrounds, but unfortunately most of them aren’t configurable by default.  Thanks to a free app and some registry changes, however, you can make the default screensavers uniquely yours!

You can customize the Bubbles, Ribbons, and Mystify screensaver to enable hidden options with this registry hack.

Skip the Annoying “Use the Web service to find the correct program” Dialog

If you’ve used Windows for any length of time, you’ve likely tried to open a file with an unknown extension. Instead of getting a list of programs to open the file with, you get an annoying dialog asking you to use a web service to find a program. So how do we change this?

You can use a registry hack to force Windows to skip this dialog altogether, and give you a list of applications to use to open the file instead, just as if you had selected the second option.

Disable Caps Lock Key in Windows 7 or Vista

The caps lock key is one of those remnants of another age of computers, back when people used to shout at each other more often. Since it’s not entirely useful anymore we’ll learn how to disable it. If you aren’t interested in the explanation you can skip to the bottom for the registry files.

Windows doesn’t have a default setting to allow for disabling the key, so what we have to do is re-map the key to something non-existent so as to completely disable it.

We’ve received lots of requests to add Defrag to the right-click menu for a drive, so we created a simple registry hack that can be easily added that does just that.

A couple of days ago I noticed a thread on our forum asking how to add Control Panel to the desktop context menu, so I decided to write up the solution for everybody, since it seems like a really useful hack.

There’s a manual registry hack that you can apply if you’d like, or you can download the reghack version and apply it easily.

Use Verbose Boot Messages to Troubleshoot Windows Startup Problems

If you’ve ever had problems with your PC starting up or shutting down slowly, there’s lots of different troubleshooting techniques that you can use—today we’ll talk about how to enable verbose messages.

Enabling these verbose messages is not going to magically solve your problems, of course—the point is to use this to identify a problem, which you can then solve through other means, generally by uninstalling a problem application or upgrading a faulty driver.

How to Enable or Disable TortoiseSVN Menus Easily

If you’re a programmer that uses TortoiseSVN to manage your Subversion source control project, you might wonder how to easily disable the menu items without completely uninstalling. Here’s a quick way to do it.

The general idea is that we’ll remove the Windows Explorer context menu items from the registry with one script, and then add the registry entries back with another script.

How to Add Control Panel to “My Computer” in Windows 7 or Vista

Back in the Windows XP days, you could easily add Control Panel to My Computer with a simple checkbox in the folder view settings. Windows 7 and Vista don’t make this quite as easy, but there’s still a way to get it back.

To make this tweak, we’ll be doing a quick registry hack, but there’s a downloadable version provided as well.

Increase the Speed of the Aero Taskbar Thumbnails in Windows 7

By default you may notice that there is a slight delay when hovering your mouse over a Taskbar Thumbnail. Here is a neat registry hack that will allow you to speed it up.

Once you apply the hack, you’ll notice when you hover your mouse over a thumbnail of an open app on the Taskbar the preview pops up instantly with no delay.

Remove Programs from the Open With Menu in Explorer

Would you like to clean up the Open with menu in Windows Explorer?  Here’s how you can remove program entries you don’t want in this menu on any version of Windows.

Add “Run as Administrator” to Any File Type in Windows 7 or Vista

Have you ever tried to unzip a file to the Program Files directory in Windows 7 or Vista? You’ll get all sorts of permission denied errors, and generally be unsuccessful. So how do we open up the zipfile as an administrator? For that matter, how do you open any file as administrator?

There’s a simple registry tweak that will let us specify the action to run as administrator for a file type. Unfortunately you’ll have to make the tweak manually, but we’ll walk you through it.

Create a Context Menu Item to Copy a Text File To the Clipboard in Windows 7 / Vista / XP

If you are the type of person that likes to keep a lot of information stored in text-format files on your drive, you’ve probably encountered a scenario where you want to copy that information to the clipboard… so you open the file in notepad, select all, then copy to the clipboard. What if you could do it with a simple context menu item instead?

Using a little registry hacking and the clip.exe utility built into Windows 7 and Vista, we can do just that, and we can even hide it behind the Shift + Right-Click menu so that it won’t waste space on the menu unless you hold down the shift key.

Disable the “Send To” Folder on the Windows Explorer Context Menu

After writing the article about adding Notepad to the context menu I noticed all the comments from users that prefer to use a shortcut in the Send To menu, which got me thinking… I wonder if you can disable the Send To folder?

Of course you can easily disable it… naturally it’s a registry hack, so standard disclaimers apply.

Disable the “Send To” Folder on the Windows Explorer Context Menu

Remove “Map Network Drive” Menu Item from Windows Vista or XP

If you have never used the “Map Network Drive” dialog box, do you ever wonder how to get rid of it? Personally I only map drives from the command line so I never use it either… so I’m thankful there’s a registry hack that can remove the menu items.

If you are unfamiliar with what I’m talking about, just right-click on the Computer icon and you’ll see it.

Remove “Map Network Drive” Menu Item from Windows Vista or XP

Some time ago I received an email from a reader curious why their Task Manager option was grayed out on the taskbar right-click menu. After a bit of research his problem was solved, and now I’m sharing the solution with everybody.

There is a registry key that will disable Task Manager, although it’s not always clear how or why it was set to disable. In many cases the problem is related to spyware, so you should also scan your computer. Here’s how to enable or disable it.

Is your Internet Explorer context menu completely out of control? Is it so long that it actually runs off the screen? Here’s how to quickly take a few steps to get rid of all that ridiculous clutter without installing Google Chrome instead.

Sometimes you can remove the items just by using the Manage Add-ons screen, but other add-ons embed themselves a lot deeper, and you’ll need to use a registry hack to get rid of them. Here’s how to do that.

How to Restore the Real Internet Explorer Desktop Icon in Windows 7

Remember how previous versions of Windows had an Internet Explorer icon on the desktop, and you could right-click it to quickly access the Internet Options screen? It’s completely gone in Windows 7, but a geeky hack can bring it back.

Microsoft removed this feature to comply with all those murky legal battles they’ve had, and their alternate suggestion is to create a standard shortcut to iexplore.exe on the Desktop, but it’s not the same thing. We’ve got a registry hack to bring it back.

Enable or Disable Displaying a Message During the Boot Process

If you’ve ever had a corporate laptop, there’s a good chance that you’ve seen a message before you login that talks about the corporate policies and all of that stuff.

Here’s how to enable or disable that login message using a registry hack.

How long does it take to make a context switch?

posted Nov 28, 2010, 11:54 PM by Ahmed El-Sharkasy

Blog
That's a interesting question I'm willing to waste some of my time on. Someone at StumbleUpon emitted the hypothesis that with all the improvements in the Nehalem architecture (marketed as Intel i7), context switching would be much faster. How would you devise a test to empirically find an answer to this question? How expensive are context switches anyway? (tl;dr answer: very expensive)

The lineup

I've put 3 different generations of CPUs to test:
• A dual Intel 5150 (Woodcrest, based on the old "Core" architecture, 2.67 GHz). The 5150 is a dual-core, and so in total the machine has 4 cores available.
• A dual Intel E5440 (Harpertown, based on the Penrynn architecture, 2.83 GHz). The E5440 is a quad-core so the machine has a total of 8 cores.
• A dual Intel E5520 (Gainestown, based on the Nehalem architecture, aka i7, 2.27 GHz). The E5520 is a quad-core, and has HyperThreading enabled, so the machine has a total of 8 cores or 16 "hardware threads".
As far as I can say, all CPUs have are set to a constant clock rate (no Turbo Boost or anything fancy).

First idea: with syscalls (fail)

My first idea was to make a cheap system call many times in a row, time how long it took, and compute the average time spent per syscall. The cheapest system call on Linux these days seems to be gettid. Turns out, this was a naive approach since system calls don't actually cause a full context switch anymore nowadays, the kernel can get away with a "mode switch" (go from user mode to kernel mode, then back to user mode). That's why when I ran my first test program, vmstat wouldn't show a noticeable increase in number of context switches. But this test is interesting too, although it's not what I wanted originally.

Source code:
timesyscall.c Results:
• Intel 5150: 105ns/syscall
• Intel E5440: 87ns/syscall
• Intel E5520: 58ns/syscall
Now that's nice, more expensive CPUs perform noticeably better. But that's not really what we wanted to know. So to test the cost of a context switch, we need to force the kernel to de-schedule the current process and schedule another one instead. And to benchmark the CPU, we need to get the kernel to do nothing but this in a tight loop. How would you do this?

Second idea: with futex

The way I did it was to abuse futex (RTFM). futex is the low level Linux-specific primitive used by most threading libraries to implement blocking operations such as waiting on a contended mutexes, semaphores that run out of permits, condition variables and friends. If you would like to know more, go read Futexes Are Tricky by Ulrich Drepper. Anyways, with a futex, it's easy to suspend and resume processes. What my test does is that it forks off a child process, and the parent and the child take turn waiting on the futex. When the parent waits, the child wakes him up and goes on to wait on the futex, until the parent wakes him and goes on to wait again. Some kind of a ping-pong "I wake you up, you wake me up...".

Source code:
timectxsw.c Results:
• Intel 5150: ~4300ns/context switch
• Intel E5440: ~3600ns/context switch
• Intel E5520: ~4500ns/context switch
Note: those results include the overhead of the futex system calls.

Now you must take those results with a grain of salt. The micro-benchmark does
nothing but context switching. In practice context switching is expensive because it screws up the CPU caches (L1, L2, L3 if you have one, and the TLB – don't forget the TLB!).

CPU affinity

Things are harder to predict in an SMP environment, because the performance can vary wildly depending on whether a task is migrated from one core to another (especially if the migration is across physical CPUs). I ran the benchmarks again but this time I pinned the processes/threads on a single core (or "hardware thread"). The performance speedup is dramatic.

Source code:
cpubench.sh Results:
• Intel 5150: ~1900ns/process context switch, ~1700ns/thread context switch
• Intel E5440: ~1300ns/process context switch, ~1100ns/thread context switch
• Intel E5520: ~1400ns/process context switch, ~1300ns/thread context switch
Performance boost: 5150: 66%, E5440: 65-70%, E5520: 50-54%.

The performance gap between thread switches and process switches seems to increase with newer CPU generations (5150: 7-8%, E5440: 5-15%, E5520: 11-20%). Overall the penalty of switching from one task to another remains very high. Bear in mind that those artificial tests do absolutely zero computation, so they probably have 100% cache hit in L1d and L1i. In the real world, switching between two tasks (threads or processes) typically incurs significantly higher penalties due to cache pollution. But we'll get back to this later.

After producing the numbers above, I quickly criticized Java applications, because it's fairly common to create shitloads of threads in Java, and the cost of context switching becomes high in such applications. Someone retorted that, yes, Java uses lots of threads but threads have become significantly faster and cheaper with the NPTL in Linux 2.6. They said that normally there's no need to do a TLB flush when switching between two threads of the same process. That's true, you can go check the source code of the Linux kernel (switch_mm in mmu_context.h):
static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,                             struct task_struct *tsk){       unsigned cpu = smp_processor_id();       if (likely(prev != next)) {               [...]               load_cr3(next->pgd);       } else {               [don't typically reload cr3]       }}
In this code, the kernel expects to be switching between tasks that have different memory structures, in which cases it updates CR3, the register that holds a pointer to the page table. Writing to CR3 automatically causes a TLB flush on x86.

In practice though, with the default kernel scheduler and busy server-type workload, it's fairly infrequent to go through the code path that skips the call to
load_cr3. Plus, different threads tend to have different working sets, so even if you skip this step, you still end up polluting the L1/L2/L3/TLB caches. I re-ran the benchmark above with 2 threads instead of 2 processes (source: timetctxsw.c) but the results aren't significantly different (this varies a lot depending on scheduling and luck, but on average on many runs it's typically only 100ns faster two switch between threads if you don't set a custom CPU affinity).

Indirect costs in context switches: cache pollution

The results above are in line with a paper published a bunch of guys from University of Rochester: Quantifying The Cost of Context Switch. On an unspecified Intel Xeon (the paper was written in 2007, so the CPU was probably not too old), they end up with an average time of 3800ns. They use another method I thought of, which involves writing / reading 1 byte to / from a pipe to block / unblock a couple of processes. I thought that (ab)using futex would be better since futex is essentially exposing some scheduling interface to userland.

The paper goes on to explain the indirect costs involved in context switching, which are due to cache interference. Beyond a certain working set size (about half the size of the L2 cache in their benchmarks), the cost of context switching increases dramatically (by 2 orders of magnitude).

I think this is a more realistic expectation. Not sharing data between threads leads to optimal performance, but it also means that every thread has its own working set and that when a thread is migrated from one core to another (or worse, across physical CPUs), the cache pollution is going to be costly. Unfortunately, when an application has many more active threads than hardware threads, this is happening all the time. That's why not creating more active threads than there are hardware threads available is so important, because in this case it's easier for the Linux scheduler to keep re-scheduling the same threads on the core they last used ("weak affinity").

Having said that, these days, our CPUs have much larger caches, and can even have an L3 cache.
• 5150: L1i & L1d = 32K each, L2 = 4M
• E5440: L1i & L1d = 32K each, L2 = 6M
• E5520: L1i & L1d = 32K each, L2 = 256K, L3 = 8M
Note that in the case of the E5520 (the one marketed as "i7"), the L2 cache is tiny but there's one L2 cache per core (with HT enabled, this gives us 128K per hardware thread). The L3 cache is shared by the 4 cores that are on each physical CPU.

Having more cores is great, but it also increases the chance that your task be rescheduled onto a different core. The cores have to "migrate" cache lines around, which is expensive. I recommend reading
What Every Programmer Should Know About Main Memory by Ulrich Drepper (yes, him again!) to understand more about how this works and the performance penalties involved.

So how does the cost of context switching increases with the size of the working set? This time we'll use another micro-benchmark,
timectxswws.c that takes in argument the number of pages to use as a working set. This benchmark is exactly the same as the one used earlier to test the cost of context switching between two processes except that now each process does a memset on the working set, which is shared across both processes. Before starting, the benchmark times how long it takes to write over all the pages in the working set size requested. This time is then discounted from the total time taken by the test. This attempts to estimate the overhead of overwriting pages across context switches.

Here are the results for the 5150:
As we can see, the time needed to write a 4K page more than doubles once our working set is bigger than what we can fit in the L1d (32K). The time per context switch keeps going up and up as the working set size increases, but beyond a certain point the benchmark becomes dominated by memory accesses and is no longer actually testing the overhead of a context switch, it's simply testing the performance of the memory subsystem.

Same test, but this time with CPU affinity (both processes pinned on the same core):
Oh wow, watch this! It's an order of magnitude faster when pinning both processes on the same core! Because the working set is shared, the working set fits entirely in the 4M L2 cache and cache lines simply need to be transfered from L2 to L1d, instead of being transfered from core to core (potentially across 2 physical CPUs, which is far more expensive than within the same CPU).

Now the results for the i7 processor:
Note that this time I covered larger working set sizes, hence the log scale on the X axis.

So yes, context switching on i7 is faster, but only for so long. Real applications (especially Java applications) tend to have large working sets so typically pay the highest price when undergoing a context switch. Other observations about the Nehalem architecture used in the i7:
• Going from L1 to L2 is almost unnoticeable. It takes about 130ns to write a page with a working set that fits in L1d (32K) and only 180ns when it fits in L2 (256K). In this respect, the L2 on Nehalem is more of a "L1.5", since its latency is simply not comparable to that of the L2 of previous CPU generations.
• As soon as the working set increases beyond 1024K, the time needed to write a page jumps to 750ns. My theory here is that 1024K = 256 pages = half of the TLB of the core, which is shared by the two HyperThreads. Because now both HyperThreads are fighting for TLB entries, the CPU core is constantly doing page table lookups
Speaking of TLB, the Nehalem has an interesting architecture. Each core has a 64 entry "L1d TLB" (there's no "L1i TLB") and a unified 512 entry "L2TLB". Both are dynamically allocated between both HyperThreads.

Virtualization

I was wondering how much overhead there is when using virtualization. I repeated the benchmarks for the dual E5440, once a normal Linux install, once while running the same install inside VMware ESX Server. The result is that, on average, it's 2.5x to 3x more expensive to do a context switch when using virtualization. My guess is that this is due to the fact that the guest OS can't update the page table itself, so when it attempts to change it, the hypervisor intervenes, which causes an extra 2 context switches (one to get inside the hypervisor, one to get out, back to the guest OS).

This probably explains why Intel added the EPT (
Extended Page Table) on the Nehalem, since it enables the guest OS to modify its own page table without help of the hypervisor, and the CPU is able to do the end-to-end memory address translation on its own, entirely in hardware (virtual address to "guest-physical" address to physical address).

Parting words

Context switching is expensive. My rule of thumb is that it'll cost you about 30µs of CPU overhead. This seems to be a good worst-case approximation. Applications that create too many threads that are constantly fighting for CPU time (such as Apache's HTTPd or many Java applications) can waste considerable amounts of CPU cycles just to switch back and forth between different threads. I think the sweet spot for optimal CPU use is to have the same number of worker threads as there are hardware threads, and write code in an asynchronous / non-blocking fashion. Asynchronous code tends to be CPU bound, because anything that would block is simply deferred to later, until the blocking operation completes. This means that threads in asynchronous / non-blocking applications are much more likely to use their full time quantum before the kernel scheduler preempts them. And if there's the same number of runnable threads as there are hardware threads, the kernel is very likely to reschedule threads on the same core, which significantly helps performance.

Another hidden cost that severely impacts server-type workloads is that after being switched out, even if your process becomes runnable, it'll have to wait in the kernel's run queue until a CPU core is available for it. Linux kernels are often compiled with
HZ=100, which entails that processes are given time slices of 10ms. If your thread has been switched out but becomes runnable almost immediately, and there are 2 other threads before it in the run queue waiting for CPU time, your thread may have to wait up to 20ms in the worst scenario to get CPU time. So depending on the average length of the run queue (which is reflected in load average), and how long your threads typically run before getting switched out again, this can considerably impact performance.

It is illusory to imagine that NPTL or the Nehalem architecture made context switching cheaper in real-world server-type workloads. Default Linux kernels don't do a good job at keeping CPU affinity, even on idle machines. You must explore alternative schedulers or use
taskset or cpuset to control affinity yourself. If you're running multiple different CPU-intensive applications on the same server, manually partitioning cores across applications can help you achieve very significant performance gains.

How To Harmonize Your Dual-Boot Setup for Windows and Ubuntu

posted Nov 23, 2010, 3:47 PM by Ahmed El-Sharkasy

Looking for some harmony between Windows 7 and Ubuntu in your dual-boot setup?  Here are a few ways you can make the tense OS situation a little more unified and copacetic.

Background

When we covered How to Choose a Partition Scheme for Your Linux PC, we noticed that some people were wondering how to use a third partition between Linux and Windows to act as a storage partition.

Why It’s Difficult

As a few commenters pointed out, you can’t use an NTFS-formatted partition for /home in Linux.  That’s because NTFS doesn’t preserve all of the properties and permissions used by Linux, and Windows doesn’t even read Linux file systems.  You can readily see this if you view a folder that’s hidden in Windows from within Linux, or a file that Linux sees as hidden in Windows.  What works for one doesn’t work for the other.  Furthermore, there isn’t an incredibly clean way to move the Users folder in Windows without messing with things.  This is why many people with nicer machines end up using virtualization software; it’s easier than forcing the two to co-operate side-by-side.

Image from cellguru.co.cc, assumed fair use

A Work-Around

There isn’t a way to run your /home directory from a FAT32 or NTFS partition, so your configuration files and scripts will have to remain there.  What you can do is redirect the other commonly used folders like Documents, Downloads, Music, etc. to another partition, one that can be read by Windows.  Then, you can add these folders to your Windows 7 Libraries and mark them as the default save location.

This isn’t a proper workaround.  Your program-associated configuration files and other user-related settings will not be in the same place for this setup.  If you have to reinstall either OS, you will have to perform a separate backup of your user settings.  That being said, however, most people are really just concerned about their documents, music, videos, and so forth.  This solves that issue by pointing both OSs to look in the same place for them.

Linux has come a long way with regards to reading and writing NTFS, and since it’s much better than FAT32 and tougher to configure this setup with, that’s what we’ll be covering in this guide.

Partition Scheme

For this to work, you’ll want your hard drive set up in a way similar to this:

• A large partition (or second hard drive!) to store your files
• A small swap partition

For later convenience, when you format your storage partition to NTFS, add an easily recognizable label to it.  It’ll be easier to find a drive called “storage” or “media” than by counting partition numbers.

Notice that we don’t have a separate /home partition this time around.  Since the vast majority of your important/large files will be on a separate partition, this negates the need for that.  You’re welcome to use a separate /home partition to make backing up the Linux-side of things easier, just remember that you can’t exceed four primary partitions per disk.

Since we’re using NTFS, it’s a good idea to specifically tell your system to mount your storage partition or disk in the same place every time you boot.  To do this, we’ll be editing the /etc/fstab system file, which is the file system table used by Linux, but first, we have some preparations to make.  Open up terminal, and if this makes you nervous, just take a deep breath and relax.  It’ll be okay.

Prep Work

We need to install ntfs-3g, the driver Linux will use to read and write to NTFS.  If you already have it installed, it’ll tell you, so don’t worry.

sudo apt-get install ntfs-3g

If you see “ntfs-3g is already the newest version” then you already have it installed, otherwise you’ll see it work, so wait for it to finish its thing.  Next, let’s create the directory where your partition will mount.  If you want the drive to appear in the “Places” menu by default, you’ll use:

sudo mkdir /media/storage

If you don’t want it to appear in “Places” and you want to manually browse to it for whatever reason, you can use this instead:

sudo mkdir /mnt/storage

This will create a “storage” directory in /media.  You can change this to something else if you like, but be sure it does not have any spaces.  Spaces will create a problem when we configure it to automatically mount in the next few steps.

fstab

Now, it’s time to edit the fstab file.  First, we’ll create a backup, just in case anything happens.

sudo cp /etc/fstab /etc/fstab.backup

It’ll prompt you for your password, so go ahead and enter it.  If, for whatever reason, you need to restore the backup in the future, you would do this:

sudo cp /etc/fstab.backup /etc/fstab

Next, you need to find what the UUID of your storage partition is.  The UUID stands for “universally unique identifier” and acts as a proper serial number that will not change until the partition is reformatted.  Run the following command:

sudo blkid

/dev/sda1: UUID=”23A87DBF64597DF1″ TYPE=”ntfs”
/dev/sda2: UUID=”2479675e-2898-48c7-849f-132bb6d8f150″ TYPE=”ext4″
/dev/sda5: UUID=”66E53AEC54455DB2″ LABEL=”storage” TYPE=”ntfs”
/dev/sda6: UUID=”05bbf608-87fa-4473-9774-cf4b2602d8d6″ TYPE=”swap”

Find the line that has the correct label to your storage partition (makes things easy, doesn’t it?) and copy the UUID.

gksudo gedit /etc/fstab

You’ll see gedit open, like so:

You may see an uglier theme on gedit than usual, but don’t worry it.  Add the following lines to the bottom of fstab, substituting your own UUID instead of mine:

# storage mount
UUID=66E53AEC54455DB2 /media/storage/    ntfs-3g        auto,user,rw 0 0

The first line is a comment, indicated by the leading hash tag.  The next line tells fstab to look for the partition with the specified UUID, mount it to /media/storage/, and to use the ntfs-3g driver.  Furthermore, it makes sure that it automatically mounts at boot, makes it accessible by users (not just root), gives both read and write privileges, and skip file-system checks (you’ll probably want to use Windows to do that).  Lastly, double-check, and triple-check to make sure you didn’t touch anything else, and that the UUID is correct.

When you’re ready, click save and then reboot.  Don’t skip the reboot, as it’s necessary for the next step as well as to make sure things work.

You should be able to boot into Ubuntu as if nothing happened, but you’ll notice that you’ve got “storage” (or whatever you named it) under the Places menu now!  If not, check to make sure you got fstab correct.  See above to restore fstab from your backup, if you need to.

Open up terminal and enter the following command:

gedit .config/user-dirs.dirs

This is the file where your “special” folders in your home directory are defined.

You can edit this to your liking.  In place of where you see “\$HOME/Downloads” you would put in an absolute folder location, like “/media/storage/Downloads”.  Go ahead and create those folders, or whatever folders you’d like to call them, and put the path down for each of these.  Here’s what the finished edit should look like:

Click save, and we’re done the crux of the configuration.  You may need to reboot for these changes to take effect, but you can just boot into Windows to finish out the process in the next section.

Basically, now when you browse and put files in your “Downloads” folder, they’ll actually go to your storage drive’s “Downloads” folder.  Anything in your home folder itself will stay in /home/yourusername/, not on your storage drive.  A few of the folders, like “Desktop” and “Templates,” probably won’t benefit from this treatment, either.  Templates are rarely used, the desktop usually gets cluttered with shortcuts and the like, and the Windows desktop isn’t elegantly redirected, unfortunately.

Boot into Windows, and you’ll see that there’s another partition called “storage” under “My Computer.”  Windows 7 has the beautiful Libraries feature built-in, so take a look at our article “Understanding the Libraries Feature in Windows 7,” and you’ll see step-by-step directions on how to add your new storage folders to your libraries.

As you can see, my storage drive folders are a part of my libraries.  My storage drive letter is E: because my network share is at D:.  Also, take a look at our “Change the Default Save Folder for Windows 7 Libraries…” article so that when you stick things in your libraries, they automatically get saved to your new storage folders as well.

It’s also worth mentioning that if you have some know-how, you could even do this with a remotely shared drive on your network, though it may prove to be too slow for actual use.  A better idea is to turn your storage partition into a shared drive that can be accessed by other computers in your network.

How to Create an Index Table Like a Pro with Microsoft Word

posted Nov 22, 2010, 4:41 AM by Ahmed El-Sharkasy

An index gives readers a way to find important words easily in our document, but creating an index by hand is very tedious and time consuming. Thankfully you can automatically create an index table in Word.

Image by Ifijay

The common approach to create an index table in Word is to manually mark each word that we wish to index, but the other alternative is to use a concordance document to automatically index our master document, which is what we will cover in today’s article.

Generating the Index

Let’s start by creating a two column table in our concordance file. Write the words that you would like to be marked for indexing in the left column. Write the text that you would like to use in the master document’s index table in the right column.

Close the concordance file and open your master document’s reference tab to index our master document.

Click on the “AutoMark” button and choose the concordance document when Word prompts you to specify the AutoMark file.

Right after you click the OK button you will see that Word creates some index entry fields in our document.

We can hide these fields by clicking the “Show/Hide Paragraph” button in the home tab.

Go to the end of the master document and click the “Insert Index” button one more time and click the OK button this time to create the index.

That’s all we have on how to create an index table with a concordance file. Let’s take a closer look on how we can customize the index style.

Creating Cross References in the Index

Word allows us to create different type of index. Here we have an index with sub-entry that is particularly useful when we want to group a set of closely related concepts in our document.

The trick of creating a sub-entry is by separating the text in the right column of our concordance document table with a colon (:). Word will treat any words that come after the colon as a sub-entry in the index.

Another useful type of index is a cross reference index that usually comes in the form of “See also …”

Unfortunately we can’t create cross references in our index table using a concordance file, so we have to manually edit the index field by adding “\t” after the indexed word followed by the cross referenced word.

Maintaining the Index

One of the challenges with maintaining an index in Word is that Word does not give us a button or menu that we can simply click to clear the index fields if we decide to redo our concordance file.

We have to use a Visual Basic script to clear the index fields in our document. Most of you must be thinking “Visual Basic Script, I am not a programmer ! What is that ?”. Don’t worry it’s not as bad as it sounds. Just copy and paste this simple script written by the awesome guys at TechRepublic into Word’s Visual Basic editor and run it to clean your master document’s index fields.

Sub DeleteIndexEntries() Dim doc As Document Dim fld As Field Set doc = ActiveDocument For Each fld In doc.Fields fld.Select If fld.Type = wdFieldIndexEntry Then fld.Delete End If Next Set fld = Nothing Set doc = Nothing End Sub 

Open the Visual Basic editor by pressing Alt+F11 and place this script into the editor. Execute the script by clicking the “run button” to clean the master document’s index fields.

Your master document should no longer have any index fields. We can now re-index the master document and recreate the index table using the “Insert Index” menu.

Applying Different Index Table Formats

Yes index is definitely useful for your reader, but most probably some of you are thinking, “Why does the index table look so boring. Can I change the way it looks to make it more appealing ?”. The answer is yes, index table does not have to look plain.

We can adjust the index table’s style by selecting the one of the available format to adjust the look and feel of the index table.

Here is an example on how the Classic index format looks like.

We can even apply our own style to the index table by choosing the “From Template” and clicking the “Modify” button.

Choose one of the available index styles and click the “Modify” button to make our own style.

We can adjust the index table’s font style.

Gives the index table some borders, or numbering;

… to give the index table a specific look and feel.

1-10 of 26