Study concluded the fourth

1, describes what GPT is how it should use

Linux disk partitions into MBR and GPT.

MBR called the Master Boot Record, the master boot record, partition is the traditional mechanisms used in the vast majority of PC BIOS used equipment.

MBR partition features:

1, MBR supports 32-bit and 64-bit system

     2, MBR supports a limited number of partitions

     3, MBR only supports 2T hard drive, the hard disk will exceed 2T only with 2T space.

GPT (full name GUID Partition Table) partition for the globally unique partition table, partition is a relatively new mechanism to address the many shortcomings MBR

GPT partition features:

1, support for disk exceeds 2T (64-bit addressing). Fdisk can only create a maximum partition size 2TB

     2, backward compatible with MBR

     3, can be used on UEFI-supported hardware (Intel proposed to replace the BIOS)

4, the system 64 must be used

5, Mac, Linux, Windows7 / 8 64bit, windows Server2008 64bits system can support GPT partition format

GPT disk partition using parted tool to achieve:

Parted usage commonly used options:

Usage: parted [option] ... [equipment [command [argument] ...] ...]

     The command with a parameter for the device. If there is no command appears, it runs in interactive mode.

Help options:

    -h, - help show this help

    -l, --list lists partition information for all devices

    -I, --interactive necessary is that the user is prompted

    -s, --script never prompt the user

    -v, --version display version

     Operation command:

        Minot # for a simple file system check

        cp [FROM-DEVICE] FROM-MINOR TO-MINOR # copied to another file system partition

        help [COMMAND] # print general help information, or information about the command

        mklable Label Type # to create a new disk label (partition table)

        mkfs MINOR # Create a file system type type "file system type" file system MINOR

        mkpart partition type [type of file system] START END to create a partition #

        mkpartfs partition type file system type START END # create a partition with a file system

        # move MINOR START END move partition number MINOR

        name MINOR name will be numbered as # MINOR partition named "name"

        print [MINOR] # print the partition table, partition or 

Exit the program quit # 

Lost rescue START END # save Near the "starting point" and "end point" of partition 

resize MINOR START END MINOR number is located at # change the partition size of the file system 

rm MINOR # delete partition number MINOR 

select the device you want to edit device # 

set MINOR flag status change number # sign partition MINOR

Example:

Step 1, using parted tool to create disk partitions on the device / dev / sdb

Copy the code
 1 [root@localhost ~]# parted /dev/sdb
 2 
 3 GNU Parted 3.1
 4 
 5 Using /dev/sdb
 6 
 7 Welcome to GNU Parted! Type 'help' to view a list of commands.
 8 
 9 (parted)
10 
11  
Copy the code

 

Step 2, we need to create a partition table (can use the help command parted print help information):

Copy the code
(parted) mklabel   

New Disk label of the type? gpt # we have to correct disk partition larger than 2TB, you should use the partition table gpt mode, enter a carriage return gpt)                                            

(parted) mkpart 

Partition name? []? myNewGPT # input to create a new district name 

file system type [ext2] ext4 # enter the file system to create the type of information, if ext2 type can simply press the enter key??              

Start 0 # enter the partition's starting point? 

End 5G # input partition termination points;? GPT different partitions and MBR partition, there can be entered directly as a starting point from 0 to 5G size 

warning:. the resulting partition is not properly aligned for best performance # here to warn the new partition will format the partition contents 

? ignore / Cancel I # ignore / cancel                                                       

(parted)   
Copy the code

 

 

Step 3, we have created a partition, use the following command to print out the print look                                                    

Copy the code
(parted) print                                                            

Model: VMware, VMware Virtual S (scsi)

Disk /dev/sdb: 21.5GB

Sector size (logical/physical): 512B/512B

Partition Table: gpt

Disk Flags:

Number  Start   End     Size    File system  Name      Flags

 1      17.4kB  5000MB  5000MB               myNewGPT

 

(parted)
Copy the code

 

 

Step 4, if the partition is wrong, you can use the rm command to delete the partition, followed by partition number, for example, we want to remove the above partition 1, and then print the results after deletion

Copy the code
(parted) rm 1

(parted) print                                                           

Model: VMware, VMware Virtual S (scsi)

Disk /dev/sdb: 21.5GB

Sector size (logical/physical): 512B/512B

Partition Table: gpt

Disk Flags:

Number  Start  End  Size  File system  Name  Flags

(parted)  

Copy the code

 

 

Step 5, since parted built mkfs is still not perfect, so we can use later to complete the quit command to exit parted and mkfs command system to format the partition, and this time if you use fdisk -l command to print the partition table will appear warning information, it is normal 

Copy the code
[root@localhost ~]# fdisk -l /dev/sdb                                    

WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.

 

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk label type: gpt

Disk identifier: E53CF9CC-6556-41C1-B188-25735A0928F7

 

 

#         Start          End    Size  Type            Name

1                 34      9765625    4.7G  Microsoft basic myFirstGPT
Copy the code

 

 

Step 6, the file system format

Copy the code
[root@localhost ~]# mkfs.ext4 /dev/sdb

mke2fs 1.42.9 (28-Dec-2013)

/dev/sdb is entire device, not just one partition!

Proceed anyway? (y,n) y

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

1310720 inodes, 5242880 blocks

262144 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=2153775104

160 block groups

32768 blocks per group, 32768 fragments per group

8192 inodes per group

Superblock backups stored on blocks:

         32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,

         4096000

 

Allocating group tables: done                           

Writing inode tables: done                           

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done  

 

