磁盤管理
查詢磁盤信息
定義:Linux系統中磁盤管理就是將硬盤通過掛載的方式掛載到linux文件系統中
1.使用df命令查看磁盤容量,不加參數則以k為單位
1.df -i 查看inode的使用情況
2.df -h 以G或T或M的人性化方式顯示
3.df -T 查看磁盤分區類型(文件系統類型)
使用df -h 命令查看磁盤,下面分別介紹每列什么含義
[root@JYC ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 475M 0 475M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.5M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/mapper/centos-root 100G 2.6G 97G 3% /
/dev/sda1 509M 131M 378M 26% /boot
tmpfs 98M 0 98M 0% /run/user/0
2.使用lsblk查看磁盤分區情況
1.[root@JYC ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 100G 0 disk
├─sda1 8:1 0 512M 0 part /boot
└─sda2 8:2 0 99.5G 0 part
└─centos-root 253:0 0 99.5G 0 lvm /
sdb 8:16 0 100G 0 disk
sr0 11:0 1 4.4G 0 rom
3.使用du查看目錄或者文件的容量,不加參數則以k為單位
1.du -sh 人性化輸出顯示大小
2.du -s 列出總和
3.du -h 人性化顯示容量信息
[root@JYC ~]# du -sh /etc
33M /etc
4.顯示當前磁盤的讀寫速度
1.iotop 顯示磁盤的讀寫
2.iotop -o 只顯示在讀寫的進程
3.dd if=/dev/zero of=/tmp/big bs=1k count=100000 該命令可用來測速

磁盤分區和掛載
1.磁盤分區命令
1.fdisk 支持mbr分區格式,2tb以內磁盤
2.gdisk 支持mbr,gpt
3.parted fdisk升級版(僅支持gpt格式)
2.fdisk
1.參看磁盤分區信息
fdisk -l
2.用fdisk進行分區
fdisk /dev/sdb
[root@JYC ~]# 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 0xbcb9ea13.
Command (m for help):
# 一些常用命令
n new 創建磁盤分區 partition(分區)
p print 顯示分區信息
d delete 刪除磁盤分區
q 退出不保存
w 保存並退出
# 創建一個磁盤分區
Command (m for help): p
Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0xbcb9ea13
Device Boot Start End Blocks Id System
Command (m for help): 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-209715199, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199): +200M
Partition 1 of type Linux and of size 200 MiB is set
Command (m for help): P
Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0xbcb9ea13
Device Boot Start End Blocks Id System
/dev/sdb1 2048 411647 204800 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
注:期間若有輸入錯誤需要取消則 ctrl+u
3.格式化文件系統
mkfs.xfs /dev/sdb1
[root@JYC ~]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=12800 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=51200, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=855, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
4.掛載
mount /dev/sdb1 /mnt
[root@JYC ~]# mount /dev/sdb1 /mnt
[root@JYC ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 100G 0 disk
├─sda1 8:1 0 512M 0 part /boot
└─sda2 8:2 0 99.5G 0 part
└─centos-root 253:0 0 99.5G 0 lvm /
sdb 8:16 0 100G 0 disk
└─sdb1 8:17 0 200M 0 part /mnt
sr0 11:0 1 4.4G 0 rom
