Linux File System Management

Source: Internet
Author: User
Tags add time disk usage

Linux File System Management

Course Outline

? File system composition and commands

? Partition and management of hard disk

? Disk quotas

? Backup and Recovery

File System composition

/usr/bin,/bin: Store the commands that all users can execute?

/usr/sbin,/sbin: Store only commands that can be executed by root?

/home: User Default host Directory

/proc: Virtual file system, storing current process information

/dev: Store device files

/lib: The shared library required to run the system program?

/lost+found: To store some system error check results

/tmp: Storing temporary files

/etc: System configuration file

/var: contains frequently changed files, such as mail, log files, scheduled tasks, etc.

/usr: Store all commands, libraries, manual pages, etc.

/boot: Kernel file and bootstrap file save location

/MNT: Installation point for temporary file system

Special permissions: Sticky bit t

The definition of a sticky bit: When a directory with a permission of 777 is granted

The user can only delete from this directory

Is the owner's file.

Common commands

? View partition usage: DF//Df-h Df-m

? View file, directory size: du//du-h/etc/services # DU-SH/ETC

? View file detail time parameters: Stat

? Checksum file MD5 value: md5sum

? Detect and Repair file systems: fsck, E2FSCK

(Single-user mode is performed after uninstalling the file system)

# e2fsck-p or # Fsck-y

Determine file type//# file/etc/services

Using the optical drive

Mount Optical Drive

# Mount/dev/cdrom/mnt/cdrom

Additional: # ls-l/dev/sda1 file Type B starts with a block device

# ls-l/dev/tty file Type C starts with a character device

#df//df-h View the Mount information for a disc

# Cd/mnt/cdrom

# Ls/mnt/cdrom

Uninstalling the optical drive

# Umount/mnt/cdrom

# Eject//If the Physical optical drive pops up

Add a hard disk partition

? Partitioning (FDISK)

? Create File System (MKFS)

? Try mounting (Mount)

? Write configuration file (/etc/fstab)

Additional:

# Dmesg:grep SDB//View the newly added second hard drive

# fdisk-l/DEV/SDB//view hard drive information

# m Help

Command (M for help) p//view partition table information

Command (M for help) n//Add new partition default file type Ext3

P Primary partition E extended partition

Command (M for help) t//change partition file type

L Show all file type codes

Command (M for help) d//delete partition

Command (M for help) w//Finally be sure to save the exit before it takes effect

