Linux如何挂载分区?【新手必看】
2019-07-13 00:53发布
生成海报
Linux添加硬盘后都需要一个操作操作才能使用那就是挂载,在企业环境中我们的数据盘和系统盘一般都是分开的。前几天一个朋友让我帮忙分下区把数据盘挂载到/home下去。(个人需求吧,有些公司一般都是专门在'/'下面创建一个data 来做数据盘)。操作记录下了来分享给大家,新手复习,老鸟绕道。
需求: 需要把系统盘搞到/home 下面。
思考: /home 下面是用户默认的家目录,如果用户家目录有数据是会被覆盖的。找朋友确认是刚安装的系统才开始搞的。更改分区大小首先想到的是lvm,但是看了客户的磁盘信息发现不需要考虑这些,怎么简单怎么来。查看硬盘信息[root@localhost /]# fdisk -l 查看硬盘信息Disk /dev/sda: 240.1 GB, 240057409536 bytes, 468862128 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x00085ef7 Device Boot Start End Blocks Id System/dev/sda1 * 2048 1026047 512000 83 Linux/dev/sda2 1026048 17803263 8388608 82 Linux swap / Solaris/dev/sda3 17803264 468860927 225528832 83 LinuxDisk /dev/sdb: 240.1 GB, 240057409536 bytes, 468862128 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/sdc: 500.1 GB, 500107862016 bytes, 976773168 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x0007a974 Device Boot Start End Blocks Id System/dev/sdc1 2048 976773119 488385536 8e Linux LVMDisk /dev/sdd: 240.1 GB, 240057409536 bytes, 468862128 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x000a4688 Device Boot Start End Blocks Id System/dev/sdd1 * 2048 1026047 512000 83 Linux/dev/sdd2 1026048 468860927 233917440 8e Linux LVM
数据的操作是需要非常严谨的,看到了这么多的硬盘,有看到了lvm分区。对于新装的系统我第一感觉是:难道要我修复lvm分区吗?经过和朋友确认发现我想多了,只是挂载,磁盘已经拔掉了。
找到对应硬盘分区格式化磁盘分区
[root@localhost /]# fdisk /dev/sdb \针对第二块盘分区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 0x6511fa23.Command (m for help): p \查看已有分区Disk /dev/sdb: 240.1 GB, 240057409536 bytes, 468862128 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x6511fa23 Device Boot Start End Blocks Id SystemCommand (m for help): n \创建分区Partition type: p primary (0 primary, 0 extended, 4 free) e extendedSelect (default p): p \主分区Partition number (1-4, default 1): First sector (2048-468862127, default 2048): Using default value 2048Last sector, +sectors or +size{K,M,G} (2048-468862127, default 468862127): Using default value 468862127Partition 1 of type Linux and of size 223.6 GiB is setCommand (m for help): p \查看确认分区 Disk /dev/sdb: 240.1 GB, 240057409536 bytes, 468862128 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x6511fa23 Device Boot Start End Blocks Id System/dev/sdb1 2048 468862127 234430040 83 LinuxCommand (m for help): w \保存改分区The partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.
分区格式化
[root@localhost /]# mkfs \tab 万能操作mkfs mkfs.btrfs mkfs.cramfs mkfs.ext2 mkfs.ext3 mkfs.ext4 mkfs.minix mkfs.xfs [root@localhost /]# mkfs.xfs /dev/sdb1 格式化sdb1meta-data=/dev/sdb1 isize=256 agcount=4, agsize=14651878 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 finobt=0data = bsize=4096 blocks=58607510, imaxpct=25 = sunit=0 swidth=0 blksnaming =version 2 bsize=4096 ascii-ci=0 ftype=0log =internal log bsize=4096 blocks=28616, version=2 = sectsz=512 sunit=0 blks, lazy-count=1realtime =none extsz=4096 blocks=0, rtextents=0查看检查分区
[root@localhost /]# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 223.6G 0 disk ├─sda1 8:1 0 500M 0 part /boot├─sda2 8:2 0 8G 0 part [SWAP]└─sda3 8:3 0 215.1G 0 part /sdb 8:16 0 223.6G 0 disk └─sdb1 8:17 0 223.6G 0 part 挂载分区到"/home"挂载分区,找到uuid,写入fstab
[root@localhost /]# blkid /dev/sdb1 查看sdb1 的uuid 写入fstab uuid 最稳定 /dev/sdb1 也可以/dev/sdb1: UUID="ffbd4feb-c55e-40ca-86d3-c43919bd9060" TYPE="xfs" [root@localhost /]# echo "/dev/sdb1: UUID="ffbd4feb-c55e-40ca-86d3-c43919bd9060" TYPE="xfs" " >> /etc/fstab [root@localhost /]# vim /etc/fstab -bash: vim: command not found[root@localhost /]# vi /etc/fstab 写入fstab[root@localhost /]# tail -n 2 /etc/fstabffbd4feb-c55e-40ca-86d3-c43919bd9060 /home xfs defaults 0 0#/dev/sdb1 /home xfs defaults 0 0 \uuid 和 /dev/sdb1 区别??[root@localhost /]# mount -a 重新读取配置文件检查挂载成果,挂载成功!!
[root@localhost /]# df -ThFilesystem Type Size Used Avail Use% Mounted on/dev/sda3 xfs 215G 852M 215G 1% /devtmpfs devtmpfs 7.8G 0 7.8G 0% /devtmpfs tmpfs 7.8G 0 7.8G 0% /dev/shmtmpfs tmpfs 7.8G 8.4M 7.8G 1% /runtmpfs tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup/dev/sda1 xfs 497M 119M 378M 24% /boottmpfs tmpfs 1.6G 0 1.6G 0% /run/user/0/dev/sdb1 xfs 224G 33M 224G 1% /home[root@localhost /]# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 223.6G 0 disk ├─sda1 8:1 0 500M 0 part /boot├─sda2 8:2 0 8G 0 part [SWAP]└─sda3 8:3 0 215.1G 0 part /sdb 8:16 0 223.6G 0 disk └─sdb1 8:17 0 223.6G 0 part /homeok,收工!!来源:http://www.linuxprobe.com/linux-mount-disk.html距离Linux云计算免费课程火热开启倒计时9天,5天免费课程抢先听,运维干货内容免费听,点击文末“阅读原文”即可免费听运维课!火速抢先~~~~PS:记得查收小编送你的免费大礼包呦~福利 | 一万多套PPT模板等你免费来拿!无条件领取!
免费送 | 1000多套简历模板免费拿,附赠简历制作教程!免费领 | 《Shell脚本 100例》电子书免费拿,运维必备干货~▼▼点击【阅读原文】,免费听5天Linux运维干货分享课,火热开讲中,速来抢!
打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