其他
Linux硬盘与文件系统(6)
lsblk 列出系统上的所有硬盘列表
选项与参数
-f 列出该磁盘内(分区的)的文件系统名称(掌握)
-p 列出磁盘的完整路径名称,而不是仅仅列出最后的设备名(掌握)
-m 输出设备文件的rwx属性
-t 列出设备的详细数据,包括磁盘队列机制,预读写的数据量大小。
-d 仅列出磁盘本身的信息,不体现分区的信息
-i 使用简单的形式输出,防止出现乱码
列出本系统的磁盘及分区信息
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 190M 0 part /boot
├─sda2 8:2 0 1.9G 0 part [SWAP]
└─sda3 8:3 0 17.9G 0 part /
sdb 8:16 0 10G 0 disk
sdc 8:32 0 1G 0 disk
sr0 11:0 1 1024M 0 rom
NAME:设备的名称(省略了/dev字样) MAJ:MIN:设置的主代码和次代码 RM:是否为可移除设备,如光盘、usb磁盘等 SIZE:磁盘的总容量 RO:是否为只读 TYPE:表明是磁盘(disk)、分区(partition)还是只读存储(rom) MOUNTPOINT:挂载点,表明设备挂载到了哪个目录下
NAME FSTYPE LABEL UUID MOUNTPOINT
/dev/sda
├─/dev/sda1 xfs 45531942-02d8-4c7a-b50e-98f4b6b8efd4 /boot
├─/dev/sda2 swap 39cb7392-e161-416a-ac14-84ff0f08b719 [SWAP]
└─/dev/sda3 xfs a512fe7c-c4ea-4cd9-87fb-cb305f2c8460 /
/dev/sdb xfs 079e1532-52a6-4c6d-bad5-b8a2e8ed1e2f
/dev/sdc ext4 3884426e-03b1-4559-b0f8-a8576b1a53bd
/dev/sr
blkid 列出设备的UUID等参数
/dev/sda1: UUID="45531942-02d8-4c7a-b50e-98f4b6b8efd4" TYPE="xfs"
/dev/sda2: UUID="39cb7392-e161-416a-ac14-84ff0f08b719" TYPE="swap"
/dev/sda3: UUID="a512fe7c-c4ea-4cd9-87fb-cb305f2c8460" TYPE="xfs"
/dev/sdb: UUID="079e1532-52a6-4c6d-bad5-b8a2e8ed1e2f" TYPE="xfs"
/dev/sdc: UUID="3884426e-03b1-4559-b0f8-a8576b1a53bd" TYPE="ext4"
[root@studyclub ~]# parted /dev/sdb print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt# 分区表的格式,这里是GPT(还有一种是MBR)
Disk Flags:
Number Start End Size File system Name Flags
# 再看看生产环境上的信息
[root@sds1 ~]# parted /dev/sdac print
Model: ATA ST8000NM0055-1RM (scsi)# 厂家及接口信息,ST8000NM0055可以看出是希捷的硬盘
Disk /dev/sdac: 8002GB# 硬盘容量
Sector size (logical/physical): 512B/4096B# 每个逻辑、物理扇区的容量
Partition Table: gpt# 分区表的格式,这里是GPT(还有一种是MBR)
Disk Flags:
Number Start End Size File system Name Flags
1 1049kB 21.5GB 21.5GB xfs ceph data
3 21.5GB 24.7GB 3221MB ceph xstore.wal
2 24.7GB 8002GB 7977GB ceph block
补充知识点:我们看到上面的生产环境有一个磁盘的名称是/dev/sdac,这是因为这个服务器上的硬盘数量超过了26个(a-z),超过26个以后,操作系统就会命名为aa、ab、ac、ad......
GPT fdisk (gdisk) version 0.8.10
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present
Found valid GPT with protective MBR; using GPT.
Command (? for help): ?# 输入问号,查看有哪些操作项
bback up GPT data to a file
cchange a partition's name
ddelete a partition# 删除一个分区
ishow detailed information on a partition
llist known partition types
nadd a new partition# 增加一个分区
ocreate a new empty GUID partition table (GPT)
pprint the partition table# 查看分区表
qquit without saving changes# 不保存修改,并退出gdisk
rrecovery and transformation options (experts only)
ssort partitions
tchange a partition's type code
vverify disk
wwrite table to disk and exit# 保存修改的信息并退出gdisk
xextra functionality (experts only)
?print this menu
Command (? for help):
Partition number (1-128, default 1):
First sector (34-20971486, default = 2048) or {+-}size{KMGTP}: # 采用默认值,直接回车
Last sector (2048-20971486, default = 20971486) or {+-}size{KMGTP}: +2G# 不用算大小,直接用加号和你需要的大小表示即可,然后回车。
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300): # 默认值即可,直接回车。这里是让用户选择将来这个分区要格式化的文件系统,默认是linux文件系统。
Changed type of partition to 'Linux filesystem'
Command (? for help): p
Disk /dev/sdb: 20971520 sectors, 10.0 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): BAA2350E-2B57-4022-9A6C-436AB1022E9D
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 20971486
Partitions will be aligned on 2048-sector boundaries
Total free space is 16777149 sectors (8.0 GiB)
Number Start (sector) End (sector) Size Code Name
1 2048 4196351 2.0 GiB 8300 Linux filesystem
Number:分区号 Start (sector):用来说明当前分区是从哪个扇区开始的,我们这个例子是从2048扇区开始属于分区1 End (sector):用来说明当前分区是在哪个扇区结束的,我们这个例子是在4196351扇区结束的1号分区 Size:对应分区的大小 Code:该分区的可能的文件系统类型,不一定是最终真实的文件系统,仅仅是一个提示而已 Name:文件系统类型的名字
0700 Microsoft basic data 0c01 Microsoft reserved 2700 Windows RE
3000 ONIE boot 3001 ONIE config 4100 PowerPC PReP boot
4200 Windows LDM data 4201 Windows LDM metadata 7501 IBM GPFS
7f00 ChromeOS kernel 7f01 ChromeOS root 7f02 ChromeOS reserved
8200 Linux swap 8300 Linux filesystem 8301 Linux reserved
8302 Linux /home 8400 Intel Rapid Start 8e00 Linux LVM
a500 FreeBSD disklabel a501 FreeBSD boot a502 FreeBSD swap
a503 FreeBSD UFS a504 FreeBSD ZFS a505 FreeBSD Vinum/RAID
a580 Midnight BSD data a581 Midnight BSD boot a582 Midnight BSD swap
a583 Midnight BSD UFS a584 Midnight BSD ZFS a585 Midnight BSD Vinum
a800 Apple UFS a901 NetBSD swap a902 NetBSD FFS
a903 NetBSD LFS a904 NetBSD concatenated a905 NetBSD encrypted
a906 NetBSD RAID ab00 Apple boot af00 Apple HFS/HFS+
af01 Apple RAID af02 Apple RAID offline af03 Apple label
af04 AppleTV recovery af05 Apple Core Storage be00 Solaris boot
bf00 Solaris root bf01 Solaris /usr & Mac Z bf02 Solaris swap
bf03 Solaris backup bf04 Solaris /var bf05 Solaris /home
bf06 Solaris alternate se bf07 Solaris Reserved 1 bf08 Solaris Reserved 2
bf09 Solaris Reserved 3 bf0a Solaris Reserved 4 bf0b Solaris Reserved 5
c001 HP-UX data c002 HP-UX service ea00 Freedesktop $BOOT
eb00 Haiku BFS ed00 Sony system partitio ed01 Lenovo system partit
Press the <Enter> key to see more codes: # 敲回车键
ef00 EFI System ef01 MBR partition scheme ef02 BIOS boot partition
fb00 VMWare VMFS fb01 VMWare reserved fc00 VMWare kcore crash p
fd00 Linux RAID
partprobe:更新分区表信息
-s 把信息打印到屏幕上,而不仅仅是更新以后没有反馈信息。
[root@studyclub ~]# partprobe -s
/dev/sda: msdos partitions 1 2 3
/dev/sdb: gpt partitions 1 2 3
[root@studyclub ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 190M 0 part /boot
├─sda2 8:2 0 1.9G 0 part [SWAP]
└─sda3 8:3 0 17.9G 0 part /
sdb 8:16 0 10G 0 disk
├─sdb1 8:17 0 2G 0 part
├─sdb2 8:18 0 2G 0 part
└─sdb3 8:19 0 6G 0 part
sdc 8:32 0 1G 0 disk
sr0 11:0 1 1024M 0 rom
fdisk:
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 0xf94d0d72.
Command (m for help): m# 输入m查看帮助信息
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition# 删除分区
g create a new empty GPT partition table# 新增一个GPT分区,我们不建议用
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition# 新增一个分区
o create a new empty DOS partition table
p print the partition table# 显示分区表信息
q quit without saving changes# 退出fdisk但不保存配置
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit# 保存配置并退出
x extra functionality (experts only)
练习gdisk的用法:删除上面创建的三个分区,并重新分区 练习fdisk的用法:创建三个分区并保存,然后看分区是否成功 总结本文用到的6个命令
微信号|bjdream-1
Cloud研习社 ·