Linux File System:
The Linux file system architecture is an interesting example of abstracting complexity. Using a common set of API functions, a large variety of file systems can be supported on a large variety of storage devices. Take, for example, the read function call, which allows some number of bytes to be read from a given file descriptor. The read function is unaware of file system types, such as ext3 or NFS. It is also unaware of the particular storage medium upon which the file system is mounted, such as AT Attachment Packet Interface (ATAPI) disk, Serial-Attached SCSI (SAS) disk, or Serial Advanced Technology Attachment (SATA) disk. Yet, when the read function is called for an open file, the data is returned as expected. This article explores how this is done and investigates the major structures of the Linux file system layer.
Virtual file system layer:
The VFS acts as the root level of the file-system interface. The VFS keeps track of the currently-supported file systems, as well as those file systems that are currently mounted.
What is a block device?
A block device is one in which the data that moves to and from it occurs in blocks (such as disk sectors) and supports attributes such as buffering and random access behavior (is not required to read blocks sequentially, but can access any block at any time). Block devices include hard drives, CD-ROMs, and RAM disks. This is in contrast to character devices, which differ in that they do not have a physically-addressable media. Character devices include serial ports and tape devices, in which data is streamed character by character.
$su : Setting root user with existing environment
$su – : Setting root access for a single command
$sudo : Setting root access for a single command
$exit or ctrol+d -> Exit from Super User
Linux File formats
ELF stands for Executable and Linking Format. This format is used for object files on most UNIX platforms including Linux. There are basically three types of object files:
– A relocatable file holds code and data suitable to be linked with other object fields to create an executable or shared object file, or another relocatable object.
– An executable file holds a program that is ready to execute.
– A shared object file holds code and data suitable to be linked to other shared objects or relocatable files. (The object file format is shown in the figure below.)
Every file has an ELF header that resides at the beginning of the file and acts like a roadmap to the rest of the file. Sections represent the smallest unit that can be processed in a file and hold the bulk of the information required for linking. A section header table contains information about the sections in the file. A program header table, if present, tells how to create a process image, which is used if the object file is an executable. The exec program uses the program header table to fork a process. Note that the position of the ELF header is constant in the file, although other parts may appear at different places than shown in the figure.
The ELF header is used by the file program, (see Utility programs and tools later in this article) to print out information about the file. (The libelf library package provides a programming interface to access information in the ELF headers.)
How to write dynamically loadable libraries
Linker – ld (Static Linking and Dynamic Linking)
$gcc –o hello hello.c
$gcc –c hello.c
$ld –lc –o hello hello.c
Listing 1: Libprint.h Code; Header file
/* file libprint.h – for example use! */
void printstring(char* str);
Listing 2: libprint.c Code
/* file libprint.c */
void printstring(char* str)
printf(“String: %s\n”, str);
Listing 3: Code for _init() and _fini()
$ gcc -fPIC -c libprint.c (PIC – Position Independent Code)
$ ld -shared -soname libprint.so.1 -o libprint.so.1.0 -lc libprint.o
Installing and using shared libraries
Now that we’ve built our library, let’s install it and make a small client program that uses it. A special program called ldconfig is used for installing shared libraries.
– Generally, shared libraries are installed in either /usr/lib, lib or /usr/local/lib. ‘
– Once the library is made, it should be copied in one of these directories.
– Then we just run the ldconfig program.
$ldconfig -v -n .
libprint.so.1 => ./libprint.so.1.0
Now we’ve created a symbolic link named libprint.so.1 to libprint.so.1.0. The next step in installing is creating another link for the linker name, like this:
Link for the linker name
$ ln -sf libprint.so.1 libprint.so
Check the IP Address in Linux:
Linux OS Info:
uname -arv / uname -s
Check the current logged user name:
Change Password for the root user:
#sudo passwd root
$mv -f source-folder-or-file target-folder/-or-/filename
File size and disk utilization in Linux:
- $du ==> used to estimate file space usage—space used under a particular directory or files on a file system
- $du /folder_or_file_name <- For all directories
- $du -H /folder_or_file_name <- For directories and total
- $du -a /folder_or_file_name <- Size for for each file
- $df ==> display the amount of available disk space for filesystems on which the invoking user has appropriate read access
Setting Git in Mac:
- Install Git (from Git-scm.org site and by default the git will be installed at /usr/local/git location. there is no UI or application to show the progress)
- Setup path (Open /etc/paths and then add a new line as /usr/local/git/bin, use $sudo root vi /etc/paths )
- Once path is set git can run now, $git or $git help or $git config –list
- AVKASHs-MacBook-Pro:~ avkashchauhan$ git config –list
AVKASHs-MacBook-Pro:~ avkashchauhan$ git config –global user.name “Avkash Chauhan”
AVKASHs-MacBook-Pro:~ avkashchauhan$ git config –global user.email “my email address .com”
AVKASHs-MacBook-Pro:~ avkashchauhan$ git config –list
user.email=my email address .com
- AVKASHs-MacBook-Pro:~ avkashchauhan$ git config –list
- Now git is ready in your mac
VMWare Image Clone Problem: eth0 Renamed As eth1
How to Run Linux without the GUI (level 3) ?
- Open /etc/inittab file and you will see this line
- change the value 5 to 3 .when you will change it line will look like this