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

Linux File System Management Tools - mkfs, mkfs.ext2, mkfs.ext3 commands

The Linux mkfs command can be used to format a Linux partition. The Linux "mkfs" command allows you to format a partition to a number of different filesystems. The Linux "mkfs" command also serves as a "front end," depending on the filesystem format. 

if you're formatting a standard ext3 filesystem, mkfs automatically calls the mkfs.ext3 command. The following commands show how create a partition using "fdisk" command and how to format the new partion using "mkfs" command.

[root@localhost ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.
The number of cylinders for this disk is set to 1044.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1044, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-1044, default 1044):
Using default value 1044
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
The above set of fdisk commands create /dev/sdb1 partition. After creating the partition, we can overlay a filesystem (format) using mkfs command as shown below.
[root@localhost ~]# mkfs -t ext3 /dev/sdb1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
1048576 inodes, 2096474 blocks
104823 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2147483648
64 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 20 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
Other Linux tools to create filesystems

• mkfs.ext2 command can be used to format a partition with ext2 filesystem.

• mkfs.ext3 command can be used to format a partition with ext3 filesystem.

• mkfs.msdos (or mkfs.vfat or mkdosfs) formats a partition to the Microsoft-compatible VFAT filesystem (The inode numbers for all three files are the same; that means they are three different names for the same command).

• mkswap command can be used to format a partition with Linux swap filesystem.

Standard Linux Filesystem Formats


Filesystem Type

Description
ext
The first Linux filesystem used on early versions.
ext2
The most featureful of the native Linux filesystems, but with no journaling support.
ext3
The ext3 filesystem has all the features of the ext2 filesystem with journaling has been added.
swap
The Linux swap filesystem is associated with dedicated swap partitions.
reiserfs
A stable journaled filesystem.
Jfs
JFS is a journaled filesystem designed by IBM to to work in high performance environments
vfat
VFAT lets you read Windows 9x/NT/2000/XP/Vista partitions formatted to the FAT16 or FAT32 filesystems.
iso9660
The standard filesystem for CD-ROMs
ntfs
The Microsoft Windows NT/2000/XP/2003/2008 filesystem designed for username/password security.
/proc
A Linux virtual filesystem. Virtual means that it doesn't occupy real disk space. Instead, files are created as needed. Used to provide information on kernel configuration and device status.
/dev/pts
The Linux implementation of the Open Group's Unix98 PTY support.
nfs
The Network File System, the system most commonly used to share files and printers between Linux and Unix computers.
cifs
The Common Internet File System (CIFS) is used to to share files and printers with Microsoft Windows operating systems.

Linux File Structure | Linux File System

In the Linux file structure files are grouped according to purpose. Ex: commands, data files, documentation. Parts of a Unix directory tree are listed below. All directories are grouped under the root entry "/". That part of the directory tree is left out of the below diagram. See the FSSTND standard (Filesystem standard).
  • root - The home directory for the root user
  • home - Contains the user's home directories along with directories for services
    • ftp
    • HTTP
    • samba
    • george
  • bin - Commands needed during bootup that might be needed by normal users
  • sbin - Like bin but commands are not intended for normal users. Commands run by LINUX.
  • proc - This filesystem is not on a disk. It is a virtual filesystem that exists in the kernels imagination which is memory.
    • 1 - A directory with info about process number 1. Each process has a directory below proc.
  • usr - Contains all commands, libraries, man pages, games and static files for normal operation.
    • bin - Almost all user commands. some commands are in /bin or /usr/local/bin.
    • sbin - System admin commands not needed on the root filesystem. e.g., most server programs.
    • include - Header files for the C programming language. Should be below /user/lib for consistency.
    • lib - Unchanging data files for programs and subsystems
    • local - The place for locally installed software and other files.
    • man - Manual pages
    • info - Info documents
    • doc - Documentation
    • tmp
    • X11R6 - The X windows system files. There is a directory similar to usr below this directory.
    • X386 - Like X11R6 but for X11 release 5
  • boot - Files used by the bootstrap loader, LILO. Kernel images are often kept here.
  • lib - Shared libraries needed by the programs on the root filesystem
    • modules - Loadable kernel modules, especially those needed to boot the system after disasters.
  • dev - Device files
  • etc - Configuration files specific to the machine.
    • skel - When a home directory is created it is initialized with files from this directory
    • sysconfig - Files that configure the linux system for devices.
  • var - Contains files that change for mail, news, printers log files, man pages, temp files
    • file
    • lib - Files that change while the system is running normally
    • local - Variable data for programs installed in /usr/local.
    • lock - Lock files. Used by a program to indicate it is using a particular device or file
    • log - Log files from programs such as login and syslog which logs all logins and logouts.
    • run - Files that contain information about the system that is valid until the system is next booted
    • spool - Directories for mail, printer spools, news and other spooled work.
    • tmp - Temporary files that are large or need to exist for longer than they should in /tmp.
    • catman - A cache for man pages that are formatted on demand
  • mnt - Mount points for temporary mounts by the system administrator.
  • tmp - Temporary files. Programs running after bootup should use /var/tmp.

Linux Filesystem Management | Linux Filesystem Overview

badblocks
Used to search a disk or partition for badblocks.
cfdisk
Similar to fdisk but with a nicer interface.
debugfs
Allows direct access to filesystems data structure.
df
Shows the disk free space on one or more filesystems.
dosfsck
Check and repair MS-Dos filesystems.
du
Shows how much disk space a directory and all its files contain.
dump
Used to back up an ext2 filesystem. Complement is restore.
dumpe2fs
Dump filesystem superblock and blocks group information. Ex: dumpe2fs /dev/hda2
e2fsck
Check a Linux second extended filesystem.
e2label
Change the label on an ext2 filesystem.
exportfs
Used to set up filesystems to export for nfs (network file sharing).
fdisk
Used to fix or create partitions on a hard drive.
fdformat
Formats a floppy disk.
fsck
Used to add new blocks to a filesystem. Must not be run on a mounted file system.
hdparm
Get/set hard disk geometry parameters, cylinders, heads, sectors.
mkfs
Initializes a Linux filesystem. This is a front end that runs a separate program depending on the filesystem's type.
mke2fs
Create a Linux second extended filesystem.
mkswap
Sets up a Linux swap area on a device or file.
mount
Used to mount a filesystem. Complement is umount.
rdev
Query/set image root device, swap device, RAM disk size of video mode. What this does is code the device containing the root filesystem into the kernel image specified.
rdump
Same as dump.
rmt
Remote magtape protocol module.
restore
Used to restore an ext2 filesystem.
setfdprm
Set floppy drive parameters.
swapoff(8)
Used to de-activate a swap partition.
swapon(8)
Used to activate a swap partition.
sync
Forces all unwritten blocks in the buffer cache to be written to disk.
tune2fs
Adjust tunable filesystem parameters on second extended filesystems.
umount
Unmounts a filesystem. Complement is mount.

Linux Directory Structure (File System Structure) Explained with Examples

Have you wondered why certain programs are located under /bin, or /sbin, or /usr/bin, or /usr/sbin?
For example, less command is located under /usr/bin directory. Why not /bin, or /sbin, or /usr/sbin? What is the different between all these directories?
In this article, let us review the 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.