Linux Partition Management

Source: Internet
Author: User

Managing Partitions
? ? ?? List block devices
?????????????? Lsblk
????????????????? Example with a few hard drives on the CENTOS6
???????????????????????? [[Email protected] ~] #lsblk??? Not recognized.
???????????????????????? [[Email protected] ~] #echo '---' >/sys/class/scsi_host/host2/scan? Force scan
???????????????????????? [[Email protected] ~] #lsblk?? has been identified
???????????????????????? [[Email protected] ~] #hexdump-C-N 512/dev/sdb? Binary view new hard disk data not in use

????????????? ? ? Example destroys MBR partition table and restores
???????????????????????? [[Email protected] ~] #dd if=/dev/sda of=/app/mbr bs=1 count=512? Backup partition table to/APP/MBR
???????????????????????? [[Email protected] ~] #ll/app/mbr?? View is 512 bytes indeed
???????????????????????? [[Email protected] ~] #hexdump-C/APP/MBR??? Binary view
???????????????????????? [[Email protected] ~] #dd if=/dev/zero of=/dev/sda bs=1 count=64 skip=446 seek=446? Break Partition Table
????????????????????????????????? Count=64 64 bytes, skip=446 skips the first 446 bytes to start reading, seek=446 skips the first 446 bytes of the target to start a search (skipping 446 bytes, overwriting only the middle 64 bytes)
???????????????????????? [[Email protected] ~] #hexdump-C-N 512/DEV/SDA? View filled by 0
???????????????????????? [[Email protected] ~] #lsblk?? You can also view the partition because there is still a copy in memory, and if the reboot is finished
???????????????????????? [[Email protected] ~] #fdisk-L/DEV/SDA??? Unable to view partition because this command is to view the partition table on disk
????????????????????????????? View four ways of partitioning
?????????????????????????????????????? Ls/dev/sd*?? How to look at the device name??? In memory
?????????????????????????????????????? Cat/proc/partitions????? Memory
?????????????????????????????????????? Lsblk?? Memory
?????????????????????????????????????? Fdisk-l/DEV/SDA??? Look at the partition table on the disk
???????????????????????? [[email protected] app] #scp MBR 192.168.27.129:/app/?? Save the Backup partition table on a different machine (CENTOS7)
???????????????????????? [[Email protected] ~] #ls/app/?? View MBR files on Centos7 that do have backups
???????????????????????? [[email protected] app] #reboot?? Reboot Discovery failed to start
???????????????????????? You can remove the hard drive and hang it on another machine to restore the partition table or enter the disc rescue mode
???????????????????????? Press ESC when restarting the progress bar and select "CD-ROM Drive" "Rescue installed System" to enter rescue mode
???????????????????????? bash-4.1# pwd??? Now the root directory is not the root directory of the hard disk, is a simplified version of the CD-ROM small Linux system
???????????????????????? bash-4.1# lsblk? Can't see
???????????????????????? bash-4.1# Fdisk-l can see the hard drive
???????????????????????? bash-4.1# IP A? See if getting to IP
???????????????????????? bash-4.1# SCP 192.168.27.129:/app/mbr.? Copy the backup to the current directory
???????????????????????? bash-4.1# DD if=mbr OF=/DEV/SDA bs=1 count=64 skip=446 seek=446? You can also overwrite all 512 bytes
???????????????????????? bash-4.1# exit? Exit and select restart

????????????? ? ?? Example to copy the SDA partition table to SDB (New hard drive) (this is not recommended in production because the two hard disk sizes are not necessarily the same, and the logical partitions are not replicated because the logical partition information is placed in the extended partition and not in the MBR)
???????????????????????? [[Email protected] ~] #lsblk??? SDB is a newly added hard drive.
???????????????????????? [[Email protected] ~] #dd if=/app/mbr of=/dev/sdb bs=1 count=66 skip=446 seek=446
???????????????????????????????? Copy the partition table to sdb,count=66 including the last two identifiers
???????????????????????? [[Email protected] ~] #partx-a/dev/sdb?? Synchronizing partitioned Tables
???????????????????????? [[Email protected] ~] #lsblk?? See SDB appears partition
???????????????????????? [[Email protected] ~] #dd if=/dev/zero of=/dev/sdb bs=1 count=512??? Delete a SDB partition
???????????????????????? [[Email protected] ~] #hexdump-C/dev/sdb?????????? Binary view
???????????????????????? [[Email protected] ~] #fdisk-L/DEV/SDB???????? View
????
????

