Linux-swap and all file types in linux

ยท

6 min read

To create swap

  1. What is SWAP? >> Particular space available on disc which can be used as RAM for emergency cases.

  2. Two types. 1) File SWAP 2) DISC/Partition SWAP

  3. free -h >> To show RAM memory.

  4. fallocate -l 2G /swap >> To create 2Gb file size SWAP memory.

  5. Ideal size of SWAP on server >>Recommended that > at max size should not be exceeded 64 or 128 GB of SWAP.

  6. mkswap /swap >> To create a swap memory with file name /swap.

  7. chmod 600 /swap >> Default permission for the file should be 600.

  8. swapon /swap >> To check swap allocation.

  9. blkid >> to check block>>

  10. To mount swap permanently >>

  11. vim /etc/fstab and make entry >> /swap swap swap defaults 0 0

  12. fallocate -l 2G /tmp/demo >>> after fstab entry need to execute this command.

  13. free -m >> see free memory >>

  14. To create partition swap >>

  15. Remove first SWAP >> go to vim /etc/fstab > remove swap line>>

  16. swapoff /swap

  17. rm -rf /swap

  18. Need to add one HDD from AWS then need to attach volume>>

  19. mkswap /dev/xvdf >> to make the partition as a SWAP.

  20. swapon /dev/xvdf >>

  21. make fstab entry for permanent swap memory.

Total 7 types of files we do have in linux.

If you use "ll" command for long list the details of permissions will be shown.

$ ll
total 12
drwxr-xr-x 2 user user 4096 Oct 18 10:00 my_directory/  ๐Ÿ“‚
-rw-r--r-- 1 user user   24 Oct 18 09:45 my_file.txt     ๐Ÿ“„
lrwxrwxrwx 1 user user   16 Oct 18 09:53 my_link -> /path/to/target  ๐Ÿ”—
crw------- 1 user user 4, 1 Oct 18 00:00 /dev/keyboard  ๐Ÿ”Œ
brw------- 1 user user 8, 0 Oct 18 00:01 /dev/sda     ๐Ÿ’พ
prw-r--r-- 1 user user    0 Oct 18 10:10 my_pipe  ๐ŸŒ
srwxr-xr-x 1 user user    0 Oct 18 10:20 my_socket  ๐Ÿงฆ

Now, let's provide some additional details about each file type:

  1. my_directory/ (๐Ÿ“‚): This is a directory indicated by the 'd' at the beginning of its permissions. It contains other files and directories.

  2. my_file.txt (๐Ÿ“„): This is a regular file marked with a '-' in the permissions column. It holds 24 bytes of data.

  3. my_link (๐Ÿ”—): This is a symbolic link represented by an 'l' at the beginning of its permissions. It points to another file or directory located at /path/to/target.

  4. /dev/keyboard (๐Ÿ”Œ): This is a character device file indicated by 'c' in the file type column. It represents a character-based device such as a keyboard.

  5. /dev/sda (๐Ÿ’พ): This is a block device file marked with 'b' in the file type column. It represents a block-based storage device, like a hard drive, typically identified by major and minor numbers.

  6. my_pipe (๐ŸŒ): This is a pipe file used for inter-process communication, often referred to as a FIFO. It has permissions like a regular file, and data can be passed between processes using it.

  7. my_socket (๐Ÿงฆ): This is a socket file, often used for network communication. It's indicated by 's' in the file type column and plays a crucial role in networking and inter-process communication.

These symbols and file types are vital in understanding the role and characteristics of different files in Linux. Whether you're managing your file system or troubleshooting issues, knowing how to interpret these symbols and permissions is key to working effectively in the Linux environment. ๐Ÿง๐Ÿ› 

Some more details

  1. cd /etc > editable text configuration >> Whenever we want to configure our system 95% of configuration files are in /etc. If we install software with binary and we mention path for configuration files then only path gets changed but for bydefaults configuration files for all is in /etc.

  2. cd /home The / is the base of our OS. By default>> The user's home directory is in /home.

  3. Default permission for home directory is only user has read, write and execute permissions. Others has no permission.

  4. cd /lib >> Every command does not execute individually. There are so many modules behind every command. Those modules found under /lib directory. These are different libraries >> these are binary files we can not read it. Cd lib/lib64 >> All library files for 64 bit are kept inside this directory.

  5. cd /media >> Either we can work with CLI or UI. If we insert pen drive/HDD ? CD-ROM >> there will be pop-up comes on window. These media (Pen drive,/HDD/CD-ROM is by defaults gets mounted on /media with some xyz name.

  6. Cd /mnt >> mnt is a temporary mount point our device. This is not a permanent mount mount.

  7. Cd /opt >> All the applications which are running on linux OS use this for data >>

  8. ls -R opt/ >> To show all folders in /opt

  9. Cd /proc >> cat cpuinfo >> /proc is a virtual file system. Everything related to the OS it will show. Inside proc the random numbers are process IDโ€™s. cd 4670 >> cd fd >. FD >> file descriptor >> Show all information about โ€ฆ cd fdinfo >> It has โ€ฆ.. >> . cd /proc/meminfo >> all memory information. In cat /etc/fstab file >> defaults means it is mentioned in cat /proc/mounts file.

  10. Cd run >> Run time information will be stored by run. Instead of lsblk we can run location of the file related to that command>. Result will be same.

  11. blkid command will show the portions which are formatted with file system. Formatted means creating file system.

  12. In ext4 file system we can create 64000 subdirectories.

  13. Cd /sbin >>. Commands which are in sbin are only executed by the root user, normal user can not execute it. All the system binaries which are used by root are kept in /sbin.

  14. If we echo $? And reply is one it means last run command is successfully run.

  15. /srv >> empty folder >> We can store application data inside it like /opt.

  16. / sys>> All the system critical data runtime is stored this. All the kerel modules are here. How the kernel behave is stored in /sys/kernel. Cd /sys/kernel/cgroup>. Control group >> kernel namespace is for isolating every singal process and it not allow to mix the process. It keeps them different. Cgroup is used to assign resource of any process. Namespaces assure that these all resources will not get utilized by both process.

  17. /tmp >> This is the only dir with full permission. >> tmp is a world writable directory. t >> at last of the permission line is stick bit. It means only owner or root user can delete the data inside this dir /tmp.

  18. /usr>.

  19. /var >. Variable data >. It has all variable data on the system stored here. Every sort of logs is stored here. yum makecache >> cache will be created inside the /var. Cd /var/log >> All log files are here.

ย