
正文
linux添加硬盘命令 linux 添加硬盘
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
linux下如何挂载硬盘?
1.插入新硬盘,启动Linux服务器,使用fdisk -l 查看硬盘
#fdisk -l
Disk /dev/sdb: 1000.2 GB, 1000204886016 bytes
2.格式化硬盘
#mkfs -t ext4 /dev/sdb
3.挂载硬盘
#mount 硬盘地址 要挂载的地址
#mount /dev/sdb /media/imgs
4.实现系统重启后自动挂载该分区
#vi /etc/fstab
在最后一行添加
/dev/sdb /media/imgs ext4 defaults 1 2
一、添加磁盘
添加加新硬盘重启服务器
添加完之后就可以重启机器了,如果你机器是开启的,进入系统并不能看见你刚添加的那块磁盘,只有等系统重启,重新加载之后才会显示安装的那块磁盘
二、进入系统
使用root用户进入系统
三、 查看硬盘信息
[root@localhost ~]# fdisk -l //磁盘命令
1
Disk /dev/sda: 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: 0x000c4cb5
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 2611 20458496 8e Linux LVM
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: 0xd0f5c869
Device Boot Start End Blocks Id System
/dev/sdb1 1 2610 20964793+ 83 Linux
Disk /dev/sdc: 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: 0x00000000
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
可以看到这台机器加载了三个磁盘sda、sdb、sdc
其中sda是初始磁盘,sdb已经初始化且经过使用,sdc是刚刚加载的,未格式化的新磁盘
四、创建新硬盘分区
[root@localhost ~]# fdisk /dev/sdc #进入磁盘
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x45a3cadb.
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 #各分区类型所对应的ID
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)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
知道命令之后就可以进行分区了
Command (m for help): p //打印分区信息,可以看到当前并没有分区
Disk /dev/sdc: 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: 0x45a3cadb
Device Boot Start End Blocks Id System
Command (m for help): n //创建一个新的分区
Command action
e extended//输入e为创建扩展分区
p primary partition (1-4) //输入p为创建逻辑分区
p
Partition number (1-4): 1//划分逻辑分区
First cylinder (1-2610, default 1): //我这里直接回车,是不想把该磁盘分成多个分区,把整个磁盘作为1个分区
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610):
Using default value 2610
Command (m for help): p //再次查看可以看到该磁盘已经有1个分区了
Disk /dev/sdc: 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: 0x45a3cadb
Device Boot Start End Blocks Id System
/dev/sdc1 1 2610 20964793+ 83 Linux
Command (m for help): w //保存分区
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
再次使用”fdisk -l”命令查看磁盘信息
Disk /dev/sdc: 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: 0x406a4c58
Device Boot Start End Blocks Id System
/dev/sdc1 1 2610 20964793+ 83 Linux
1
2
3
4
5
6
7
8
9
第三块磁盘/dev/sdc已经分区好了
五、格式化分区
[root@localhost ~]# mkfs.ext3 /dev/sdc1
//将/dev/sdc1格式化为ext3类型,好像大部分的磁盘都是格式化为ext3类型,具体为什么没有深入研究,暂时不清楚,想了解的朋友可以自己查一下
1
2
[root@localhost ~]# mkfs.ext3 /dev/sdc1
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5241198 blocks
262059 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=4294967296
160 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
正在写入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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
格式化完毕,此时就可以使用“mount”命令挂载分区了,然后使用这个磁盘空间了
六、挂载分区以及开机自动挂载
[root@localhost ~]# df -h //此时只有sda1和sdb1两个磁盘挂载
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 18G 15G 1.5G 92% /
tmpfs 932M 76K 932M 1% /dev/shm
/dev/sda1 485M 40M 421M 9% /boot
/dev/sdb1 20G 1.2G 18G 7% /disk/diskone
/dev/sr0 4.2G 4.2G 0 100% /media/CentOS_6.5_Final
[root@localhost /]# cd /disk/
[root@localhost disk]# ll
总用量 4
drwxr-xr-x. 4 root root 4096 7月 28 17:04 diskone
[root@localhost disk]# cd diskone/
[root@localhost diskone]# ll
总用量 20
drwx------. 2 root root 16384 7月 28 16:12 lost+found
drwxr-xr-x. 2 root root 4096 7月 28 17:09 software
[root@localhost diskone]# cd ../
[root@localhost disk]# mkdir disktwo //创建被挂载的路径
[root@localhost disk]# ll
总用量 8
drwxr-xr-x. 4 root root 4096 7月 28 17:04 diskone
drwxr-xr-x. 2 r
相关问答
Q1: Linux磁盘管理
是一个创建和维护分区表的程序,它兼容DOS类型的分区表、BSD或者SUN类型的磁盘列表。
语法
fdisk [必要参数][选择参数]
必要参数:
-l 列出素所有分区表
-u 与"-l"搭配使用,显示分区数目
选择参数:
-s分区编号 指定分区
-v 版本信息
菜单操作说明
m :显示菜单和帮助信息
a :活动分区标记/引导分区
d :删除分区
l :显示分区类型
n :新建分区
p :显示分区信息
q :退出不保存
t :设置分区号
v :进行分区检查
w :保存修改
x :扩展应用,高级功能
(英文全拼:make file system)命令用于在特定的分区上建立 linux 文件系统。
使用方式 :
mkfs [-V] [-t fstype] [fs-options] filesys [blocks]
参数 :
device : 预备检查的硬盘分区,例如:/dev/sda1
-V : 详细显示模式
-t : 给定档案系统的型式,Linux 的预设值为 ext2
-c : 在制做档案系统前,检查该partition 是否有坏轨
-l bad_blocks_file : 将有坏轨的block资料加到 bad_blocks_file 里面
block : 给定 block 的大小
命令是经常会使用到的命令,它用于挂载Linux系统外的文件。
语法
mount [-hV]mount -a [-fFnrsvw] [-t vfstype]mount [-fnrsvw] [-o options [,...]] device | dir
mount [-fnrsvw] [-t vfstype] [-o options] device dir
参数说明:
-V:显示程序版本
-h:显示辅助讯息
-v:显示较讯息,通常和 -f 用来除错。
-a:将 /etc/fstab 中定义的所有档案系统挂上。
-F:这个命令通常和 -a 一起使用,它会为每一个 mount 的动作产生一个行程负责执行。在系统需要挂上大量 NFS 档案系统时可以加快挂上的动作。
-f:通常用在除错的用途。它会使 mount 并不执行实际挂上的动作,而是模拟整个挂上的过程。通常会和 -v 一起使用。
-n:一般而言,mount 在挂上后会在 /etc/mtab 中写入一笔资料。但在系统中没有可写入档案系统存在的情况下可以用这个选项取消这个动作。
-s-r:等于 -o ro
-w:等于 -o rw
-L:将含有特定标签的硬盘分割挂上。
-U:将档案分割序号为 的档案系统挂下。-L 和 -U 必须在/proc/partition 这种档案存在时才有意义。
-t:指定档案系统的型态,通常不必指定。mount 会自动选择正确的型态。
-o async:打开非同步模式,所有的档案读写动作都会用非同步模式执行。
-o sync:在同步模式下执行。
-o atime、-o noatime:当 atime 打开时,系统会在每次读取档案时更新档案的『上一次调用时间』。当我们使用 flash 档案系统时可能会选项把这个选项关闭以减少写入的次数。
-o auto、-o noauto:打开/关闭自动挂上模式。
-o defaults:使用预设的选项 rw, suid, dev, exec, auto, nouser, and async.
-o dev、-o nodev-o exec、-o noexec允许执行档被执行。
-o suid、-o nosuid:
允许执行档在 root 权限下执行。
-o user、-o nouser:使用者可以执行 mount/umount 的动作。
-o remount:将一个已经挂下的档案系统重新用不同的方式挂上。例如原先是唯读的系统,现在用可读写的模式重新挂上。
-o ro:用唯读模式挂上。
-o rw:用可读写模式挂上。
-o loop=:使用 loop 模式用来将一个档案当成硬盘分割挂上系统。
(base) zfy@zfy-PC:~$ sudo fdisk -l
Disk /dev/sda: 80 GiB, 85899345920 bytes, 167772160 sectors
#块设备名称为/dev/sda,此设备的大小为80 GB,85899345920 bytes是转换成字节后的大小,共167772160 个扇区
Disk model: VMware Virtual S
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x3b1ffeba
Device Boot Start End Sectors Size Id Type
#分区序列 | 引导 | 开始 | 终止 | Sectors | 容量 | 分区类型ID | 分区类型
/dev/sda1 * 2048 3147775 3145728 1.5G 83 Linux
/dev/sda2 3147776 138412031 135264256 64.5G 5 Extended
/dev/sda3 138412032 161480703 23068672 11G 83 Linux
/dev/sda4 161480704 167770111 6289408 3G 82 Linux swap / Solaris
/dev/sda5 3149824 34605055 31455232 15G 83 Linux
/dev/sda6 34607104 66062335 31455232 15G 83 Linux
/dev/sda7 66064384 138412031 72347648 34.5G 83 Linux
Partition table entries are not in disk order.
a. 在虚拟机中添加硬盘,添加后使用fdisk -l命令查看,磁盘变成两个,在sda中还没有分区
root@zfy-PC:/home/zfy# fdisk -l
Disk /dev/sda: 2 GiB, 2147483648 bytes, 4194304 sectors
Disk model: VMware Virtual S
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 /dev/sdb: 80 GiB, 85899345920 bytes, 167772160 sectors
Disk model: VMware Virtual S
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x3b1ffeba
Device Boot Start End Sectors Size Id Type
/dev/sdb1 * 2048 3147775 3145728 1.5G 83 Linux
/dev/sdb2 3147776 138412031 135264256 64.5G 5 Extended
/dev/sdb3 138412032 161480703 23068672 11G 83 Linux
/dev/sdb4 161480704 167770111 6289408 3G 82 Linux swap / Solaris
/dev/sdb5 3149824 34605055 31455232 15G 83 Linux
/dev/sdb6 34607104 66062335 31455232 15G 83 Linux
/dev/sdb7 66064384 138412031 72347648 34.5G 83 Linux
Partition table entries are not in disk order.
b.下面对sda进行分区
root@zfy-PC:/home/zfy# fdisk /dev/sda
Welcome to fdisk (util-linux 2.33.1).
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.
Created a new DOS disklabel with disk identifier 0xb985e226.
Command (m for help): m
#输入m查看帮助
Help:
DOS (MBR)
a toggle a bootable flag
b edit nested BSD disklabel
c toggle the dos compatibility flag
Generic
d delete a partition
F list free unpartitioned space
l list known partition types
n add a new partition
p print the partition table
t change a partition type
v verify the partition table
i print information about a partition
Misc
m print this menu
u change display/entry units
x extra functionality (experts only)
Script
I load disk layout from sfdisk script file
O dump disk layout to sfdisk script file
Save Exit
w write table to disk and exit
q quit without saving changes
Create a new label
g create a new empty GPT partition table
G create a new empty SGI (IRIX) partition table
o create a new empty DOS partition table
s create a new empty Sun partition table
Command (m for help): n
#输入n创建一个分区
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
#选择主分区
Partition number (1-4, default 1): 1
#选择编号为1
First sector (2048-4194303, default 2048): 2500000
#起始sector 设为2500000
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2500000-4194303, default 4194303): 4194303
#终止sector 设为4194303
Created a new partition 1 of type 'Linux' and of size 827.3 MiB.
#分区完成,分区大小为827.3 MiB
Command (m for help): n
#继续创建一个分区
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p): e
#新增扩展分区
Partition number (2-4, default 2): 2
#选择编号为2
First sector (2048-4194303, default 2048): 2048
#起始sector为2048
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-2499999, default 2499999):
#终止sector为2499999
Created a new partition 2 of type 'Extended' and of size 1.2 GiB.
#新增完成,大小为1.2GiB
Command (m for help): w
#保存
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
c.查看分区后磁盘信息,此时sda磁盘已经有两个分区
Disk /dev/sda: 2 GiB, 2147483648 bytes, 4194304 sectors
Disk model: VMware Virtual S
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xb985e226
Device Boot Start End Sectors Size Id Type
/dev/sda1 2500000 4194303 1694304 827.3M 83 Linux
/dev/sda2 2048 2499999 2497952 1.2G 5 Extended
Partition table entries are not in disk order.
Disk /dev/sdb: 80 GiB, 85899345920 bytes, 167772160 sectors
Disk model: VMware Virtual S
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x3b1ffeba
Device Boot Start End Sectors Size Id Type
/dev/sdb1 * 2048 3147775 3145728 1.5G 83 Linux
/dev/sdb2 3147776 138412031 135264256 64.5G 5 Extended
/dev/sdb3 138412032 161480703 23068672 11G 83 Linux
/dev/sdb4 161480704 167770111 6289408 3G 82 Linux swap / Solaris
/dev/sdb5 3149824 34605055 31455232 15G 83 Linux
/dev/sdb6 34607104 66062335 31455232 15G 83 Linux
/dev/sdb7 66064384 138412031 72347648 34.5G 83 Linux
Partition table entries are not in disk order.
d.用ext3的文件系统对分区进行格式化
root@zfy-PC:/home/zfy# mkfs -t ext3 /dev/sda1
mke2fs 1.44.5 (15-Dec-2018)
Creating filesystem with 211788 4k blocks and 52976 inodes
Filesystem UUID: db384338-4af1-4eec-a62d-f2b2f8e0ec96
Superblock backups stored on blocks:
32768, 98304, 163840
Allocating group tables: done
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
e.新建一个分区目录 /data,并挂载
root@zfy-PC:/home/zfy# mkdir data
root@zfy-PC:/home/zfy# mount /dev/sda1 /data
root@zfy-PC:/home/zfy# df -TH /data/#查看是否挂载成功
文件系统 类型 容量 已用 可用 已用% 挂载点
/dev/sda1 ext3 838M 881k 793M 1% /data
f. 用vim打开 etc/fstab并假如 /dev/sda1/data ext3 defaults 0 0,这样重启后便不需要再挂载
参考文献:
【1】 Linux mount命令 | 菜鸟教程 (runoob.com)
【2】 linux添加新磁盘和创建分区 - IT(小菜鸡) - 博客园 (cnblogs.com)
Q2: linux中为什么插上两块新硬盘后用fdisk -l命令看不到新增的硬盘?
linux中插上两块新硬盘后用fdisk -l命令看不到新增linux添加硬盘命令的硬盘是设置错误造成linux添加硬盘命令的linux添加硬盘命令,解决方法为linux添加硬盘命令:
1、执行fdisk -l 查看新添加的硬盘,可以看到 sdb为新添加的硬盘。
2、fdisk /dev/sdb对新加硬盘格式化。
3、输入m可以查看帮助。
4、输入n新建分区,输入p新建主分区,输入1(主分区号),分别磁盘分区的起始终止位置,这里采用默认,即分区为硬盘大小。
5、输入w对分区进行保存。
6、fdisk -l 查看分区,有了sdb1 ;输入mkfs.ext4将分区格式化为ext4格式。
注意事项:
linux除了在服务器操作系统方面保持着强劲的发展势头以外,在个人电脑、嵌入式系统上都有着长足的进步。使用者不仅可以直观地获取该操作系统的实现机制,而且可以根据自身的需要来修改完善这个操作系统,使其最大化地适应用户的需要。[1]
Q3: linux下挂载磁盘的命令是什么?
Linux系统在使用光盘、软盘或U盘时,必须先执行挂载(mount)命令。挂载命令会将这些存储介质指定成系统中的某个目录,以后直接访问相应目录即可读写存储介质上的数据。 \x0d\x0a1、挂载光盘,挂载光盘的命令如下:# mount -t is09660 /dev/cdrom /mnt/cdrom \x0d\x0a该命令将光盘挂载到/mnt/cdrom目录,使用“ls /mnt/cdrom”命令即可显示光盘中数据和文件。卸载光盘的命令如下:# umount /mnt/cdrom\x0d\x0a2、挂载软盘,将软盘挂载到/mnt/floppy目录的命令如下:# mount /dev/fd0 /mnt/floppy卸载软盘的命令如下:#umount /mnt/floppy\x0d\x0a3、挂载U盘挂载U盘相对复杂一些。首先使用“fdisk -l”命令查看外挂闪存的设备号,一般为/dev/sda1。然后用“mkdir \x0d\x0a/mnt/usb”命令建立一个挂载U盘用的目录。之后使用如下命令挂载FAT格式的U盘:# mount -t msdos /dev/sda1 /mnt/usb\x0d\x0a使用如下命令挂载FAT32格式的U盘:# mount -t vfat /dev/sda1 /mnt/usb\x0d\x0a4、挂载外挂硬盘分区,挂载外挂硬盘分区(FAT32格式)同样需要先用“fdisk \x0d\x0a-1”查看外挂的硬盘分区设备号,假设为/dev/hda1。建立/mnt/vfat挂载目录后,使用如下命令进行挂载:# mount -t vfat /dev/hda1 /mnt/vfat\x0d\x0a注意,默认情况下Linux只允许root用户执行mount命令。如果想让一般用户也能挂载,并且希望在系统启动时自动挂载光盘或软盘,需要修改/etc/fstab配置文件,加入以下内容: LABEL=/ / ext3 defaults11\x0d\x0a/dev/cdrom/mnt/cdrom iSo9660 auto,owner,kudzu,ro,user 00\x0d\x0a/dev/fdo /mnt/floppy auto auto,owner,kudzu,ro,user 00 其中,“user”表示将mount命令赋予一般用户使用。
Q4: 服务器挂载硬盘在硬盘里跑
博主最近在研究服务器运维,由于Linux服务器相对比较困难,所以博主对她情有独钟。而window服务器几乎跟我们平常使用的电脑一样,相对简单感觉索然无味。下面正式进入主题教大家linux如何挂载硬盘。
首先解答一个新手朋友都会问的问题,而且这些问题在百度上面好像找不到很合适的答案。
Linux服务器要挂载硬盘原因是什么?不挂载磁盘可以吗?
Linux服务器要挂载硬盘的原因主要有以下几点:
1、Linux服务器在默认情况下,所有的东西都是装在系统盘。系统盘的空间有限,如果站点和数据较多很容易把空间撑满,导致环境和数据库等等服务启动不了。
2、Linux服务器挂载磁盘可以避免因为系统损坏导致网站数据丢失。
3、Linux服务器挂载硬盘可以更合理的使用储存资源,因为不挂载默认所有东西装系统盘(类似电脑的c盘),导致其他数据盘闲置。比如你有200G的硬盘:系统盘20G、数据盘180G,如果不挂载硬盘那么只能用20G的系统盘,另外180G的数据盘无法使用,造成空间的巨大浪费。
了解具体原因请看另外一篇文章:Linux服务器为什么要挂载硬盘?
下面如何来挂载Linux服务器的硬盘教程开始:
挂载硬盘(磁盘)的方法博主收集了两种,全部介绍给大家。
第一种方法:使用工具自动挂载硬盘(博主强烈推荐使用这种方法,简单又不会出错)两分钟可以搞定。
使用磁盘自动挂载工具,支持Centos、Ubuntu、Debian、Fedora。
注意: 请在安装面板之前挂载磁盘,否则程序将直接跳过挂载过程。
Centos/Fedora:
yum install wget -y wget -O auto_disk.sh bash auto_disk.sh
Ubuntu:
wget -O auto_disk.sh sudo bash auto_disk.sh
Debian:
wget -O auto_disk.sh bash auto_disk.sh
选择对应的系统,把自动挂载的代码复制到xshell里面按回车键执行即可。如图:
程序说明:
1、本工具默认将数据盘挂载到/www目录
2、若服务器上已存在/www目录,为了您的数据安全,挂载工具会自动跳过
3、若您的服务器之前安装过Windows系统,需要手动删除NTFS分区,挂载工具会直接跳过NTFS分区
4、若您的磁盘已分区,且未挂载,工具会自动将分区挂载到/www
5、若您的磁盘是新磁盘,工具会自动分区并格式化成ext4文件系统
6、本工具只自动挂载一个分区,若您有多块数据盘,请手动挂载未被自动挂载的磁盘
7、若要挂载到其它目录,请在第一个参数传入目录名
第二种方法:手动挂载硬盘(博主不推荐使用,因为手动挂载很容易出现未知错误而且很耗时间),下面把方法贴出来大家可以参考参考。
声明:主流服务器上面的磁盘主要有三种命名方式:/dev/xvdb 、 /dev/sdb、 /dev/vdb。文中的磁盘名称/dev/vdb为作者的测试服务器上的命名,请大家以自己的磁盘为准进行修改。
1、检查网站的磁盘状态,确认是否有没有分区的磁盘。
fdisk -l
如上图所示,这个服务器有两个硬盘第一个42.9G,第二个236.2G。这种情况说明硬盘已经分区。
如果没有分区请看另外一篇文章:Linux服务器磁盘分区命令(图解)执行磁盘分区操作,分区完毕完成以下步骤。
2、格式化分区
mkfs.ext4 /dev/vdb(xvdb1)
3、分区挂载添加到开机启动挂载。
echo “/dev/vdb /www ext4 defaults 0 0” /etc/fstab
4、重新挂载所有分区
mount -a
5、最后检查磁盘是否挂载成功
df
挂载完毕,安装面板和网站WEB环境,下面是作者的服务器管理面板,可以看到多了一个WWW数据分区。
关注查看全文

