非交互式添加分區

非交互式添加分區

方法一

添加/deb/sdb 下的分區,其實位置為11000M,第二個分區位置為10013000M,位置千萬不能指定錯誤

parted  /dev/sdb  mkpart  primary  1  1000M
parted  /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/sdb
WARNING: 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 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
#         Start          End    Size  Type            Name
 1         2048      2000895    976M  Microsoft basic part1
 2      2001953      4000000  975.6M  Microsoft basic part2

接下來運行命令:parted  /dev/sdb < part.txt

[root@local ~]# parted  /dev/sdb < part.txt
GNU Parted 3.1
Using /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mkpart                                                          
Partition name?  []? part4                                                
File system type?  [ext2]? ext4                                          
Start? 3073                                                              
End? 4096                                                                
(parted) q                                                               
Information: You may need to update /etc/fstab.

再來查看分區情況

[root@local ~]# 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: 5368 MB, 5368709120 bytes, 10485760 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
#         Start          End    Size  Type            Name
 1         2048      2000895    976M  Microsoft basic part1
 2      2001953      4000000  975.6M  Microsoft basic part2
 3      6002688      7999487    975M  Microsoft basic part4

方法三

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

1)寫一個文本文件gdisk.txt

2)文本內容如下

[root@local ~]# cat gdisk.txt
n
     #空行
     #空行
+1G
     #空行
w
y

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

         gdisk  /dev/sdb < gdisk.txt

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

[root@local ~]# gdisk -l /dev/sdc
GPT fdisk (gdisk) version 0.8.6 
Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present 
Found valid GPT with protective MBR; using GPT.
Disk /dev/sdc: 10485760 sectors, 5.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): F227EC43-CB17-4248-9B1A-13A35CEF8E92
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 10485726
Partitions will be aligned on 2048-sector boundaries
Total free space is 6291389 sectors (3.0 GiB)
 
Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         4196351   2.0 GiB     8300  Linux filesystem

下來運行命令:gdisk  /dev/sdb < gdisk.txt

[root@local ~]# gdisk  /dev/sdb < gdisk.txt
GPT fdisk (gdisk) version 0.8.6
 
Partition table scan:
  MBR: protective
  BSD: not present
  APM: not present
  GPT: present
 
Found 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 EXISTING
PARTITIONS!! 
Do you want to proceed? (Y/N): OK; writing new GUID partition table (GPT) to /dev/sdb.
The operation has completed successfully.
[root@local ~]#

再來查看分區情況

[root@local ~]# gdisk -l /dev/sdb
GPT fdisk (gdisk) version 0.8.6
[……]
Total free space is 2394845 sectors (1.1 GiB)
 
Number  Start (sector)    End (sector)  Size       Code  Name
   1            2048         2000895   976.0 MiB   0700  part1
   2         2001953         4000000   975.6 MiB   0700  part2
   3         6002688         7999487   975.0 MiB   0700  part4
   4         7999488        10096639   1024.0 MiB  8300  Linux filesystem
[root@local ~]#

可以看到已經添加成功

 

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

原創文章,作者:linux is not unix,如若轉載,請注明出處:http://www.www58058.com/74074

(2)
linux is not unixlinux is not unix
上一篇 2017-04-24 19:11
下一篇 2017-04-24 19:13

相關推薦

  • N25-第16周博客作業

    1、源碼編譯安裝LNMP架構環境;     安裝nginx:      1)安裝依賴包 ]# yum groupinstall “Development Tools” “Development Libraries” -y ]# yum install wget openssl-devel ncurses-de…

    2017-05-21
  • while until 循環用法和 case 條件base編程

    寫一個腳本: (1)能接受四個參數:start、stop、restart、status 輸入start輸出starting,腳本名為finished (2)其它任意參數均報錯退出 #!bin/bash #author:jian #date:2017-11-12 #discription: read -p “please input a strin…

    Linux干貨 2017-11-14
  • 十個讓你變成糟糕的程序員的行為

    之前本站發表過《優秀程序員的十個習慣》以及《程序員需要具備的基本技能》,那是我們需要去學習和培養的。這里,我們主要討論十個糟糕程序員的特征,主要是需要讓我們去避免和小心的。 1) 情緒化的思維 如果你開始使用不同顏色的眼光來看待這個世界的話,那么你可能會成為一個很糟糕的程序員。情緒化的思維或態度很有可能會把自己變成一個怪物。相信你經??梢钥吹胶芏嗪茉愀獾某绦颉?/p>

    Linux資訊 2015-04-03
  • 使用yum源碼編譯安裝程序

    需要的安裝包:httpd-2.2.29.tar.bz2 1、安裝develpment tools     yum groupinstall "Development Tools" 2、下載服務器中的http源安裝包到本地,然后解壓到指定文件夾中 lftp 10.1.0.1:/pub/Sources/…

    Linux干貨 2016-08-24
  • 關于綁定與不綁定CPU的對比

        此文嚴格意義上說,我沒有很大的把握,其中關于CPU調度域的概念現在還有些混淆,但還是發出來,希望能做點鋪路的貢獻吧。    另外CPU調度域的原理我沒辦法自己寫,能力尚淺, 只能將IBM知識庫 和 另一位博主的文章摘錄如下,并添加了些幫助理解的圖片,希望能幫助到初學者。 …

    Linux干貨 2016-05-03
  • N26-第二周

    一、文件管理類命令 pwd:顯示工作目錄 cd:切換目錄 cd [dir] cd: 切換回家目錄;注意:bash中, ~表示家目錄; cd ~:切換回自己的家目錄 cd ~USERNAME:切換至指定用戶的家目錄; cd -:在上一次所在目錄與當前目錄之間來回切換; 相關的環境變量 $PWD:當前工作目錄 $OLDPWD:上一次的工作目錄 file:查看文件…

    Linux干貨 2017-03-07

評論列表(1條)

  • renjin
    renjin 2017-04-28 10:04

    主要介紹了一種很好用的linux分區方法——非交互式分區,內容介紹的非常好,也很詳細,排版很好, 由其是像這樣的分區方式( parted /dev/sdb < part.txt)提高了分區時的安全性。排版也非常的好,加油!

欧美性久久久久