cd .. on root folder

According to the Open Group (responsible for the POSIX standard):

Each directory has exactly one parent directory which is represented by the name dot-dot in the first directory. [...] What the filename dot-dot refers to relative to the root directory is implementation-defined. In Version 7 it refers to the root directory itself; this is the behavior mentioned in POSIX.1-2008. In some networked systems the construction /../hostname/ is used to refer to the root directory of another host, and POSIX.1 permits this behavior.

A.4.13 Pathname Resolution

The dot-dot entry in the root directory is interpreted to mean the root directory itself. Thus, dot-dot cannot be used to access files outside the subtree rooted at the root directory.

chroot - change root directory


You don't get an error because even the / directory actually has a valid directory entry for .., but unlike with other directories it points to the directory itself and thus behaves identical to .:

$ ls -lid / /. /..
128 drwxr-xr-x 22 root root 4096 Apr 15 11:26 /
128 drwxr-xr-x 22 root root 4096 Apr 15 11:26 /.
128 drwxr-xr-x 22 root root 4096 Apr 15 11:26 /..
$

As the first column tells you, ., .., and / all have the same inode-number and thus are the same filesystem entries.

So even if you cd .. inside of / you just stay in /.


It's there because removing it would require creating special-case handling code in the kernel and the C libraries. Right now you can assume that there will always be a . and .. in any directory you go to.

The only special-case code required right now is in filesystem mounting code, where the code overrides the inode value of .. to point to the directory containing the mount point, since root directories aren't always root directories.