Disk Management for Linux

Source: Internet
Author: User

1. Introduction to Disk terms

The MBR master boot record (MBR, main boot record) is a section of boot (Loader) code located at the front of the disk. MPT HDD Validity indicator. 0 tracks a sector of 512 bytes is the former 446:MBR master boot record. Responsible for finding/boot this partition, 447-510 is the MPT primary partition table, and the last two bytes is the validity identifier of the MPT hard drive.
There are three disk partitions, primary partitions, extended disk partitions, logical partitions. A hard disk can have a primary partition, an extended partition, or only one primary partition without an extended partition.  Logical partitions can be several.  The primary partition is the boot partition of the hard disk, which is independent and the first partition of the hard disk.  After dividing the main partition, the rest of the sections can be divided into extended partitions, which are generally divided into extended partitions, or not fully divided, and the remainder is wasted. However, the extended partition is not used directly, and is used in logical partitioning, so the extended partition can be divided into logical partitions. Their relationship is a contained relationship, all logical partitions are part of the extended partition, the capacity of the hard disk = the capacity of the primary partition + the capacity of the extended partition partition capacity = The sum of the capacity of each logical partition.


2. Disk View commands
Fdisk-l all disk devices in the system

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M00/9D/79/wKioL1mAim-BltXMAACbvrTVAoY809.png "title=" Screenshot from 2017-08-01 22-03-22.png "alt=" Wkiol1maim-bltxmaacbvrtvaoy809.png "/>

df-th disk devices that are being mounted on the system

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/9D/79/wKiom1mAioPit9CMAABMaZGzOLY097.png "title=" Screenshot from 2017-08-01 22-03-50.png "alt=" Wkiom1maiopit9cmaabmazgzoly097.png "/>

Blkid the disk device ID that the system can mount

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/9D/79/wKioL1mAipXRyI4JAAAc-_T2eGo225.png "title=" Screenshot from 2017-08-01 22-04-13.png "alt=" Wkiol1maipxryi4jaaac-_t2ego225.png "/>


3. Partition Division
View partition, start partition Fidsk/dev/vdb

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/9D/79/wKiom1mAiumyYzCOAAGzeMWZ5H8598.png "title=" Screenshot from 2017-08-01 14-32-11.png "alt=" Wkiom1maiumyyzcoaagzemwz5h8598.png "/>

Command (M for help): M get assistance
Command Action (common comments are as follows)
A toggle a bootable flag set boot partition

b Edit BSD Disklabel editing partition labels

   c   toggle the DOS compatibility flag
   d    Delete a partition                 Delete Partition
   g   Create a new empty GPT partition table
   g   Create an IRIX (SGI) p Artition table
   l   list known partition types     list system available partition types
   m   Print this menu                      help
   n   Add a new partition              new partition
    o   Create a new empty DOS partition table   creates a fresh blank dos< /span> Partition Table

P Print the partition table display partition
Q Quit without saving changes exit
s create a new empty Sun Disklabel
t change a partition ' s system ID modify partition feature ID
U change display/entry units changing the units displayed

V Verify the partition table Check Verify partition Tables

W Write table to disk and exit save changes to partition table
X Extra functionality (experts only)

Select n new partition, partition type primary partition p, primary partition ID is 1, start location default, end position default, partition size is 100m,wq save and exit, input Q only indicates discard change exit
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M02/9D/79/wKioL1mAi7GjPC79AADg9m0igog970.png "title=" Screenshot from 2017-08-01 14-33-32.png "alt=" Wkiol1mai7gjpc79aadg9m0igog970.png "/>
Partprobe Synchronization Partition Table

Cat/proc/partitions View a list of partitions

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/9D/79/wKioL1mAjJiQLb8rAAB9pQ2qdzQ034.png "title=" Screenshot from 2017-08-01 14-36-32.png "alt=" Wkiol1majjiqlb8raab9pq2qdzq034.png "/>


File system

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/9D/79/wKiom1mAjXri5SMYAAbO44Alsyc244.png "title=" Screenshot from 2017-08-01 22-16-26.png "alt=" Wkiom1majxri5smyaabo44alsyc244.png "/>


MKFS.XFS/DEV/VDB1 formatting

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/9D/79/wKioL1mAjiXTlvhaAADEM9xxzoA446.png "title=" Screenshot from 2017-08-01 14-56-06.png "alt=" Wkiol1majixtlvhaaadem9xxzoa446.png "/>

