Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Monday, April 26, 2010

Deleted Linux partition! How to get back into Windows?


Recently one of my computers' Linux partition was deleted by mistake. As the Linux partition held the multi-boot information, it made the computer stuck at grub prompt with no way of knowing where to load the OS images from. I think that is known as grub stage 2. I was able to find grub commands and successfully booted into Windows XP. So, if Linux partition of your multi-boot system is inadvertently deleted and you are stuck at grub prompt without access to Windows cd, then try this list of commands at grub prompt
grub>

grub> root(hd0, 0)
grub>makeactive
grub>chainloader +1
grub>boot

Note the first command " root(hd0, x) "here x could be a different number on your system...mine worked for 0.
This booted the Windows XP on the computer. But each time the computer is restarted after this, it's stuck at grub prompt and you have to follow the same list of commands. Another search and I found and installed a very nice utility called "mbrfix". Booted Windows and ran the utility; it created the master boot record (MBR) for Windows and fixed the problem and I could reboot without any problem.

Alternatively, I have read that if you have access to Windows cd, booting from it and running command "fixmbr" also does the trick.




Monday, March 29, 2010

Wubi and Ubuntu

I was trying out Wubi installer for Ubuntu. What it does basically is install Ubuntu on a Windows file system. It creates a windows file and makes it look like a hard disk to Ubuntu i.e. a virtual hard disk. So, while Ubuntu is installing on windows file system (loopback mounting), Windows need not boot if we want to work on Ubuntu. We are using Windows file system but not booting Windows as a host. Ubuntu is running on its own.The installation creates an entry in boot.ini file so that Ubuntu can be booted up as a separate OS just like a dual-boot system. Also, the installation shows up as an installed application on Windows, so if you need to remove Ubuntu, remove it as any Windows program. This is good for newbies as it saves them from the hassles of partitioning the disk.

Another cool thing about having Ubuntu on the system is that I can use my mobile broadband that is available in modem right out of the box. No need to configure or install any extra softwares. Just go to network connections, select the provider from the list, and the Ubuntu is ready to use the usb modem. Just enable it with a click of mouse. Very neat!

Thursday, July 23, 2009

Redirection and 2>&1

In Unix, one often finds a input and output redirection "<", ">", ">>". These are simple to understand.

Users can also do redirect one stream into another stream. This is done by using standard file descriptors. So, if someone wants to redirect all standard errors to whereever standard output is going, add 2>&1 in the end of the command. 2>&1 means send the standard errors to where standard output is going. 2 is the default file descriptor for stderr and 1 for stdout. If certain command is redirecting stdout to, say some file, stderr still goes to default screen. If you want stderr also to be sent to the file where stdout is going, use 2>&1.
Similarly, you can also redirect stdout to whereever stderr is going by 1>&2.

Also, remember that "some unix command > some_file 2>&1" is different from "some unix command 2>&1 > some_file". The first one redirects stderr to some_file, whereas the second won't.

Saturday, July 11, 2009

A tutorial on setuid and sticky bits in Unix

Unix users are sometimes confused with setuid and sticky bit permissions on files and directories. Below is a small tutorial on the most common use of setuid and sticky bits.

There are certain files or devices that are writable only by root. Nevertheless, ordinary users often have to use root-owned programs that try to write to those files. Since these files are writable only by root, how would a non-root user run the program that writes into that file. The solution in Unix is setuid bit. When this bit is set on a root-owned program, the program gets the effective privileges of root even when run by non-root user. This happens only for setuid programs i.e. for programs that have setuid bit set by owner/root. Example is passwd program that modifies the password files that are writable only by root. Since passwd program is setuid id, any non-root user can run this program and modify his/her password. Another example is ping program that is also setuid since ordinary users also run the ping program that accesses network devices.

In the file permission listing found by command “ls –l” setuid programs have the s in place of x. This means the program is both executable by owner and setuid. Another possibility is S in place of x which means the program is setuid but NOT executable. The program permissions could look like

rwsr-xr-x ( executable by root and setuid; what matters for setuid bit is the third letter)

OR

rwSr-xr-x ( hmmm…does it make sense !?)

One can make a program setuid by

chmod u+s prog_name

OR

chmod 4755 prog_name

Although the explanation above was specific to root-owned files, it could apply to any owner. So any user can make a program owned by himself/herself setuid and let others modify some of the owner’s files by this program.

Another related special permission setting for a program is setgid bit which is similar to above, but is useful only to the owner’s group. The setuid and setgid bits have different meanings when applied to directories. setgid bit on directory "d" means that any file or directory created under it would get the group id of "d". Remember that normally the group id of any newly created directory is the group id of the user who created it.

Yet another special permission is the sticky bit. Now-a-days, it is mainly used for directories. Let us first understand what directory permissions mean. Some directories are writable by all users. That means all users can create files as well as delete files inside such directories. Execute permission for a directory means search permission into that directory. So, execute permission is necessary to descend into that directory.

