日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux 用脚本建分区,脚本创建磁盘分区

發布時間:2023/12/10 linux 52 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux 用脚本建分区,脚本创建磁盘分区 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

首先最好添加一個空白的磁盤,以免對原數據產生破壞,若果不想添加磁盤也可以,用一個里面數據無關緊要的磁盤,當然前提是必須要對該磁盤內已有的分區進行清空,方法后面第三步會有

1.先看腳本內容:

[root@localhost shell]# cat auto_fdisk.sh

#!/bin/bash

#auto fdisk shell

echo '

n

p

1

#這里的一個空格別忘了,必不可少的,這是創建分區時填寫開始柱面時的Enter,也就是使用默認柱面

+100M

n

p

2

#一個空格

+200M

n

p

3

#一個空格

+300M

n

e

4

#兩個空格

t

3

82

w' ? ?| ? ?fdisk /dev/sdc

這里我對/dev/sdc創建了3個大小分別為100M,200M,300M的主分區,然后將剩余空間給了擴展分區,并且將第三個分區類型調整為82

2.然后給該腳本賦予可執行權限,最后執行,執行結果是

[root@localhost shell]# chmod +x auto_fdisk.sh

[root@localhost shell]# ./auto_fdisk.sh

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel with disk identifier 0x0cf693d0.

Changes will remain in memory only, until you decide to write them.

After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to

switch off the mode (command 'c') and change display units to

sectors (command 'u').

Command (m for help): Command (m for help): Command action

e ? extended

p ? primary partition (1-4)

Partition number (1-4): First cylinder (1-2349, default 1): Using default value 1

Last cylinder, +cylinders or +size{K,M,G} (1-2349, default 2349):

Command (m for help): Command action

e ? extended

p ? primary partition (1-4)

Partition number (1-4): First cylinder (15-2349, default 15): Using default value 15

Last cylinder, +cylinders or +size{K,M,G} (15-2349, default 2349):

Command (m for help): Command action

e ? extended

p ? primary partition (1-4)

Partition number (1-4): First cylinder (41-2349, default 41): Using default value 41

Last cylinder, +cylinders or +size{K,M,G} (41-2349, default 2349):

Command (m for help): Command action

e ? extended

p ? primary partition (1-4)

Selected partition 4

First cylinder (80-2349, default 80): Value out of range.

First cylinder (80-2349, default 80): Using default value 80

Last cylinder, +cylinders or +size{K,M,G} (80-2349, default 2349): Using default value 2349

Command (m for help): Partition number (1-5): Hex code (type L to list codes): Changed system type of partition 3 to 82 (Linux swap / Solaris)

Command (m for help): The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

看一下執行結果

[root@localhost shell]# fdisk -l /dev/sdc

Disk /dev/sdc: 19.3 GB, 19327352832 bytes

255 heads, 63 sectors/track, 2349 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x0cf693d0

Device Boot ? ? ?Start ? ? ? ? End ? ? ?Blocks ? Id ?System

/dev/sdc1 ? ? ? ? ? ? ? 1 ? ? ? ? ?14 ? ? ?112423+ ?83 ?Linux

/dev/sdc2 ? ? ? ? ? ? ?15 ? ? ? ? ?40 ? ? ?208845 ? 83 ?Linux

/dev/sdc3 ? ? ? ? ? ? ?41 ? ? ? ? ?79 ? ? ?313267+ ?82 ?Linux swap / Solaris

/dev/sdc4 ? ? ? ? ? ? ?80 ? ? ? ?2349 ? ?18233775 ? ?5 ?Extended

3.最后如果想重新創建或者使開頭提到的情況,需要把一個已有分區清空,可以這樣

[root@localhost shell]# dd if=/dev/zero of=/dev/sdc bs=512 count=1

1+0 records in

1+0 records out

512 bytes (512 B) copied, 0.0178267 s, 28.7 kB/s

內核重新讀取后再看一下此時的分區情況

[root@localhost shell]# partprobe

Warning: WARNING: the kernel failed to re-read the partition table on /dev/sdb (Device or resource busy). ?As a result, it may not reflect all of your changes until after reboot.

Warning: Unable to open /dev/sr0 read-write (Read-only file system). ?/dev/sr0 has been opened read-only.

Warning: Unable to open /dev/sr0 read-write (Read-only file system). ?/dev/sr0 has been opened read-only.

Error: Invalid partition table - recursive partition on /dev/sr0.

[root@localhost shell]# fdisk -l /dev/sdc

Disk /dev/sdc: 19.3 GB, 19327352832 bytes

255 heads, 63 sectors/track, 2349 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000

好了,就是這樣!

閱讀(821) | 評論(0) | 轉發(0) |

總結

以上是生活随笔為你收集整理的linux 用脚本建分区,脚本创建磁盘分区的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。