############# 磁盘管理 ################
1.mbr
mpt
硬盘有效性标识
主分区
扩展分区
逻辑分区
######## 2.磁盘管理命令 ##########
fdisk -l ##系统中正在挂载的磁盘
df -Th ##系统中正在挂载的磁盘设备
blkid ##系统中可以挂载的磁盘设备
############ 分区划分 ########
mbr分区
fdisk 磁盘名
[root@foundation34 mnt]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
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 ##删除分区
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
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 ##修改分区功能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): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (2048-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +4G
Partition 1 of type Linux and of size 4 GiB is set
Command (m for help): wq
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
############################################################
先有硬盘分区,后有系统
446个字节剩余66个字节,包括64个字节主分区表,最后两个字节55aa硬盘的有效期标识
######### 3.文件系统 ###########
vfat ext xfs ntfs
开源
[root@foundation34 ~]# partprobe ##同步分区表
[root@foundation34 ~]# cat /proc/partitions ##查看系统能识别的分区
mkfs.xfs /dev/vdb1 ##格式化,给磁盘添加文件系统
mount /dev/vdb1 /mnt ##临时挂载
vim /etc/fstab ##永久挂载
编写格式:
device mountpoint ftype defaults(mountpoint) 0 0
/dev/vdb1 /mnt xfs defaults 0 0
设备 挂载目录 文件系统类型 挂载参数 不检查 不备份
mount -a ##使/etc/fastab中记录的挂载生效
删除分区
先使用umount命令解除挂载
注:当挂载点被使用时,无法解除挂载,需要用fuser -kvm结束使用的进程,然后进行解除挂载
解除挂载之后,使用fdisk /dev/vdb命令 删除分区
设定分区方式,将mkdocs 改为 gpt
更改之前需要把正在使用的分区关闭,才可以进行更改
partoff /dev/vdb1
parted /dev/vdb
[root@server34 ~]# parted /dev/vdb
GNU Parted 3.1
Using /dev/vdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel
New disk label type? gpt
Warning: The existing disk label on /dev/vdb will be destroyed and all data on this disk will be lost. Do you
want to continue?
Yes/No? y
(parted) quit
Information: You may need to update /etc/fstab.
更改分区方式为gpt,后续分区和mbr一样。
################ 添加swap分区 ###########
fdisk /dev/vdb ##添加一个分区
[root@server34 Desktop]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (2048-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +4G
Partition 1 of type Linux and of size 4 GiB is set
Command (m for help): T
Selected partition 1
Hex code (type L to list all codes): L
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx
5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data
6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility
8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt
9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access
a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT
f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary
16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT
1e Hidden W95 FAT1 80 Old Minix
Hex code (type L to list all codes): 82
Changed type of partition 'Linux' to 'Linux swap / Solaris'
Command (m for help): wq
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@server34 Desktop]# partprobe ##同步分区表
[root@server34 Desktop]# mkswap /dev/vdb1 ##格式化成swap类型
mkswap: /dev/vdb1: warning: wiping old swap signature.
Setting up swapspace version 1, size = 4194300 KiB
no label, UUID=2a5d4446-d180-4a56-b83e-afcccace8d51
[root@server34 Desktop]# swapon -a /dev/vdb1 ##加入swap
[root@server34 Desktop]# swapon -s
Filename Type Size Used Priority
/dev/vdb1 partition 4194300 0 -1
用文件来添加swap
dd if=/dev/zero of=/swapfile bs=1M count=1000 ##创建一个1G大小的文件
mkswap /swapfile ##格式化为swap类型
swapon -a /swapfile -p 数字 ##临时添加到swap里,更改优先级
vim /etc/fstab ##永久添加swap分区
类型:
/swapfile swap swap defaults,pri=1 0 0 #pri优先级
[root@server34 Desktop]# dd if=/dev/zero of=/swwapfile bs=1M count=1000
m1000+0 records in
1000+0 records out
1048576000 bytes (1.0 GB) copied, 16.8181 s, 62.3 MB/s
[root@server34 Desktop]# mkswap /swwapfile
Setting up swapspace version 1, size = 1023996 KiB
no label, UUID=2cdb0d2c-08ba-4bae-bb95-26f0af3b0e75
[root@server34 Desktop]# swapon -a /swwapfile
swapon: /swwapfile: insecure permissions 0644, 0600 suggested.
[root@server34 Desktop]# swapon -s
Filename Type Size Used Priority
/dev/vdb1 partition 4194300 0 -1
/swwapfile file 1023996 0 -2
9.删除swap
vim /etc/fstab ##删除此文件中添加的swap行
swapoff /swapfile ##断开swap文件链接
swapoff /dev/vdb1 ##断开swap磁盘链接
rm -rf /swapfile ##删除文件
fdisk /dev/vdb ##删除磁盘分区
1.mbr
mpt
硬盘有效性标识
主分区
扩展分区
逻辑分区
######## 2.磁盘管理命令 ##########
fdisk -l ##系统中正在挂载的磁盘
df -Th ##系统中正在挂载的磁盘设备
blkid ##系统中可以挂载的磁盘设备
############ 分区划分 ########
mbr分区
fdisk 磁盘名
[root@foundation34 mnt]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
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 ##删除分区
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
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 ##修改分区功能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): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (2048-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +4G
Partition 1 of type Linux and of size 4 GiB is set
Command (m for help): wq
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
############################################################
先有硬盘分区,后有系统
446个字节剩余66个字节,包括64个字节主分区表,最后两个字节55aa硬盘的有效期标识
######### 3.文件系统 ###########
vfat ext xfs ntfs
开源
[root@foundation34 ~]# partprobe ##同步分区表
[root@foundation34 ~]# cat /proc/partitions ##查看系统能识别的分区
mkfs.xfs /dev/vdb1 ##格式化,给磁盘添加文件系统
mount /dev/vdb1 /mnt ##临时挂载
vim /etc/fstab ##永久挂载
编写格式:
device mountpoint ftype defaults(mountpoint) 0 0
/dev/vdb1 /mnt xfs defaults 0 0
设备 挂载目录 文件系统类型 挂载参数 不检查 不备份
mount -a ##使/etc/fastab中记录的挂载生效
删除分区
先使用umount命令解除挂载
注:当挂载点被使用时,无法解除挂载,需要用fuser -kvm结束使用的进程,然后进行解除挂载
解除挂载之后,使用fdisk /dev/vdb命令 删除分区
设定分区方式,将mkdocs 改为 gpt
更改之前需要把正在使用的分区关闭,才可以进行更改
partoff /dev/vdb1
parted /dev/vdb
[root@server34 ~]# parted /dev/vdb
GNU Parted 3.1
Using /dev/vdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel
New disk label type? gpt
Warning: The existing disk label on /dev/vdb will be destroyed and all data on this disk will be lost. Do you
want to continue?
Yes/No? y
(parted) quit
Information: You may need to update /etc/fstab.
更改分区方式为gpt,后续分区和mbr一样。
################ 添加swap分区 ###########
fdisk /dev/vdb ##添加一个分区
[root@server34 Desktop]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (2048-20971519, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +4G
Partition 1 of type Linux and of size 4 GiB is set
Command (m for help): T
Selected partition 1
Hex code (type L to list all codes): L
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx
5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data
6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility
8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt
9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access
a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT
f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary
16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT
1e Hidden W95 FAT1 80 Old Minix
Hex code (type L to list all codes): 82
Changed type of partition 'Linux' to 'Linux swap / Solaris'
Command (m for help): wq
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@server34 Desktop]# partprobe ##同步分区表
[root@server34 Desktop]# mkswap /dev/vdb1 ##格式化成swap类型
mkswap: /dev/vdb1: warning: wiping old swap signature.
Setting up swapspace version 1, size = 4194300 KiB
no label, UUID=2a5d4446-d180-4a56-b83e-afcccace8d51
[root@server34 Desktop]# swapon -a /dev/vdb1 ##加入swap
[root@server34 Desktop]# swapon -s
Filename Type Size Used Priority
/dev/vdb1 partition 4194300 0 -1
用文件来添加swap
dd if=/dev/zero of=/swapfile bs=1M count=1000 ##创建一个1G大小的文件
mkswap /swapfile ##格式化为swap类型
swapon -a /swapfile -p 数字 ##临时添加到swap里,更改优先级
vim /etc/fstab ##永久添加swap分区
类型:
/swapfile swap swap defaults,pri=1 0 0 #pri优先级
[root@server34 Desktop]# dd if=/dev/zero of=/swwapfile bs=1M count=1000
m1000+0 records in
1000+0 records out
1048576000 bytes (1.0 GB) copied, 16.8181 s, 62.3 MB/s
[root@server34 Desktop]# mkswap /swwapfile
Setting up swapspace version 1, size = 1023996 KiB
no label, UUID=2cdb0d2c-08ba-4bae-bb95-26f0af3b0e75
[root@server34 Desktop]# swapon -a /swwapfile
swapon: /swwapfile: insecure permissions 0644, 0600 suggested.
[root@server34 Desktop]# swapon -s
Filename Type Size Used Priority
/dev/vdb1 partition 4194300 0 -1
/swwapfile file 1023996 0 -2
9.删除swap
vim /etc/fstab ##删除此文件中添加的swap行
swapoff /swapfile ##断开swap文件链接
swapoff /dev/vdb1 ##断开swap磁盘链接
rm -rf /swapfile ##删除文件
fdisk /dev/vdb ##删除磁盘分区
partprobe ##同步分区表