系统分区管理
df <= blkid < cat /proc/partitions < fdisk -l
df ##查看系统正在使用的设备
blkid ##查看系统里面可以使用的设备
cat /proc/partitions ##查看系统识别的设备
fdisk -l ##查看硬盘
df -h ##2的n次方,1024
df -H ##10的n次方 1000 -h比-H统计出来的数小,但是精确
在真机里做以下实验:
硬盘的挂载卸载
先插入U盘,用df查看有/dev/sdb1 –>u盘
[root@foundation68 ~]# umount /dev/sdb1/ ##卸载u盘[root@foundation68 ~]# mount /dev/sdb1 /mnt/ ##将u盘挂载到/mnt下[root@foundation68 ~]# cd /mnt
再打开一个shell
[root@foundation68 ~]# umount /dev/sdb1/ ##卸载u盘[root@foundation68 ~]# mount /dev/sdb1 /mnt/ ##将u盘挂载到/mnt下[root@foundation68 ~]# cd /mnt另开一个shell[root@foundation68 ~]# umount /dev/sdb1/umount: /mnt: target is busy. ##u盘正在运行,卸载不掉(In some cases useful info about processes that usethe device is found by lsof(8) or fuser(1))[root@foundation28 ~]# fuser -kvm /dev/sdb1/ ##杀死后台运行USER PID ACCESS COMMAND/dev/sdb1: rootkernel mount /mntroot 9277 ..c.. bash[root@foundation68 ~]# umount /dev/sdb1 ##现在就可以卸载了
切换到第一个shell
[root@foundation68 mnt]# Killed ##进程已经被杀死
[root@foundation68 ~]# fuser -vm /dev/sdb1/ ##查看USER PID ACCESS COMMAND/dev/sdb1: rootkernel mount /run/media/kiosk/00A4-2CBF
指定设备激活或更改
[root@foundation68 ~]# mount -o ro /dev/sdb1 /mnt/ ##mount -o添加参数[root@foundation68 ~]# touch /mnt/file1touch: cannot touch ‘/mnt/file1’: Read-only file system
用mount查看为ro不能建立文件只读
[root@foundation68 ~]# umount /dev/sdb1[root@foundation68 ~]# mount -o rw /dev/sdb1 /mnt/
用mount查看为rw可以建立文件为可写
划分分区
以下实验步骤需在虚拟机server里完成:
[root@localhost ~]# 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.Device does not contain a recognized partition tableBuilding a new DOS disklabel with disk identifier mand (m for help): m####获得帮助Command actiona toggle a bootable flagb edit bsd disklabelc toggle the dos compatibility flagd delete a partition ##删除分区g create a new empty GPT partition tableG create an IRIX (SGI) partition tablel list known partition typesm print this menun add a new partition ##新建分区o create a new empty DOS partition tablep print the partition table ##显示分区表信息q quit without saving changes ##退出s create a new empty Sun disklabelt change a partitions system id ##修改分区idu change display/entry unitsv verify the partition tablew 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): p Partition number (1-4, default 1): 1##确定主分区idFirst sector (2048-20971519, default 2048): ##分区起始块的位置,默认Using default value 2048Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +100M ##分区结束位置,用+大小的方式指定Partition 1 of type Linux and of size 100 MiB is set
重复以上步骤到第四个分区:
Command (m for help): nPartition type:p primary (3 primary, 0 extended, 1 free)e extendedSelect (default e):##显示分区表信息Using default response eSelected partition