非交互式添加分区

非交互式添加分区

方法一

添加/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

相关推荐

  • N26-第四周博客

    1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。 [root@localhost skel]# cp -r /etc/skel /home/tuser1[root@localhost skel]# chmod -R go=— /home/tuser1 2、编辑/etc/…

    系统运维 2017-02-08
  • SELinux在httpd服务端中的使用

    一、启用SELinux策略并安装httpd服务,改变网站的默认主目录为/website,添加SELinux文件标签规则,使网站可访问(以CentOS7系统操作) 1、首先查看本系统是否已经安装httpd服务 2、查看httpd的配置文件所在路径 3、创建主目录为/website与网页文件"index.html",并更改httpd服务为该路…

    Linux干货 2016-09-16
  • Linux批量创建用户、passwd、shadow、组管理、group、gshadow、默认配置文件login.defs、切换用户su、提升权限(二)

    Linux批量创建用户、passwd、shadow、组管理、group、gshadow、默认配置文件login.defs、切换用户su、提升权限(二) Linux对于权限的管理非常完善,其强大的权限管理机制体现了它的魅力之处,让无数人为之操碎了心。Linux中的权限既能放也能收,既可以管理整个组的权限,也可以管理单个用户的权限,正是因为有了ACL的加入变得非…

    Linux干货 2016-08-06
  • class7 文本处理命令及文本处理工具grep

    一、文本处理命令   1、文件内容查看cat, tac,rev     cat [OPTION]… [FILE]…      正序查看文本文件          -E:  显示行结束符$ [roo…

    Linux干货 2016-08-08
  • RAID各级别的特性及使用介绍(8.3博客作业)

    RAID各级别的特性及使用介绍 介绍: 独立硬盘冗余阵列(RAID:Redundant Array of Independent Disks),旧称廉价磁盘冗余阵列,简称磁盘阵列。 组成: 多块磁盘,RAID控制器(硬件RAID、软件RAID)     硬件RAID:自带CPU的RAID卡,不消耗服务器资源,可通过备份…

    Linux干货 2016-07-16
  • MariaDB数据类型总结

        数据类型是数据的一种属性,它决定了数据的存储格式、有效范围及其它相应的限制。MariaDB的数据类型包括:字符型、整型、浮点值、日期时间型、布尔型及内建类型。 一、字符型     1、CHAR和VARCHAR类型     &nbsp…

    Linux干货 2015-06-30

评论列表(1条)

  • renjin
    renjin 2017-04-28 10:04

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