- Mount命令工具主要用于将设备或者分区挂载至Linux系统目录下,Linux系统在分区时,也是基于mount机制将/dev/sda分区挂载至系统目录,将设备与目录挂载之后,Linux操作系统方可进行文件的存储。
mount [-Vh]
mount -a [-fFnrsvw] [-t vfstype]
mount [-fnrsvw] [-o options [,…]] device | dir
mount [-fnrsvw] [-t vfstype] [-o options] device dir
-V: 显示mount工具版本号;
-l: 显示已加载的文件系统列表;
-h: 显示帮助信息并退出;
-v: 输出指令执行的详细信息;
-n: 加载没有写入文件/etc/mtab中的文件系统;
-r: 将文件系统加载为只读模式;
-a: 加载文件/etc/fstab中配置的所有文件系统;
-o: 指定mount挂载扩展参数,常见扩展指令:rw、remount、loop等,其中-o相关指令如下:
-o atime: 系统会在每次读取文档时更新文档时间;
-o noatime: 系统会在每次读取文档时不更新文档时间;
-o defaults: 使用预设的选项 rw,suid,dev,exec,auto,nouser等;
-o exec 允许执行档被执行;
-o user、-o nouser: 使用者可以执行 mount/umount的动作;
-o remount: 将已挂载的系统分区重新以其他再次模式挂载;
-o ro: 只读模式挂载;
-o rw: 可读可写模式挂载;
-o loop 使用loop模式,把文件当成设备挂载至系统目录。
-t: 指定mount挂载设备类型,常见类型nfs、ntfs-3g、vfat、iso9660等,其中-t相关指令如下:
iso9660 光盘或光盘镜像;
msdos Fat16文件系统;
vfat Fat32文件系统;
ntfs NTFS文件系统;
ntfs-3g 识别移动硬盘格式;
smbfs 挂载Windows文件网络共享;
nfs Unix/Linux文件网络共享。
- MOUNT 常用案例
mount /dev/sdb1 /data 挂载/dev/sdb1分区至/data/目录
mount /dev/cdrom /mnt 挂载Cdrom光盘至/mnt目录;
mount -t ntfs-3g /dev/sdc /data1 挂载/dev/sdc移动硬盘至/data1目录;
mount -o remount,rw / 重新以读写模式挂载/系统;
mount -t iso9660 -o loop centos7.iso /mnt 将centos7.iso镜像文件挂载至/mnt目录;
mount -t fat32 /dev/sdd1 /mnt 将U盘/dev/sdd1挂载至/mnt/目录;
mount -t nfs 192.168.10.11:/data/ /mnt 将远程192.168.10.11:/data目录挂载至本地/mnt目录。
- 使用 gdisk 创建一个 500M 的 xfs 文件系统,并将它挂载到 /data/test目录下
1.列出所有磁盘
[admin@rivers~]$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 40G 0 disk
├─sda1 8:1 0 2M 0 part
├─sda2 8:2 0 1G 0 part /boot
├─sda3 8:3 0 10G 0 part /
├─sda4 8:4 0 5G 0 part /home
└─sda5 8:5 0 1G 0 part [SWAP]
sr0 11:0 1 4.2G 0 rom /run/media/admin/CentOS 7 x86_64
2. 查看磁盘分区表类型
[admin@rivers~]$ sudo parted /dev/sda print
[sudo] admin 的密码:
Model: VMware, VMware Virtual S (scsi) # (厂商)模块名称
Disk /dev/sda: 42.9GB # 磁盘总容量
Sector size (logical/physical): 512B/512B # 物理扇区容量
Partition Table: gpt # 这里显示是gpt格式
Disk Flags: pmbr_boot
Number Start End Size File system Name 标志
1 1049kB 3146kB 2097kB bios_grub
2 3146kB 1077MB 1074MB xfs
3 1077MB 11.8GB 10.7GB xfs
4 11.8GB 17.2GB 5369MB xfs
5 17.2GB 18.3GB 1074MB linux-swap(v1)
[admin@rivers~]$
3.使用gdisk 创建分区
[admin@rivers~]$ sudo gdisk /dev/sda
GPT fdisk (gdisk) version 0.8.6
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present
Found valid GPT with protective MBR; using GPT.
Command (? for help): ? # ? 命令帮助,想到fdisk中的m
b back up GPT data to a file
c change a partition’s name
d delete a partition # 删除一个分区
i show detailed information on a partition
l list known partition types
n add a new partition # 增加一个分区
o create a new empty GUID partition table (GPT)
p print the partition table #打印出分区表 (常用)
q quit without saving changes # 不保存分区直接离开
r recovery and transformation options (experts only)
s sort partitions
t change a partition’s type code
v verify disk
w write table to disk and exit #保存分区后离开
x extra functionality (experts only)
? print this menu
Command (? for help): p
Disk /dev/sda: 83886080 sectors, 40.0 GiB # 磁盘文件名/扇区总数与总容量
Logical sector size: 512 bytes # 单一扇区大小为512 bytes
Disk identifier (GUID): 00B9BA4D-D71C-462B-82F4-091B4C43A1D5 #磁盘的GPT标识码
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 83886046
Partitions will be aligned on 2048-sector boundaries
Total free space is 48230333 sectors (23.0 GiB) # 下面为完整的分区信息
Number Start (sector) End (sector) Size Code Name
1 2048 6143 2.0 MiB EF02 # 第一个分区信息
2 6144 2103295 1024.0 MiB 0700
3 2103296 23074815 10.0 GiB 0700
4 23074816 33560575 5.0 GiB 0700
5 33560576 35657727 1024.0 MiB 8200
Command (? for help): n # 新增加一个
Partition number (6-128, default 6): # 标识符
First sector (34-83886046, default = 35657728) or {±}size{KMGTP}: # 开始扇区
Last sector (35657728-83886046, default = 83886046) or {±}size{KMGTP}: +500M
Current type is ‘Linux filesystem’
Hex code or GUID (L to show codes, Enter = 8300): #在分区内可能的文件系统类型 8300
Changed type of partition to ‘Linux filesystem’
Command (? for help): p
Disk /dev/sda: 83886080 sectors, 40.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 00B9BA4D-D71C-462B-82F4-091B4C43A1D5
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 83886046
Partitions will be aligned on 2048-sector boundaries
Total free space is 47206333 sectors (22.5 GiB)
Number Start (sector) End (sector) Size Code Name
1 2048 6143 2.0 MiB EF02
2 6144 2103295 1024.0 MiB 0700
3 2103296 23074815 10.0 GiB 0700
4 23074816 33560575 5.0 GiB 0700
5 33560576 35657727 1024.0 MiB 8200
6 35657728 36681727 500.0 MiB 8300 Linux filesystem
8300 linux 文件系统
8200 swap 文件系统
Command (? for help): w # 保存
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): Y # 按Y 退出
OK; writing new GUID partition table (GPT) to /dev/sda.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot.
The operation has completed successfully.
[admin@rivers~]$
[admin@rivers~]$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 40G 0 disk
├─sda1 8:1 0 2M 0 part
├─sda2 8:2 0 1G 0 part /boot
├─sda3 8:3 0 10G 0 part /
├─sda4 8:4 0 5G 0 part /home
└─sda5 8:5 0 1G 0 part [SWAP]
sr0 11:0 1 4.2G 0 rom /run/media/admin/CentOS 7 x86_64
4. 更新linux 内核的分区表信息
[admin@rivers~]$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 40G 0 disk
├─sda1 8:1 0 2M 0 part
├─sda2 8:2 0 1G 0 part /boot
├─sda3 8:3 0 10G 0 part /
├─sda4 8:4 0 5G 0 part /home
├─sda5 8:5 0 1G 0 part [SWAP]
└─sda6 8:6 0 500M 0 part
sr0 11:0 1 4.2G 0 rom /run/media/admin/CentOS 7 x86_64
[admin@rivers~]$
5.格式化刚建立的分区
[admin@rivers~]$ sudo mkfs.xfs /dev/sda6
meta-data=/dev/sda6 isize=512 agcount=4, agsize=32000 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=128000, 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
[admin@rivers~]$
6.查看/dev/sda6的UUID
[admin@rivers~]$ sudo blkid|grep “/dev/sda6”
/dev/sda6: UUID=“fc584ce9-b4ff-4c54-8c2c-9ed6cf54dc1d” TYPE=“xfs” PARTLABEL=“Linux filesystem” PARTUUID=“1aa87728-47cd-428d-b5bd-32a076c8f537”
[admin@rivers~]$
7.创建挂载点,且挂载
[admin@rivers~]$ sudo mount UUID=“fc584ce9-b4ff-4c54-8c2c-9ed6cf54dc1d” /data/test
[admin@rivers~]$ df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda3 10G 4.6G 5.5G 46% /
devtmpfs 1.8G 0 1.8G 0% /dev
tmpfs 1.8G 0 1.8G 0% /dev/shm
tmpfs 1.8G 9.1M 1.8G 1% /run
tmpfs 1.8G 0 1.8G 0% /sys/fs/cgroup
/dev/sda4 5.0G 37M 5.0G 1% /home
/dev/sda2 1014M 158M 857M 16% /boot
tmpfs 367M 4.0K 367M 1% /run/user/42
tmpfs 367M 36K 367M 1% /run/user/1000
/dev/sr0 4.3G 4.3G 0 100% /run/media/admin/CentOS 7 x86_64
/dev/sda6 497M 26M 472M 6% /data/test
[admin@rivers~]$
8.删除刚建立的 6号分区,先卸载,再说删除
[admin@rivers~]$ sudo umount /data/test/
[admin@rivers~]$ sudo gdisk /dev/sda
GPT fdisk (gdisk) version 0.8.6
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present
Found valid GPT with protective MBR; using GPT.
Command (? for help): p # 打印下以存在的分区
Disk /dev/sda: 83886080 sectors, 40.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 00B9BA4D-D71C-462B-82F4-091B4C43A1D5
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 83886046
Partitions will be aligned on 2048-sector boundaries
Total free space is 47206333 sectors (22.5 GiB)
Number Start (sector) End (sector) Size Code Name
1 2048 6143 2.0 MiB EF02
2 6144 2103295 1024.0 MiB 0700
3 2103296 23074815 10.0 GiB 0700
4 23074816 33560575 5.0 GiB 0700
5 33560576 35657727 1024.0 MiB 8200
6 35657728 36681727 500.0 MiB 8300 Linux filesystem
Command (? for help): d # 按 d 删除分区
Partition number (1-6): 6
Command (? for help): p
Disk /dev/sda: 83886080 sectors, 40.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 00B9BA4D-D71C-462B-82F4-091B4C43A1D5
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 83886046
Partitions will be aligned on 2048-sector boundaries
Total free space is 48230333 sectors (23.0 GiB)
Number Start (sector) End (sector) Size Code Name
1 2048 6143 2.0 MiB EF02
2 6144 2103295 1024.0 MiB 0700
3 2103296 23074815 10.0 GiB 0700
4 23074816 33560575 5.0 GiB 0700
5 33560576 35657727 1024.0 MiB 8200
Command (? for help): w # 保存
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): Y
OK; writing new GUID partition table (GPT) to /dev/sda.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot.
The operation has completed successfully.
[admin@rivers~]$ sudo lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 40G 0 disk
├─sda1 8:1 0 2M 0 part
├─sda2 8:2 0 1G 0 part /boot
├─sda3 8:3 0 10G 0 part /
├─sda4 8:4 0 5G 0 part /home
└─sda5 8:5 0 1G 0 part [SWAP]
sr0 11:0 1 4.2G 0 rom /run/media/admin/CentOS 7 x86_64
[admin@rivers~]$
- 使用parted 创建一个swap 分区
0.检查是否有parted 工具,没有就安装一个这里我有,不需安装
[admin@rivers~]$ which parted
/usr/sbin/parted
#[admin@rivers~]$ yum -y install parted
1. 先列出 磁盘分区表类型,及分区情况
[admin@rivers~]$ sudo parted /dev/sda print
最后
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数Java工程师,想要提升技能,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助。
因此收集整理了一份《2024年Java开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Java开发知识点,不论你是刚入门Java开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门!
如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!
及分区情况
[admin@rivers~]$ sudo parted /dev/sda print
最后
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数Java工程师,想要提升技能,往往是自己摸索成长,自己不成体系的自学效果低效漫长且无助。
因此收集整理了一份《2024年Java开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
[外链图片转存中…(img-vGYEOVMi-1715801345641)]
[外链图片转存中…(img-qpkZryki-1715801345641)]
[外链图片转存中…(img-8LQ7C0M8-1715801345642)]
既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Java开发知识点,不论你是刚入门Java开发的新手,还是希望在技术上不断提升的资深开发者,这些资料都将为你打开新的学习之门!
如果你觉得这些内容对你有帮助,需要这份全套学习资料的朋友可以戳我获取!!
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且会持续更新!