8.29_linux Disk Management (II)

Source: Internet
Author: User
Tags uuid

Mount points and/etc/fstab

/etc/fstab Configuration file System architecture

Used by Mount, FSCK, and other programs

Writes the mount path to the configuration file, preserving the filesystem system when the system restarts

You can use the file System volume label on the device bar

Use the Mount-a command to mount all file systems in the/etc/fstab


File Mount configuration file


/etc/fstab each row defines a file system to mount;

Device or pseudo file system to be mounted

Mount point

File system type

Mount Options

Dump frequency

Self-Test order


Device or pseudo file system to mount: (Comparison of the recommended UUID)

Device file, LABEL (label= "), UUID (uuid=" "), pseudo file system name (proc, SYSFS)


Mount option: Defaults


Dump frequency: 0: Do not make backup

1: Daily dumps

2: Dump every other day


Self-Test sequence: 0: no self-test

1: Boot first self-test; usually only Rootfs 1

2: Secondary self-test, different devices can use the same self-test order

3: After 2 in turn

Attention:

If the Mount option is unsuccessful, it will not be able to be opened and can only be repaired in front of the computer, as far as possible, do not use self-test


Example:/etc/fstab file description

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/86/93/wKiom1fEL36gf479AADDoRc9O7s033.png "title=" 35.png "alt=" Wkiom1fel36gf479aaddorc9o7s033.png "/>


Processing swap files Swap and partitioning


Swap partition swap is a complement to system RAM that replaces RAM with swap partitions when system RAM is low

Basic settings include:

Create a swap partition or file

Write a special signature using Mkswap

Add the appropriate entry in the/etc/fstab file

Activating swap space with swapon-a

Tip: Swap partitions as close as possible to the disk's 0 tracks as the outermost disk is faster


Mount Swap Partition


Enabled: Swapon

Swapon [OPTION] ... [DEVICE]

-A: Activates all swap partitions;

-P Priority: Specify precedence

/etc/fstab:pri=value

Disabled: Swapoff [OPTION] ... [DEVICE]


Priority of Swap


You can specify the priority of the swap partition 0 to 32767, the higher the value the higher the priority

If the user does not specify, then the core will automatically assign a priority to the swap, which starts at 1, and each addition to a new swap with no user-specified priority will give the priority one reduction.

The default priority for the swap that is added first is higher, unless the user specifies a priority, and the user-specified priority (a positive number) is always higher than the priority specified by the core default (negative).

Optimized performance: Distributed storage, high-performance disk storage


Example: Create a swap partition and increase the priority level

1. First create a swap partition with a system ID of 82

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/86/93/wKioL1fEMuTi4uuJAABHfcd4L5o654.png "title=" 36.png "alt=" Wkiol1femuti4uujaabhfcd4l5o654.png "/>

2. Create a partition as a swap partition

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/86/93/wKiom1fEOAHCDJZEAAAZi0qVlGw707.png "title=" 39.png "alt=" Wkiom1feoahcdjzeaaazi0qvlgw707.png "/>

3. Write/etc/fstab

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/86/93/wKioL1fEOD6DQjfPAACS1ldgKko717.png "style=" float: none; "title=" 37.png "alt=" Wkiol1feod6dqjfpaacs1ldgkko717.png "/>

4. Mount the swap partition and set the priority

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/86/93/wKiom1fEOD-BVMCfAABDxjmB4ic519.png "style=" float: none; "title=" 38.png "alt=" Wkiom1feod-bvmcfaabdxjmb4ic519.png "/>



Moving Media mounts

Mounting means making a foreign file system look like part of the home directory tree

Media must be mounted before access

When removed, the media must be unloaded

By default, non-root users can mount only certain devices (optical discs, DVDs, floppy disks, USB, and so on)

Mount points are usually under/media or/mnt


CD mount

Automatically start Mount/run/media/<user>/<label> in a graphical environment

Otherwise, it must be manually mounted.

mount/dev/cdrom/mnt/

Eject command to unmount or eject a disk

Eject-t turn off the optical drive (this depends on the optical drive support not supported)

Create an ISO file

Cp/dev/cdrom/root/centos7.iso

Mkisofs-r-o/root/etc.iso/etc

Burning discs

Wodim–v–eject Centos.iso


Mounting USB Media

Detected by the kernel as a SCSI device

/dev/sdax,/dev/sdbx, or similar device files

Automatically mounts in a graphical environment

Icon created in the [Computer] window

Mount in/run/media/<user>/<label>

Manual mount

Mount/dev/sdb1/mnt

Note: Copy the data to the U-disk, you need to enter sync to sync the files, and perform at least 3 times to ensure the data is fine.


Disk Management Common Tools

Memory Space usage Status:

free [OPTION]

-M: in megabytes

-G: in gigabytes

-H: Easy-to-read format

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/86/97/wKiom1fE7GuiPMpsAAAZDYkBmvs065.png "title=" 40.png "alt=" Wkiom1fe7guipmpsaaazdykbmvs065.png "/>

Viewing tools for information such as file system space usage:

DF [OPTION] ... [FILE] ...

-H in 1000 units

-T File system type

-h:human-readable

-i:inodesinstead of Blocks

-P: Output in POSIX-compatible format

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/86/97/wKiom1fE7XLTF9MzAABBjGCU944744.png "title=" 41.png "alt=" Wkiom1fe7xltf9mzaabbjgcu944744.png "/>


To view the overall space consumption status of a directory:

Du [OPTION] ... DIR

-h:human-readable

-s:summary

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/86/98/wKiom1fE7aGAWHZ8AAALbtcRRj0264.png "title=" 42.png "alt=" Wkiom1fe7agawhz8aaalbtcrrj0264.png "/>


Tool DD

DD command: Convert and copy a file

Usage:

DD IF=/PATH/FROM/SRC of=/path/to/dest

Bs=#:block size, copying unit sizes

count=#: How many BS do you copy?

Of=file writes to the named file instead of to the standard output

If=file read from the named file instead of the standard input

BS=SIZE Specifies the block size (both IBS and OBS)

Ibs=size read size byte at a time

Obs=size write a size byte at a time

Cbs=size One conversion size a byte

Skip=blocks ignores blocks of IBS-sized blocks from the beginning

Seek=blocks ignoring blocks of obs size from the beginning of a block

Count=n Copy only N records

Cbs=size how many bytes are converted at a time


Conv=conversion[,conversion ...] Convert a file with the specified parameters

Conversion parameters:

ASCII conversion EBCDIC to ASCII

EBCDIC convert ASCII to EBCDIC

Block converts a row of data to a CBS-length record, and the insufficient portion is padded with spaces.

Unblock replaces CBS length with a new line at the end of each line

LCase converting uppercase characters to lowercase characters

UCase converting lowercase characters to uppercase characters

Nocreat do not create output file

NoError does not stop when an error occurs

Notrunc Not truncated output file

Sync fills each input block into IBS bytes, and the less part is padded with empty (NUL) characters


Example:

Disk Copy:

DD IF=/DEV/SDA OF=/DEV/SDB

Backup MBR:

DD IF=/DEV/SDA Of=/testdir/mbr.bak count=1 bs=512

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/86/97/wKioL1fE8xvBxpbzAAAwROEn3i0109.png "title=" 43.png "alt=" wkiol1fe8xvbxpbzaaawroen3i0109.png "/> Restore MBR:

DD If=/testdir/mbr.bak of=/dev/sdb Bs=1 count=512

Restoring 512 bytes of MBR data does not restore EBR information because the MBR's 512 bytes do not include the EBR extended partition file.

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/86/98/wKioL1fE9gmSObL4AAChUJgLtG0768.png "title=" 44.png "alt=" Wkiol1fe9gmsobl4aachujgltg0768.png "/>

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/86/98/wKioL1fE94-hK6JjAADSbgbro1g853.png "title=" 46.png "Style=" Float:none; "alt=" Wkiol1fe94-hk6jjaadsbgbro1g853.png "/>

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/86/98/wKiom1fE94-Q_xUoAADPhP3lNoA686.png "title=" 45.png "Style=" Float:none; "alt=" Wkiom1fe94-q_xuoaadphp3lnoa686.png "/>

To destroy a partitioned table in the MBR:

DD If=/dev/zero of=/dev/sdb Bs=1 count=64 seek=446

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/86/98/wKiom1fE-YbASXqdAACG9j806CE718.png "title=" 47.png "alt=" Wkiom1fe-ybasxqdaacg9j806ce718.png "/>


Thinking: There is a large binary file with 2K Filea. Now want to start reading from the 64th byte position, the size to be read is 128Byts. And Fileb, want to read the above 128Bytes write to the beginning of the 32nd byte position, replace 128Bytes, how can I do?

DD If=filea bs=1 count=128 skip=63 of=fileb seek=31 conv=notrunc

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/86/98/wKioL1fE_czA4MAoAACmhJnbgis205.png "title=" 48.png "alt=" Wkiol1fe_cza4maoaacmhjnbgis205.png "/>


Backup Example:

DD IF=/DEV/SDX OF=/DEV/SDY

Back up the local/DEV/SDX full disk to the/DEV/SDY

DD IF=/DEV/SDX Of=/path/to/image

To back up the/DEV/SDX full data to the image file of the specified path

DD IF=/DEV/SDX | Gzip >/path/to/image.gz

Backup/DEV/SDX full data and compress with gzip tool to save to specified path


Recovery example:

DD If=/path/to/image OF=/DEV/SDX

Restore the backup file to the specified disk

gzip-dc/path/to/image.gz | DD OF=/DEV/SDX

Restores a compressed backup file to a specified disk


Copy memory data to hard disk

DD If=/dev/mem Of=/root/mem.bin bs=1024

Copy the in-memory data to the Mem.bin file in the root directory


Copy ISO image from disc

DD If=/dev/cdrom Of=/root/cd.iso

Copy the disc data to the root folder and save it as a Cd.iso file


Destroying disk data

DD If=/dev/urandom OF=/DEV/SDA1

The use of random data to populate the hard disk, in some necessary occasions can be used to destroy data. After you do this, the/dev/sda1 cannot be mounted, and the Create and copy operations cannot be performed.


Get the most appropriate block size

DD If=/dev/zero bs=1024 count=1000000 of=/root/1gb.file

DD If=/dev/zero bs=2048 count=500000 of=/root/1gb.file

DD If=/dev/zero bs=4096 count=250000 of=/root/1gb.file

The best block size for the system can be determined by comparing the command execution time shown in the output of the DD instruction.


Test drive Read and write speed

DD If=/dev/zero of=/root/1gb.file bs=1024 count=1000000

DD If=/root/1gb.file bs=64k | DD Of=/dev/null

The Write/read/speed of the test drive can be calculated by the execution time of the last two command outputs.


Repairing the hard drive

DD IF=/DEV/SDA OF=/DEV/SDA

When the hard disk is not used for a long time (for example, 1, 2 years), a degaussing point is generated on the disk. When the heads read these areas, they encounter difficulties and can cause I/O errors. When this condition affects the first sector of the hard disk, it may cause the hard disk to retire. The command above may bring the data back to the dead, and the process is safe and efficient.


This article is from the "~ Breeze ~" blog, please be sure to keep this source http://wanweifeng.blog.51cto.com/1957995/1844306

8.29_linux Disk Management (ii)

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.