The use of partitioning tools in Linux

Source: Internet
Author: User
Tags readable reserved uuid

List the available disk devices

Graphical Disk Management tool: Click "Applications", "System Tools", "Disk" or execute command gnome-disks

List block devices

Lsblk



To create a partition using:

FDISK creates an MBR partition, also supports GPT, and can manage up to 15 partitions for a hard disk

Gdisk creating a GPT partition

GNU parted advanced partitioning operations (create, copy, resize, etc.)

partprobe-re-setting the kernel partition table version in memory


Partitioning tools Fdisk and Gdisk

Fdisk/dev/sdb

GPT Partitioning tool for GFISK/DEV/SDB class Fdisk


FDISK command: Fdisk-manipulate disk partition Table

1. View the partition information of the disk

Fdisk-l [-u] [device ...]: Lists partitions on the specified disk device

2. Managing partitions

FDISK device

[Email protected] ~]# fdisk/dev/sdbwelcome to fdisk (Util-linux 2.23.2). Changes'll remain in memory only, until the decide to write them. Be careful before using the write Command.command (M for help):

FDISK provides an interactive interface to manage partitions, and he has a number of subcommands for different management functions, all of which are done in memory, not directly synchronized to disk, and saved directly to disk using the W command;

Sub-command:

M Get help

P Partition List

t change the partition type

n Create a new partition

D Delete Partition

W Save and exit

Q Do not save and exit

Note: A new partition created on a disk device that already has a partition and is already hanging on one of the partitions may not be recognized directly by the kernel after the creation is complete;


To see if the kernel has identified a new partition:

# cat/proc/partations

Notifies the kernel to re-read the hard disk partition table


New Partition with

Partx-a-N m:n/dev/device

Kpartx-a/dev/device-f: Force

Delete partition with

Partx-d-N m:n/dev/device

Centos6:–nrn-m


CentOS 5, 7: Using Partprobe

Partprobe [/dev/device]



parted command

Parted operations are in real time, use caution

Usage: parted [options] ... [Device [command [parameters] ...] ...]

Parted/dev/sdbmklabelgpt|msdos

Parted/dev/sdbprint

Parted/dev/sdbmkpartprimary 1 200 (default m)

Parted/dev/sdbrm1

Parted-l



File system:

A file system is the method and data structure used by the operating system to explicitly store files on a device or partition; The method of organizing files on a storage device. The software structure that manages and stores the file information in the operating system is called the file management system, referred to as file system.

From a system perspective, a file system is a system that organizes and distributes the space of a file storage device, which is responsible for storing files and protecting and retrieving the files deposited. Specifically, it is responsible for creating files for users, deposit, read, modify, dump files, control file access, security control, logging, compression, encryption and so on.


File system type

Linux file systems:: ext2 (Extended file system), Ext3, Ext4, XFS (SGI), Btrfs (Oracle), ReiserFS, JFS (AIX), swap

Disc: iso9660

Windows:fat32, NTFS

Unix:ffs (FAST), UFS (Unix), JFS2

Network File system: NFS, CIFS

Clustered file system: GFS2, OCFS2 (Oracle)

Distributed File systems: Ceph, Moosefs, MogileFS, Glusterfs, Lustre

RAW: Unprocessed or unformatted file system


File System classification

Depending on whether it supports the "journal" feature:

journaled file system: ext3, Ext4, XFS, ...

Non-journaled file system: ext2, VFAT

Part of the file system:

Modules in the kernel: Ext4, XFS, VFAT

User space management tools: MKFS.EXT4, Mkfs.xfs,mkfs.vfat

Virtual file system for Linux: VFS

Pre-check supported file systems: Cat/proc/filesystems



Creating a file system

MKFS command:

(1) # MKFS. Fs_type/dev/device

Ext4

Xfs

Btrfs

Vfat

[Email protected] ~]# mkfs.mkfs.btrfs mkfs.ext2 mkfs.ext4 mkfs.minix mkfs.vfat Mkfs.cramfs mkfs.ext3 MKF S.fat Mkfs.msdos MKFS.XFS

(2) # mkfs-t Fs_type/dev/device

