parted分区和挂载及非交互式操作

author : headsen  chen   

date : 2017-11-17  09:45:36 

个人原创,转载请注明作者,出处,否则依法追究法律责任

 

1,将磁盘上原有的分区删除掉:

    进入:#parted   /dev/sdb

    查看:(parted)p

    删除:(parted)rm  1

              (parted)rm  2

 2,将磁盘格式变成gpt的格式(因为parted只能针对gpt格式的磁盘进行操作)

   转换:(parted) mklabel  gpt

   分区:(parted) mkpart  primary  1  500                  (分第一个主分区500MB)

   分区:(parted) mkpart  primary  501  1000              (分第二个主分区500MB)

   分区:(parted) mkpart  logical  1001  2000              (分第三个逻辑分区1000MB)  (parted的逻辑分区不用先分扩展分区,直接一步到位)

   查看:(parted) p

   退出:(parted)quit             ( parted分区自动保存,不用手动保存 )

3,格式化已经分好的区

   # mkfs -t ext4 /dev/sdb1

4,挂载

  # mount  /dev/sdb1 /mnt

5,开机自动挂载:

 # echo  “/dev/sdb1 /mnt ext4 defaults 0 0”  >>/etc/fstab

 

 

非交互式parted分区命令

------------------------------------------------------------------------------------------------------------------------------------

[root@localhost 桌面]# parted /dev/sdb mklabel gpt 

 

[root@localhost 桌面]# parted /dev/sdb mkpart primary 1 500
[root@localhost 桌面]# parted /dev/sdb mkpart primary 501 1000 

[root@localhost 桌面]# parted /dev/sdb mkpart logical 1001 2000 

[root@localhost 桌面]# parted /dev/sdb p

...

Number    Start    End         Size        File       system Name      标志
  1       1049kB   500MB     499MB    primary
  2        501MB   1000MB   499MB    primary
  3      1001MB   2000MB   998MB    logical

[root@localhost 桌面]# mkfs -t ext4 /dev/sdb1

[root@localhost 桌面]# mkfs -t ext4 /dev/sdb2

[root@localhost 桌面]# mkfs -t ext4 /dev/sdb3

[root@localhost 桌面]# mount /dev/sdb1 /a
[root@localhost 桌面]# mount /dev/sdb2 /b
[root@localhost 桌面]# mount /dev/sdb3 /c
[root@localhost 桌面]# touch /a/a{1..100}
[root@localhost 桌面]# touch /b/b{1..100}
[root@localhost 桌面]# touch /c/c{1..100}
[root@localhost 桌面]# ls /a
a1 a16 a23 a30 a38 a45 a52 a6 a67 a74 a81 a89 a96
a10 a17 a24 a31 a39 a46 a53 a60 a68 a75 a82 a9 a97
a100 a18 a25 a32 a4 a47 a54 a61 a69 a76 a83 a90 a98
a11 a19 a26 a33 a40 a48 a55 a62 a7 a77 a84 a91 a99
a12 a2 a27 a34 a41 a49 a56 a63 a70 a78 a85 a92 lost+found
a13 a20 a28 a35 a42 a5 a57 a64 a71 a79 a86 a93
a14 a21 a29 a36 a43 a50 a58 a65 a72 a8 a87 a94
a15 a22 a3 a37 a44 a51 a59 a66 a73 a80 a88 a95
[root@localhost 桌面]# ls /b
b1 b16 b23 b30 b38 b45 b52 b6 b67 b74 b81 b89 b96
b10 b17 b24 b31 b39 b46 b53 b60 b68 b75 b82 b9 b97
b100 b18 b25 b32 b4 b47 b54 b61 b69 b76 b83 b90 b98
b11 b19 b26 b33 b40 b48 b55 b62 b7 b77 b84 b91 b99
b12 b2 b27 b34 b41 b49 b56 b63 b70 b78 b85 b92 lost+found
b13 b20 b28 b35 b42 b5 b57 b64 b71 b79 b86 b93
b14 b21 b29 b36 b43 b50 b58 b65 b72 b8 b87 b94
b15 b22 b3 b37 b44 b51 b59 b66 b73 b80 b88 b95
[root@localhost 桌面]# ls /c
c1 c16 c23 c30 c38 c45 c52 c6 c67 c74 c81 c89 c96
c10 c17 c24 c31 c39 c46 c53 c60 c68 c75 c82 c9 c97
c100 c18 c25 c32 c4 c47 c54 c61 c69 c76 c83 c90 c98
c11 c19 c26 c33 c40 c48 c55 c62 c7 c77 c84 c91 c99
c12 c2 c27 c34 c41 c49 c56 c63 c70 c78 c85 c92 lost+found
c13 c20 c28 c35 c42 c5 c57 c64 c71 c79 c86 c93
c14 c21 c29 c36 c43 c50 c58 c65 c72 c8 c87 c94
c15 c22 c3 c37 c44 c51 c59 c66 c73 c80 c88 c

[root@localhost 桌面]# echo "/dev/sdb1 /a ext4 defaults 0 0" >>/etc/fstab
[root@localhost 桌面]# echo "/dev/sdb2 /b ext4 defaults 0 0" >>/etc/fstab
[root@localhost 桌面]# echo "/dev/sdb3 /c ext4 defaults 0 0" >>/etc/fstab

 

 

posted @ 2017-11-17 10:12 开始认识 阅读(...) 评论(...) 编辑 收藏