Add partitions in non-interactive mode and add partitions in interactive mode

Source: Internet
Author: User
Tags hex code

Add partitions in non-interactive mode and add partitions in interactive mode

 

Add partitions in non-interactive mode

Method 1

Add a partition under/deb/sdb, in fact, the location is 1 to 1000 M, the second partition location is 1001 to 3000 M, the location cannot be specified Error

parted /dev/sdb mkpart primary 1 1000Mparted /dev/sdb     mkpart     primary 1001    3000M

 

Method 2

(1 write the command you want to input in the partedcommand line into a file, such as part.txt

(2 after part.txt, the content is similar to this

    [root@local ~]# cat part.txt    mkpart        part4        ext4            3073        4096        q      

(3) Use a command similar to the following to implement automatic partitioning:

  parted /dev/sdb < part.txt

First, check the current/dev/sdb partitions.

[root@local ~]# fdisk -l /dev/sdbWARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.Disk /dev/sdb: 5368 MB, 5368709120 bytes, 10485760 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: gpt# Start End Size Type Name1 2048 2000895 976M Microsoft basic part12 2001953 4000000 975.6M Microsoft basic part2 

Run the following command:

parted /dev/sdb < part.txt
[root@local ~]# parted /dev/sdb < part.txtGNU Parted 3.1Using /dev/sdbWelcome to GNU Parted! Type 'help' to view a list of commands.(parted) mkpartPartition name? []? part4File system type? [ext2]? ext4Start? 3073End? 4096(parted) qInformation: You may need to update /etc/fstab. 

Check the partition information.

[root@local ~]# fdisk -l /dev/sdbWARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.Disk /dev/sdb: 5368 MB, 5368709120 bytes, 10485760 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: gpt# Start End Size Type Name1 2048 2000895 976M Microsoft basic part12 2001953 4000000 975.6M Microsoft basic part23 6002688 7999487 975M Microsoft basic part4

  

 

Method 3

Method 2 is similar, but use the gdisk command

(1.txt write a local file gdisk.txt

(2) edit the file used by the partition

[Root @ local ~] # Cat gdisk.txt n # Empty rows, but must have # Empty rows, but must have + 1G # Empty rows, but wy

(3) Use a command similar to the following to implement automatic partitioning:

gdisk /dev/sdb < gdisk.txt

First, check the current partition of/dev/sdc.

[root@local ~]# gdisk -l /dev/sdcGPT fdisk (gdisk) version 0.8.6Partition table scan:MBR: protectiveBSD: not presentAPM: not presentGPT: presentFound valid GPT with protective MBR; using GPT.Disk /dev/sdc: 10485760 sectors, 5.0 GiBLogical sector size: 512 bytesDisk identifier (GUID): F227EC43-CB17-4248-9B1A-13A35CEF8E92Partition table holds up to 128 entriesFirst usable sector is 34, last usable sector is 10485726Partitions will be aligned on 2048-sector boundariesTotal free space is 6291389 sectors (3.0 GiB)Number Start (sector) End (sector) Size Code Name1 2048 4196351 2.0 GiB 8300 Linux filesystem

Run the following command:

gdisk /dev/sdb < gdisk.txt
[root@local ~]# gdisk /dev/sdb < gdisk.txtGPT fdisk (gdisk) version 0.8.6Partition table scan:MBR: protectiveBSD: not presentAPM: not presentGPT: presentFound valid GPT with protective MBR; using GPT.Command (? for help): Partition number (4-128, default 4): 
First sector (34-10485726, default = 7999488) or {+-}size{KMGTP}: Last sector (7999488-10485726,
default = 10485726) or {+-}size{KMGTP}: Current type is 'Linux filesystem'Hex code or GUID (L to show codes, Enter = 8300): Changed type of partition to 'Linux filesystem' Command (? for help):Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTINGPARTITIONS!!Do you want to proceed? (Y/N): OK; writing new GUID partition table (GPT) to /dev/sdb.The operation has completed successfully. 

Check the partition information.

[root@local ~]# gdisk -l /dev/sdbGPT fdisk (gdisk) version 0.8.6[……]Total free space is 2394845 sectors (1.1 GiB)Number Start (sector) End (sector) Size Code Name1 2048 2000895 976.0 MiB 0700 part12 2001953 4000000 975.6 MiB 0700 part23 6002688 7999487 975.0 MiB 0700 part44 7999488 10096639 1024.0 MiB 8300 Linux filesystem

You can see that it has been added successfully.

Fdisk can also be used to achieve non-interactive partitioning.

 

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.