(1).临时挂载:
[[email protected] 桌面]# fdisk /dev/sdb Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x4ef8fb05. Changes will remain in memory only, until you decide to write them. After that, of course, the previous content won't be recoverable. Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite) WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): n //新建分区 Command action e extended p primary partition (1-4) p //创建主分区 Partition number (1-4): 1 //分区号 First cylinder (1-2610, default 1): //起始位置,一般默认即可 Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): //给定的大小,不是默认一定要有加号'+' Using default value 2610 Command (m for help): w //保存退出 The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [[email protected] 桌面]# mkdir /newpar //创建挂载的文件夹 //ext4格式化,xfs格式化就是mkfs.xfs /dev/sdb1 [[email protected] 桌面]# mkfs.ext4 /dev/sdb1 //如果已经存在文件系统,需要使用-f选项对分区强制格式化 mke2fs 1.41.12 (17-May-2010) 文件系统标签= 操作系统:Linux 块大小=4096 (log=2) 分块大小=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 1310720 inodes, 5241198 blocks 262059 blocks (5.00%) reserved for the super user 第一个数据块=0 Maximum filesystem blocks=4294967296 160 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 正在写入inode表: 完成 Creating journal (32768 blocks): 完成 Writing superblocks and filesystem accounting information: 完成 This filesystem will be automatically checked every 22 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [[email protected] 桌面]# mount /dev/sdb1 /newpar //将分区挂载 [[email protected] 桌面]# df -h //查看挂载情况 Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_centos6-lv_root 50G 3.7G 43G 8% / tmpfs 932M 228K 932M 1% /dev/shm /dev/sda1 477M 40M 412M 9% /boot /dev/mapper/vg_centos6-lv_home 45G 52M 43G 1% /home /dev/sdb1 20G 44M 19G 1% /newpar
注意:CentOS7默认文件系统是xfs,CentOS6默认文件系统是ext4
(2).永久挂载
永久挂载方法一:使用分区名挂载
使用命令’vim /etc/fstab’进入文件增加一行
/dev/sdb1 /newpar ext4 defaults 0 0
永久挂载方法二:使用UUID挂载(建议使用UUID)
[[email protected] ~]# blkid /dev/sda1: UUID="0516ad0c-a018-41a2-a384-f607ed06db40" TYPE="xfs" /dev/sda2: UUID="81986899-73d9-4029-b5bb-a30e652d766c" TYPE="swap" /dev/sda3: UUID="526be8cd-59d8-4ffa-bb0b-9ac8ad2a02af" TYPE="xfs" /dev/sdb1: UUID="da309857-1362-4ff8-8219-ddc1d177755f" TYPE="xfs" /dev/sr0: UUID="2018-05-03-20-55-23-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos" [[email protected] ~]# echo "UUID=da309857-1362-4ff8-8219-ddc1d177755f /sdb1 xfs defaults 0 0" >> /etc/fstab
在重启系统前可以先使用命令’mount -a’检测是否可以正常运行,如果没有报错可以重启系统。
另外ext4可以根据实际使用更换,具体如下:
光盘或光盘镜像iso9660 DOS fat16文件系统msdos Windows 9x fat32文件系统vfat Windows NT ntfs文件系统ntfs Mount Windows文件网络共享smbfs UNIX(LINUX)文件网络共享nfs
说明:
/dev/sdb1 | /sdb1 | xfs | defaults | 0 | 0 |
要挂载的分区设备 | 挂载点 | 文件系统类型 | 挂载选项 | 是否备份 | 是否检测 |
defaults对应的挂载选项请看Linux命令之mount中(1)常用选项中的-o option选项。可以使用英文逗号选择多个选项(option,option,option,…)
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/tech/aiops/2792.html