新秀篇 ##Linux磁盘管理##

一.硬盘查看:
fdisk -l 系统真实存在的
这里写图片描述
vda第一个虚拟磁盘
vdb第二个虚拟磁盘
–IDE表示老式硬盘(并口硬盘)
/dev/sda表示第一块串口硬盘,a表示第一块
这里写图片描述
硬盘名字sata
/dev/hd0串口硬盘
/dev/cdrom /dev/sr0表示光驱,cdrom为sro的快捷方式,cdrom可以不存在
/dev/mapper
blkid 可以使用的
cat /proc/partitions 系统识别的

大小对比:df <= blkid < cat /proc/partitions < fdisk -l
df -h 2n次方『更准确』 df -H 10n次方
%%%优盘挂载与卸载实验:
第一个真机shell:
【1】插上移动设备
【2】打开一个真机shell,切换到超级用户
【3】fdisk -l 查看优盘
【4】用df查看优盘挂载路径
【5】挂载优盘到/mnt/下
【6】移动路径到/mnt/下
[kiosk@foundation20 Desktop]$ su - ##切换用户
Password:
Last login: Mon Apr 30 09:35:53 CST 2018 on pts/4
[root@foundation20 ~]# fdisk -l ##查看优盘
这里写图片描述
Disk /dev/sda: 120.0 GB, 120034123776 bytes, 234441648 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: 0x0002ea0d

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 234440703 116707328 8e Linux LVM

Disk /dev/mapper/rhel_foundation20-root: 53.7 GB, 53687091200 bytes, 104857600 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 /dev/mapper/rhel_foundation20-swap: 4026 MB, 4026531840 bytes, 7864320 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 /dev/mapper/rhel_foundation20-home: 61.7 GB, 61723377664 bytes, 120553472 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 /dev/sdb: 15.7 GB, 15745482752 bytes, 30752896 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: 0x0045d92a

