Linux filesystem
structures and understand the meaning of individual high-level directories.


1. / – Root
§ Every single file and directory starts from
the root directory.
§ Only root user has write privilege under this
directory.
§ Please note that /root is root user’s home
directory, which is not same as /.
2. /bin – User
Binaries
§ Contains binary executables.
§ Common linux commands you need to use in
single-user modes are located under this directory.
§ Commands used by all the users of the system
are located here.
§ For example: ps, ls, ping, grep, cp.
3. /sbin – System
Binaries
§ Just like /bin, /sbin also contains binary
executables.
§ But, the linux commands located under this
directory are used typically by system aministrator, for system maintenance
purpose.
§ For example: iptables, reboot, fdisk,
ifconfig, swapon
4. /etc –
Configuration Files
§ Contains configuration files required by all
programs.
§ This also contains startup and shutdown shell
scripts used to start/stop individual programs.
§ For example: /etc/resolv.conf,
/etc/logrotate.conf
5. /dev – Device Files
§ Contains device files.
§ These include terminal devices, usb, or any
device attached to the system.
§ For example: /dev/tty1, /dev/usbmon0
6. /proc – Process
Information
§ Contains information about system process.
§ This is a pseudo filesystem contains
information about running process. For example: /proc/{pid} directory contains
information about the process with that particular pid.
§ This is a virtual filesystem with text
information about system resources. For example: /proc/uptime
7. /var – Variable
Files
§ var stands for variable files.
§ Content of the files that are expected to grow
can be found under this directory.
§ This includes — system log files (/var/log);
packages and database files (/var/lib); emails (/var/mail); print queues
(/var/spool); lock files (/var/lock); temp files needed across reboots
(/var/tmp);
8. /tmp – Temporary
Files
§ Directory that contains temporary files
created by system and users.
§ Files under this directory are deleted when
system is rebooted.
9. /usr – User
Programs
§ Contains binaries, libraries, documentation,
and source-code for second level programs.
§ /usr/bin contains binary files for user
programs. If you can’t find a user binary under /bin, look under /usr/bin. For
example: at, awk, cc, less, scp
§ /usr/sbin contains binary files for system
administrators. If you can’t find a system binary under /sbin, look under
/usr/sbin. For example: atd, cron, sshd, useradd, userdel
§ /usr/lib contains libraries for /usr/bin and
/usr/sbin
§ /usr/local contains users programs that you
install from source. For example, when you install apache from source, it goes
under /usr/local/apache2
10. /home – Home
Directories
§ Home directories for all users to store their
personal files.
§ For example: /home/john, /home/nikita
11. /boot – Boot
Loader Files
§ Contains boot loader related files.
§ Kernel initrd, vmlinux, grub files are located
under /boot
§ For example: initrd.img-2.6.32-24-generic,
vmlinuz-2.6.32-24-generic
12. /lib – System
Libraries
§ Contains library files that supports the
binaries located under /bin and /sbin
§ Library filenames are either ld* or lib*.so.*
§ For example: ld-2.11.1.so, libncurses.so.5.7
13. /opt – Optional
add-on Applications
§ opt stands for optional.
§ Contains add-on applications from individual
vendors.
§ add-on applications should be installed under
either /opt/ or /opt/ sub-directory.
14. /mnt – Mount
Directory
§ Temporary mount directory where sysadmins can
mount filesystems.
15. /media – Removable
Media Devices
§ Temporary mount directory for removable
devices.
§ For examples, /media/cdrom for CD-ROM;
/media/floppy for floppy drives; /media/cdrecorder for CD writer
16. /srv – Service
Data
§ srv stands for service.
§ Contains server specific services related
data.
§ For example, /srv/cvs contains CVS related
data.
Linux
supports numerous file system types
§ Ext2: It has the concepts of
blocks, inodes and directories.
§ Ext3: It is ext2 filesystem
enhanced with journalling capabilities. Journalling allows fast file system
recovery.
§ Isofs (iso9660): Used by
CDROM file system.
§ Sysfs: It is a ram-based
filesystem initially based on ramfs. It is use to exporting kernel objects so
that end user can use it easily.
§ Procfs: The proc file system
acts as an interface to internal data structures in the kernel. It can be used
to obtain information about the system and to change certain kernel parameters
at runtime using sysctl command.
ext2, ext3 and ext4 are all
filesystems created for Linux. This article explains the following:
§ High level difference between
these filesystems.
§ How to create these
filesystems.
§ How to convert from one
filesystem type to another.
Ext2
§ Ext2 stands for second
extended file system.
§ It was introduced in 1993.
Developed by Rémy Card.
§ This was developed to
overcome the limitation of the original ext file system.
§ Ext2 does not have journaling
feature.
§ On flash drives, usb drives,
ext2 is recommended, as it doesn’t need to do the over head of journaling.
§ Maximum individual file size can
be from 16 GB to 2 TB
§ Overall ext2 file system size
can be from 2 TB to 32 TB
Ext3
§ Ext3 stands for third
extended file system.
§ It was introduced in 2001.
Developed by Stephen Tweedie.
§ Starting from Linux Kernel
2.4.15 ext3 was available.
§ The main benefit of ext3 is
that it allows journaling.
§ Journaling has a dedicated
area in the file system, where all the changes are tracked. When the system
crashes, the possibility of file system corruption is less because of
journaling.
§ Maximum individual file size
can be from 16 GB to 2 TB
§ Overall ext3 file system size
can be from 2 TB to 32 TB
§ There are three types of
journaling available in ext3 file system.
§ Journal – Metadata and
content are saved in the journal.
§ Ordered – Only metadata is
saved in the journal. Metadata are journaled only after writing the content to
disk. This is the default.
§ Writeback – Only metadata is
saved in the journal. Metadata might be journaled either before or after the
content is written to the disk.
§ You can convert a ext2 file
system to ext3 file system directly (without backup/restore).
Ext4
§ Ext4 stands for fourth
extended file system.
§ It was introduced in 2008.
§ Starting from Linux Kernel
2.6.19 ext4 was available.
§ Supports huge individual file
size and overall file system size.
§ Maximum individual file size
can be from 16 GB to 16 TB
§ Overall maximum ext4 file
system size is 1 EB (exabyte). 1 EB = 1024 PB (petabyte). 1 PB = 1024 TB
(terabyte).
§ Directory can contain a
maximum of 64,000 subdirectories (as opposed to 32,000 in ext3)
§ You can also mount an
existing ext3 fs as ext4 fs (without having to upgrade it).
§ Several other new features
are introduced in ext4: multiblock allocation, delayed allocation, journal
checksum. fast fsck, etc. All you need to know is that these new features have
improved the performance and reliability of the filesystem when compared to
ext3.
§ In ext4, you also have the
option of turning the journaling feature “off”.
#######################################################
/etc/shadow file stores actual password in encrypted
format for user's account with additional properties related to user password
i.e. it stores secure user account information. All fields are separated by a
colon (:) symbol. It contains one entry per line for each user listed in /etc/passwd file Generally, shadow file entry looks as
follows (click to enlarge image):
/etc/shadow file fields
(Fig.01: /etc/shadow file fields)
1.
User name : It is your
login name
2.
Password: It your
encrypted password. The password should be minimum 6-8 characters long
including special characters/digits
3.
Last password change
(lastchanged): Days since Jan 1, 1970 that password was last changed
4.
Minimum: The minimum
number of days required between password changes i.e. the number of days left
before the user is allowed to change his/her password
5.
Maximum: The maximum
number of days the password is valid (after that user is forced to change
his/her password)
6.
Warn : The number of
days before password is to expire that user is warned that his/her password
must be changed
7.
Inactive : The number of
days after password expires that account is disabled
8.
Expire : days since Jan
1, 1970 that account is disabled i.e. an absolute date specifying when the
login may no longer be used
The last 6 fields
provides password aging and account lockout features (you need to use chage
command to setup password aging). According to man page of shadow - the
password field must be filled. The encrypted password consists of 13 to 24
characters from the 64 character alphabet a through z, A through Z, 0 through
9, \. and /. Optionally it can start with a "$" character. This means
the encrypted password was generated using another (not DES) algorithm. For
example if it starts with "$1$" it means the MD5-based algorithm was
used
A. /etc/passwd file stores essential information,
which is required during login i.e. user account information.
/etc/passwd is a text
file, that contains a list of the system's accounts, giving for each account
some useful information like user ID, group ID, home directory, shell, etc. It
should have general read permission as many utilities, like ls use it to map
user IDs to user names, but write access only for the superuser (root).
Understanding fields in /etc/passwd
The /etc/passwd contains
one entry per line for each user (or user account) of the system. All fields
are separated by a colon (:) symbol. Total seven fields as follows.
Generally, passwd file
entry looks as follows (click to enlarge image):
1.
Username: It is used when user logs in. It should be
between 1 and 32 characters in length.
2.
Password: An x character indicates that encrypted
password is stored in /etc/shadow file.
3.
User
ID (UID): Each user must be
assigned a user ID (UID). UID 0 (zero) is reserved for root and UIDs 1-99 are
reserved for other predefined accounts. Further UID 100-999 are reserved by
system for administrative and system accounts/groups.
4.
Group
ID (GID): The primary group ID
(stored in /etc/group file)
5.
User
ID Info: The comment field. It
allow you to add extra information about the users such as user's full name,
phone number etc. This field use by finger command.
6.
Home
directory: The absolute path to
the directory the user will be in when they log in. If this directory does not
exists then users directory becomes /
7.
Command/shell: The absolute path of a command or shell
(/bin/bash). Typically, this is a shell. Please note that it does not have to
be a shell.
No comments:
Post a Comment