centos 磁盘挂载
2021-03-22 本文已影响0人
梅村_9643
一、parted的用途及说明
概括使用说明:
parted用于对磁盘(或RAID磁盘)进行分区及管理,与fdisk分区工具相比,支持2TB以上的磁盘分区,并且允许调整分区的大小。使用它你可以创建、清除、调整、移动和复制ext2、ext3、ext4、linux-swap、FAT、FAT32和reiserfs分区;也能创建、调整和移动苹果系统的HFS分区;还能检测jfs、ntfs、ufs和xfs分区。该工具常用于为新安装的操作系统创建空间,重新分配硬盘使用情况,在将数据拷贝到新硬盘的时候也常常使用。
二、 parted的使用方法及步骤
fdisk -l 查看硬盘分区格式信息
————————————————
[root@localhost ~]# fdisk -l
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.
磁盘 /dev/sdb:536.9 GB, 536870912000 字节,1048576000 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:gpt
Disk identifier: FCD85220-83B7-436C-8BD9-D34E4878119D
Start End Size Type Name
1 2048 1048573951 500G Microsoft basic ofs
磁盘 /dev/sdc:322.1 GB, 322122547200 字节,629145600 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/sda:53.7 GB, 53687091200 字节,104857600 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0x00012d21
设备 Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 104857599 51379200 8e Linux LVM
磁盘 /dev/mapper/centos-root:50.5 GB, 50457477120 字节,98549760 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘 /dev/mapper/centos-swap:2147 MB, 2147483648 字节,4194304 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
2.1进入parted对磁盘进行分区
[root@localhost ~]# parted /dev/sd
sda sda1 sda2 sdb sdb1 sdc
[root@localhost ~]# parted /dev/sdc **选择需要分区的磁盘**
GNU Parted 3.1
使用 /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) help **help查看parted下命令介绍**
align-check TYPE N check partition N for TYPE(min|opt) alignment
help [COMMAND] print general help, or help on COMMAND
mklabel,mktable LABEL-TYPE create a new disklabel (partition table)
mkpart PART-TYPE [FS-TYPE] START END make a partition
name NUMBER NAME name partition NUMBER as NAME
print [devices|free|list,all|NUMBER] display the partition table, available devices, free space, all found
partitions, or a particular partition
quit exit program
rescue START END rescue a lost partition near START and END
rm NUMBER delete partition NUMBER
select DEVICE choose the device to edit
disk_set FLAG STATE change the FLAG on selected device
disk_toggle [FLAG] toggle the state of FLAG on selected device
set NUMBER FLAG STATE change the FLAG on partition NUMBER
toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER
unit UNIT set the default unit to UNIT
version display the version number and copyright information of GNU Parted
(parted) mklabel
新的磁盘标签类型? gpt **写入磁盘便签**
(parted) mkpart **创建分区**
分区名称? []? test
文件系统类型? [ext2]? ext4
起始点? 1 **可以输入具体的起始点(1M或者1G)1表示扇区最小的起始点**
结束点? -1 **结束点一样也可以输入具体的结束点(100M或者300G)-1表示扇区最后的结束点**
(parted) p **全拼print查看分区**
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 322GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name 标志
1 1049kB 322GB 322GB test
(parted) quit **退出parted分区**
信息: You may need to update /etc/fstab.
[root@localhost ~]# mkfs.ext4 /dev/sd
sda sda1 sda2 sdb sdb1 sdc sdc1
[root@localhost ~]# mkfs.ext4 /dev/sdc1 **mkfs.ext4 对刚刚创建的分区进行格式化**
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
19660800 inodes, 78642688 blocks
3932134 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=2227175424
2400 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616
Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
[root@localhost ~]# mkdir /ysj **创建一个分区的挂载点**
[root@localhost ~]# mount /dev/sdc1 /ysj **mount将新建的分区挂载到新建的挂载点**
[root@localhost ~]# df -h **df -h 查看磁盘分区的使用情况**
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root 47G 8.0G 40G 17% /
devtmpfs 905M 0 905M 0% /dev
tmpfs 920M 0 920M 0% /dev/shm
tmpfs 920M 9.1M 911M 1% /run
tmpfs 920M 0 920M 0% /sys/fs/cgroup
/dev/sdb1 493G 73M 467G 1% /ofs
/dev/sda1 1014M 179M 836M 18% /boot
tmpfs 184M 32K 184M 1% /run/user/0
/dev/sr0 4.3G 4.3G 0 100% /run/media/root/CentOS 7 x86_64
/dev/sdc1 296G 65M 281G 1% /ysj
[root@localhost ~]#
三,修改 vi/etc/fstab 设置开机自动挂载
[root@localhost ~]# vi /etc/fstab **进去该目录下设置开机自动挂载**
#
# /etc/fstab
# Created by anaconda on Wed Apr 29 18:09:55 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=7d7c13fd-ff7e-4ffe-b923-159e4b7f1f65 /boot xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
/dev/sdb1 /ofs ext4 defaults 0 0
/dev/sdc1 /ysj ext4 defaults 0 0
~
~
~
~
:wq **shift+; 输入小写wq 保存退出,不小心误删的可以q!不保存退出**
四,卸载分区
[root@localhost ~]# umount /dev/sdc1 **使用umount命令卸载挂载的分区**
[root@localhost ~]# df -h **df -h 查看磁盘分区的使用情况**
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root 47G 8.0G 39G 17% /
devtmpfs 905M 0 905M 0% /dev
tmpfs 920M 0 920M 0% /dev/shm
tmpfs 920M 9.1M 911M 1% /run
tmpfs 920M 0 920M 0% /sys/fs/cgroup
/dev/sdb1 493G 73M 467G 1% /ofs
/dev/sda1 1014M 179M 836M 18% /boot
tmpfs 184M 32K 184M 1% /run/user/0
/dev/sr0 4.3G 4.3G 0 100% /run/media/root/CentOS 7 x86_64
**发现我们刚刚挂载的ysj挂载点已经删除***
[root@localhost ~]# parted /dev/sd
sda sda1 sda2 sdb sdb1 sdc sdc1
[root@localhost ~]# parted /dev/sdc ****parted再次进入分区删除残旧的磁盘信息***
GNU Parted 3.1
使用 /dev/sdc
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) p **查看当前的磁盘分区**
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 322GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name 标志
1 1049kB 322GB 322GB ext4 test
(parted) rm 1 **rm 删除分区 1指的是Number下的磁盘ID**
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdc: 322GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name 标志
*在查看发现我们创建的磁盘分区已经被删除了**
(parted) quit **保存退出**
信息: You may need to update /etc/fstab.
[root@localhost ~]# vi /etc/fstab ****进入此文件夹下注释掉之前的自启动信息 否则可能影响系统的正常启动在对应的行列前加#号表示注销***
#
# /etc/fstab
# Created by anaconda on Wed Apr 29 18:09:55 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=7d7c13fd-ff7e-4ffe-b923-159e4b7f1f65 /boot xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
/dev/sdb1 /ofs ext4 defaults 0 0
#/dev/sdc1 /ysj ext4 defaults 0 0
~
~
~
~
:wq **保存退出**
五.fdisk 分区使用
上面我们已经介绍了如何通过fdisk -l 查看硬盘分区格式信息,这里不做重复的介绍,
[root@test4 ~]# fdisk /dev/sda **对sda磁盘进行分区**
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.
The number of cylinders for this disk is set to 2597.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
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 **删除一个分区**
l list known partition types **列出分区类型**
m print this menu **输出帮助信息**
n add a new partition **建立一个新的分区**
o create a new empty DOS partition table **创建一个新的空白DOS分**区表
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
Command action
e extended **e是扩展分区**
p primary partition (1-4) **p是主分区**
p
Partition number (1-4): 1 **定义分区数量 --主分区最多只能有四个**
First cylinder (1-2597, default 1): 1
Last cylinder or +size or +sizeM or +sizeK (1-2597, default 2597): +100M
Command (m for help): w **保存刚才的配置信息。**
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 22: 无效的参数.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
[root@test6 ~]# partprobe /dev/sda **对硬盘进行更新**
所有新建的磁盘都需要mkfs.ext2/3/4 进行格式化 mount进行挂载并设置开启自启动。
from https://blog.csdn.net/weixin_45065440/article/details/105856712