fdisk
- 查看分区
[root@web ~]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000ccde8
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 411647 204800 83 Linux
/dev/sda2 411648 415743 2048 82 Linux swap / Solaris
/dev/sda3 415744 41943039 20763648 83 Linux
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
- 添加分区
[root@web ~]# 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 table
Building a new DOS disklabel with disk identifier 0x78668cb4.
Command (m for help): p #按"p"打印分区列表
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x78668cb4
Device Boot Start End Blocks Id System #此磁盘尚未分区
Command (m for help): n #按"n"新建一个分区
Partition type:
p primary (0 primary, 0 extended, 4 free) #p表示主分区
e extended #e表示扩展分区
Select (default p): p #按"p"键出现提示:"Partition number (1-4): "选择主分区号
Partition number (1-4, default 1): #输入"1"表示第一个主分区
First sector (2048-2097151, default 2048): 2048 #分区从哪里开始
Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151): +250M #表示第一个分区容量250M
Partition 1 of type Linux and of size 250 MiB is set
Command (m for help): p #打印分区列表
Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x78668cb4
Device Boot Start End Blocks Id System
/dev/sdb1 2048 514047 256000 83 Linux #第一分区已完成
Command (m for help): n #新建第二分区,剩余容量都分为第二分区
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (2-4, default 2):
First sector (514048-2097151, default 514048):
Using default value 514048
Last sector, +sectors or +size{K,M,G} (514048-2097151, default 2097151):
Using default value 2097151
Partition 2 of type Linux and of size 773 MiB is set
Command (m for help): w #保存退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
- 查看分区情况
[root@web ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 200M 0 part /boot
├─sda2 8:2 0 2M 0 part [SWAP]
└─sda3 8:3 0 19.8G 0 part /
sdb 8:16 0 1G 0 disk
├─sdb1 8:17 0 250M 0 part
└─sdb2 8:18 0 773M 0 part
sr0 11:0 1 4.3G 0 rom
- 在使用硬盘之前必须对其分区进行格式化
[root@web ~]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=16000 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=64000, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=855, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
- 并挂载
mount /dev/sdb1 /mnt/ - 查看
[root@web ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 20G 2.0G 18G 10% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.7M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda1 197M 105M 93M 54% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/sdb1 247M 13M 234M 6% /mnt
/dev/sdb2 770M 33M 738M 5% /data
(未完待续)
删除和恢复分区
[root@system ~]# umount /dev/sdb1
[root@system ~]# parted /dev/sdb
GNU Parted 2.1
使用 www.fencaiyule.cn /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) rm 1
(parted) rescue #恢复分区
起始点? 1
结束点? 10G
信息: A ext2 primary partition was found at 1049kB -> 10.0GB. Do you want to add it
to the partition table?
是/Yes/否/No/放弃/Cancel? Yes
(parted) quit
信息: You may need to update /etc/fstab.