RHEL7 Disk Management

Source: Internet
Author: User

First, MBR master boot record
The MBR has 512 bytes and is divided into three parts: the first part is 446 bytes, the boot partition is stored, the second part 64 bytes is the partition table, the third part is 2 byte terminator, and each partition requires 16 bytes, so MBR mode can only divide 4 primary partition or 3 primary partition and extended partition The primary partition can be used directly, the extended partition cannot be used directly, and the logical partition is reused on the extended partition;
[Email protected] ~]# cat/proc/partitions Major minor #blocks name 8 20971520 SDB 8 0 2621440 0 SDA 8 1 1024000 sda1 8 2 18432000 sda2 8 3 1024000 sda3 one 0 3655680 sr0 two, Gpt
GPT can record 128 primary partitions;
Iii. using commands to manage disk partitions
1. fdisk command
Partition disks by using FDISK, which is divided into MBR-formatted disks by default
Fdisk-l view current disk and partition conditions:
[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. Device does not contain a recognized partition tablebuilding a new DOS disklabel with disk identifier 0X39C77FAE. Command (M for help): Mcommand action
A toggle a bootable flag
b Edit BSD Disklabel
C Toggle the DOS compatibility flag
d Delete a partition delete a partition
G Create a new empty GPT partition table
G Create an IRIX (SGI) partition table
L list known partition types list partition type
M Print this menu print Help menu 
  n  Add a new partition    add a fresh partition  
  o  Create a new empty DOS partition Table 
  p  Print the partition table    printing partition table  
  q  quit without saving Changes  
  s  Create a new empty Sun disklabel 
  t  Change a partition ' s system ID
  u  change display/entry units
  v  Verify the partition table 
  w  write table to disk and exit    exit and save Then use Partprobe or PARTX/DEV/SDX to refresh  
  x  extra functionality ( Experts only)
Add partition:
Command (M for help): Npartition Type:p Primary (0 primary, 0 extended, 4 free) e extendedselect (default p): P
Partition number (1-4, default 1): First sector (2048-41943039, default 2048): Using default value 2048Last sector, +secto RS or +size{k,m,g} (2048-41943039, default 41943039): +2gpartition 1 of type Linux and of size 2 GiB is set

Command (M for help):p
disk/dev/sdb:21.5 GB, 21474836480 bytes, 41943040 sectorsunits = sectors of 1 * = bytessector size (logical/phys ical): bytes/512 bytesi/o size (minimum/optimal): bytes/512 bytesdisk label Type:dosdisk identifier:0x39c77f AE Device Boot Start End Blocks Id system/dev/sdb1 2048 4196351 2097152 L Inux Command (M for help): Only four primary partitions can be divided, if you want to partition the extra four partitions, you need to create an extended partition on the fourth partition to create the logical partition on the extended partition:
Device Boot Start End Blocks Id system/dev/sdb1 2048 4196351 2097152-linux/d 4196352 8390655 2097152 ev/sdb2 linux/dev/sdb3 8390656 12584959 2097152 EV/SDB4 12584960 41943039 14679040 5 extended/dev/sdb5 12587008 16781311 2097152 X
[[email protected] ~]# fdisk-l/DEV/SDA has * identity represents boot partition: Device boot start End Blocks Id system/dev/sd A1 * 2048 2050047 1024000, linux/dev/sda2 2050048 38914047 18432000 A3 38914048 40962047 1024000 for the Linux swap/solaris partition type, use the T command to modify the type of partition:
Command (M for help): l
0 Empty NEC DOS bayi minix/old Lin BF Solaris 1 FAT12 Hidden NTFS Win 82 Linux swap/so C1 drdos/sec (FAT-2 Xenix root Plan 9 for Linux C4 drdos/sec (FAT-3 Xeni X usr 3c partitionmagic os/2 hidden c:c6 drdos/sec (FAT-4 FAT16 <32m x Venix 80286) Linu X Extended C7 Syrinx 5 Extended PPC PReP Boot x NTFS volume set da non-fs data .... Omitted


2. Gdisk command
Partitioning disks by using Gdisk, which is partitioned by default in GPT-formatted disks
[[email protected] ~]# gdisk/dev/sdbgpt fdisk (gdisk) version 0.8.6 Partition table Scan:MBR:not present Bsd:not Pre Sent Apm:not present Gpt:not present Creating new GPT entries. Command (? For help):
The use method is basically the same as Fdisk, which is not repeated here.
3, parted command: You can choose to divide the format
The parted command can modify the MBR structure to a GPT structure, but be cautious because the partition table is missing:
[Email protected] ~]# Parted/dev/sdbgnu parted 3.1using/dev/sdbwelcome to GNU parted! Type ' help ' to view a list of commands.                                                                  (parted) Help------------look under the aid, not commonly used to remember. To convert a partition type using Mklabel:
AIX Amiga BSD DVH GPT Loop mac Msdos PC98 Sun
(parted) Mklabel
New disk label type? GPT (parted)
Command (M for help): Wthe partition table have been altered! Calling IOCTL () to re-read partition table. Syncing disks. [Email protected] ~]# partprobe or [[email protected] ~]# partx-a
4. Use MKFS to set file system for partition:
[[email protected] ~]# mkfs-t xfs/dev/sdb1meta-data=/dev/sdb1              isize =256    agcount=4, agsize=131072 blks         =           &NBS P           sectsz=512   attr=2, projid32bit=1         =   &NBSP ;                   crc=0data     =         &NBSP ;             bsize=4096   blocks=524288, imaxpct=25         = & nbsp                     sunit=0      swidth=0 blksnaming &nbs P =version 2              bsize=4096   ascii-ci=0 ftype=0log      =in Ternal log           bsize=4096   blocks=2560, version=2         =   &nbsp                   sectsz=512   sunit=0 blks, Lazy-count=1realtime =none                   extsz=4096   blocks=0, rtextents=0 specify block size: [[EMA Il protected] ~]# mkfs.xfs-b size=1024/dev/sdb2

Mount partition to File system:
[[email protected] ~]# mkdir/aa[[email protected] ~]# mount/dev/sdb1/aa[[email protected] ~]# Df-hfilesystem Size           Used Avail use% mounted on/dev/sda2 18G 14G 3.8G 79%/devtmpfs 482M 0 482M 0%/devtmpfs 490M 0 490M 0%/dev/shmtmpfs 490M 6.9M 484M 2%/runtmpfs 490M 0 490M 0%/sys/fs/c GROUP/DEV/SDA1 997M 123M 875M 13%/boot/dev/sdb1 2.0G 33M 2.0G 2%/aa You can use Xfs_info to view file system Information:
[[email protected] ~]# xfs_info/aameta-data=/dev/sdb1              isize=256 &NB Sp  agcount=4, agsize=131072 blks         =               &N Bsp       sectsz=512   attr=2, projid32bit=1         =       &NBSP ;               crc=0data     =             &NBSP ;         bsize=4096   blocks=524288, imaxpct=25         =     & nbsp                 sunit=0      swidth=0 blksnaming   =version 2              bsize=4096   ascii-ci=0 ftype=0log      =internal &nbs P             bsize=4096   blocks=2560, version=2         = &nbs P                    sectsz=512   sunit=0 Blks, Lazy-count=1realtime =none                   extsz=4096   blocks=0, rtextents=0
To view the blkid of a partition using Xfs_admin:
[Email protected] ~]# xfs_admin-u/dev/sdb1uuid = 12d99538-2241-42b0-b873-6406266cc8e2
You can also use Blkid to view:
[Email protected] ~]# blkid/dev/sdb1:uuid= "12d99538-2241-42b0-b873-6406266cc8e2" type= "XFS" partuuid= " E71103e9-668d-444b-bc96-70501467cc43 "/dev/sdb2:uuid=" 9a951c66-78e1-416e-aa0e-7d41a55efc6d "TYPE=" XFS "PARTUUID=" 38a4a2ea-2571-419d-b80f-8ea801f4291e "/dev/sda1:uuid=" 7dfc741a-395f-46d9-ba69-a037f24ae107 "TYPE=" XFS "/DEV/SDA2: Uuid= "82934945-3802-4f45-ada3-1d43f0b2a1c5" type= "XFS"/dev/sda3:uuid= "6dde9ce3-2757-4c88-b082-5665daa2d584" TYPE = "swap"/dev/sr0:uuid= "2014-05-07-03-58-46-00" label= "RHEL-7.0 server.x86_64" type= "iso9660" pttype= "DOS" If a partition is not formatted, there will be no UUID if there is no file system:
You can use Xfs_admin-u to modify the UUID of a partition:
[Email protected] ~]# Uuidgen
292e2919-11fa-4f1c-8006-4a506095d377
[Email protected] ~]# xfs_admin-u 292E2919-11FA-4F1C-8006-4A506095D377/DEV/SDB1
Clearing log and setting UUID
Writing all SBs
New UUID = 292e2919-11fa-4f1c-8006-4a506095d377
XFS file system size can be increased, but not reduced


