非交互式添加分区

非交互式添加分区

方法一

添加/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.178linux.com/74074

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

相关推荐

  • grub详解

    #GRUB详解 grub基础概念 前面的开机过程我们知道:按照BIOS定义的硬件设备启动顺序,第一启动设备中的MBR去读取boot loader。boot loader功能很强大,要重新自检硬件设备,开始有一个菜单供用户选择系统或者内核版本,还要加载内核将内核解压到RAM中并执行,最后将控制权移交给内核。屈屈446个字节怎么让它完成那么多功能。所以Linux…

    Linux干货 2016-11-25
  • Linux程序包管理(rpm、yum、make)

    linux系统程序安装的方法有rpm yum 以及make手动编译3种方法: rpm这个机制最早由Redhat公司开发出来,后来由于实在好用,所以被很多发行版所使用作为软件安装的管理方式。不过由于使用RPM安装软件时有时会涉及到文件的依赖信,此时需要手动去逐个安装被依赖的包操作起来十分复杂,于是yum这种线上升级的机制便出现了,它会自己主动解决各文件的依赖关…

    Linux干货 2017-10-02
  • 马哥教育网络班22期+第1周课程练习

    1.描述计算机的组成及其功能 计算机的组成及各功能:  计算机主要由硬件、操作系统、软件三大部分组成 硬件 :主要由五部分组成 :运算器:主要是做数据运算              控制器:控制计算机各部件的协调和寻址操作         …

    Linux干货 2016-08-15
  • 马哥教育-第一周作业

    第一部分:计算机组成及功能 电子真空管的出现促使了计算机的诞生; 根据冯●诺依曼的哲学思想,计算机的组成分为五大部分。分别为: 1.     运算器 2.     控制器 3.     存储器 4.   &nb…

    Linux干货 2016-12-04
  • class8 文本处理工具sed和vim编辑器

    一、处理文本的工具sed     Stream EDitor,  行编辑器     sed是linux上一款比较重要的流编辑器。     特点:一次处理一行内容,处理完成后,把缓冲区的内容送往屏幕。这样不断重复,直到文件末尾。 &…

    Linux干货 2016-08-11
  • 文件系统层次标准FHS

    FHS针对目录树架构仅定义出三层目录下应该放置哪些数据,分别是下面三个目录: /(根目录):与开机系统有关; /usr(unix software resource):与软件安装执行有关; /var(variable):与系统运作过程有关。   下面分别对上述三层目录进行详细的阐述。   (1) /(根目录)   根目录是整个系统最重要的一个目录,…

    Linux干货 2016-10-19

评论列表(1条)

  • renjin
    renjin 2017-04-28 10:04

    主要介绍了一种很好用的linux分区方法——非交互式分区,内容介绍的非常好,也很详细,排版很好, 由其是像这样的分区方式( parted /dev/sdb < part.txt)提高了分区时的安全性。排版也非常的好,加油!