An example of directory with sticky bit set is /tmp. This directory stores temporary data that is created by user programs. Since these directories are writable by all, any user can delete any file! Even those files that are owned by others! To fix this state, such directories have sticky bit set. Now only the owners can delete any file in such directories.

Directories with sticky bit set have t letter in the execute permission set for others, as seen by the output of “ls –l”.

rwxrwxrwt ( sticky bit is set and execute permission for others)

OR

rwxrwxrwT ( sticky bit set but no execute permission for others)

Capital T means that others don’t have execute permission for that directory, so they can’t search into it.

update: Added setgid directory explanation.


Thursday, June 14, 2007

Linus likes ZFS, but

Online world is abuzz with discussions on the mail that Linus Torvalds sent to lkmk.org with some seemingly incendiary anti-Sun remarks, and a more cool-headed response by the Sun CEO Jonathan Schwartz. It has sent all the Paris Hilton front page stories down to page 5 to bite the dust. Some things this all seems to imply:

- OpenSolaris has surely begun to ruffle some feathers; even Linus says OpenSolaris' ZFS is something which could make Linux to change its license. That is something!

- The only thing most Linux developers including Linus think OpenSolaris needs Linux for are drivers. Does it imply that if a user can get a machine working with OpenSolaris, there'd be no need to install Linux?

- Linux users want ZFS. Linux developers have started to realize its importance as a Filesystem, but are diverting the issue with licensing and patent issues. Why not directly talk to Sun and implement the stuff? Surely. if FreeBSD and Mac OS X can implement it, so can Linux. It could be that it is harder to port it to Linux and the developers have become lazy.

- Somehow Linus seems to know that "Linux code is _better_". Does it mean he already has peeked into OpenSolaris code and compared it with the Linux before coming to conclusion? That is interesting, and as illuminating as his assertion.

I have a great respect for Linus as is evidenced by one of my earlier posts. But mails like this are uncharacteristic of him. I even feel that it could have been rebuked as FUD-spreading if it had come from someone other, say Microsoft. Hopefully, in the future, Linux and OpenSolaris will be living at peace and users will have choice of an OS not dictated by the license.

Tuesday, May 15, 2007

Microsoft threatens Linux with patents

According to a news article, Microsoft has alleged that Linux and other Open Source software violate its patents. This includes 42 by Linux kernel alone and many by OpenOffice, totalling 235 patents in all.

Looks like an open source arm-twisting effort by MS directly related to their deal with Novell last year.

More at :
CNN
CRN

Wednesday, January 3, 2007

Memory Overcommit and the OOM Killer

Linux has a feature called memory overcommit. Put simply, it means kernel allocates memory even if it doesn't have enough. This happens when a new process is created using fork(). This effectively copies the parent's address space, and so requires twice the parent process' memory once the new process (child) is created. The memory overcommit feature means that fork() always returns a success. Even if there is not enough memory to create a new child process!
The idea behind a memory overcommit feature of Linux is that the child process rarely uses all the memory allocated to it. fork() is followed by exec() which overlays the child address space with some exectutable. Once the exec() is done, the child process exits and the parent process (which goes into wait() after creation of child) resumes.
Failing to allocate enough memory when it is needed by the child results in another process being invoked. This process is called Out Of Memory (OOM) killer. The job of this process is to select a process to kill so that the memory requirements after fork() can be satisfied. Not a very desirable feature, but it is necessary to keep memory overcommit feature of Linux. This made OOM killer infamous. How to select a process to kill is tricky. It might happen that some important processes (e.g. a database) gets killed by OOM killer. Analogies like this show how serious the situation is when killer is invoked.
It seems that during 2.4, OOM killer's favourite process to kill was the Netscape browser. The browser would crash all of a sudden and you'd have no idea why.
The memory overcommit along with OOM is not an example of a good design feature, but has even made its way into AIX. With 2.6 the memory overcommit feature can be suppressed using some variables, but by default the feature is present.
Fortunately, it doesn't exist in Solaris. Solaris never used memory overcommit. First it was vfork() instead of fork() to prevent the failure of process creation. In Solaris 10, posix_spawn() is used instead of vfork() since vfork() is not MT-safe.

Thursday, December 14, 2006

Linus Torvalds on GPL kernel modules