Command (M for help) Q//Do not save exit

  1. Partitioning (FDISK)

    Add: Create File System (MKFS)//class is Windows formatted

    Mkfs Formatting Mkfs.ext3

    Mkfs-t ext3

    # MKFS.EXT3/DEV/SDB1//formatted partition

    -b//Specify data block size 1024 2048 4096

    Added: # mkdir/web

    # Mount/dev/sdb1/web//Mount partition/web empty directory

    # Df-h// Show file system disk usage

    Attach: After mounting, restart the computer and then re-mount, how to solve?

    # Vi/etc/fstab

    Physical Partition name/volume label mount point file system default check detection sequence

    label=//ext3 defaults 1/0 0/1/2

    /dev/sda1

    /dev/sdb1/web ext3 Defaults 1 2

    # E2LABEL/DEV/SDB1 Apache//Set the volume labeled Apache, without the label is the detection volume label, set the volume label, edit/etc/fstab can write Lavel=apache

    /etc/fstab Mount Settings

    ? RO Read Only

    ? noexec executable file is not operational

    ? Nosuid setuid Command not enforceable

    ? Noauto not automatically mounted

    ? ACL start ACL permission control

    Commands: Getfacl view, SETFACL settings

    Swapfile implementation

    1. # Mkdir/var/swap

    # chmod 700/var/swap

  2. # dd If=/dev/zero of=/var/swap/file.swp bs=1024 count=65536//create 64M size files

    Add # dd IF=/DEV/SDA of=/dev/sdb//SDA Copy to SDB

    # Find/-name ABC > Abc.find 2>/dev/null//Find ABC file results input into the Abc.find file, the error is not read

    # du-h/VAR/SWAP/FILE.SWP

    3. # MKSWAP/VAR/SWAP/FILE.SWP//Use the file you just created as a swap space

    4. # Vi/etc/fstab

    /VAR/SWAP/FILE.SWP swap swap defaults 0 0//edit on Start swap

    5. Free//# FREE-M

    6. SWAPON/VAR/SWAP/FILE.SWP//enable this space to close the command Swapoff

    7. Free

    Disk quotas

    1. Enable Partition quota function

    Edit the/etc/fstab file to add a flag on the Mount attribute

    Usrquota user quotas or Grpquota user group quotas

    /dev/sda3/home ext3 Defaults,usrquota 1 2

    Mount-o Remount/home

    Temporary settings: Mount-o remount,usrquota/home

    2. Set up quota database (enter single user mode)

    Quotacheck-cvuga

    Generates Aquota.user, aquota.group two files

    3. Start Quota function

    Quotaon Partition name Quotaon/home

    Quotaoff Closing Quotas Quotaon/home

    4. Edit User Quotas

    Edquota User Name

    Edquota-g User Group Name

    Edquota-t Setting the grace period

    Copy user Quotas

    Edquota-p template User Replication User 1 replication User 2

    Quota command to view user quota usage

    Administrator View quota information: repquota-a

    Options for creating quotas

    ? Soft limits (Soft limit): Defines the amount of magnetism that a user can occupy

    Number of disk spaces. When a user exceeds the limit, a warning is received that exceeds the quota.

    ? Hard limit: When a user tries to store a file

    A file system error is reported when it has exceeded the limit value directory.

    ? Grace period: Defines the period in which users can use their file systems under soft limits.

    Potential threats to the system

    ? System hardware Failure

    ? Software failure

    ? Power failure

    ? User's error operation

    ? Human destruction

    ? Content in the cache is not written to disk in a timely manner

    ? Natural disasters

    Selection of Backup media

    ? Backup media

    ? Hard disk

    ? Disc

    ? Tape

    Removable Storage devices

    ? Typically, when selecting backup media, trade-offs from reliability, speed, and media prices

    Backup policy

    ? Full backup

    Make a full backup of the system at every time,

    This allows the system to fail during the backup interval

    When data is lost, the last number of backups can be used

    Back to the last backup.

    ? Incremental backup

    Make a full backup first, and then each short

    Time, but just back up each short

    Changes in the time period.

    Classification of backups

    ? System backup

    ? Implementing backups of operating systems and applications

    ? Try to restore the system's operation quickly and easily after the system crashes

    ? Main backup/etc,/boot,/var/log,/usr/local, etc.

    ? Generally only occurs when the system content changes

    ? User Backup

    ? Implementing a backup of the user's files/home

    ? Frequent changes in user data

    ? The incremental backup strategy is often used

    Record changes to establish a backup log

    ? Recording system changes

    ? Record a detailed description of what changes were made to the system and why it was modified

    ? Create a BACKUP Log

    ? Use the BACKUP Log table

    ? Proper safekeeping

    Example of a BACKUP log table

    ? Machine name, IP address, storage location

    ? Backup time

    ? Backup media and its number

    ? Backed-up file system

    ? Backed-up directories and files

    ? Backup commands to use

    ? Backup personnel and other

    Example of CP command backup

    Backup directory:

    CP-RPU Backup Directory Destination Directory

    -P Keep backup directory and file attributes

    -U Incremental Backup

    Remote Backup available SCP

    Added: # cp-p/etc/inittab/backup/inittab_20110325.bak

    Example of using the TAR command

    # Tar-zcf/backup/sys_20110303.tar.gz/etc/boot

    Backup/etc directory, can package multiple directories at the same time

    # TAR-ZCF BACKUP_USER_20110303.TAR.GZ/ETC/PASSWD

    /etc/shadow/etc/group/etc/gshadow

    Backup of specified files in/etc directory

    # TAR-ZTF Backup_user_20110303.tar.gz

    To view a file in a backup package (no package)

    # tar-zxf/backup/etc_20110303.tar.gz

    Restore/etc directory, default restore to the packaged file source directory,

    -C To specify the restore directory

    # TAR-ZXF backup_user_20110303.tar.gz Etc/group

    Restore only the specified files in the backup

    # TAR-RF Backup_user_20110303.tar

    /etc/default/useradd/etc/login.defs

    Append the contents of/etc/default/useradd,/etc/login.defs to Backup_user_20110303.tar

    # Tar-uf BACKUP_USER_20110303.TAR/ETC/PASSWD

    Append the modified content in the/ETC/PASSWD directory to the backup file

    *-R and-u options can only be used for tar packages

    Example of a tar command backup

    Add time to the backup file name (Month day)

    # tar-zcf/backup/etc_$ (Date +%f). tar.gz/etc

    Add Month day hour minute

    # tar-zcf/backup/etc_$ (Date +%y.%m.%d-%h%m). tar.gz/etc

    Summary of Knowledge points

    ? Linux File System composition

    ? File System Administration Commands

    ? Sticky bit permissions

    ? How to add a new hard disk

    ? /etc/fstab configuration File Settings

    ? Swapfile function settings

    ? Disk quota Settings

    ? Backup concept and CP, tar command backup application

    Practice

    ? Adhesive position Test

    ? ACL permission settings

    ? To add a new hard drive partition

    ? Increase swap space with swapfile function

    ? Set User disk quotas

    ? Backup system data combined with scheduled Tasks application

    ? File System Operations Command

Linux File System Management

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.