Device Boot Start End Blocks Id System
/dev/sdb1 * 64 30752895 15376416 b W95 FAT32 ##我的移动设备
[root@foundation20 ~]# df ##查看优盘挂载路径
这里写图片描述
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/rhel_foundation20-root 52403200 16262600 36140600 32% /
devtmpfs 1867064 0 1867064 0% /dev
tmpfs 1881152 588 1880564 1% /dev/shm
tmpfs 1881152 9112 1872040 1% /run
tmpfs 1881152 0 1881152 0% /sys/fs/cgroup
/dev/mapper/rhel_foundation20-home 60247304 4063900 56183404 7% /home
/dev/sda1 508588 153088 355500 31% /boot
/dev/loop0 3654720 3654720 0 100% /var/www/html/source7.0
/dev/loop1 3947824 3947824 0 100% /var/www/html/source7.2
tmpfs 376232 36 376196 1% /run/user/1000
tmpfs 376232 0 376232 0% /run/user/0
/dev/sdb1 15346360 6020016 9326344 40% /run/media/kiosk/KINGSTON ##表示我的移动设备
[root@foundation20 ~]# umount /dev/sdb1 ##卸载
[root@foundation20 ~]# mount /dev/sdb1 /mnt ##把优盘挂载到/mnt下
[root@foundation20 ~]# cd /mnt ##切换到/mnt/下
第二个真机shell:
【1】切换到超级用户
【2】卸载移动设备
【3】关闭进程
【4】成功卸载
这里写图片描述
[kiosk@foundation20 Desktop]$ su - ##切换用户
Password:
Last login: Mon Apr 30 09:33:50 CST 2018 on pts/3
[root@foundation20 ~]# 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@foundation20 ~]# fuser -kvm /dev/sdb1 ##结束进程
USER PID ACCESS COMMAND
/dev/sdb1: root kernel mount /mnt
root 5831 ..c.. bash
[root@foundation20 ~]# umount /mnt/ ##进行卸载
成功标示:在第一个shell出现killed
[root@foundation20 mnt]# Killed ##卸载成功
%%%指定设备激活或更改:
[kiosk@foundation21 Desktop]$ su -
Password:
Last login: Mon Apr 30 09:32:09 CST 2018 on pts/3
[root@foundation21 ~]# 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@foundation21 ~]# fuser -kvm /dev/sdb1 ##查看占用后台的PID
USER PID ACCESS COMMAND
/dev/sdb1: root kernel mount /mnt
root 14537 ..c.. bash
[root@foundation21 ~]# fuser -kvm /dev/sdb1 ##杀死后台
USER PID ACCESS COMMAND
/dev/sdb1: root kernel mount /mnt
root 14537 ..c.. bash
[root@foundation21 ~]# umount /mnt/ ##卸载成功
%%lsof查看占用后台的PID就可以结合kill -9强制杀死
%%mount -o添加参数。
[root@foundation21 ~]# mount -o ro /dev/sdb1 /mnt/
[root@foundation21 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda3 307974224 29625448 278348776 10% /
devtmpfs 1868044 0 1868044 0% /dev
tmpfs 1881152 188 1880964 1% /dev/shm
tmpfs 1881152 9036 1872116 1% /run
tmpfs 1881152 0 1881152 0% /sys/fs/cgroup
/dev/sda1 505580 149472 356108 30% /boot
/dev/loop0 3654720 3654720 0 100% /var/www/html/source7.0
/dev/loop1 3947824 3947824 0 100% /var/www/html/source7.2
tmpfs 376232 36 376196 1% /run/user/1000
tmpfs 376232 0 376232 0% /run/user/0
/dev/sdb1 15100688 8722224 6378464 58% /mnt
[root@foundation21 ~]# touch /mnt/file1
touch: cannot touch ‘/mnt/file1’: Read-only file system
用mount查看为ro不能建立文件只读
[root@foundation21 ~]# umount /dev/sdb1
[root@foundation21 ~]# mount -o rw /dev/sdb1 /mnt/
用mount查看为rw可以建立文件可写
[root@foundation21 ~]# touch /mnt/file1

二.管理系统存储
磁盘介绍与分区规则:电脑的系统都放在磁盘中,磁盘管理着系统的启动,当pc接上电源后,停在固定磁道的磁头需要去到系统所在的扇形区域启动系统,所以需要在磁头开始的地方写上引导程序,让接通电源后,磁头直接去系统所在的扇区,启动系统。这个引导程序是写在磁盘上的,为了不浪费空间,它应该尽可能的小,现在最小的是446个字节,而与其最接近的完整字节应该为512字节,512-446=66,将这多余的66个字节分为64和2,63记录的是分区表,而我们通过实验知道一个分区需要在分区表中占据16个字节,所以64个字节的空间只能有四个分区。如果我们想要得到多于4个的分区,则需要将第四个分区变为扩展分区,在扩展分区里还可以添加逻辑分区。
mb2主引导记录,打开分区。
mpt记录分区信息
512-446(mb2)(最小的字节)=66=64(mpt)+2
mbr分区方式,主分区,剩下的放在容器中叫做扩展分区,容器里面的东西为逻辑分区,在linux中最多放16个,每个不超过2t

分区划分

fdisk /dev/vdb ##查看硬盘
elcome 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)
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): 1 ##主分区id
First sector (2048-20971519, default 2048): ##此分区起始位置 【默认】
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +100M ##分区大小
这里写图片描述
Partition 1 of type Linux and of size 100 MiB is set
建立4个主分区后,就不能建立主分区,只能删除其中的一个主分区,然后建立拓展分区即可
Command (m for help): n
If you want to create more than four partitions, you must replace a
primary partition with an extended partition first.

Command (m for help): d
Partition number (1-4, default 4): 4
Partition 4 is deleted

Command (m for help): n
Partition type:
p primary (3 primary, 0 extended, 1 free)
e extended
Select (default e): e
Selected partition 4
First sector (2069-20971519, default 6144):
Using default value 6144
Last sector, +sectors or +size{K,M,G} (6144-204799, default 204799): +18M
Partition 4 of type Extended and of size 18 MiB is set
这里写图片描述
p显示分区结果
这里写图片描述
Command (m for help): wq ##保存退出,如果按q表示放弃更改退出
[root@localhost mnt]# partprobe ##同步分区表
cat /proc/partitions ##查看系统识别的分区信息
这里写图片描述
对磁盘分区结束后,并不能进行挂载,我们需要让他获取文件系统后才能进行挂载,对1,2,3进行格式化,而4不能执行这个命令,因为他本来就是一个容器,不能进行挂载【mkfs.xfs/dev/vdb1】
这里写图片描述

将新建分区变化到gpt类型

[root@localhost ~]# parted /dev/vdb
GNU Parted 3.1
Using /dev/vdb
Welcome to GNU Parted! Type ‘help’ to view a list of commands.
(parted) mklabel

New disk label type? gpt ##选择类型
(parted) quit
Information: You may need to update /etc/fstab.

[root@localhost ~]# fdisk /dev/vdb #建立gpt类型的主分区
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
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): n
Partition number (1-128, default 1): 1 ##能建立128个主分区
First sector (34-20971486, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-20971486, default 20971486): +100
First sector (34-20971486, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-20971486, default 20971486): +10M
Created partition 1

Command (m for help): n
Partition number (2-128, default 2): 2
First sector (34-209714

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值