版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/panchao888888/article/details/82951999
Linux中磁盘管理
Linux中磁盘管理Linux磁盘管理基本命令df查看磁盘分区使用情况- -l : 仅显示本地磁盘(默认)
- -a : 显示所有文件系统的磁盘使用情况,包含比如/proc/
- -h : 以1024进制计算最适合的单位显示磁盘容量
- -H : 以1000进制计算最适合的单位显示磁盘容量
- -T : 显示磁盘分区类型
- -t : 显示指定类型文件系统的磁盘分区
- -x : 不现实指定类型文件系统的磁盘分区
du统计磁盘上的文件大小- -b : 以byte为单位统计文件
- -k : 以KB为单位统计文件
- -m : 以MB为单位统计文件
- -h : 按照1024进制以最适合的单位统计文件
- -H : 按照1000进制以最适合的单位统计文件
- -s : 指定统计目标
Linux磁盘分区和格式化概述- 主分区和扩展分区总数不能超过4个
- 扩展分区最多只能有一个
- 扩展分区不能直接存取数据
之前为你们学习了在安装过程中使用图形界面进行分区的技能,但是当系统装好之后,随着不断地使用,会导致硬盘空间小号殆尽,这时候怎么办呢?
答:在保留原硬盘的基础上,给服务器添加新的硬盘。
在VM虚拟机中添加硬盘- 将虚拟机中的Linux系统关闭;
- 点击设置
- 添加新硬盘
- 重启linux系统
- 即可完成添加硬盘步骤
Linux中分区模式分区模式分类:分区模式之MBR:分区模式之GPT:- 主分区的个数"几乎"没有限制(在GPT的分区表中最多可以支持128个主分区)
- 单个分区容量"几乎"没有限制(在GPT的分区模式中,每个分区的大小突破了MBR分区的2TB限制;GPT模式下每个分区的大小最多可以达到18EB)
- GPT的主分区中,不适合安装X86架构的系统
- GPT分区模式中没有主分区、扩展分区和逻辑分区的概念,就叫分区
1EB = 1024PB,1PB = 1024TB,1TB = 1024GB
18EB = 18 * 1024PB = 18 * 1024 * 1024TB = 18 * 1024 * 1024 * 1024GB
Linux中MBR分区- Linux中硬件设备都是一文件的形式存在于根目录下的dev目录下
- 硬件设备都是由Linux系统自动是别的
- 必须对硬盘进行分区、格式化、挂载后才能使用
- 分区需要使用一个硬盘分区工具fdisk
- fdisk工具只能给硬盘做MBR的分区
使用fdisk进行硬盘分区:fdisk工具只能给硬盘做MBR的分区
- fdisk /dev/sdb
- m : 查看命令的帮助信息
- n : 给硬盘中添加一个新分区
- p : 添加主分区
- 指定分区编号(默认是1)
- 指定扇区的起始位置
- 指定扇区的终止位置(例如:+3000M或+3G)
- p : 查看新建的分区
- n : 给硬盘中添加一个新分区
- e : 添加扩展分区
- 指定分区编号(默认是2)
- 指定扇区的起始位置(默认)
- 指定扇区的终止位置(默认)
- n : 给硬盘中添加一个新分区
- l : 添加逻辑分区
- 指定分区编号(默认5)
- 指定扇区的起始位置(默认)
- 指定扇区的终止位置(例如:+3000M或+3G)
- n : 给硬盘中添加第二块逻辑新分区
- l : 添加逻辑分区
- 指定分区编号(默认6)
- 指定扇区的起始位置(默认)
- 指定扇区的终止位置(例如:+3000M或+3G)
- d : 删除分区
- 输入要删除的分区编号
- 2 : 删除扩展分区(因为逻辑分区是在扩展分区内的,所以逻辑分区也会被删除)
- p : 查看新建的分区
- 再次从新分区后
- w : 将磁盘的分区方案写入磁盘分区表中
- fdisk -l 查看分区是否成功
例如:
root@localhost:~# fdisk -lDisk /dev/loop0: 87.9 MiB, 92119040 bytes, 179920 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/loop1: 86.6 MiB, 90759168 bytes, 177264 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/sda: 30 GiB, 32212254720 bytes, 62914560 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: gptDisk identifier: B453A511-713D-490D-8F29-4F146C823C49Device Start End Sectors Size Type/dev/sda1 2048 4095 2048 1M BIOS boot/dev/sda2 4096 413695 409600 200M Linux filesystem/dev/sda3 413696 2510847 2097152 1G Linux swap/dev/sda4 2510848 23482367 20971520 10G Linux filesystem/dev/sda5 23482368 62912511 39430144 18.8G Linux filesystemDisk /dev/sdb: 8 GiB, 8589934592 bytes, 16777216 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesroot@localhost:~# ^Croot@localhost:~# root@localhost:~# fdisk -lDisk /dev/loop0: 87.9 MiB, 92119040 bytes, 179920 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/loop1: 86.6 MiB, 90759168 bytes, 177264 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/sda: 30 GiB, 32212254720 bytes, 62914560 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: gptDisk identifier: B453A511-713D-490D-8F29-4F146C823C49Device Start End Sectors Size Type/dev/sda1 2048 4095 2048 1M BIOS boot/dev/sda2 4096 413695 409600 200M Linux filesystem/dev/sda3 413696 2510847 2097152 1G Linux swap/dev/sda4 2510848 23482367 20971520 10G Linux filesystem/dev/sda5 23482368 62912511 39430144 18.8G Linux filesystemDisk /dev/sdb: 8 GiB, 8589934592 bytes, 16777216 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesroot@localhost:~# fdisk /dev/sdb 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 0xab6f1544.Command (m for help): mHelp: DOS (MBR) a toggle a bootable flag b edit nested BSD disklabel c toggle the dos compatibility flag Generic d delete a partition F list free unpartitioned space l list known partition types n add a new partition p print the partition table t change a partition type v verify the partition table i print information about a partition Misc m print this menu u change display/entry units x extra functionality (experts only) Script I load disk layout from sfdisk script file O dump disk layout to sfdisk script file Save & Exit w write table to disk and exit q quit without saving changes Create a new label g create a new empty GPT partition table G create a new empty SGI (IRIX) partition table o create a new empty DOS partition table s create a new empty Sun partition tableCommand (m for help): nPartition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions)Select (default p): pPartition number (1-4, default 1): 1First sector (2048-16777215, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-16777215, default 16777215): +3000MCreated a new partition 1 of type 'Linux' and of size 3 GiB.Command (m for help): pDisk /dev/sdb: 8 GiB, 8589934592 bytes, 16777216 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0xab6f1544Device Boot Start End Sectors Size Id Type/dev/sdb1 2048 6146047 6144000 3G 83 LinuxCommand (m for help): nPartition type p primary (1 primary, 0 extended, 3 free) e extended (container for logical partitions)Select (default p): ePartition number (2-4, default 2): 2First sector (6146048-16777215, default 6146048): Last sector, +sectors or +size{K,M,G,T,P} (6146048-16777215, default 16777215): Created a new partition 2 of type 'Extended' and of size 5.1 GiB.Command (m for help): pDisk /dev/sdb: 8 GiB, 8589934592 bytes, 16777216 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0xab6f1544Device Boot Start End Sectors Size Id Type/dev/sdb1 2048 6146047 6144000 3G 83 Linux/dev/sdb2 6146048 16777215 10631168 5.1G 5 ExtendedCommand (m for help): nAll space for primary partitions is in use.Adding logical partition 5First sector (6148096-16777215, default 6148096): Last sector, +sectors or +size{K,M,G,T,P} (6148096-16777215, default 16777215): +2000MCreated a new partition 5 of type 'Linux' and of size 2 GiB.Command (m for help): pDisk /dev/sdb: 8 GiB, 8589934592 bytes, 16777216 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0xab6f1544Device Boot Start End Sectors Size Id Type/dev/sdb1 2048 6146047 6144000 3G 83 Linux/dev/sdb2 6146048 16777215 10631168 5.1G 5 Extended/dev/sdb5 6148096 10244095 4096000 2G 83 LinuxCommand (m for help): nAll space for primary partitions is in use.Adding logical partition 6First sector (10246144-16777215, default 10246144): Last sector, +sectors or +size{K,M,G,T,P} (10246144-16777215, default 16777215): Created a new partition 6 of type 'Linux' and of size 3.1 GiB.Command (m for help): pDisk /dev/sdb: 8 GiB, 8589934592 bytes, 16777216 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0xab6f1544Device Boot Start End Sectors Size Id Type/dev/sdb1 2048 6146047 6144000 3G 83 Linux/dev/sdb2 6146048 16777215 10631168 5.1G 5 Extended/dev/sdb5 6148096 10244095 4096000 2G 83 Linux/dev/sdb6 10246144 16777215 6531072 3.1G 83 LinuxCommand (m for help): nAll space for primary partitions is in use.Adding logical partition 7No free sectors available.Command (m for help): dPartition number (1,2,5,6, default 6): 2Partition 2 has been deleted.Command (m for help): pDisk /dev/sdb: 8 GiB, 8589934592 bytes, 16777216 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0xab6f1544Device Boot Start End Sectors Size Id Type/dev/sdb1 2048 6146047 6144000 3G 83 LinuxCommand (m for help): nPartition type p primary (1 primary, 0 extended, 3 free) e extended (container for logical partitions)Select (default p): pPartition number (2-4, default 2): 2First sector (6146048-16777215, default 6146048): Last sector, +sectors or +size{K,M,G,T,P} (6146048-16777215, default 16777215): +1000MCreated a new partition 2 of type 'Linux' and of size 1000 MiB.Command (m for help): pDisk /dev/sdb: 8 GiB, 8589934592 bytes, 16777216 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0xab6f1544Device Boot Start End Sectors Size Id Type/dev/sdb1 2048 6146047 6144000 3G 83 Linux/dev/sdb2 6146048 8194047 2048000 1000M 83 LinuxCommand (m for help): nPartition type p primary (2 primary, 0 extended, 2 free) e extended (container for logical partitions)Select (default p): ePartition number (3,4, default 3): 3First sector (8194048-16777215, default 8194048): Last sector, +sectors or +size{K,M,G,T,P} (8194048-16777215, default 16777215): Created a new partition 3 of type 'Extended' and of size 4.1 GiB.Command (m for help): pDisk /dev/sdb: 8 GiB, 8589934592 bytes, 16777216 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0xab6f1544Device Boot Start End Sectors Size Id Type/dev/sdb1 2048 6146047 6144000 3G 83 Linux/dev/sdb2 6146048 8194047 2048000 1000M 83 Linux/dev/sdb3 8194048 16777215 8583168 4.1G 5 ExtendedCommand (m for help): nAll space for primary partitions is in use.Adding logical partition 5First sector (8196096-16777215, default 8196096): Last sector, +sectors or +size{K,M,G,T,P} (8196096-16777215, default 16777215): +1000MCreated a new partition 5 of type 'Linux' and of size 1000 MiB.Command (m for help): pDisk /dev/sdb: 8 GiB, 8589934592 bytes, 16777216 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0xab6f1544Device Boot Start End Sectors Size Id Type/dev/sdb1 2048 6146047 6144000 3G 83 Linux/dev/sdb2 6146048 8194047 2048000 1000M 83 Linux/dev/sdb3 8194048 16777215 8583168 4.1G 5 Extended/dev/sdb5 8196096 10244095 2048000 1000M 83 LinuxCommand (m for help): nAll space for primary partitions is in use.Adding logical partition 6First sector (10246144-16777215, default 10246144): Last sector, +sectors or +size{K,M,G,T,P} (10246144-16777215, default 16777215): Created a new partition 6 of type 'Linux' and of size 3.1 GiB.Command (m for help): pDisk /dev/sdb: 8 GiB, 8589934592 bytes, 16777216 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0xab6f1544Device Boot Start End Sectors Size Id Type/dev/sdb1 2048 6146047 6144000 3G 83 Linux/dev/sdb2 6146048 8194047 2048000 1000M 83 Linux/dev/sdb3 8194048 16777215 8583168 4.1G 5 Extended/dev/sdb5 8196096 10244095 2048000 1000M 83 Linux/dev/sdb6 10246144 16777215 6531072 3.1G 83 LinuxCommand (m for help): wThe partition table has been altered.Calling ioctl() to re-read partition table.Syncing disks.root@localhost:~# - 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
- 214
- 215
- 216
- 217
- 218
- 219
- 220
- 221
- 222
- 223
- 224
- 225
- 226
- 227
- 228
- 229
- 230
- 231
- 232
- 233
- 234
- 235
- 236
- 237
- 238
- 239
- 240
- 241
- 242
- 243
- 244
- 245
- 246
- 247
- 248
- 249
- 250
- 251
- 252
- 253
- 254
- 255
- 256
- 257
- 258
- 259
- 260
- 261
- 262
- 263
- 264
- 265
- 266
- 267
- 268
- 269
- 270
- 271
- 272
- 273
- 274
- 275
- 276
- 277
- 278
- 279
- 280
- 281
- 282
- 283
- 284
- 285
- 286
- 287
- 288
- 289
- 290
- 291
- 292
- 293
- 294
- 295
- 296
- 297
- 298
- 299
- 300
- 301
- 302
- 303
- 304
- 305
- 306
- 307
- 308
- 309
- 310
- 311
- 312
- 313
- 314
- 315
- 316
- 317
- 318
- 319
- 320
- 321
Linux中GPT分区- Linux中硬件设备都是一文件的形式存在于根目录下的dev目录下
- 硬件设备都是由Linux系统自动是别的
- 必须对硬盘进行分区、格式化、挂载后才能使用
- GPT分区需要使用另一个硬盘分区工具parted
- parted工具既可以给硬盘做MBR分区,又可以给硬盘做GPT分区
- GPT分区模式中没有主分区、扩展分区和逻辑分区的概念,就叫分区
使用parted进行硬盘分区:parted工具既可以给硬盘做MBR分区,又可以给硬盘做GPT分区
- parted : 进入parted分区工具
- help : 查看分区帮助信息
- select /dev/sdc : 切换分区的目标硬盘
- mklable : 给目标硬盘指定分区表的类型
- mklable msdos : 给目标硬盘指定分区表的类型为MBR
- mklable gpt : 给目标硬盘指定分区表的类型为GPT
- print : 查看当前硬盘的分区详情
- print all : 查看所有硬盘的分区详情
- 分区时可以选择使用交互模式或者命令模式
- 先选择交互模式进行分区
- mkpart : 给硬盘中添加一个新分区
- 填写分区名称:games
- 指定分区文件系统:默认ext2
- 指分区起始位置:从1开始(单位为M)
- 指分区结束位置:从2000(单位为M)
- print : 查看当前硬盘的分区详情
- 先选择命令模式进行分区
- mkpart test 2000 3000 : 使用命令模式进行分区,分出一个名为test的分区(单位为M)
- print : 查看当前硬盘的分区详情
- unit GB : 默认分区时指定分区起始和结束位置是以MB为单位的,通过这个命令可以设置单位
- quit : 退出parted分区工具
例如:
root@localhost:~# partedGNU Parted 3.2Using /dev/sdaWelcome to GNU Parted! Type 'help' to view a list of commands.(parted) help align-check TYPE N check partition N for TYPE(min|opt) alignment help [COMMAND] print general help, or help on COMMAND mklabel,mktable LABEL-TYPE create a new disklabel (partition table) mkpart PART-TYPE [FS-TYPE] START END make a partition name NUMBER NAME name partition NUMBER as NAME print [devices|free|list,all|NUMBER] display the partition table, available devices, free space, all found partitions, or a particular partition quit exit program rescue START END rescue a lost partition near START and END resizepart NUMBER END resize partition NUMBER rm NUMBER delete partition NUMBER select DEVICE choose the device to edit disk_set FLAG STATE change the FLAG on selected device disk_toggle [FLAG] toggle the state of FLAG on selected device set NUMBER FLAG STATE change the FLAG on partition NUMBER toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER unit UNIT set the default unit to UNIT version display the version number and copyright information of GNU Parted(parted) select /dev/sdsda sda1 sda2 sda3 sda4 sda5 sdb sdb1 sdb2 sdb3 sdb5 sdb6 sdc (parted) select /dev/sdcUsing /dev/sdc(parted) mklabel gpt(parted) print Model: VMware, VMware Virtual S (scsi)Disk /dev/sdc: 8590MBSector size (logical/physical): 512B/512BPartition Table: gptDisk Flags: Number Start End Size File system Name Flags(parted) print all Model: VMware, VMware Virtual S (scsi)Disk /dev/sda: 32.2GBSector size (logical/physical): 512B/512BPartition Table: gptDisk Flags: Number Start End Size File system Name Flags 1 1049kB 2097kB 1049kB bios_grub 2 2097kB 212MB 210MB ext4 3 212MB 1286MB 1074MB linux-swap(v1) 4 1286MB 12.0GB 10.7GB ext4 5 12.0GB 32.2GB 20.2GB ext4Model: VMware, VMware Virtual S (scsi)Disk /dev/sdb: 8590MBSector size (logical/physical): 512B/512BPartition Table: msdosDisk Flags: Number Start End Size Type File system Flags 1 1049kB 3147MB 3146MB primary 2 3147MB 4195MB 1049MB primary 3 4195MB 8590MB 4395MB extended 5 4196MB 5245MB 1049MB logical 6 5246MB 8590MB 3344MB logicalModel: VMware, VMware Virtual S (scsi)Disk /dev/sdc: 8590MBSector size (logical/physical): 512B/512BPartition Table: gptDisk Flags: Number Start End Size File system Name FlagsWarning: Unable to open /dev/sr0 read-write (Read-only file system). /dev/sr0 has been opened read-only.Model: NECVMWar VMware SATA CD01 (scsi) Disk /dev/sr0: 845MBSector size (logical/physical): 2048B/2048BPartition Table: macDisk Flags: Number Start End Size File system Name Flags 1 2048B 6143B 4096B Apple 2 807MB 809MB 2392kB EFI(parted) mkpart Partition name? []? games File system type? [ext2]? Start? 1 End? 1024 (parted) print Model: VMware, VMware Virtual S (scsi)Disk /dev/sdc: 8590MBSector size (logical/physical): 512B/512BPartition Table: gptDisk Flags: Number Start End Size File system Name Flags 1 1049kB 1024MB 1023MB ext2 games(parted) mkpart test 1024 3000(parted) print Model: VMware, VMware Virtual S (scsi)Disk /dev/sdc: 8590MBSector size (logical/physical): 512B/512BPartition Table: gptDisk Flags: Number Start End Size File system Name Flags 1 1049kB 1024MB 1023MB ext2 games 2 1024MB 3000MB 1976MB test(parted) mkpart test 3000 4100(parted) print Model: VMware, VMware Virtual S (scsi)Disk /dev/sdc: 8590MBSector size (logical/physical): 512B/512BPartition Table: gptDisk Flags: Number Start End Size File system Name Flags 1 1049kB 1024MB 1023MB ext2 games 2 1024MB 3000MB 1976MB test 3 3000MB 4100MB 1100MB test(parted) mkpart test 3000 5100 Warning: You requested a partition from 3000MB to 5100MB (sectors 5859375..9960937).The closest location we can manage is 4100MB to 5100MB (sectors 8007680..9960937).Is this still acceptable to you?Yes/No? yes (parted) print Model: VMware, VMware Virtual S (scsi)Disk /dev/sdc: 8590MBSector size (logical/physical): 512B/512BPartition Table: gptDisk Flags: Number Start End Size File system Name Flags 1 1049kB 1024MB 1023MB ext2 games 2 1024MB 3000MB 1976MB test 3 3000MB 4100MB 1100MB test 4 4100MB 5100MB 1000MB test(parted) mkpart aaa 3000 5100 Warning: You requested a partition from 3000MB to 5100MB (sectors 5859375..9960937).The closest location we can manage is 5100MB to 5100MB (sectors 9960938..9960938).Is this still acceptable to you?Yes/No? no (parted) mkpart aaa 3000End? End? End? 9999 Error: The location 9999 is outside of the device /dev/sdc.(parted) 8000 align-check TYPE N check partition N for TYPE(min|opt) alignment help [COMMAND] print general help, or help on COMMAND mklabel,mktable LABEL-TYPE create a new disklabel (partition table) mkpart PART-TYPE [FS-TYPE] START END make a partition name NUMBER NAME name partition NUMBER as NAME print [devices|free|list,all|NUMBER] display the partition table, available devices, free space, all found partitions, or a particular partition quit exit program rescue START END rescue a lost partition near START and END resizepart NUMBER END resize partition NUMBER rm NUMBER delete partition NUMBER select DEVICE choose the device to edit disk_set FLAG STATE change the FLAG on selected device disk_toggle [FLAG] toggle the state of FLAG on selected device set NUMBER FLAG STATE change the FLAG on partition NUMBER toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER unit UNIT set the default unit to UNIT version display the version number and copyright information of GNU Parted(parted) print Model: VMware, VMware Virtual S (scsi)Disk /dev/sdc: 8590MBSector size (logical/physical): 512B/512BPartition Table: gptDisk Flags: Number Start End Size File system Name Flags 1 1049kB 1024MB 1023MB ext2 games 2 1024MB 3000MB 1976MB test 3 3000MB 4100MB 1100MB test 4 4100MB 5100MB 1000MB test(parted) mkpart aaa 3000 8100Warning: You requested a partition from 3000MB to 8100MB (sectors 5859375..15820312).The closest location we can manage is 5100MB to 8100MB (sectors 9960938..15820312).Is this still acceptable to you?Yes/No? yesWarning: The resulting partition is not properly aligned for best performance.Ignore/Cancel? Cancel (parted) mkpart aaa 5100 8888Error: The location 8888 is outside of the device /dev/sdc.(parted) mkpart aaa 5100 8000(parted) pring align-check TYPE N check partition N for TYPE(min|opt) alignment help [COMMAND] print general help, or help on COMMAND mklabel,mktable LABEL-TYPE create a new disklabel (partition table) mkpart PART-TYPE [FS-TYPE] START END make a partition name NUMBER NAME name partition NUMBER as NAME print [devices|free|list,all|NUMBER] display the partition table, available devices, free space, all found partitions, or a particular partition quit exit program rescue START END rescue a lost partition near START and END resizepart NUMBER END resize partition NUMBER rm NUMBER delete partition NUMBER select DEVICE choose the device to edit disk_set FLAG STATE change the FLAG on selected device disk_toggle [FLAG] toggle the state of FLAG on selected device set NUMBER FLAG STATE change the FLAG on partition NUMBER toggle [NUMBER [FLAG]] toggle the state of FLAG on partition NUMBER unit UNIT set the default unit to UNIT version display the version number and copyright information of GNU Parted(parted) print Model: VMware, VMware Virtual S (scsi)Disk /dev/sdc: 8590MBSector size (logical/physical): 512B/512BPartition Table: gptDisk Flags: Number Start End Size File system Name Flags 1 1049kB 1024MB 1023MB ext2 games 2 1024MB 3000MB 1976MB test 3 3000MB 4100MB 1100MB test 4 4100MB 5100MB 1000MB test 5 5100MB 8000MB 2899MB aaa(parted) quit Information: You may need to update /etc/fstab.root@localhost:~#- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
- 214
- 215
- 216
- 217
- 218
- 219
- 220
- 221
- 222
- 223
- 224
- 225
- 226
- 227
- 228
- 229
- 230
- 231
Linux中分区的格式化分区的格式化工具mkfsmkfs.ext3 /dev/sdb1
mkfs -t ext4 /dev/sdb2
扩展分区是不可以格式化的,只有主分区和逻辑分区才可以格式化
Linux中挂载分区分区默认的挂载目录/mnt目录
挂载命令mountmount /dev/sdb1 /mnt/test
卸载命令umountumount /mnt/test
使用mount和umount挂载只是暂时性的,系统重启后需要重新手动挂载
编辑/etc/fstab文件使挂载永久生效在/etc/fstab最后重新起一行,添加
/dev/sdb1 /mnt/test ext4 default 0 0- /dev/sdb1代表设备名称
- /mnt/test代表挂载点
- ext4代表文件系统的类型
Linux中创建swap分区如何为硬盘添加swap交换分区?- 建立一个普通的linux分区
- 修改分区类型的16进制编码
- 格式化交换分区
- 启用交换分区
1.建立一个普通的linux分区2.修改分区类型的16进制编码- fdisk /dev/sdb : 进入fdisk分区工具
- p : 查看分区详情
- t : 修改分区类型编号
- 5 : 分区编号(/dev/sdb5分区)
- L : 查看编码列表
- 82 : linux中swap交换分区的编码
- w : 将修改后磁盘的分区方案写入磁盘分区表中并保存
- mkswap /dev/sdb5 : 格式化swap交换分区
- swapon /dev/sdb5 : 启用swap交换分区
- 编辑/etc/fstab是系统启动时自动启动swap交换分区,新增一行
/dev/sdb5 swap swap defaults 0 0- free : 查看swap交换分区加载状况
- swapoff /dev/sdb5 : 停止swap交换分区
Linux中创建swap文件当创建系统后发现没有swap分区,并且当前系统没有剩余未分配的空间,由于这个时候没有空间创建swap分区,所以我们创建一个swap文件已达到swap交换分区的目的。
- 创建要作为swap分区的文件:增加1GB大小的交换分区,则命令写法如下,其中的count等于想要的块的数量(bs*count=文件大小)。
dd if=/dev/zero of=/root/.swapfile bs=1M count=1024mkswap /root/.swapfile #建立swap的文件系统swapon /root/.swapfile #启用swap文件- 使系统开机时自启用,在文件/etc/fstab中添加一行:
/root/.swapfile swap swap defaults 0 0- free : 查看swap交换文件加载状况
- swapoff /root/.swapfile : 停止swap交换文件
【转载】https://blog.csdn.net/panchao888 ... 999?utm_source=copy
|
|