-L ' LABEL ': Set volume label



Create ext File System

Mke2fs:ext Series file system dedicated management tools

-T {EXT2|EXT3|EXT4}

-B {1024|2048|4096}

-L ' LABEL '

-j: Equivalent to-t ext3

' Mkfs.ext3 ' = ' mkfs-t ext3 ' = ' mke2fs-j ' = ' mke2fs-t ext3 '

-i#: Create an inode for each number of bytes in the data space, which should not be smaller than the block size

-N #: How many inode to create for a data space

-I one inode record size---4096

-M #: Default 5%, Percentage of total space reserved for administrative staff

-O feature[...] : Enable the specified attribute

-O ^feature: Turn off specified attributes


File System Tags

Another way to point to a device

Device-Independent

Blkid: Block Device properties Information view

Blkid[option] ... [DEVICE]

-U UUID: Find the corresponding device based on the specified UUID

-L Label: finds the corresponding device according to the specified label

Blkid does not follow any option to display all the block device attribute information in the system


E2label: Manage Label for ext series File system

# E2label DEVICE [LABEL]


Findfs: Finding partitions

Findfs [Options] label=<label>

Findfs [Options] uuid=<uuid>


TUNE2FS: Reset the values of the EXT series file system adjustable parameters

-L: View the specified file system super block information; Super Block

-L ' LABEL ': Modify volume label

-M #: Fixed percentage of space reserved for administrators

-j: Upgrade ext2 to Ext3

-O: File System Properties enabled or disabled, –O ^has_journal

-O: Adjust default mount options for the file system, –o ^acl

-U uuid: Modifying the UUID number

Randomly generated UUID command: Uuidgen or Cat/proc/sys/kernel/random/uuid

DUMPE2FS: Super block and fast group information for printing the "ext2/ext3" file system

DUMPE2FS [-BFHIXV] [-O superblock=superblock] [-O blocksize=blocksize] Device

-H: View Super Block information (grouping information), partition with group management

File system detection and Repair

Often occurs after the crash or abnormal shutdown

Mount for file system labeled "Dirty"

Fsck:file System Check

Fsck-t Fs_type

Fsck. Fs_type

[Email protected] ~]# fsck.fsck.btrfs fsck.ext2 fsck.ext4 fsck.minix fsck.vfat Fsck.cramfs fsck.ext3 FSC K.fat Fsck.msdos FSCK.XFS

-A: Auto fix error

-r: Interactive fix error

Note: Fs_type must be the same as the file type on the partition;


E2fsck:ext series file-specific detection and repair tool

-Y: Auto Answer Yes

-F: Forced repair


Mount Mount

Mount: An association between an additional file system and an existing directory of the root file system, which makes this directory a gateway to other file accesses

Uninstall: The process for removing this association relationship

To associate a device with a mount point: mount points

Mount

On uninstall: The device can be used or the mount point can be used

Umount

The existing files under mount point are temporarily hidden after the mount is completed

Mount point directory is generally empty



Mount the file system with the Mount command

Mount method: Mount DEVICE Mount_point

Mount: Displays all devices that are currently mounted by viewing the/etc/mtab file

Mount [-FNRSVW] [-t vfstype] [-O options] Device dir

Device: Indicate the equipment to be mounted;

(1) device files: e.g./dev/sda5

(2) Label:-L ' LABEL ', e.g.-l ' MYDATA '

(3) UUID,-u ' uuid ': for example-U ' 0c50523c-43f1-45e7-85c0-a126711d406e '

(4) Pseudo file system name: Proc, SYSFS, Devtmpfs, Configfs

Dir: Mount point

Pre-existing; Recommended use of Empty directory

The device that the process is in use cannot be uninstalled


Mount Common Command Options

-T Vsftype: Specifies the type of file system on the device you want to mount

-r:readonly, read-only Mount

-w:read and write, read-write Mount

-N: Do not update/etc/mtab, equivalent to #mount

-A: Automatically mounts all devices that support automatic mounts (defined in the/etc/fstab file with auto function in the Mount option)

-L ' LABEL ': Specify mount device with volume label

-U ' UUID ': Specifies the device to be mounted with the UUID