[root@localhost ~]#
Copy the code

 

 

Step 7, mount

[root@localhost ~]# mkdir /mnt/myFirstGPT

[root@localhost ~]# mount /dev/sdb /mnt/myFirstGPT/

 

 

2. Create a 10G partition, and format for the etx4 file system. Claim:

Copy the code
[root@localhost ~]# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.23.2).

 

Changes will remain in memory only, until you decide to write them.

Be careful before using the write command.

 

Device does not contain a recognized partition table

Building a new DOS disklabel with disk identifier 0x3a339f3a.

 

Command (m for help): n

Partition type:

   p   primary (0 primary, 0 extended, 4 free)

   e   extended

Select (default p): p

Partition number (1-4, default 1): 1

First sector (2048-41943039, default 2048):

Using default value 2048

Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +10G

Partition 1 of type Linux and of size 10 GiB is set

 

Command (m for help): w
Copy the code

 

(1) block size of 2048, 20% reserve space, the volume label MYDATA

Copy the code
[root@localhost ~]# mkfs -t ext4 -b 2048 -m 20 -L MYDATA /dev/sdb1

mke2fs 1.42.9 (28-Dec-2013)

Filesystem label=MYDATA

OS type: Linux

Block size=2048 (log=1)

Fragment size=2048 (log=1)

Stride=0 blocks, Stripe width=0 blocks

655360 inodes, 5242880 blocks

1048576 blocks (20.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=273678336

320 block groups

16384 blocks per group, 16384 fragments per group

2048 inodes per group

Superblock backups stored on blocks:

    16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816, 1327104,

    2048000, 3981312

 

Allocating group tables: done                           

Writing inode tables: done                           

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done  

 

[root@localhost ~]#
Copy the code

 

(2) Mount / mydata directory, to ban the program to run automatically when the mount, and does not update the file access time stamps

[root@localhost ~]# mkdir /mydata

[root@localhost ~]# mount -o noatime,noexec /dev/sdb1 /mydata

 

(3) can be switched automatically mount

Copy the code
[root@localhost ~]# blkid /dev/sdb1

/dev/sdb1: LABEL="MYDATA" UUID="af467f45-8b5c-426f-9aa6-6327e0a4e064" TYPE="ext4"

[root@localhost ~]# vim /etc/fstab

UUID=af467f45-8b5c-426f-9aa6-6327e0a4e064 /mydata                 ext4    defaults        0 0

[root@localhost ~]# mount –a
Copy the code

 

 

3, create a swap partition size for the 1G and enable

Copy the code
[root@localhost ~]# fdisk /dev/sdb

Welcome to fdisk (util-linux 2.23.2).

 

Changes will remain in memory only, until you decide to write them.

Be careful before using the write command.

 

 

Command (m for help): n

Partition type:

   p   primary (1 primary, 0 extended, 3 free)

   e   extended

Select (default p): p

Partition number (2-4, default 2): 2

First sector (20973568-41943039, default 20973568):

Using default value 20973568

Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039): +1G

Partition 2 of type Linux and of size 1 GiB is set

 

Command (m for help): t

Partition number (1,2, default 2): 2

Hex code (type L to list all codes): 82

Changed type of partition 'Linux' to 'Linux swap / Solaris'

 

Command (m for help): w

The partition table has been altered!

 

Calling ioctl() to re-read partition table.

 

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.

The kernel still uses the old table. The new table will be used at

the next reboot or after you run partprobe(8) or kpartx(8)

Syncing disks.

[root@localhost ~]# fdisk -l /dev/sdb

 

Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk label type: dos

Disk identifier: 0x3a339f3a

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1            2048    20973567    10485760   83  Linux

/dev/sdb2        20973568    23070719     1048576   82  Linux swap / Solaris

[root@localhost ~]# mkswap /dev/sdb2

[root@localhost ~]# swapon /dev/sdb3

 
Copy the code

 

4, calculates scripting / etc / passwd file 10 and the user 20 of the user id and

Copy the code
#!/bin/bash

#fileName addId.sh

#author gongxu

#data 2019/12/9

id1=$(head -10  /etc/passwd | tail -1  | cut  -d:  -f3)
id2=$(head -20   /etc/passwd | tail -1  | cut  -d:  -f3)

id_sum=$[$id1+$id2]

echo “id_sum=$id_sum”

执行脚本:

 [root@localhost ~]# bash .addId.sh

“id_sum=1008”
Copy the code

 

 

5, save the current host name to hostName variable, if the host name is empty or is localhost.localdomain will be set to www.magedu.com

hostName=$(hostname)

[ -z "$hostName" -o "$hostName" == "localhost.localdomain" -o "$hostName" == "localhost" ] && hostname www.magedu.com           

 

                                

                                           

 

6, scripting, command line parameters into a user name, id judgment of even or odd

Copy the code
#! / bin / bash 

# 
the If [$ # -eq 1]; the then! 

  echo "Please the INPUT AT lessest One userName" 

  Exit 2 

fi 

$ uid = grep "^ $ 1 \>" / etc / passwd | Cut -d: - f3 

$ 2% = $ UID uid_yu 

the If uid_yu -eq $ 0; the then 

  echo "$ ID No. 1 is even" 

the else 

  echo "$ ID No. 1 is an odd number" 

Fi         
Copy the code

 7, lvm basic applications and extend down to achieve.

Basic use LVM refer to this blog post LVM

 

Guess you like

Origin www.cnblogs.com/yurong001122/p/11222913.html