如何查看linux服务器上有几块磁盘?

如何查看linux服务器上有几块磁盘?,第1张

有多种方式查看linux服务器上有几块磁盘

方法1:

[root@localhost xly]# lsblk

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT

sr0 11:01 1024M 0 rom

sda 8:00 40G 0 disk

├─sda1 8:10 300M 0 part /boot

├─sda2 8:20 17.8G 0 part /

└─sda3 8:302G 0 part [SWAP]

sdb 8:16 0 20G 0 disk /opt

可知系统有sda和sdb两块磁盘

方法2:

[root@localhost xly]# fdisk -l

Disk /dev/sda: 42.9 GB, 42949672960 bytes

255 heads, 63 sectors/track, 5221 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: 0x00041bdd

Device Boot Start End Blocks Id System

/dev/sda1 * 1 39 307200 83 Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2 39235818631680 83 Linux

/dev/sda323582611 2031616 82 Linux swap / Solaris

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: 0x00000000

du -- disk usage,用来查看某个文件或目录占用的磁盘空间数量。

usage: du -shbkm [ file | directory]

-h: 很有用的参数, 将显示的结果以human readable的方式打印,如20K,1.3M,4.5G等

-s :summarize,如果要查看的是目录,则显示其总体占有空间,而不是显示其所有子目录及其文件占用的空间

如 du -s /domain 则显示domain这个目录及其子目录总共占用了多少空,而不是显示其所有子目录的情况

-b:byte ,结果以byte为单位显示

-k:kilobyte,结果以KB为单位显示

-m:megabyte,结果以MB为单位显示

df -- report file system disk space usage, 用来查看文件系统的磁盘空间使用情况

usage : df -htk

h,k与du一样 ,-t 指定要查看的文件系统

一、整体流程

1、把新硬盘连接起来

2、在CMOS里配置新硬盘

3、查看硬盘代号

4、用 fdisk 对硬盘进行分区

5、格式化分区

6、创建挂载点

7、设置/dev/fstab 以便开机时自动挂载分区

8、设置新硬盘分区的读写权限

二、具体 *** 作步骤

1、把新硬盘连接起来,属于硬件 *** 作,注意主板和硬盘的接口插正确就可以了。

2、在CMOS里配置新硬盘

启动计算机,并进入CMOS,让机器找到新硬盘。

IDE Channel 0Master: none (没有盘)

IDE Channel 0Slave: none (没有盘)

IDE Channel 1Master: 是DVD-ROM

IDE Channel 1Slave: none (没有盘)

IDE Channel 2Master: HDS728080PLA380 (原来的80GBSATA I 硬盘)

IDE Channel 3Master: none (没有盘)

在none 的Channels一个一个地让计算机自动寻找硬盘。最后发现了:

IDE Channel 3Master: ST31000528AS (新的1000GB SATA II型硬盘)

3、 查看硬盘代号

$ df

发现:

写道

/dev/sda1 /C_disk 15GB 7 (reserved for Windows XP, my PC is adual- system)

/dev/sda2 / 15GB 83 (Linux)

/dev/sda3 LinuxLVM 8e (Linux)

/dev/sda4 extended

/dev/sda5 82 (Linux Swap, 512MB, twice of the momoey)

/dev/sda6 /data 83 (Linux, mounted on /data, 45.5GB)

注意: SATA (通常称串口盘) 在Linux下被视为SCSI 盘(一种早期用在Sun工作站上和服务器 的高速硬盘,那时很贵!)。

可以判定: 新的硬盘应该就是/dev/sdb 了。

进入超级用户:

写道

$ su -l

password: yoursecrets

[root@Lenovo~]#

[root@Lenovo~]# fdisk -l

出现类似下面的信息(以下提示信息仅供参考,有的并非本人实际 *** 作时的屏幕显示,但意思是一样 的):

写道

Disk/dev/sda: 10.7 GB, 10737418240 bytes

255heads, 63 sectors/track, 1305 cylinders

Units= cylinders of 16065 * 512 = 8225280 bytes

Diskidentifier: 0x0007d856

DeviceBoot Start End Blocks Id System

/dev/sda1 * 1 25 200781 83 Linux

/dev/sda2 26 1305 10281600 8e LinuxLVM

Disk /dev/sdb: 2147 MB, 2147483648 bytes <=新硬盘

255heads, 63 sectors/track, 261 cylinders

Units= cylinders of 16065 * 512 = 8225280 bytes

Diskidentifier: 0x00000000

Disk /dev/sdb doesn't contain a validpartition table

4、 用 fdisk 对硬盘进行分区

写道

[root@Lenovo~]#fdisk /dev/sdb

Devicecontains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Buildinga new DOS disklabel with disk identifier 0x623223a1.

Changeswill remain in memory only, until you decide to write them.

Afterthat, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 ofpartition table 4 will be corrected by w(rite)

Command (m for help): p <=显示信息

Disk /dev/sdb: 1002.2 GB, 10*** bytes

255heads, 63 sectors/track, 121601 cylinders

Units= cylinders of 16065 * 512 = 8225280 bytes

Diskidentifier: 0x623223a1

DeviceBoot Start End Blocks Id System

Command (m for help): n <=新建分区

Commandaction

e extended

p primarypartition (1-4)

p <=新建主分区

Partitionnumber (1-4): 1 <=分区号为1,即/dev/sdb1

Firstcylinder (1-261, default 1): 回车取默认值

Usingdefault value 1

Lastcylinder or +size or +sizeM or +sizeK (1-261, default 261): 回车取默认值

Usingdefault value 261

Command (m for help): p <=显示分区信息

Disk /dev/sdb: 2147 MB, 2147483648 bytes

255heads, 63 sectors/track, 261 cylinders

Units= cylinders of 16065 * 512 = 8225280 bytes

Diskidentifier: 0x623223a1

DeviceBoot Start End Blocks Id System

/dev/sdb1 1 261 2096451 83 Linux

Command (m for help): w <=保存退出

Thepartition table has been altered!

Callingioctl() to re-read partition table.

Syncingdisks.

5、格式化分区

写道

# mkfs.ext4 -L disk2 /dev/sdb1 --格式化的同时给新硬盘加标签为 disk2

或者 mkfs.ext4 /dev/sdb1 --只格式化但不加标签

单独加标签的命令是: # e2label /dev/sdb1 /disk2

6、创建挂载点

写道

[root@Lenovo~]# mkdir /disk2

7、设置/dev/fstab 以便开机时自动挂载分区:

写道

[root@Lenovo~]# vi /etc/fstab

添加一行:

/dev/sdb1 /disk2 ext4 auto 1 2

若一次性手动挂载分区 ,使用命令: #mount /dev/sdb1 /disk2/

8、设置新硬盘或分区的读写权限:

# chmod a+w /disk2

这样所有计算机的用户都可以读写该分区,即/disk2盘了


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/7675369.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-08
下一篇 2023-04-08

发表评论

登录后才能评论

评论列表(0条)

保存