-B,--bind: Bind directory to another directory


To view all mounted devices tracked by the kernel:

Cat/proc/mounts


-O Options: (option to mount file system), multiple options separated by commas

Async: Async Mode

Sync: Synchronous mode, when memory changes, write disk simultaneously

Atime/noatime: Include Directories and files

Diratime/nodiratime: Access timestamp for directory

Auto/noauto: Whether automatic mount is supported, whether the-a option is supported

Exec/noexec: Whether to support running the application on the file system

Dev/nodev: Whether to support the use of device files on this file system

Suid/nosuid: Suid and Sgid permissions not supported

Remount: Re-mount

RO: Read-only

RW: Read and Write

Loop: Used to attach a file as a hard disk partition on the system

Iocharset: Specifies the character set used to access the file system

User/nouser: Whether a normal user is allowed to mount this device, the default administrator can mount

ACL: Enable the ACL feature on this file system

Defaults: Equivalent to RW, suid, dev, exec, auto, nouser, async


Uninstall command

To view mount conditions:

#findmnt Mount_point

To view the process that is accessing the specified file system:

#lsof Mount_point

#fuser-V Mount_point

Terminates all processes that are accessing the specified file system:

# fuser-km Mount_point

Unloading:

# Umount DEVICE

# Umount Mount_point


Mount points and/etc/fstab

Configuration file System Architecture

Used by Mount, FSCK, and other programs

Preserves file system system when 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;

Each line includes:

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:

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: first self-test; usually only Rootfs 1


Working with swap files and partitions

Swap partition is a complement to system RAM

Basic settings include:

    • Create a swap partition or file

      FDISK device creates a partition; t change the partition ID to 82

      Device Boot Start End Blocks Id System
      /DEV/SDC1 2048 4196351 2097152, Linux Swap/solaris

      W Save exit

    • Write a special signature using Mkswap

      Mkswap decive

    • Add the appropriate entry in the/etc/fstab file

    • Activating swap space with swapon-a



Mount Swap Partition

Enabled: Swapon

Swapon [OPTION] ... [DEVICE]

[Email protected] ~]# swaponname TYPE SIZE used PRIO/DEV/SDA5 partition 2G 0B-1/DEV/SDC1 partition 2G 0b-2

-A: Activates all swap partitions;

-P Priority: Specify precedence

Or add in the/etc/fstab file: Pri=value (the higher the value, the higher the priority)

[[email protected] ~]# swapon-p 10/dev/sdc1[[email protected] ~]# swaponname TYPE SIZE used PRIO/DEV/SDA5 part ition 2G 0B-1/DEV/SDC1 partition 2G 0B 10

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


Priority of Swap

    • The user can assign a 0 to 32767 priority to a swap

    • 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


Moving Media

    • 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


Using discs

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


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


Common tools

Memory Space usage Status:

free [OPTION]

-M: in megabytes

-G: in gigabytes

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

To view the overall space consumption status of a directory:

Du [OPTION] ... DIR

-h:human-readable

-s:summary

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 a size byte at a time

Obs=size: Write a size byte at a time

Cbs=size: One conversion of size byte

Skip=blocks: Ignores blocks of IBS-sized blocks from the beginning

Seek=blocks: Ignores blocks of blocks obs size from the beginning

Count=n: Copy only N records

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

Conversion parameters:

ASCII conversion EBCDIC to ASCII

EBCDIC convert ASCII to EBCDIC

The block is converted to a cbs-length record, and the insufficient portions are 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

Swab Swap bytes per pair of inputs

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


Disk Copy:

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

Backup MBR:

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

Destroy the bootloader in the MBR:

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

Cases:

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 of=fileb bs=1 count=128 skip=63 seek=31 conv=notrunc

Backup:

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:

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

DD If=/dev/zero bs=8192 count=125000 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=/root/1gb.file bs=64k | DD Of=/dev/null

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

The read/write 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 above command may bring the data back to the dead. And the process is safe and efficient.


This article is from the "I ' m Groot" blog, so be sure to keep this source http://groot.blog.51cto.com/11448219/1844066

The use of partitioning tools in Linux

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.