Mount/dev/vdb1/mnt Temporary Mount
Vim/etc/fstab Permanent Mount
Writing format:
Device Mountpoint ftype defaults (mountpoint) 0 0
/dev/vdb1/mnt XFS Defaults 0
Mount-a make the recorded mount in/etc/fastab effective
650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/9D/79/wKiom1mAjoeCXbVEAADqgWJa3SY647.png "title=" Screenshot from 2017-08-01 15-00-20.png "alt=" Wkiom1majoecxbveaadqgwja3sy647.png "/>


4. Deleting a partition

Use the Umount command to lift the Mount first
Note: When the mount point is used, the mount cannot be lifted, the process needs to end with FUSER-KVM, and then the mount is lifted
Remove a partition by using the FDISK/DEV/VDB command after lifting the mount

FUSER-VM/directory View the processes used by the user

FUSER-KVM/Directory Direct delete process, can complete cancel mount

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M01/9D/79/wKiom1mAkC_DgUrTAAEIDhBP-iQ272.png "title=" Screenshot from 2017-08-01 15-24-01.png "alt=" Wkiom1makc_dgurtaaeidhbp-iq272.png "/>


5. Set the partitioning method to change the Mkdocs to GPT

The GUID partition table (GUID Partition table, abbreviation: GPT), which means "globally unique identity disk partition table", is the standard for the structural layout of the partitioned table of an entity hard disk. It is part of the Extensible Firmware Interface (EFI) standard (BIOS used by Intel to replace a personal computer) and is used instead of a 32bits in the BIOS system to store the logical block address and size information of the master boot Record (MBR) partition table. The number of partitions, GPT seems to be able to support unlimited partitions, but only 128 on the window, and the GPT partition is not divided into primary partition, logical partition, it can be understood that all are primary partitions, it is equivalent to allow you a partition of a system, 128 systems. And this is the MBR can not do, MBR only have four systems, if you want more than four partitions, it will have to sacrifice to install a system of the primary partition, that is, to replace it into a logical partition.
On security, GPT is more secure because partitioned tables are backed up, and a validation algorithm is added, and once a virus infection or misuse can be discovered in a timely manner, use a secure backup of the partition table to remediate.


On the partition capacity, GPT can identify hard disks larger than 2T, and the MBR will need to shut down the partition in use before the maximum 2t capacity changes can be made
Partoff/dev/vdb2
Parted/dev/vdb

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M02/9D/79/wKioL1mAkKeyKljnAACwKAWmD60374.png "title=" Screenshot from 2017-08-01 15-33-21.png "alt=" Wkiol1makkeykljnaacwkawmd60374.png "/>

Partition already partitioned into GPT format

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/9D/7A/wKiom1mAkirAbhHyAAF5K0k4VX0226.png "style=" float : none; "title=" screenshot from 2017-08-01 15-38-01.png "alt=" Wkiom1makirabhhyaaf5k0k4vx0226.png "/>

Unit new G,t,p

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/9D/7A/wKioL1mAkirDpnfiAABveTnz8O8004.png "style=" float : none; "title=" screenshot from 2017-08-01 15-38-50.png "alt=" Wkiol1makirdpnfiaabvetnz8o8004.png "/>

GPT format adds a partuuid globally unique identifier than MBR


6. Add a Swap partition
FDISK/DEV/VDB # #添加一个分区
650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M00/9D/7A/wKiom1mAkzjhUHAVAAGdMV0LzMk503.png "title=" Screenshot from 2017-08-01 15-57-27.png "alt=" Wkiom1makzjhuhavaagdmv0lzmk503.png "/>
Command (M for help): t
Partition Number (2, default): 2
Partition type (type L to list all types): l
Linux Swap 0657FD6D-A4AB-43C4-84E5-0933C84B4F4F
After pressing "L" to view 14 for the Linux swap partition, type select 14

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M02/9D/7A/wKiom1mAk72ALHUUAAGgO4TBARI053.png "title=" Screenshot from 2017-08-01 15-57-56.png "alt=" Wkiom1mak72alhuuaaggo4tbari053.png "/>

