磁盘 fdisk

fdisk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
❯ sudo fdisk  /dev/nvme0n1 -l
Disk /dev/nvme0n1: 1.82 TiB, 2000398934016 bytes, 3907029168 sectors
Disk model: KINGSTON SNV2S2000G
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 567141B0-39E4-467E-B67D-61B05D225406

Device Start End Sectors Size Type
/dev/nvme0n1p1 2048 117186559 117184512 55.9G Linux filesystem
/dev/nvme0n1p2 117186560 234373119 117186560 55.9G Linux filesystem
/dev/nvme0n1p3 234373120 644530175 410157056 195.6G Linux filesystem
/dev/nvme0n1p4 644530176 1386717183 742187008 353.9G Linux filesystem
/dev/nvme0n1p5 1386717184 1402341375 15624192 7.5G Linux swap
/dev/nvme0n1p6 1402341376 1403473919 1132544 553M EFI System
/dev/nvme0n1p7 1403473920 1571248127 167774208 80G Microsoft basic data

创建新分区
分配未使用的分区
Command (m for help): F
Unpartitioned space /dev/nvme0n1: 1.09 TiB, 1195919875584 bytes, 2335781007 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes

Start End Sectors Size 1571248128 3907029134 2335781007 1.1T
Command (m for help): n Partition number (8-128, default 8): First sector (1571248128-3907029134, default 1571248128): Last sector, +/-sectors or +/-size{K,M,G,T,P} (1571248128-3907029134, default 3907029134): +80G
Created a new partition 8 of type 'Linux filesystem' and of size 80 GiB.

uuid

1
2
❯ sudo blkid /dev/nvme0n1p8
/dev/nvme0n1p8: PARTUUID="18fd9320-fea9-404c-817f-e4d401f9f453"

mkfs.ext4

1
2
3
4
5
6
7
8
9
10
11
12
13
14
❯ sudo mkfs.ext4 /dev/nvme0n1p8
mke2fs 1.46.6 (1-Feb-2023)
Discarding device blocks: done
Creating filesystem with 20971520 4k blocks and 5242880 inodes
Filesystem UUID: f55f67da-11b0-4085-8dce-b49f9c8322e4
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000

Allocating group tables: done
Writing inode tables: done
Creating journal (131072 blocks): done
Writing superblocks and filesystem accounting information: done

删除

1
❯ sudo fdisk  /dev/sdb

Welcome to fdisk (util-linux 2.36.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): p
Disk /dev/sdb: 238.47 GiB, 256060514304 bytes, 500118192 sectors
Disk model:
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: F4388C00-21CE-418F-86AA-3A1CD95B1CF3

Device Start End Sectors Size Type
/dev/sdb6 304701440 500117503 195416064 93.2G Linux filesystem
/dev/sdb7 167002112 194111487 27109376 12.9G Linux filesystem

Partition table entries are not in disk order.
Command (m for help): d
Partition number (6,7, default 7): 6

Partition 6 has been deleted.
Command (m for help): d
Selected partition 7
Partition 7 has been deleted.

Command (m for help): p
Disk /dev/sdb: 238.47 GiB, 256060514304 bytes, 500118192 sectors
Disk model:
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: F4388C00-21CE-418F-86AA-3A1CD95B1CF3

Command (m for help): w
The partition table has been altered.
Syncing disks.

创建

1
❯ sudo fdisk  /dev/sdb

Welcome to fdisk (util-linux 2.36.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): n
Partition number (1-128, default 1): 1
First sector (34-500118158, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-500118158, default 500118158): +120G


Created a new partition 1 of type ‘Linux filesystem’ and of size 120 GiB.


Command (m for help): n
Partition number (2-128, default 2): 2
First sector (251660288-500118158, default 251660288):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (251660288-500118158, default 500118158):


Created a new partition 2 of type ‘Linux filesystem’ and of size 118.5 GiB.


Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

挂载

1
2
3
4
5
6
7
sudo mkfs.ext4 /dev/sdb1
sudo mkfs.ext4 /dev/sdb2

❯ sudo lsblk -o name,uuid | grep sdb
sdb
├─sdb1 08f1efd4-5d29-4755-bf00-6d9fb634d219
└─sdb2 af969762-0e0b-4e34-a0c8-47c05ef085f1

/etc/fstab

1
2
3
4
5
$ cat /etc/fstab | grep  -A 1 /mnt/data
#/mnt/data
UUID=f55f67da-11b0-4085-8dce-b49f9c8322e4 /mnt/data ext4 defaults 0 2

$ sudo mount -a

脚本挂载,u盘怕误拨导致无法开机

1
2
3
4
5
❯ sudo ln -s /etc/rc.local  /opt/tools/init/rc.local
❯ sudo chown :cs /etc/rc.local
❯ sudo chmod g+wr /etc/rc.local
❯ sudo chmod +x /etc/rc.local

gparted

1
sudo apt-get install gparted

smartctl

测试硬盘健康状态

1
2
3
4
5
#debian
❯ sudo apt-get install smartmontools

#centos
❯ yum -y install smartmontools
1
❯ sudo smartctl -i /dev/sdb1

smartctl 7.2 2020-12-30 r5155 [x86_64-linux-6.1.0-0.deb11.7-amd64] (local build)
Copyright (C) 2002-20, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Vendor: ACASIS
Product:
Revision: 1214
Compliance: SPC-4
User Capacity: 256,060,514,304 bytes [256 GB]
Logical block size: 512 bytes
Physical block size: 4096 bytes
LU is resource provisioned, LBPRZ=0
Logical Unit id: 0x3000000000063700
Serial number: 000000000F37
Device type: disk
Local Time is: Sat Nov 4 09:01:21 2023 CST
SMART support is: Unavailable - device lacks SMART capability.

点击打赏
文章目录
  1. 1. fdisk
    1. 1.1. mkfs.ext4
    2. 1.2. 删除
    3. 1.3. 创建
    4. 1.4. 挂载
  2. 2. gparted
  3. 3. smartctl
载入天数...载入时分秒... ,