linux
服务器
运维
开发语言
搜索引擎
【正版下载】方舟生存进化到底有多爽?试试就知道!
精选推荐
广告

linux添加硬盘和挂载,Linux添加硬盘和挂载
170阅读·0评论·0点赞
2021年5月15日
【2022新教程】Linux硬盘分区方法-挂载方法——CentOS7.6
238阅读·0评论·0点赞
2022年10月13日
服务器(linux)磁盘挂载nfs
591阅读·2评论·2点赞
2022年10月11日
Linux虚拟机增加硬盘和挂载
745阅读·0评论·0点赞
2021年4月19日
linux开机自动挂载硬盘命令,Linux系统开机自动挂载硬盘分区
4255阅读·0评论·0点赞
2021年5月8日
Linux添加新硬盘并挂载(mount)到目录下
1.8W阅读·3评论·19点赞
2018年12月28日
【正版下载】方舟生存进化到底有多爽?试试就知道!

精选推荐
广告
linux服务器上挂载磁盘
1.4W阅读·0评论·4点赞
2018年9月18日
Linux将硬盘挂载到指定目录上
4609阅读·0评论·2点赞
2022年4月24日
错误集:Linux端挂载Windows共享的目录时报错mount error(112): Host is down
3645阅读·6评论·4点赞
2021年3月17日
Linux 挂载移动硬盘
1712阅读·0评论·1点赞
2022年8月7日
linux服务器挂载磁盘的两种方式
5540阅读·0评论·1点赞
2021年12月16日
Linux三种挂载方式
9879阅读·0评论·3点赞
2021年8月23日
linux硬盘添加和挂载(linux硬盘的热插拔)
2319阅读·1评论·1点赞
2021年11月15日
Linux添加磁盘及分区挂载
1113阅读·0评论·2点赞
2022年10月11日
Linux磁盘分区、挂载
883阅读·0评论·1点赞
2019年10月14日
linux开机自动挂载磁盘
6610阅读·0评论·2点赞
2022年3月3日
Linux挂载硬盘
1499阅读·0评论·0点赞
2022年8月6日
linux机械硬盘如何挂载,Linux下挂载机械硬盘
1260阅读·0评论·0点赞
2021年5月13日
linux新增磁盘挂载
749阅读·0评论·1点赞
2021年5月28日
去首页
看看更多热门内容
Q5: linux的进入磁盘命令
在linux系统我们查看磁盘可以通过相关命令进入磁盘。下面由我为大家整理了linux下进入磁盘命令的相关知识,希望对大家有所帮助!
一、linux的进入磁盘命令
使用dos命令进入D盘的 方法 如下:
1.按windows和r键打开运行界面;
2.在运行界面输入cmd,按回车进入命令提示符中;
3.在命令提示符中输入 D: ,按回车即可进入D盘。
用CMD命令进入D盘的方法如下:
1、首先需要先进入cmd,点击电脑左下角的开始按钮,点击运行按钮,就会出现运行输入窗口,输入cmd就会进入。
2、如果开始按钮中没有运行按钮,那么可以通过右键查看开始属性,在开始菜单自定义中勾选运行,确定后就会出现了。
3、然后再cmd运行窗口中输入d:就是进入D盘根目录了。这时候只会提示你进入d盘了,而不会显示D盘都有哪些文件。如果在 其它 磁盘目录下需要返回D盘时,输入cd命令然后回车,再输入ldquo;D:rdquo; 即可回到D盘。
4、这时候在cmd中输入dir,就可以看到d盘下的各个文件名称了。
二、扩展:linux下查看磁盘命令
Df命令是Linux查看磁盘空间系统以磁盘分区为单位查看文件系统,可以加上参数查看磁盘剩余空间信息,命令格式:
df -hl
Linux查看磁盘空间 显示格式为:
文件系统 容量 已用 可用 已用% 挂载点
Filesystem Size Used Avail Use% Mounted on
/dev/hda2 45G 19G 24G 44% /
/dev/hda1 494M 19M 450M 4% /boot
/dev/hda6 4.9G 2.2G 2.5G 47% /home
/dev/hda5 9.7G 2.9G 6.4G 31% /opt
none 1009M 0 1009M 0% /dev/shm
/dev/hda3 9.7G 7.2G 2.1G 78% /usr/local
/dev/hdb2 75G 75G 0 100% /
/dev/hdb2 75G 75G 0 100% /
以上面的输出为例,表示的意思为:
HD硬盘接口的第二个硬盘(b),第二个分区(2),容量是75G,用了75G,可用是0,因此利用率是100%, 被挂载到根分区目录上(/)。
linux添加硬盘命令的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于linux 添加硬盘、linux添加硬盘命令的信息别忘了在本站进行查找喔。








