Linux系統——磁盤管理
一、規劃硬碟中的磁區 fdisk命令
1、作用:在互動式的操作環境中管理磁盤磁區
2、格式:fdisk [磁盤設備]
3、常用選項:
m:查看操作指令的幫助資訊
p:串列查看磁區資訊
n:新建磁區
d:洗掉磁區
t:變更磁區型別
w:保存磁區設定并退出
q:放棄磁區設定并退出
Ctrl+退格鍵:洗掉輸入的錯誤字符
4、示例:
為主機新增一塊20G的SCSI硬碟
對該硬碟進行磁區
劃分兩個主磁區,各5G,剩余空間為擴展磁區
在擴展磁區中建立兩個邏輯磁區,第一個邏輯磁區1G,型別為swap。第二個邏輯 磁區為9G。
(1)關機
(2)新增硬碟
(3)開機,查看新硬碟是否添加
(4)使用fdisk進行磁區
[root@www ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x4f3a72ac.
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): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help): p
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x4f3a72ac
Device Boot Start End Blocks Id System
Command (m for help): n
Command action
e extended 【擴展磁區】
p primary partition (1-4) 【主磁區】
p
Partition number (1-4): 1
First cylinder (1-2610, default 1): 回車
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +5G
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (655-2610, default 655): 回車
Using default value 655
Last cylinder, +cylinders or +size{K,M,G} (655-2610, default 2610): +5G
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e
Partition number (1-4): 4
First cylinder (1309-2610, default 1309): 回車
Using default value 1309
Last cylinder, +cylinders or +size{K,M,G} (1309-2610, default 2610): 回車
Using default value 2610
Command (m for help): n
Command action
l logical (5 or over) 【邏輯磁區】
p primary partition (1-4)
l
First cylinder (1309-2610, default 1309): 回車
Using default value 1309
Last cylinder, +cylinders or +size{K,M,G} (1309-2610, default 2610): +1G
Command (m for help): t
Partition number (1-5): 5
Hex code (type L to list codes): 82
Changed system type of partition 5 to 82 (Linux swap / Solaris)
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First cylinder (1441-2610, default 1441): 回車
Using default value 1441
Last cylinder, +cylinders or +size{K,M,G} (1441-2610, default 2610): 回車
Using default value 2610
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
二、大小超過2T的磁區規劃 parted命令
1、作用:規劃大小超過2T的磁區,也可用于小磁區的規劃
2、格式:parted [選項] [磁區設備]
3、互動式狀態下的常用命令:
?/help/--help:幫助
quit/q:保存退出
print/p:列印
mklabel:改變硬碟的檔案型別
mkpart:磁區
rm:洗掉某磁區,后面跟磁區號,例如:rm 3
4、示例:
為主機新增一塊20G的SCSI硬碟
對該硬碟進行磁區
將硬碟型別改為gpt
劃分三個磁區,前兩個磁區各5G,剩下的都空間都劃分給第三磁區
(1)關機
(2)新增硬碟
(3)開機,查看新硬碟是否添加
[root@www ~]# parted -l
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system 標志
1 1049kB 525MB 524MB primary ext4 啟動
2 525MB 107GB 107GB primary lvm
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system 標志
[root@www ~]# parted /dev/sdb
GNU Parted 2.1
使用 /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) help
align-check TYPE N check partition N for TYPE(min|opt) alignment
check NUMBER do a simple check on the file system
cp [FROM-DEVICE] FROM-NUMBER TO-NUMBER copy file system to another partition
help [COMMAND] print general help, or help on COMMAND
mklabel,mktable LABEL-TYPE create a new disklabel (partition table)
mkfs NUMBER FS-TYPE make a FS-TYPE file system on partition NUMBER
mkpart PART-TYPE [FS-TYPE] START END make a partition
mkpartfs PART-TYPE FS-TYPE START END make a partition with a file system
move NUMBER START END move partition NUMBER
name NUMBER NAME name partition NUMBER as NAME
print [devices|free|list,all|NUMBER] display the partition table, available devices,
free space, all found partitions, or a particular partition
quit exit program
rescue START END rescue a lost partition near START and END
resize NUMBER START END resize partition NUMBER and its file system
rm NUMBER delete partition NUMBER
select DEVICE choose the device to edit
set NUMBER FLAG STATE change the FLAG on partition NUMBER
toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER
unit UNIT set the default unit to UNIT
version display the version number and copyright
information of GNU Parted
(parted) mklabel
新的磁盤標簽型別? 【兩次tab鍵】
aix amiga bsd dvh gpt loop mac msdos pc98 sun
新的磁盤標簽型別? gpt
警告: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be
lost. Do you want to continue?
是/Yes/否/No? y
(parted) mkpart
磁區名稱? []? part1
檔案系統型別? [ext2]? ext4
起始點? 1
結束點? 5G
(parted) mkpart
磁區名稱? []? part2
檔案系統型別? [ext2]? ext4
起始點? 5G
結束點? 10G
(parted) mkpart
磁區名稱? []? part3
檔案系統型別? [ext2]? ext4
起始點? 10G
結束點? -1
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name 標志
1 1049kB 5000MB 4999MB part1
2 5000MB 10.0GB 5001MB part2
3 10.0GB 21.5GB 11.5GB part3
(parted) quit
[root@www ~]# ls -l /dev/sdb*
brw-rw----. 1 root disk 8, 16 1月 30 17:35 /dev/sdb
brw-rw----. 1 root disk 8, 17 1月 30 17:02 /dev/sdb1
brw-rw----. 1 root disk 8, 18 1月 30 17:02 /dev/sdb2
brw-rw----. 1 root disk 8, 19 1月 30 17:02 /dev/sdb3
[root@www ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
檔案系統標簽=
作業系統:Linux
塊大小=4096 (log=2)
分塊大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
305216 inodes, 1220352 blocks
61017 blocks (5.00%) reserved for the super user
第一個資料塊=0
Maximum filesystem blocks=1249902592
38 block groups
32768 blocks per group, 32768 fragments per group
8032 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
正在寫入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 21 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@www ~]# mkdir /sdb1
[root@www ~]# mount /dev/sdb1 /sdb1/
[root@www ~]# cd /sdb1/
[root@www sdb1]# echo ceshiwenjian > test.txt
[root@www sdb1]# cd
[root@www ~]# umount /sdb1/
[root@www ~]# parted /dev/sdb
GNU Parted 2.1
使用 /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start End Size File system Name 標志
1 1049kB 5000MB 4999MB ext4 part1
2 5000MB 10.0GB 5001MB part2
3 10.0GB 21.5GB 11.5GB part3
uj5u.com熱心網友回復:
這是發了一篇文章嗎uj5u.com熱心網友回復:
好像又捕捉到一個發錯的小老弟轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/7970.html
標籤:服務器
下一篇:docker埠映射問題
