非互動式添加分區,互動式添加分區

來源:互聯網
上載者:User

非互動式添加分區,互動式添加分區

 

非互動式添加分區

方法一

添加/deb/sdb 下的分區,其實位置為1到1000M,第二個分區位置為1001至3000M,位置千萬不能指定錯誤

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

 

方法二

(1)將你要在parted命令列輸入的命令實現寫入一個文字檔,比如叫做part.txt

(2)然後part.txt的內容類別似於這樣

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

(3)然後用類似如下命令實現自動分區:

  parted /dev/sdb < part.txt

首先來查看/dev/sdb現有分區情況

[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 

接下來運行命令:

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. 

再來查看分區情況

[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

  

 

方法三

類似方法二,不過使用gdisk命令

(1)寫一個文字檔gdisk.txt

(2)編輯分區用到的檔案

[root@local ~]# cat gdisk.txtn    ##空行,但必須有    ##空行,但必須有+1G    ##空行,但必須有wy 

(3)然後用類似如下命令實現自動分區:

gdisk /dev/sdb < gdisk.txt

首先來查看/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

下來運行命令:

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. 

再來查看分區情況

[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

可以看到已經添加成功

fdisk也可以通過這種方法實現非互動是分區

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.