使用parted对Linux未分区部分进行分区

1. 使用命令parted -l 查看当前分区

可以看到硬盘有2396GB即有2.5T , 但是分区就分了50G一个盘, 需要分剩下部分

[root@localhost ~]# parted -l
Model: IBM ServeRAID M5210 (scsi)
Disk /dev/sda: 2396GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: pmbr_boot

Number  Start   End     Size    File system  Name  Flags
 1      1049kB  2097kB  1049kB                     bios_grub
 2      2097kB  526MB   524MB   xfs
 3      526MB   56.4GB  55.8GB                     lvm


Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/centos-swap: 2143MB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags: 

Number  Start  End     Size    File system     Flags
 1      0.00B  2143MB  2143MB  linux-swap(v1)


Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/centos-root: 53.7GB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags: 

Number  Start  End     Size    File system  Flags
 1      0.00B  53.7GB  53.7GB  xfs

 

2.直接进去parted

[root@localhost ~]# parted /dev/sda

 

3.使用mkpart进行分区

(parted) mkpart xfs 56.4GB 50%
(parted) mkpart xfs 50% 100%                                    
(parted) print                                                            
Model: IBM ServeRAID M5210 (scsi)
Disk /dev/sda: 2396GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: pmbr_boot

Number  Start   End     Size    File system  Name  Flags
 1      1049kB  2097kB  1049kB                     bios_grub
 2      2097kB  526MB   524MB   xfs
 3      526MB   56.4GB  55.8GB                     lvm
 4      56.4GB  1198GB  1142GB               xfs
 5      1198GB  2396GB  1198GB               xfs

可以看到下面分了2个分区 , 都有1.1T

 

4.退出parted

(parted) quit
Information: You may need to update /etc/fstab.

提示你需要更新分区表

 

5.对分区进行格式化

现在分区还没格式化,而且也没挂载,看不见,我们可以用blkid来查看

[root@localhost ~]# blkid
/dev/sda1: PARTUUID="a89cb88b-8c37-4f4b-ac63-20e6fc134e6f" 
/dev/sda2: UUID="5918f242-30d5-4d9d-a68c-669005b59e9b" TYPE="xfs" PARTUUID="540d4b40-2a86-4f0e-bf35-478383e18040" 
/dev/sda3: UUID="uMUriJ-GfeV-l2a4-cjW2-YRKN-Si8a-crFttV" TYPE="LVM2_member" PARTUUID="8338343a-953d-4afc-8980-217cbc4f91b0" 
/dev/sda4: PARTLABEL="xfs" PARTUUID="1eb7a686-bb83-4687-ab2f-4d81b3bba646" 
/dev/sda5: PARTLABEL="xfs" PARTUUID="aae90423-b656-4c5b-baca-692a493f9822" 
/dev/mapper/centos-root: UUID="1c34892c-0c18-4056-b93a-919db8d706eb" TYPE="xfs" 
/dev/mapper/centos-swap: UUID="b7f51dbc-cbd6-433a-beda-fa4018931e17" TYPE="swap" 

明显看到 /dev/sda4 /dev/sda5 这2个就是我们新分的分区

使用mkfs对2个分区进行格式化

[root@localhost ~]# mkfs -t xfs /dev/sda4
meta-data=/dev/sda4              isize=256    agcount=4, agsize=69679936 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=278719744, imaxpct=5
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=136093, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@localhost ~]# mkfs -t xfs /dev/sda5
meta-data=/dev/sda5              isize=256    agcount=4, agsize=73119936 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=292479744, imaxpct=5
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=142812, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

 

6.挂载分区

写入分区表中

暂定我们挂载目录为 : 

/dev/sda4 我们挂载到目录 /u01

/dev/sda5 我们挂载到目录 /u02

[root@localhost ~]# more /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Tue Aug 20 21:05:33 2019
#
# 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=5918f242-30d5-4d9d-a68c-669005b59e9b /boot                   xfs     defaults        0 0
/dev/mapper/centos-swap swap                    swap    defaults        0 0
/dev/sda4    /u01    xfs    defaults    0    0
/dev/sda5       /u02    xfs     defaults 0       0

 

创建目录并手工挂载

[root@localhost ~]# mkdir /u01
[root@localhost ~]# mkdir /u02
[root@localhost ~]# mount /dev/sda4 /u01
[root@localhost ~]# mount /dev/sda5 /u02

 

6.分区完成

[root@localhost ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   50G  1.5G   49G   3% /
devtmpfs                  32G     0   32G   0% /dev
tmpfs                     32G     0   32G   0% /dev/shm
tmpfs                     32G   25M   32G   1% /run
tmpfs                     32G     0   32G   0% /sys/fs/cgroup
/dev/sda2                497M  123M  375M  25% /boot
tmpfs                    6.3G     0  6.3G   0% /run/user/0
/dev/sda4                1.1T   33M  1.1T   1% /u01
/dev/sda5                1.1T   33M  1.1T   1% /u02

可以看到分区已经挂载完成了

 

posted on 2019-08-24 21:46  太清  阅读(...)  评论(... 编辑 收藏

统计