博客
关于我
Linux之磁盘管理
阅读量:532 次
发布时间:2019-03-08

本文共 13806 字,大约阅读时间需要 46 分钟。

本章重点提示:

1):理解基础命令,df,fdisk.

2):磁盘分区的理论基础。

1:查看当前系统分区与挂载情况:

[root@localhost ~]# df Filesystem     1K-blocks    Used Available Use% Mounted on/dev/sda2       18208184 2984040  14292560  18% /tmpfs             502176      80    502096   1% /dev/shm/dev/sda1         289293   28473    245460  11% /boot

2:查看系统所有能识别的分区情况(包括系统已识别,未挂载的分区):

1 [root@localhost ~]# fdisk -l 2  3 Disk /dev/sda: 21.5 GB, 21474836480 bytes 4 255 heads, 63 sectors/track, 2610 cylinders 5 Units = cylinders of 16065 * 512 = 8225280 bytes 6 Sector size (logical/physical): 512 bytes / 512 bytes 7 I/O size (minimum/optimal): 512 bytes / 512 bytes 8 Disk identifier: 0x00077367 9 10    Device Boot      Start         End      Blocks   Id  System11 /dev/sda1   *           1          39      307200   83  Linux12 Partition 1 does not end on cylinder boundary.13 /dev/sda2              39        2358    18631680   83  Linux14 /dev/sda3            2358        2611     2031616   82  Linux swap / Solaris15 16 Disk /dev/sdb: 21.5 GB, 21474836480 bytes17 255 heads, 63 sectors/track, 2610 cylinders18 Units = cylinders of 16065 * 512 = 8225280 bytes19 Sector size (logical/physical): 512 bytes / 512 bytes20 I/O size (minimum/optimal): 512 bytes / 512 bytes21 Disk identifier: 0x0000000022 23 24 Disk /dev/sdc: 7776 MB, 7776239616 bytes25 240 heads, 62 sectors/track, 1020 cylinders26 Units = cylinders of 14880 * 512 = 7618560 bytes27 Sector size (logical/physical): 512 bytes / 512 bytes28 I/O size (minimum/optimal): 512 bytes / 512 bytes29 Disk identifier: 0xcb2e3fe730 31    Device Boot      Start         End      Blocks   Id  System

其中Disk /dev/sdc: 7776 MB,是外接的8G U盘

3:进入分区(8G U盘):

[root@localhost ~]# fdisk /dev/sdcWARNING: DOS-compatible mode is deprecated. It's strongly recommended to         switch off the mode (command 'c') and change display units to         sectors (command 'u').Command (m for help):

4:m,查看帮助命令:

Command (m for help): mCommand action   a   toggle a bootable flag   b   edit bsd disklabel   c   toggle the dos compatibility flag   d   delete a partition    #删除一个分区   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 #退出帮助并不保存操作   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)

5:n,新增分区:

Command (m for help): nCommand action   e   extended   p   primary partition (1-4)pPartition number (1-4): 1First cylinder (1-1020, default 1): Using default value 1Last cylinder, +cylinders or +size{K,M,G} (1-1020, default 1020): +500Command (m for help): mCommand action   a   toggle a bootable flag   b   edit bsd disklabel   c   toggle the dos compatibility flag   d   delete a partition   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   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)Command (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.

6:显示分区信息,可以发现刚才新建的分区:

[root@localhost ~]# fdisk -lDisk /dev/sda: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00077367   Device Boot      Start         End      Blocks   Id  System/dev/sda1   *           1          39      307200   83  LinuxPartition 1 does not end on cylinder boundary./dev/sda2              39        2358    18631680   83  Linux/dev/sda3            2358        2611     2031616   82  Linux swap / SolarisDisk /dev/sdb: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/sdc: 7776 MB, 7776239616 bytes240 heads, 62 sectors/track, 1020 cylindersUnits = cylinders of 14880 * 512 = 7618560 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0xcb2e3fe7   Device Boot      Start         End      Blocks   Id  System/dev/sdc1               1         501     3727409   83  Linux

7:重复刚才的操作,先新建一个扩展分区,再新建一个逻辑分区:

[root@localhost ~]# fdisk -lDisk /dev/sda: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00077367   Device Boot      Start         End      Blocks   Id  System/dev/sda1   *           1          39      307200   83  LinuxPartition 1 does not end on cylinder boundary./dev/sda2              39        2358    18631680   83  Linux/dev/sda3            2358        2611     2031616   82  Linux swap / SolarisDisk /dev/sdb: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/sdc: 7776 MB, 7776239616 bytes240 heads, 62 sectors/track, 1020 cylindersUnits = cylinders of 14880 * 512 = 7618560 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0xcb2e3fe7   Device Boot      Start         End      Blocks   Id  System/dev/sdc1               1         501     3727409   83  Linux[root@localhost ~]# fdisk /dev/sdcWARNING: DOS-compatible mode is deprecated. It's strongly recommended to         switch off the mode (command 'c') and change display units to         sectors (command 'u').Command (m for help): mCommand action   a   toggle a bootable flag   b   edit bsd disklabel   c   toggle the dos compatibility flag   d   delete a partition   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   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)Command (m for help): nCommand action   e   extended   p   primary partition (1-4)ePartition number (1-4): 2First cylinder (502-1020, default 502): Using default value 502Last cylinder, +cylinders or +size{K,M,G} (502-1020, default 1020): Using default value 1020Command (m for help): mCommand action   a   toggle a bootable flag   b   edit bsd disklabel   c   toggle the dos compatibility flag   d   delete a partition   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   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)Command (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.[root@localhost ~]# fdisk -lDisk /dev/sda: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00077367   Device Boot      Start         End      Blocks   Id  System/dev/sda1   *           1          39      307200   83  LinuxPartition 1 does not end on cylinder boundary./dev/sda2              39        2358    18631680   83  Linux/dev/sda3            2358        2611     2031616   82  Linux swap / SolarisDisk /dev/sdb: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/sdc: 7776 MB, 7776239616 bytes240 heads, 62 sectors/track, 1020 cylindersUnits = cylinders of 14880 * 512 = 7618560 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0xcb2e3fe7   Device Boot      Start         End      Blocks   Id  System/dev/sdc1               1         501     3727409   83  Linux/dev/sdc2             502        1020     3861360    5  Extended[root@localhost ~]# fdisk /dev/sdcWARNING: DOS-compatible mode is deprecated. It's strongly recommended to         switch off the mode (command 'c') and change display units to         sectors (command 'u').Command (m for help): mCommand action   a   toggle a bootable flag   b   edit bsd disklabel   c   toggle the dos compatibility flag   d   delete a partition   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   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)Command (m for help): nCommand action   l   logical (5 or over)   p   primary partition (1-4)lFirst cylinder (502-1020, default 502): Using default value 502Last cylinder, +cylinders or +size{K,M,G} (502-1020, default 1020): Using default value 1020Command (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.[root@localhost ~]# fdisk -lDisk /dev/sda: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00077367   Device Boot      Start         End      Blocks   Id  System/dev/sda1   *           1          39      307200   83  LinuxPartition 1 does not end on cylinder boundary./dev/sda2              39        2358    18631680   83  Linux/dev/sda3            2358        2611     2031616   82  Linux swap / SolarisDisk /dev/sdb: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x00000000Disk /dev/sdc: 7776 MB, 7776239616 bytes240 heads, 62 sectors/track, 1020 cylindersUnits = cylinders of 14880 * 512 = 7618560 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0xcb2e3fe7   Device Boot      Start         End      Blocks   Id  System/dev/sdc1               1         501     3727409   83  Linux/dev/sdc2             502        1020     3861360    5  Extended/dev/sdc5             502        1020     3861329   83  Linux

8:查看当前系统格式:

[root@localhost ~]# df -THFilesystem     Type   Size  Used Avail Use% Mounted on/dev/sda2      ext4    19G  3.1G   15G  18% /tmpfs          tmpfs  515M   82k  515M   1% /dev/shm/dev/sda1      ext4   297M   30M  252M  11% /boot

9:格式化分区:

[root@localhost ~]# ]mkfs -t ext3 /dev/sdc1-bash: ]mkfs: command not found[root@localhost ~]# mkfs -t ext4 /dev/sdc1mke2fs 1.41.12 (17-May-2010)Filesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks233392 inodes, 931852 blocks46592 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=95630131229 block groups32768 blocks per group, 32768 fragments per group8048 inodes per groupSuperblock backups stored on blocks:     32768, 98304, 163840, 229376, 294912, 819200, 884736Writing inode tables: done                            Creating journal (16384 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 38 mounts or180 days, whichever comes first.  Use tune2fs -c or -i to override.[root@localhost ~]# mkfs -t ext4 /dev/sdc5mke2fs 1.41.12 (17-May-2010)Filesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks241440 inodes, 965332 blocks48266 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=98985574430 block groups32768 blocks per group, 32768 fragments per group8048 inodes per groupSuperblock backups stored on blocks:     32768, 98304, 163840, 229376, 294912, 819200, 884736Writing inode tables: done                            Creating journal (16384 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 38 mounts or180 days, whichever comes first.  Use tune2fs -c or -i to override.

10:挂载分区:

[root@localhost ~]# mount /dev/sdc1 /mnt/; mount /dev/sdc5 /mnt/

11:查看当前系统挂载分区信息:

[root@localhost ~]# df -THFilesystem     Type   Size  Used Avail Use% Mounted on/dev/sda2      ext4    19G  3.1G   15G  18% /tmpfs          tmpfs  515M   82k  515M   1% /dev/shm/dev/sda1      ext4   297M   30M  252M  11% /boot/dev/sdc1      ext4   3.9G  7.8M  3.7G   1% /mnt/dev/sdc5      ext4   3.9G  7.8M  3.7G   1% /mnt

 

转载地址:http://plfiz.baihongyu.com/

你可能感兴趣的文章
MySQL-【1】配置
查看>>
MySQL-【4】基本操作
查看>>
Mysql-丢失更新
查看>>
Mysql-事务阻塞
查看>>
Mysql-存储引擎
查看>>
mysql-开启慢查询&所有操作记录日志
查看>>
MySQL-数据目录
查看>>
MySQL-数据页的结构
查看>>
MySQL-架构篇
查看>>
MySQL-索引的分类(聚簇索引、二级索引、联合索引)
查看>>
Mysql-触发器及创建触发器失败原因
查看>>
MySQL-连接
查看>>
mysql-递归查询(二)
查看>>
MySQL5.1安装
查看>>
mysql5.5和5.6版本间的坑
查看>>
mysql5.5最简安装教程
查看>>
mysql5.6 TIME,DATETIME,TIMESTAMP
查看>>
mysql5.6.21重置数据库的root密码
查看>>
Mysql5.6主从复制-基于binlog
查看>>
MySQL5.6忘记root密码(win平台)
查看>>