parted partition command, format and mount

parted partition command
Detailed explanation of partition command Parted
1, Overview
We usually use the fdisk command as the partition tool, but now the disk is getting cheaper and the disk space is getting larger and larger. The fdisk tool has a size limit on partitions, which can only partition disks less than 2T. Now the disk space is far larger than 2T. There are two ways to solve this problem: one is to realize it through volume management, and the other is to realize the partition operation of 2T disk through Parted tool.
The disk in GPT format is equivalent to 4 * 16 bytes of the original four partition tables in the original MBR disk, leaving only the first 16 bytes, which is similar to the extended partition. After the 512 bytes of the real partition table, the GPT partition mode has no limit of four main partitions, up to 128 main partitions
2, Usage

17|[root@chenyi ~]#parted --help
Usage: parted [OPTION]... [DEVICE [COMMAND [PARAMETERS]...]...]
Apply COMMANDs with PARAMETERS to DEVICE.  If no COMMAND(s) are given, run in
interactive mode.

Options:
  -h, --help                      Show this help info
  -l, --list                      lists partition layout on all block devices
  -m, --machine                   displays machine parseable output
  -s, --script                    Never prompt users
  -v, --version                   Display version
  -a, --align=[none|cyl|min|opt]  alignment for new partitions

Command:
  align-check TYPE N                        check partition N for TYPE(min|opt)
        alignment
  help [COMMAND]                           print general help, or help on
        COMMAND
  mklabel,mktable LABEL-TYPE               create a new disklabel (partition
        table)
  mkpart PART-TYPE [FS-TYPE] START END     make a partition
  name NUMBER NAME                         name partition NUMBER as NAME
  print [devices|free|list,all|NUMBER]     display the partition table,
        available devices, free space, all found partitions, or a particular
        partition
  quit                                     exit program
  rescue START END                         rescue a lost partition near START
        and END
  
  resizepart NUMBER END                    resize partition NUMBER
  rm NUMBER                                delete partition NUMBER
  select DEVICE                            choose the device to edit
  disk_set FLAG STATE                      change the FLAG on selected device
  disk_toggle [FLAG]                       toggle the state of FLAG on selected
        device
  set NUMBER FLAG STATE                    change the FLAG on partition NUMBER
  toggle [NUMBER [FLAG]]                   toggle the state of FLAG on partition
        NUMBER
  unit UNIT                                set the default unit to UNIT
  version                                  display the version number and
        copyright information of GNU Parted

Report bugs to bug-parted@gnu.org