????????? To create a partition using:
?????????????????? Fdisk creating an MBR partition
?????????????????? Gdisk creating a GPT partition
?????????????????? Parted advanced partitioning operations
?????? ? partprobe-re-setting the kernel partition table version in memory


parted command
????????? Parted operations are in real-time, and use
with caution????????? Usage: parted [options] ... [Device [command [parameters] ...] ...]??
?????????????? Parted/dev/sdb? Mklabel Gpt|msdos???? Create a GPT or MBR partition
?????????????? Parted/dev/sdb? Print?
?????????????? Parted/dev/sdb? Mkpart Primary 1 200 (default m)?
?????????????? Parted/dev/sdb? RM 1?
?????????????? Parted-l
???????????????? example [[email protected] ~] #parted/dev/sdb Mklabel GPT, creating a GPT partition on a new hard disk SDB
???????????? ??? ?? ?? [[email protected] ~] #parted/dev/sdb print? View the
???????????????????? [[email protected] ~] #fdisk-l/DEV/SDB?? Legacy tools can also be viewed, but you will be prompted not to support
????????????????????? [[email protected] ~] #parted/dev/sdb Mkpart primary 1 1000?? Create primary partition 1-1000m
????????????????????? [[email protected] ~] #parted/dev/sdb print? View the
????????????????????? [[email protected] ~] #parted/dev/sdb RM 1?? Delete Partition


Partition tool fdisk and Gdisk
????????? The GPT partitioning tool for the Gdisk/dev/sdb class, Fdisk
????????? Fdisk-l [-u] [device ...] view partition
????????? Fdisk/dev/sdb? Manage Partition
?????????????? Example redirection method to create a partition
??????????????????? [[email protected] ~] #echo-e ' n\np\n2\n\n+10g\nw\n ' | FDISK/DEV/SDC
??????????????????? [[email protected] ~] #fdisk/dev/sdc <<eof?? or multi-line redirection
???????????????????????? > N
???????????????????????? > P
???????????????????????? > 2
???????????????????????? >
???????????????????????? > +5g
???????????????????????? > W
???????????????????????? > EOF
????????? Sub-command:
?????????????????? P Partition List
?????????????????? t change the partition type
?????????????????? n Create a new partition
?????????????????? D Delete Partition
?????????????????? V-Check partition
?????????????????? U Conversion Unit
?????????????????? W Save and exit
?????????????????? Q Do not save and exit

Synchronizing Partitioned Tables
? ? ?? See if the kernel has identified a new partition:?
?????????????? Cat/proc/partitions
? ? ?? CENTOS6 notifies the kernel to re-read the hard disk partition table?
?????????????? New partition with??
??????????????????? Partx-a? /dev/device????
??????????????????? Kpartx-a/dev/device-f: Force?
?????????????? Delete partition with? partx-d--nr m-n/dev/device
??????????????????? example [[email protected] ~] #partx-D--nr 1-4/dev/sde??? (Sde1 sde2 sde3 sde4 caused by deleting the different steps)
????? CentOS 5, 7: Using Partprobe?
?????????????? Partprobe [/dev/device]


creating a file system
? ? ? ? MKFS command:
? ? ? ?? (1) mkfs. Fs_type/dev/device??
??????????????????????? Ext4??
??????????????????????? Xfs??
??????????????????????? A btrfs??
??????????????????????? Vfat
????????? (2) mkfs-t Fs_type/dev/device??
??????????????????????? -L ' LABEL ': Set volume label
????????? example [[email protected]/] #mkfs. ext4/dev/sdb2?? Creating a file system
??????? ? ? ? [[email protected]/] #blkid? View
????????? Examples of three ways of writing
?????????????? [[email protected]/] #mkfs. ext2/dev/sdb3
?????????????? [[email protected]/] #mkfs-t EXT2/DEV/SDB3
?????????????? [[email protected]/] #mke2fs/DEV/SDB3

