1 磁盘挂载
df -h
# 查看新增的的磁盘
fdisk -l
# 对新增磁盘/dev/sdb进行分区
fdisk /dev/sdb # 输入n后四次回车,然后输入w[Command (m for help): w]
# 格式化磁盘
mkfs.xfs -f /dev/sdb1
# 创建挂载的目录
mkdir -p /u01
# 将新硬盘临时挂载在一个目录下
mount /dev/sdb1 /u01
# 验证查看,如图2,可看到已出现刚刚挂载的磁盘
df -h
# 设置开机挂载
vim /etc/fstab # 末尾增加一行,如图3
# 重启
reboot
# 查看
df -h
1.1 查看磁盘
fdisk -l
# 查看sd开头的
[root@initnode ~]# fdisk -l |grep "Disk /dev/sd*"
Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Disk /dev/sdb: 2147 MB, 2147483648 bytes, 4194304 sectors
Disk /dev/sdc: 3221 MB, 3221225472 bytes, 6291456 sectors
1.2 添加分区
[root@initnode ~]# fdisk /dev/sdb
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.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x27e71404.
Command (m for help): n # 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-4194303, default 2048): # 开始扇区
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-4194303, default 4194303): # 结束扇区
Using default value 4194303
Partition 1 of type Linux and of size 2 GiB is set
Command (m for help): w # 写入磁盘
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
若 ls /dev/sd* 没有看到对应的分区,则可以执行 partprobe /dev/sdb
1.3 格式化磁盘
[root@initnode ~]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=131008 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=524032, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
# mkfs.ext4 /dev/sdb1
1.4 挂载文件
mkdir /u01
mount /dev/sdb1 /u01
# 能看到已经挂载了
df -h
1.5 设置开机挂载
echo "/dev/sdb1 /u01 xfs defaults 0 0" >> /etc/fstab
2 其他操作
2.1 删除分区
[root@initnode ~]# fdisk /dev/sdb
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): p
Disk /dev/sdb: 2147 MB, 2147483648 bytes, 4194304 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: dos
Disk identifier: 0x506d56fe
Device Boot Start End Blocks Id System
/dev/sdb1 2048 4194303 2096128 83 Linux
Command (m for help): d # 这边如果有多个分区,会让选择删除哪个分区
Selected partition 1
Partition 1 is deleted
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
2.2 卸载文件
umount /u01
2.3 挂载光驱
# 前提是有光盘在
[root@initnode ~]# mount /dev/cdrom /mnt
mount: /dev/sr0 is write-protected, mounting read-only
2.4 挂载iso镜像文件
mount -t iso9660 /opt/centos7.iso /mnt
2.5 显示所有设备UUID
[root@initnode ~]# lsblk -f
NAME FSTYPE LABEL UUID MOUNTPOINT
sda
├─sda1 xfs 3670ff92-e7fa-479d-be77-4294b811beba /boot
└─sda2 LVM2_member rYXCnn-WRex-9TwU-d85i-HugM-3kKs-I7iLzz
├─centos-root xfs 2a463313-efa5-44af-93dd-075f52f3e38b /
└─centos-swap swap 8a9c9447-d992-484c-a29c-947fbcc84ed1 [SWAP]
sdb
└─sdb1 xfs eb0147ee-7793-46a7-ae1e-37c0b4e52b3a /u01
sdc
sr0 iso9660 CentOS 7 x86_64 2018-11-25-23-54-16-00
2.6 parted 分区
当磁盘需要分区>=2T时候,那么就需要使用gpt模式,需要使用parted来进行分区(fdisk 只支持 mbr,只能到2T)
(1)支持msdos和gpt,可以支持大硬盘,也支持小硬盘。
(2)区分parted命令给msdos类型和gpt类型硬盘分区的不同。
(3)不能使用 fdisk -l 查看
(4) 命令执行立即生效
[root@initnode ~]# parted /dev/sdb
GNU Parted 3.1
Using /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: 2147MB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
(parted) mklabel
New disk label type? gpt # 修改为 gpt 模式
Warning: 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) p # 打印看下
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 2147MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
(parted) mkpart oracledata 0 -1 # 名称自起,默认单位M,0 -1表示所有, 0 100 表示这个分区设置为为 100M,下一个可设置为 100 500G
Warning: The resulting partition is not properly aligned for best performance.
Ignore/Cancel? I # 确认
(parted) p # 再次查看
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 2147MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 17.4kB 2146MB 2146MB oracledata