3. Grammatical structure
parted [option]... [device [command [parameter]...]

4. Command options
Option description
-h – help displays this help message
-l – list the partition information of all settings
-i – interactive prompts the user if necessary
-s – script never prompts the user
-v – version displays the version

5. parted operation command
parted interactive command description

  1. check NUMBER perform a simple file system check cp [FROM-DEVICE] FROM-NUMBER
    TO-NUMBER copy file system to another partition help [COMMAND] display all command help mklabel,mktable
    LABEL-TYPE create a new disk volume label (partition table) mkfs NUMBER FS-TYPE create a file system mkpart on the partition
    PART-TYPE [FS-TYPE] START END create a partition mkpartfs PART-TYPE FS-TYPE
    START END create partition and create file system move NUMBER START END move partition name NUMBER
    NAME name the partition print [devices|free|list,all|NUMBER] displays the partition table, active devices, free space and all partitions
    quit exit rescue START END repair the missing partition resize NUMBER START END modify the partition size rm
    NUMBER delete partition select DEVICE select the device to be edited set NUMBER FLAG STATE change partition mark
    toggle [NUMBER [FLAG]] switch the state of the partition table unit UNIT set the default unit Version display Version
    6. Actual operation of parted command
    ① First confirm whether there is a change command on your virtual machine. If not, download one through yum:
    Some words are as follows:
|18|[root@chenyi ~]#parted
GNU Parted 3.1
 use /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
                                                                       (parted) 

If not, download as follows:

[root@chenyi ~]#yum -y install parted

(1) For partition operation, take / dev/sdb / as an example. Use help to check the commands in parted first

|19|[root@chenyi ~]#parted /dev/sdb
GNU Parted 3.1
 use /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
                                                                       (parted) help
  align-check TYPE N                        check partition N for
        TYPE(min|opt) alignment
  help [COMMAND]                           print general help, or help
        on COMMAND
  mklabel,mktable LABEL-TYPE               create a new disklabel
        (partition table)
  mkpart PART-TYPE [FS-TYPE] START END     make a partition
  name NUMBER NAME                         name partition NUMBER as
        NAME
  print [devices|free|list,all|NUMBER]     display the partition table,
        available devices, free space, all found partitions, or a
        particular partition
  quit                                     exit program
  rescue START END                         rescue a lost partition near
        START and END
  
  resizepart NUMBER END                    resize partition NUMBER
  rm NUMBER                                delete partition NUMBER
  select DEVICE                            choose the device to edit
  disk_set FLAG STATE                      change the FLAG on selected
        device
  disk_toggle [FLAG]                       toggle the state of FLAG on
        selected device
  set NUMBER FLAG STATE                    change the FLAG on partition
        NUMBER
  toggle [NUMBER [FLAG]]                   toggle the state of FLAG on
        partition NUMBER
  unit UNIT                                set the default unit to UNIT
  version                                  display the version number
        and copyright information of GNU Parted
                                                                       (parted) 

(2) Select GPT partition mode first

(parted) mklabel gpt                                                      
warning: The existing disk label on /dev/sdb will be destroyed and all data on
this disk will be lost. Do you want to continue?
yes/Yes/no/No? yes                                                         
(parted)         

(3) Create a partition (as shown in the code)

(parted) mkpart primary
 File system type?  [ext2]? ext4
 Starting point? 0%                                                               
End point? ten%                                                              
(parted) p                                                                
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name     sign
 1      1049kB  1074MB  1073MB               primary

(parted)                           

(4) parted is saved automatically, and you can quit directly
(5) View partition

|23|[root@chenyi ~]#lsblk /dev/sdb                                        
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sdb      8:16   0   10G  0 disk 
└─sdb1   8:17   0 1023M  0 part

(6) Format

24|[root@chenyi ~]#mkfs.ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
File system label=
OS type: Linux
 Block size=4096 (log=2)
Block size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65536 inodes, 261888 blocks
13094 blocks (5.00%) reserved for the super user
 First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376
```cpp
 Insert code slice here

Allocating group tables: complete
Writing inode table: done
Creating journal (4096 blocks): complete
Writing superblocks and filesystem accounting information:

(7) Create mount directory

|26|[root@chenyi ~]#mkdir xiner

(8) Temporary mount

|29|[root@chenyi ~]#mount /dev/sdb1 xiner/

(9) View mount status

|30|[root@chenyi ~]#df -h
 file system                 Capacity used available used% Mount point
devtmpfs                 475M     0  475M    0% /dev
tmpfs                    487M     0  487M    0% /dev/shm
tmpfs                    487M  7.7M  479M    2% /run
tmpfs                    487M     0  487M    0% /sys/fs/cgroup
/dev/mapper/centos-root   87G   14G   74G   16% /
/dev/sr0                  11G   11G     0  100% /data
/dev/loop1               3.7G  3.7G     0  100% /var/ftp/centos6.8
/dev/loop0               6.6G  6.6G     0  100% /var/ftp/centos7-1611
/dev/sda1                197M  141M   57M   72% /boot
/dev/mapper/centos-home   10G   33M   10G    1% /home
tmpfs                     98M     0   98M    0% /run/user/0
/dev/sdb1                991M  2.6M  922M    1% /root/xiner

(10) Permanent mount needs to be written into the corresponding configuration file

Posted by zander213 on Wed, 11 May 2022 20:02:34 +0300