Supported file systems:/lib/modules/' uname–r '/kernel/fs?
Pre-check supported file systems: Cat/proc/filesystems

Create ext File system
? ? ? ? Mke2fs:ext Series file system dedicated management tools?
??????????????? -t {EXT2|EXT3|EXT4}?
??????????????? -B {1024|2048|4096}? Specify block size
??????????????????? example [[email PROTECTED]TOS6 ~] #tune2fs-L/DEV/SDB3??? Watch out for Block size
??????????????????? ? ? ? [[Email protected] ~] #mkfs-b 1024/dev/sdb3?? Specified as 1024x768??? 1024 bytes, 1K
??????????????????????? ? [[Email protected] ~] #mke2fs-B 2048/dev/sdb3? Specified as 2048?? 2 K

??????????????? -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 less than the size of the block?
??????????????? -N #: Specify how many inode to create in a partition?
??????????????? -I an Inode record takes up a disk space size,---4096?
??????????????? -M #: Default 5%, what percentage of total space is 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
??????????????????? Example finding a device by/app the corresponding UUID
???????????????????????? [[Email protected] ~] #blkid-u ' sed-rn ' s#^uuid= (. *)/app. *#\1#p '/etc/fstab ' (/app after adding spaces to prevent name APPPP)
?????????????? -L Label: finds the corresponding device according to the specified label
??????????????????? Cases? [[Email protected] ~] #mkfs. xfs-f/dev/sdb1-l/mnt/sdb1?
???????????????????????? SDB1 mount to Folder/MNT/SDB1??? Recommended volume label name set to the folder name of the device mount point

???? ?? E2label: Manage the label of the Ext series file system?
?????????????? E2label DEVICE [LABEL]
??????????????????? example [[email protected] ~] #e2label/dev/sdb2/mnt/sdb2??? Add a volume label (Mount Point as volume label)
????? ? Findfs: Find partitions?
?????????????? Findfs [options] label=<label>?
?????????????? Findfs [Options] uuid=<uuid>

TUNE2FS: Reset the value of the EXT series file system adjustable parameter ?
????-L: View the specified file system super block information; Super block?
????-l ' LABEL ': Modify the volume label?
????-M #: Fix the percentage of space reserved for administrators?
????-j: Upgrade ext2 to ext3?
????-o: File System Properties enabled or disabled, –O ^has_journal
????????????? example [[[email protected] ~] #tune2fs-o has_journal/dev/sdb 3 (SDB3 originally ext2, changed to ext3)
??????????????? [[email protected] ~] #tune2fs-o ^has_journal/dev/sdb3 again removed? (Note that the UUID does not change)
????????-o: Adjust the default mount options for the file system, –o ^acl??
????????-U uuid: Modify the UUID number
dumpe2fs: ?
?????????? Block group management, 32768 bucks?
?????????? -H: View Super block information, do not display grouping information

file system detection and repair
????? ? Often occurs after the crash or abnormal shutdown
????? ? Mount for file system labeled "No clean"
???????? Note: Be sure not to fix it in a mounted state
????? ? Fsck:file System Check? (It is actually called e2fsck)
?????????????? Fsck. Fs_type?
?????????????? Fsck-t Fs_type?
?????????????? -P: Auto fix error?
?????????????? -r: Interactive fix error?
?????????????? Fs_type must be the same as the file type on the partition
???? ?? E2fsck:ext series file-specific detection repair tool?
?????????????? -Y: Auto answer yes?
?????????????? -F: Forced repair

????? ? Cases
?????????????? [[Email protected] ~] #dd if=/dev/zero of=/dev/sdb2 bs=1m count=10?? Destroying SDB2
?????????????? [[Email protected] ~] #dumpe2fs/dev/sdb2??? Super block information cannot be viewed
?????????????? [[Email protected] ~] #fsck/dev/sdb2?? Fix, need to answer a lot of Yes
?????????????? [[Email protected] ~] #fsck-a/dev/sdb2?? -A does not automatically answer Yes


Linux Partition Management

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.