#parted交互式方式创建磁盘分区(parted操作是实时生效的) [root@cobbler-node1 ~]# parted /dev/sdb GNU Parted 2.1 Using /dev/sdb Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) mklabel gpt Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue? Yes/No? yes (parted) mkpart primary 0 100 Warning: The resulting partition is not properly aligned for best performance. Ignore/Cancel? Ignore (parted) mkpart primary linux-swap 101 201 (parted) mkpart logical ext4 202 302 (parted) p Model: VMware, VMware Virtual S (scsi) Disk /dev/sdb: 2147MB Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags 1 17.4kB 100MB 100MB primary 2 101MB 201MB 101MB primary 3 202MB 302MB 99.6MB logical (parted) quit Information: You may need to update /etc/fstab. #查看分区是否立即生效 [root@cobbler-node1 ~]# ls /dev/sdb* /dev/sdb /dev/sdb1 /dev/sdb2 /dev/sdb3 [root@cobbler-node1 ~]# cat /proc/partitions | grep -w "sdb[0-3]+" 8 17 97639 sdb1 8 18 98304 sdb2 8 19 97280 sdb3 #格式化分区创建文件系统 [root@cobbler-node1 ~]# mkfs.ext4 /dev/sdb3 mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=1024 (log=0) Fragment size=1024 (log=0) Stride=0 blocks, Stripe width=0 blocks 24384 inodes, 97280 blocks 4864 blocks (5.00%) reserved for the super user First data block=1 Maximum filesystem blocks=67371008 12 block groups 8192 blocks per group, 8192 fragments per group 2032 inodes per group Superblock backups stored on blocks: 8193, 24577, 40961, 57345, 73729 Writing inode tables: done Creating journal (4096 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 26 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. #查看块设备的属性信息 [root@cobbler-node1 ~]# blkid /dev/sdb3 /dev/sdb3: UUID="95f2058c-385e-484b-9f4a-64d62bdd0a98" TYPE="ext4" #创建挂载目录 [root@cobbler-node1 ~]# mkdir /applog1 #挂载文件系统到相应的目录 [root@cobbler-node1 ~]# mount /dev/sdb3 /applog1 #验证挂载是否成功 [root@cobbler-node1 ~]# df -h | grep "sdb" /dev/sdb3 92M 5.6M 82M 7% /applog1 #加载文件系统随开机自动挂载 [root@cobbler-node1 ~]# echo "UUID=95f2058c-385e-484b-9f4a-64d62bdd0a98 /applog1 ext4 defaults 0 0" >> /etc/fstab [root@cobbler-node1 ~]# tail -1 /etc/fstab UUID=95f2058c-385e-484b-9f4a-64d62bdd0a98 /applog1 ext4 defaults 0 0
方法二:非交互式创建磁盘分区