It's no news that Linus is a very good software programmer. There are other aspects of his character that are admirable. On the Linux mailing list today he stressed on why it is not good on the part of developers or open source zealots to force people to use software only the way developers want.
Responding to a suggestion that a time limit be set ( 12 months was suggested) after which kernel won't be allowed to load non- GPL tagged module, he said users should be allowed to use software the way they want. He tries to make the difference between use and distribution clear.
Software developers can only force people to distribute software the way developers want. How they use it should be left to the individuals.
Linus says, "There's a big difference between "copy" and "use". It's exatcly the same issue whether it's music or code. You can't re-distribute other peoples music (becuase it's _their_ copyright), but they shouldn't put limits on how you personally _use_ it (because it's _your_ life)."
He further makes it clear that he hates the idea of forcing on people the GPL way,
"In other words, you guys know my stance. I'll not fight the combined opinion of other kernel developers, but I sure as hell won't be the first to merge this, and I sure as hell won't have _my_ tree be the one that causes this to happen.
So go get it merged in the Ubuntu, (Open)SuSE and RHEL and Fedora trees first. This is not something where we use my tree as a way to get it to other trees. This is something where the push had better come from the other direction.
Because I think it's stupid. So use somebody else than me to push your political agendas, please."
Well said!
List archived at:
http://lkml.org/lkml/2006/12/13/370

Monday, December 11, 2006

Microsoft Unix

It sounds funny now, but Microsoft once actually had the most widely installed Unix base. Its version of Unix was called Xenix and it was distributed in the 80's by many vendors. What happened to it since then? Well, Microsoft sold it to SCO and moved on to develop OS/2 with IBM and then Windows NT.

Wikipedia has some interesting tidbits of information for Xenix here.
How it looked like back in the 80's? Here is a screenshot from wikipedia.

System V release 4, the standard for Unix today was formed by merging SunOS, BSD, Xenix, and System V.

Of course, the legacy of Microsoft Xenix is still around. But where to look to see the history of Unix ? All the flavours of Unix are closed source, or are they? Thanks to open sourcing of Solaris, we can now take a look into all the real Unix code and find some gems of Copyrights that silently narrate the history of Unix development.

For example, to see how the development of Unix has passed on from the University of California at Berkeley to AT&T and Microsoft to Sun Microsystems, have a look at this tar code.

Such is the beauty of Unix. Decades older than any other present day OSs and still holding on its own in the modern world. Not only that, it manages to beat others often in their own game and still come out at other times with such innovations that are the envy of the youngsters. Even spawning dozens of clones which are cool in their own way. Ubuntu, anyone?

Me? I'm happy with my good ol' Unix. Solaris, that is. For me.

Sunday, December 10, 2006

MacOS X and Linux expert views , anyone

I must confess I haven't touched Linux for a long time now. The last time I seriously worked on it was RedHat 7.2 Linux which I used to learn MPI during my masters. I know it definitely has progressed a lot in the last few yrs. So, what are the new features added to the kernel or the distributions since then. I can't seem to remember any apart from some filesystems and lots of drivers.
Newer version of MacOS X will have X-Ray technology which is nothing but DTrace with a nice GUI on top.
If you know of some good features that are in Linux now, especially which are as revolutionary as the ones in Solaris ( see my last post) and are not available elsewhere, please leave a comment. I might try a new distro sometime soon.
Xen, I think would be a cool addition, but it is not unique for Linux. It will be very interesting to work with, though.

Best Operating System for geeks?

Most wannabe geeks would say Linux, though it is just a kernel and not an OS. Some would answer Ubuntu or Gentoo depending on which is the 'in thing'. A few people would perhaps say MacOS X is the best. Windows, of course, is not the one geeks want to be associated with.

One more OS is making waves in the academia and business world and with serious geeks for the last yr or so, after it was open sourced. For all the right reasons. That is the grand daddy of all, the most popular Unix - Solaris OS. No other operating system, not even Linux can claim to have as much geeky meat as Solaris. Some of the mouth watering stuff in Solaris 10, especially for geeks include:

Zones - software virtualization feature which has no match in any other OS. I can't remember which technology in any other OS comes even close. BSD jails, perhaps.

ZFS - the ultra modern file system, again with no match. The only thing that comes close is VxFS but ZFS is free with source code in the open.

DTrace - again no match anywhere. The capability to look into each and every place into the kernel and other parts in a running system using DTrace is unparalleled. It has been winning accolades all over. SystemTap for Linux is still not complete and its design makes it unlikely to be able to compete with DTrace in the future.

BrandZ - It gives you the capability to run Linux apps on top of Solaris. For example, you can run a version of Linux like CentOS right inside a Solaris Zone. Say you want to play Quake or use Google Earth which don't have Solaris apps; just create a Zone in Solaris, install your Linux in the zone and play away with the apps which are available in Linux. How more geeky can one get!

Of course, serious business won't play games. For them there are other more serious features like:
Fault Management Architecture (FMA), Service Management Framework(SMF), etc.

Linux is a good Operating System and has the advantage of having more drivers. But in almost everything else, Solaris scores higher. Now that it is open sourced it should get people interested in creating drivers. The community and codebase of Solaris is called OpenSolaris. Looking at the number of posts and projects there, it really looks like a dynamic and vibrant group of geeks.

Steps to install PyTorch on VMware workstation (Ubuntu guest)

  The following is the list of steps to install pytorch 2.0 in VMware workstation (Ubuntu guest): $ mkdir ~/pytorch $ mkdir ~/pytorch/as...