1、查看当前未挂载的硬盘fdisk -l
或lsblk
- 方式1:
fdisk -l
> fdisk -l
Disk /dev/xvda: 536.9 GB, 536870912000 bytes
255 heads, 63 sectors/track, 65270 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: 0x00055d89
Device Boot Start End Blocks Id System
/dev/xvda1 * 1 66 524288 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/xvda2 66 13120 104857600 83 Linux
/dev/xvda3 13120 26174 104857600 83 Linux
/dev/xvda4 26174 65271 314047488 5 Extended
/dev/xvda5 26174 30091 31457280 83 Linux
/dev/xvda6 30091 32702 20971520 82 Linux swap / Solaris
/dev/xvda7 32702 35313 20971520 83 Linux
/dev/xvda8 35313 36618 10485760 83 Linux
/dev/xvda9 36618 65271 230156256+ 83 Linux
Disk /dev/xvde: 2147.5 GB, 2147483648000 bytes #这里是未挂载的磁盘
255 heads, 63 sectors/track, 261083 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
- 方式2:
lsblk
> lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 500G 0 disk
├─xvda1 202:1 0 512M 0 part /boot
├─xvda2 202:2 0 100G 0 part /
├─xvda3 202:3 0 100G 0 part /home
├─xvda4 202:4 0 1K 0 part
├─xvda5 202:5 0 30G 0 part /tmp
├─xvda6 202:6 0 20G 0 part [SWAP]
├─xvda7 202:7 0 20G 0 part /var
└─xvda8 202:8 0 10G 0 part /usr
sr0 11:0 1 1024M 0 rom
xvde 202:64 0 2T 0 disk
- 磁盘分区
> fdisk /dev/sdb
根据提示,依次输入"n","p" "1",两次回车,"wq",分区就开始了,很快就会完成。
2、格式化硬盘mkfs.ext4 /dev/xvde
> mkfs.ext4 /dev/xvde
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
131072000 inodes, 524288000 blocks
26214400 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=4294967296
16000 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000, 214990848, 512000000
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
3、建立挂载目录
- 创建需要挂载的目录:
/data
> mkdir /data
4、挂载硬盘
> mount /dev/xvde /data
5、设置开机自动挂载
> vi /etc/fstab
- 在
vi
中输入i
进入INERT
模式,将光标移至文件结尾处并回车,将下面的内容复制/粘贴,然后按Esc
键,输入:wq
保存并退出
/dev/sdb /data ext4 defaults 0 0
*如图
6、查看磁盘是否挂载成功df -h
> df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda2 99G 91G 3.0G 97% /
tmpfs 16G 72K 16G 1% /dev/shm
/dev/xvda1 488M 57M 406M 13% /boot
/dev/xvda3 99G 24G 71G 25% /home
/dev/xvda5 30G 44M 28G 1% /tmp
/dev/xvda8 9.8G 3.7G 5.6G 40% /usr
/dev/xvda7 20G 314M 19G 2% /var
/dev/xvde 2.0T 71M 1.9T 1% /home/root
7、新建磁盘创建分区
查看剩余
[root@localhost ~]$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 300G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 99G 0 part
├─centos-root 253:0 0 50G 0 lvm /
├─centos-swap 253:1 0 7.9G 0 lvm [SWAP]
└─centos-home 253:2 0 41.1G 0 lvm /home
sr0 11:0 1 1024M 0 rom
sudo cfdisk /dev/sda
-
创建分区 - 回车
-
选择主分区 - 回车
-
选择大小 - 回车
- 写入 - 回车
如果写入失败执行:sudo partx -a /dev/sda3 /dev/sda
sudo partx -a /dev/sda3 /dev/sda
/dev/sda3 分区名称
/dev/sda 磁盘驱动器
取消挂载
- 安装psmisc
yum install psmisc -y
- 取消目录占用
fuser -k /file1
fuser -k /dev/sdb1
取消挂载点
umount /file1
umount /dev/sdb1
删除/dev/sdb所有分区
fdisk /dev/sdb
Command (m for help): p(查看当前分区状态)
Command (m for help): d(删除分区)
Partition number (1-2): 1(选择要删除的分区)
Command (m for help): d(删除分区)
Partition number (1-2): 2(选择要删除的分区)
Command (m for help): p(查看当前分区状态)
Command (m for help): w(回车保存新的分区)
Archlinux磁盘挂载
lsblk -l
- 结果
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 1.8T 0 disk /data
sdb 8:16 0 1.8T 0 disk
sdb1 8:17 0 1.8T 0 part
sdc 8:32 0 1.8T 0 disk
sdd 8:48 0 1.8T 0 disk
sde 8:64 1 0B 0 disk
sr0 11:0 1 1024M 0 rom
nvme0n1 259:0 0 476.9G 0 disk
nvme0n1p1 259:1 0 550M 0 part /boot
nvme0n1p2 259:2 0 100G 0 part /
nvme0n1p3 259:3 0 376.4G 0 part /home
- 创建挂载的目录
cd /data
mkdir dev2
- 分区格式化
sudo mkfs.ext4 /dev/sdb
sudo mount /dev/sdb /data/dev2
- 添加开机启动
sudo nano /etc/fstab
- 添加内容到
/etc/fstab
结尾
/dev/sdb /data ext4 defaults 0 0