linux系统中的磁盘管理
看到的不一定可以使用
可以被用,不一定在用
1.本地存储的设备
fdisk -l #真实存在的设备
cat /proc/partitions #系统识别的设备
blkid #系统可使用的设备
df #系统正在挂载的设备
2.设备的挂载与卸载
1).设备名称
/dev/xdx #/dev/hd0 /dev/hd1 /dev/sda /dev/sda1 /dev/sdb /dev/sdb1
/dev/sr0 #光驱
/dev/mapper/*虚拟设备
2).设备的挂载
mount 设备 挂载点
mount /dev/sdb1 /mnt
将/dev/sdb1挂载到 /mnt下,用df查看是否已经挂载成功:
正常卸载:
有时候会出现busy情况,无法正常将挂载点卸载
3).解决设备正忙情况
解决方法1:
[root@foundation14 mnt]# umount /mnt
umount: /mnt: target is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
[root@foundation14 mnt]# fuser -kvm /mnt
USER PID ACCESS COMMAND
/mnt: root kernel mount /run/media/kiosk/KINGSTON
root 3024 ..c.. bash
kiosk 4388 ..c.. bash
root 4475 ..c.. bash
Killed
Killed
Killed
[root@foundation14 mnt]# umount /mnt
解决方法2:
[root@foundation14 mnt]# umount /mnt
[root@foundation14 mnt]# lsof /mnt/
lsof:WARNING:information may be incomplate。
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
bash 4626 root cwd DIR 8,17 4096 2 /mnt
[root@foundation14 mnt]# kill -9 4626
[root@foundation14 mnt]# umount /mnt
3.磁盘分区
1.硬盘0磁道1扇区的512个字节中记录的信息如下
512=446 + 64 + 2
^ ^ ^
mbr(主引导记录) mpt(主分区标) 55aa(硬盘的有效标示)
硬盘分区标
64
一个分区占16个字节
硬盘上最多可以划分4个主分区
4.分区步骤
1).查看真实存在的设备
[root@server-sshd ~]# fdisk -l
Disk /dev/vda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x00013f3e
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 20970332 10484142+ 83 Linux
Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 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: 0x45d1ee73
Device Boot Start End Blocks Id System
2).分区的管理
[root@server-sshd ~]# fdisk /dev/vdb
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.
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 #删除
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
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 #修改分区id
u change display/entry units
v verify the partition table
w write table to disk and exit #保存分区标信息到硬盘
x extra functionality (experts only)
3).查看分区信息
4).新建分区
建立三个分区
5).如果已经建立了三个分区,那么新建第四个分区将会默认为扩展分区
6).这时就可以在扩展分区里再建立分区,只要分区的存储足够大