本文共 7225 字,大约阅读时间需要 24 分钟。
前期准备:Vmware workstaton虚拟机软件及可用的Centos7系统
1、在虚拟机中新添一块120G的硬盘,已备分区使用,重启系统即可进行分区操作。
2、查看系统上是否识别出的新增的硬盘:[root@centos7 ~]# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot├─sda2 8:2 0 50G 0 part /├─sda3 8:3 0 2G 0 part [SWAP]├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 10G 0 part /datasdb 8:16 0 120G 0 disk sr0 11:0 1 10G 0 rom3、下面对/dev/sdb硬盘进行分区,硬盘一共120G要求分3个分区,第一个分区为40G,第二个分区为50G,第三个分区为30G:
[root@centos7 ~]# fdisk /dev/sdbWelcome 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 table
Building a new DOS disklabel with disk identifier 0x15c20061.Command (m for help): n
Partition type:p primary (0 primary, 0 extended, 4 free)e extendedSelect (default p): Using default response pPartition number (1-4, default 1): First sector (2048-251658239, default 2048): Using default value 2048Last sector, +sectors or +size{K,M,G} (2048-251658239, default 251658239): +40GPartition 1 of type Linux and of size 40 GiB is setCommand (m for help): N
Partition type:p primary (1 primary, 0 extended, 3 free)e extendedSelect (default p): Using default response pPartition number (2-4, default 2): First sector (83888128-251658239, default 83888128): Using default value 83888128Last sector, +sectors or +size{K,M,G} (83888128-251658239, default 251658239): +50GPartition 2 of type Linux and of size 50 GiB is setCommand (m for help): n
Partition type:p primary (2 primary, 0 extended, 2 free)e extendedSelect (default p): Using default response pPartition number (3,4, default 3): First sector (188745728-251658239, default 188745728): Using default value 188745728Last sector, +sectors or +size{K,M,G} (188745728-251658239, default 251658239): Using default value 251658239Partition 3 of type Linux and of size 30 GiB is setCommand (m for help): w
The partition table has been altered!Calling ioctl() to re-read partition table.
Syncing disks.4、查看分区效果:
[root@centos7 ~]# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot├─sda2 8:2 0 50G 0 part /├─sda3 8:3 0 2G 0 part [SWAP]├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 10G 0 part /datasdb 8:16 0 120G 0 disk ├─sdb1 8:17 0 40G 0 part ├─sdb2 8:18 0 50G 0 part └─sdb3 8:19 0 30G 0 part sr0 11:0 1 10G 0 romNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot├─sda2 8:2 0 50G 0 part /├─sda3 8:3 0 2G 0 part [SWAP]├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 10G 0 part /datasdb 8:16 0 10G 0 disk ├─sdb1 8:17 0 1G 0 part └─sdb2 8:18 0 2G 0 part sdc 8:32 0 10G 0 disk sr0 11:0 1 10G 0 rom 此处我们新创建了sdb和sdc两个硬盘,并且将sdb分了sdb1和sdb2两个分区,若想将sdc的分区与sdb一样,我们将sdb的分区表克隆至sdc即可,我们要做如下操作:[root@centos7 ~]# hexdump -C -n 512 /dev/sdb00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|000001b0 00 00 00 00 00 00 00 00 ae bb 79 e2 00 00 00 20 |..........y.... |000001c0 21 00 83 aa 28 82 00 08 00 00 00 00 20 00 00 15 |!...(....... ...|000001d0 51 05 83 2a a0 0a 00 00 40 00 00 00 40 00 00 00 |Q......@...@...|000001e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |..............U.|00000200[root@centos7 ~]# hexdump -C -n 512 /dev/sdc00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|00000200我们看到sdb有数据。sdc是空的,[root@centos7 ~]# dd if=/dev/sdb of=/dev/sdc bs=1 count=66 skip=446 seek=446 (注:count=66,是因为中间的64位字节还要加上55 aa 两个标记位!)66+0 records in66+0 records out66 bytes (66 B) copied, 0.00506342 s, 13.0 kB/s[root@centos7 ~]# hexdump -C -n 512 /dev/sdc00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|000001b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 20 |............... |000001c0 21 00 83 aa 28 82 00 08 00 00 00 00 20 00 00 15 |!...(....... ...|000001d0 51 05 83 2a a0 0a 00 00 40 00 00 00 40 00 00 00 |Q..*....@...@...|000001e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |..............U.|00000200[root@centos7 ~]# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 200G 0 disk ├─sda1 8:1 0 1G 0 part /boot├─sda2 8:2 0 50G 0 part /├─sda3 8:3 0 2G 0 part [SWAP]├─sda4 8:4 0 1K 0 part └─sda5 8:5 0 10G 0 part /datasdb 8:16 0 10G 0 disk ├─sdb1 8:17 0 1G 0 part └─sdb2 8:18 0 2G 0 part sdc 8:32 0 10G 0 disk ├─sdc1 8:33 0 1G 0 part └─sdc2 8:34 0 2G 0 part sr0 11:0 1 10G 0 rom 此时的sdc与sdb已然同步。5、通知内核读取更新的分区表:查看分区表是否更新:[root@centos7 ~]# partprobe /dev/sdb[root@centos7 ~]# cat /proc/partitionsmajor minor #blocks name8 0 209715200 sda
8 1 1048576 sda18 2 52428800 sda28 3 2097152 sda38 4 1 sda48 5 10485760 sda58 16 125829120 sdb8 17 41943040 sdb18 18 52428800 sdb28 19 31456256 sdb311 0 10491904 sr0成功分区后即可制作文件系统了。6、对新硬盘分区创建文件系统
新增磁盘分区完成后,开始制作文件系统。对sdb1分区进行制做xfs文件系统为例,以演示创建文件系统,其它分区方法一样。[root@centos7 ~]# mkfs.xfs /dev/sdb1meta-data=/dev/sdb1 isize=512 agcount=4, agsize=2621440 blks= sectsz=512 attr=2, projid32bit=1= crc=1 finobt=0, sparse=0data = bsize=4096 blocks=10485760, imaxpct=25= sunit=0 swidth=0 blksnaming =version 2 bsize=4096 ascii-ci=0 ftype=1log =internal log bsize=4096 blocks=5120, version=2= sectsz=512 sunit=0 blks, lazy-count=1realtime =none extsz=4096 blocks=0, rtextents=0查看/dev/sdb1的分区类型:[root@centos7 ~]# blkid/dev/sda1: UUID="bfb9c261-33b4-4602-91ea-a71995a8ef96" TYPE="xfs" /dev/sda2: UUID="4f823650-e522-46fa-9904-c1e7476f89ad" TYPE="xfs" /dev/sda3: UUID="8cc37a26-d321-4331-a020-05f3a08af552" TYPE="swap" /dev/sda5: UUID="0f16b61c-d601-4783-8e3d-0a6452aad27d" TYPE="xfs" /dev/sdb1: UUID="fd61aaf0-bc8e-4da4-8e66-d29d5696b2d5" TYPE="xfs" /dev/sr0: UUID="2018-11-26-14-22-58-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"可见sdb1分区已经创建完成,下面就可以挂载分区后正常使用了。7、挂载新硬盘分区:挂载/dev/sdb1分区:
创建/dev/sdb1分区的挂载点:[root@centos7 ~]# mkdir /madedu_data[root@centos7 ~]# mount /dev/sdb1 /madedu_data[root@centos7 ~]# df -hFilesystem Size Used Avail Use% Mounted on/dev/sda2 50G 3.9G 47G 8% /devtmpfs 1.2G 0 1.2G 0% /devtmpfs 1.2G 0 1.2G 0% /dev/shmtmpfs 1.2G 11M 1.2G 1% /runtmpfs 1.2G 0 1.2G 0% /sys/fs/cgroup/dev/sda5 10G 33M 10G 1% /data/dev/sda1 1014M 174M 841M 18% /boottmpfs 233M 0 233M 0% /run/user/0tmpfs 233M 12K 233M 1% /run/user/42/dev/sdb1 40G 33M 40G 1% /madedu_data8、配置开机自动挂载
挂载完成后,记住要写在/etc/fstab配置文件里,使其新增磁盘分区在开机后能自动挂载。[root@centos7 ~]# vim /etc/fstab#
#
#
UUID=4f823650-e522-46fa-9904-c1e7476f89ad / xfs defaults 0 0UUID=bfb9c261-33b4-4602-91ea-a71995a8ef96 /boot xfs defaults 0 0UUID=0f16b61c-d601-4783-8e3d-0a6452aad27d /data xfs defaults 0 0UUID=8cc37a26-d321-4331-a020-05f3a08af552 swap swap defaults 0 0/dev/sdb1 /madedu_data xfsdefaults 0 0 将此内容添加其中:/dev/sdb1 /magedu_data xfs defaults 0 0检查配置文件的语法:[root@Magedu ~]# mount -a执行该命令后,没有报错,说明配置文件正确,能开机自动挂载,到此整个新增硬盘、分区、制作文件系统以及自动挂载配置全过程完成结束。
转载于:https://blog.51cto.com/14128387/2348574