您的位置:首页 > 运维架构 > Linux

linux基本操作---磁盘管理

2017-12-11 23:45 246 查看

磁盘管理

1. 查看当前磁盘使用情况

[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
18G  3.5G   13G  22% /
tmpfs                 491M   80K  491M   1% /dev/shm
/dev/sda1             477M   35M  418M   8% /boot
/dev/sr0              3.7G  3.7G     0 100% /media/CentOS_6.8_Final


2.磁盘命令

fdisk命令管理磁盘

[root@localhost ~]# fdisk -l

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

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


sda代表第一块硬盘,s代表接口,d代表disk磁盘

sda1/2…代表硬盘中的分区

cylinders磁柱- 就是查看分区情况

start End

3.添加磁盘

添加磁盘之前先关机,关闭所有的进程,通过VMWare 添加一块scsi类型的磁盘


4.分区

通过#fdisk -l

可以看到多了一块sdb磁盘 ,但是没有分区,下面进行分区:

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


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


输入m查看帮助信息

输入n进行分区

e extended -》扩展分区

p primary partition (1-4)-》主分区

主分区+扩展分<=4

必须保证要有一个扩展分区

2+1或者3+1的模式

主分区分完格式化之后可以直接使用

扩展分区分完之后还需要进行逻辑分区才能使用

注意:分完区之后按w进行信息的保存

分完区之后建议重启机器,让系统重新加载一次信息

执行完成之后fdisk -l 查看现在的分区情况

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

Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1959    15735636   83  Linux
/dev/sdb2            1960        2610     5229157+   5  Extended


5.格式化磁盘

分区之后还不能使用,还需要进行格式化:

Linux中的文件系统

ext2、ext3、ext4、xfs等

格式化命令:mkfs.ext4 /dev/sdb6

[root@localhost ~]# mkfs.ext4 /dev/sdb1


6.挂载磁盘

挂载临时命令:mount

mount /dev/sdb6 /mnt

/mnt挂载点:是访问这个分区的唯一入口,是必须已经存在的

使用:df -h来验证是否挂载成功

永久生效的挂载方法:# vi /etc/fstab 写入配置文件

/dev/sdb6 /mnt ext4 defaults 0 0

挂载成功

[root@localhost ~]# mount /dev/sdb1 /mnt
[root@localhost ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root
18G  3.5G   13G  22% /
tmpfs                 491M   72K  491M   1% /dev/shm
/dev/sda1             477M   35M  418M   8% /boot
/dev/sdb1              15G   38M   14G   1% /mnt
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux 管理 磁盘