GPT(GUID Partition Table)是一种磁盘分区表的标准,用于在计算机系统中管理硬盘驱动器的分区信息。与传统的MBR(Master Boot Record)分区表相比,GPT提供了更强大和灵活的分区管理机制。
查找未挂载的硬盘并挂载它
sudo fdisk -l
硬盘通常会显示为类似 /dev/sdX
的设备。
找到想要挂载的分区:lsblk
使用 mount 命令挂载硬盘到目录:
sudo mount /dev/sdXY /mnt/mydrive
确认文件系统类型:
sudo blkid /dev/sdX
检查文件系统的完整性:
sudo fsck /dev/sdaX
使用工具如 smartctl
检查硬盘的健康状况:
sudo smartctl -a /dev/sda
使用工具parted
查看分区的详细信息:
sudo parted /dev/sda print
场景
实验室服务器新增了一块SSD,现在要把自己的实验空间迁移去新的SSD中。
fdisk -l
得到目前新的ssd和hdd的情况。接着迁移workspace:
root@PowerEdge-R750:/home/Documents# fdisk /dev/sda
Welcome to fdisk (util-linux 2.31.1).
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.
Created a new DOS disklabel with disk identifier 0x1f065fec.
Command (m for help): n # 新建分区
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p # 基本分区
Partition number (1-4, default 1): 1 # 表示新建一个分区
First sector (2048-3123183615, default 2048): # 默认
Last sector, +sectors or +size{K,M,G,T,P} (2048-3123183615, default 3123183615): # 默认
Created a new partition 1 of type 'Linux' and of size 1.5 TiB.
Command (m for help): w # 将表写入磁盘并退出
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
root@PowerEdge-R750:/home/Documents# fdisk -l
# ……
# 这些是服务器硬盘空间的分配
# SSD SAS
Disk /dev/sda: 1.5 TiB, 1599070011392 bytes, 3123183616 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 262144 bytes / 524288 bytes
Disklabel type: dos
Disk identifier: 0x1f065fec
Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 3123183615 3123181568 1.5T 83 Linux
# HDD SAS
Disk /dev/sdb: 4.4 TiB, 4799625953280 bytes, 9374269440 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 262144 bytes / 524288 bytes
# SSD SATA
Disk /dev/sdc: 446.6 GiB, 479559942144 bytes, 936640512 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 262144 bytes / 262144 bytes
Disklabel type: gpt
Disk identifier: 02C050F2-3252-47D3-928A-556A13617985
Device Start End Sectors Size Type
/dev/sdc1 2048 1050623 1048576 512M EFI System
/dev/sdc2 1050624 936638463 935587840 446.1G Linux filesystem
# ……
磁盘格式ext4,并格式化:
root@PowerEdge-R750:/home/Documents# df -Th
Filesystem Type Size Used Avail Use% Mounted on
udev devtmpfs 63G 0 63G 0% /dev
tmpfs tmpfs 13G 3.3M 13G 1% /run
/dev/sdc2 ext4 439G 229G 188G 55% /
# ……
root@PowerEdge-R750:/home/Documents# mkfs -t ext4 /dev/sda1
mke2fs 1.44.1 (24-Mar-2018)
Creating filesystem with 390397696 4k blocks and 97599488 inodes
Filesystem UUID: 856ea741-4a84-4794-96ea-4084ddbee879
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000, 214990848
Allocating group tables: done
Writing inode tables: done
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done
挂载和设置开机自动挂载:
root@PowerEdge-R750:/home/Documents# mount -t ext4 /dev/sda1 /home/ssd
root@PowerEdge-R750:/home/Documents# mount -t ext4 /dev/sdb /home/hdd
vim /etc/fstab
# <file system> <mount point> <type> <options> <dump> <pass>
# / was on /dev/sdb2 during installation
UUID=ce0c24b8-724b-4f33-9b2c-618433560aef / ext4 errors=remount-ro 0 1
# /boot/efi was on /dev/sdb1 during installation
UUID=987B-EEFC /boot/efi vfat umask=0077 0 1
/swapfile none swap sw 0 0
/dev/sda1 /home/ssd ext4 defaults 0 0
/dev/sdb /home/hdd ext4 defaults 0 0
OK正常运行的,然后把我的文件夹复制过去。