MKSWAP/DEV/VDB2 format into Swap type
Swapon-a/DEV/VDB2 Join Swap
Swapon-s Viewing swap partitions
650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M00/9D/7A/wKioL1mAlAmwsGijAACbr1eT9zU656.png "title=" Screenshot from 2017-08-01 15-59-10.png "alt=" Wkiol1malamwsgijaacbr1et9zu656.png "/>

Mount Mount after Setup is complete, permanent mount requires configuration of etc/fstab file

7. Change the swap under GPT to Mkdos

Cancel mount, close swap partition

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/9D/7A/wKiom1mAlNSw6d2EAAATx18VraE893.png "style=" float : none; "title=" screenshot from 2017-08-01 16-17-51.png "alt=" Wkiom1malnsw6d2eaaatx18vrae893.png "/>

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/9D/7A/wKioL1mAlNSQ99tmAACr1SMaE_M386.png "style=" float : none; "title=" screenshot from 2017-08-01 16-20-21.png "alt=" Wkiol1malnsq99tmaacr1smae_m386.png "/>

Set MBR partition

650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M00/9D/7A/wKioL1mAlNbAXICuAAIi7L0PKwM455.png "style=" float : none; "title=" screenshot from 2017-08-01 16-21-48.png "alt=" Wkiol1malnbaxicuaaii7l0pkwm455.png "/>


Creating a swap partition with an MBR partition

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M02/9D/7A/wKioL1mAlUfBLlKVAAFwUW3yyOg393.png "title=" Screenshot from 2017-08-01 16-25-34.png "alt=" Wkiol1malufbllkvaafwuw3yyog393.png "/>

Note: MBR's Linux swap partition code is 82, not the same as GPT 14


650) this.width=650; "src=" Https://s3.51cto.com/wyfs02/M02/9D/7A/wKioL1mAlc7QxjpGAAEWm2L-dVw717.png "title=" Screenshot from 2017-08-01 16-28-34.png "alt=" Wkiol1malc7qxjpgaaewm2l-dvw717.png "/>


Mount Mount after Setup is complete, permanent mount requires configuration of etc/fstab file

650) this.width=650; "src=" Https://s2.51cto.com/wyfs02/M01/9D/7A/wKiom1mAltjxuJ05AAChLV1ykII261.png "title=" Screenshot from 2017-08-01 16-50-30.png "alt=" Wkiom1maltjxuj05aachlv1ykii261.png "/>


8. Add swap with File

DD If=/dev/zero of=/swapfile bs=1m count=1000 Create a 1G size file
Mkswap/swapfile format to swap type
Swapon-a/swapfile temporarily added to swap
-p + Number change priority
Vim/etc/fstab permanently add a swap partition
Type:
/swapfile swap swap defaults,pri=1 0 0 pri priority, Priority = 1 priority mount

650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/9D/7A/wKioL1mAlpGzsoVnAAFLBCZVmPQ352.png "style=" float : none; "title=" screenshot from 2017-08-01 16-43-52.png "alt=" Wkiol1malpgzsovnaaflbczvmpq352.png "/>

Configuring permanent Mounts

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M00/9D/7A/wKioL1mAlpGwDEqYAADG0ZzDvg0124.png "style=" float : none; "title=" screenshot from 2017-08-01 16-50-38.png "alt=" Wkiol1malpgwdeqyaadg0zzdvg0124.png "/>

View status

650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M00/9D/7A/wKioL1mAlxawvAGxAABxgkD6DBU290.png "title=" Screenshot from 2017-08-01 16-53-38.png "alt=" Wkiol1malxawvagxaabxgkd6dbu290.png "/>


9. Delete Swap

first .vim/etc/fstab                Delete the swap line added in this file
Second .swapoff/swapfile       break swap file link
         swapoff/dev/vdb1      Disconnect swap disk link
Third .rm-rf/swapfile            Delete the file
fourth. Fdisk/dev/vdb               Delete a disk partition
fifth .partprobe                     Synchronization Partition Table
Sixth .swapon-s                  View swap partition status

650) this.width=650; "src=" Https://s4.51cto.com/wyfs02/M00/9D/7A/wKiom1mAl4TxyJgeAAHXOZlQR2s238.png "title=" Screenshot from 2017-08-01 17-01-00.png "alt=" Wkiom1mal4txyjgeaahxozlqr2s238.png "/>

Disk Management for Linux

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.