Swap swap partition, similar to Windows virtual memory:
is to use some of the space inside the disk to simulate memory:
1, the use of zoning;
2, create the file;
To view swap partitions:
[Email protected] ~]# cat/proc/swaps Filenametypesizeusedpriority/dev/sda3 partition102399 60-1 the command T modifies the partition to swap format:
Command (M for help): tselected partition 1Partition type (type L to list all types): 14Changed type of partition ' EFI Sys Tem ' to ' Linux swap ' formatted swap partition: [[email protected] ~]# mkswap/dev/sdb1mkswap:/dev/sdb1:warning:wiping old XFS signature. Setting up Swapspace version 1, size = 1048572 kibno label, uuid=b633a131-d314-487b-b1f8-a5516626c081
To enable or disable a swap partition using Swapon and Swapoff:
[[email protected] ~]# swapon/dev/sdb1[[email protected] ~]# free            &NB Sp;total       used       free     GKFX    buffers     Cache DMem:       1003456     420340     583116       7020     &NBSP ; 1328     138184-/+ Buffers/cache:     280828     722628Swap:      2072568 &NB Sp        0    2072568[[email protected] ~]# swapoff/dev/sdb1[[email protected] ~ ]# free             total       used       free   &N Bsp Shared    buffers     CACHEDMEM:       1003456     419936     58352 0       7020       1324     138220-/+ Buffers/cache:     280392   & nbsp 723064Swap:      1023996          0    1023996  Create a file as a swap partition:
[[email protected] ~]# dd If=/dev/zero of=/swapfile bs=1m count=200
[[email protected] ~]# mkswap/swapfile Setting up swapspace version 1, size = 204796 kibno label, uuid=630ac3d6-94fd-4b68 -8148-00f0b780bb2d
[Email protected] ~]# chmod 0600/swapfile
[[email protected] ~]# swapon/swapfile[[email protected] ~]# free            &NB Sp;total       used       free     GKFX    buffers     Cache DMem:       1003456     630596     372860       7016     &NBSP ; 1328     343160-/+ Buffers/cache:     286108     717348Swap:      1228792 &NB Sp        0    1228792[[email protected] ~]# swapoff/swapfile [[email  Protected] ~]# free             total       used       FR EE     GKFX    buffers     CACHEDMEM:       1003456     630556 &N Bsp   372900       7016       1328     343160-/+ Buffers/cache:     286 068     717388Swap:      1023996          0    1023996

Finally, remember to add the appropriate parameters in/etc/fstab [[email protected] ~]# Cat/etc/fstab #/etc/fstab# Created by Anaconda on Fri Jan 1 11:14:17 2 016## Accessible filesystems, by reference, is maintained under '/dev/disk ' # See mans Pages Fstab (5), Findfs (8), Mount (8) and/or Blkid (8) For more INFO#UUID=82934945-3802-4F45-ADA3-1D43F0B2A1C5/XFS defaults 1 1uuid=7dfc741a-395f-46d9-ba69-a037f24ae107/boot XFS Defaults 1 2uuid=6dde9ce3-2757-4c88-b082 -5665daa2d584 swap swap defaults 0 0
This part is not introduced, check it.

RHEL7 Disk 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.