Linux学习记载ITeye - 牛牛娱乐

Linux学习记载ITeye

2019年03月10日08时37分09秒 | 作者: 山菡 | 标签: 分区,扩展,逻辑 | 浏览: 2875

255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280bytes Device Boot Start End Blocks Id System /dev/sda1 * 1 13 104391 83 Linux /dev/sda2 14 1288 10241437+ 83 Linux /dev/sda3 1289 1925 5116702+ 83 Linux /dev/sda4 1926 2610 5502262+ 5 Extended /dev/sda5 1926 2052 1020096 82 Linux swap / Solaris /dev/sda6 2053 2302 2008093+ 83 Linux


1.       检查磁盘文件名

[root@localhost ~]# df /

文件体系               1K-块        已用     可用 已用% 挂载点

/dev/sda2              9920624   4329108  5079448  47% /

 

2.       检查磁盘分区功用

[root@localhost ~]# fdisk /dev/sda //这儿不带数字
The number of cylinders for this disk isset to 2610.
There is nothing wrong with that, but thisis larger than 1024,
and could in certain setups cause problemswith:
1) software that runs at boot time (e.g.,old versions of LILO)
2) booting and partitioning software fromother OSs
 (e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): m
Command action
 a toggle a bootable flag
 b edit bsd disklabel
 c toggle the dos compatibilityflag
 d delete a partition //删去磁盘分区
 l list known partition types
 m print this menu //检查磁盘分区功用
 n add a new partition //添加一个磁盘分区
 o create a new empty DOSpartition table
 p print the partition table //检查磁盘分区
 q quit without saving changes
 s create a new empty Sundisklabel
 t change a partitions system id
 u change display/entry units
 v verify the partition table
 w write table to disk and exit
 x extra functionality (expertsonly)

 

删去磁盘分区
[root@localhost ~]# fdisk /dev/sda
The number of cylinders for this disk isset to 2610.
There is nothing wrong with that, but thisis larger than 1024,
and could in certain setups cause problemswith:
1) software that runs at boot time (e.g.,old versions of LILO)
2) booting and partitioning software fromother OSs
 (e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): p
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
 Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1288 10241437+ 83 Linux
/dev/sda3 1289 1925 5116702+ 83 Linux
/dev/sda4 1926 2610 5502262+ 5 Extended
/dev/sda5 1926 2052 1020096 82 Linux swap / Solaris
/dev/sda6 2053 2302 2008093+ 83 Linux

由上可知我的磁盘首要分为6个分区,1,2,3为主分区,4为扩展分区,5为swap分区,6是逻辑分区

 

Command (m for help): d
Partition number (1-6): 3
Command (m for help): p
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
 Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1288 10241437+ 83 Linux
/dev/sda4 1926 2610 5502262+ 5 Extended
/dev/sda5 1926 2052 1020096 82 Linux swap / Solaris
/dev/sda6 2053 2302 2008093+ 83 Linux
删去主分区sad3 后能够看到磁盘信息不在包括sad3
Command (m for help): d
Partition number (1-6): 4
Command (m for help): p
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
 Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1288 10241437+ 83 Linux

删去扩展分区sad4 后能够看到扩展分区,逻辑分区都被删去(因为逻辑分区是由扩展分区衍生而来的)。

 

添加磁盘分区

磁盘分区最多只能有4个主分区+扩展分区组成,其间扩展分区最多只能有一个,剩下在创立的分区都是由扩展分区衍生出来的逻辑分区

 举例1. 因为磁盘现分区分为3个主分区,1个扩展分区。因而在创立时将直接创立逻辑分区,而不在问询是否创立主分区或许扩展分区

[root@localhost ~]# fdisk /dev/sda
The number of cylinders for this disk isset to 2610.
There is nothing wrong with that, but thisis larger than 1024,
and could in certain setups cause problemswith:
1) software that runs at boot time (e.g.,old versions of LILO)
2) booting and partitioning software fromother OSs
 (e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): p
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
 Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1288 10241437+ 83 Linux
/dev/sda3 1289 1925 5116702+ 83 Linux
/dev/sda4 1926 2610 5502262+ 5 Extended
/dev/sda5 1926 2052 1020096 82 Linux swap / Solaris
/dev/sda6 2053 2302 2008093+ 83 Linux
Command (m for help): n
First cylinder (2303-2610, default 2303):


举例2:创立主/扩展分区

[root@localhost ~]# fdisk /dev/sda
The number of cylinders for this disk isset to 2610.
There is nothing wrong with that, but thisis larger than 1024,
and could in certain setups cause problemswith:
1) software that runs at boot time (e.g.,old versions of LILO)
2) booting and partitioning software fromother OSs
 (e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): d //先将主分区和逻辑分区删去(假如为4个则默许创立逻辑分区)
Partition number (1-6): 2
Command (m for help): d
Partition number (1-6): 4
Command (m for help): p
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
 Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda3 1289 1925 5116702+ 83 Linux
Command (m for help): n
Command action
 e extended
 p primary partition (1-4)

 

提示用户挑选是是创立主分区仍是扩展分区

 

举例3.创立逻辑分区与扩展分区

root@localhost ~]# fdisk /dev/sda
The number of cylinders for this disk isset to 2610.
There is nothing wrong with that, but thisis larger than 1024,
and could in certain setups cause problemswith:
1) software that runs at boot time (e.g.,old versions of LILO)
2) booting and partitioning software fromother OSs
 (e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): p
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
 Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1288 10241437+ 83 Linux
/dev/sda3 1289 1925 5116702+ 83 Linux
/dev/sda4 1926 2610 5502262+ 5 Extended
/dev/sda5 1926 2052 1020096 82 Linux swap / Solaris
/dev/sda6 2053 2302 2008093+ 83 Linux
Command (m for help): d
Partition number (1-6): 4
Command (m for help): n
Command action
 e extended
 p primary partition (1-4)
Selected partition 4
First cylinder (1926-2610, default 1926):
Using default value 1926
Last cylinder or +size or +sizeM or +sizeK(1926-2610, default 2610):
Using default value 2610
Command (m for help): p
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
 Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1288 10241437+ 83 Linux
/dev/sda3 1289 1925 5116702+ 83 Linux
/dev/sda4 1926 2610 5502262+ 5 Extended

 

sd4为新创立的扩展分区,巨细为从柱面1926到2610

 

Command (m for help): nFirstcylinder (1926-2610, default 1926):
Usingdefault value 1926
Lastcylinder or +size or +sizeM or +sizeK (1926-2610, default 2610): +500M

 

关于此处能够指定柱面号码,以能够经过+XXM指定巨细,让其自动分配柱面

 

Command (m for help): p
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
 Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1288 10241437+ 83 Linux
/dev/sda3 1289 1925 5116702+ 83 Linux
/dev/sda4 1926 2610 5502262+ 5 Extended
/dev/sda5 1926 1987 497983+ 83 Linux

 

sd5为新创立的逻辑分区,巨细为500M

 

内核查找分区

当咱们添加分区后,体系让咱们reboot 以加载分区。也能够不必重启,只需求告诉内容从头查找分区即可

The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition tablefailed with error 16: 设备或资源忙.
The kernel still uses the old table.
The new table will be used at the nextreboot.
Syncing disks.[root@localhost~]# partprobe

 

 

磁盘格局化

分区完毕后要进行文件体系的格局化

 

语法:mkfs[-t 文件体系格局] 设备文件名

选项与参数:

-t:文件体系格局,例如ext3,ext2,vfat等

 

举例

[root@localhost ~]# mkfs -t ext3 /dev/sda7
mke2fs 1.39 (29-May-2006)
Filesystemlabel=
OS type: Linux
Blocksize=1024 (log=0)
Fragment size=1024 (log=0)
50200 inodes, 200780 blocks
10039 blocks (5.00%) reserved for the superuser
First data block=1
Maximum filesystem blocks=67371008
25 block groups
8192 blocks per group, 8192 fragments pergroup
2008 inodes per group
Superblock backups stored on blocks:
 8193, 24577, 40961, 57345, 73729
Writing inode tables: done 
Creating journal (4096 blocks): done
Writing superblocks and filesystemaccounting information: done
This filesystem will be automaticallychecked every 37 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

 

其间文件体系Label 以及iBLOCK巨细均选用默许巨细。假如关于EXT2/EXT3 咱们对这些信息由特别的需求,能够运用mke2fs

 

mke2fs

语法:mke2fs[-b block巨细] [-i inode 巨细] [-L 卷标] [-cj] 设备

选项与参数:

-b:设置block巨细,现在支撑1024,2048,4096

-i:多少容量给予一个inode

-c:检查磁盘过错

-L:卷标称号(Label)

-j:自动参加日志体系成为EXT3文件体系,不加在默许为EXT2

举例

[root@localhost ~]# mke2fs -b 2048 -i 4096-L "TKFDISK" -j /dev/sda7
mke2fs 1.39 (29-May-2006)
Filesystemlabel=TKFDISK
OS type: Linux
Blocksize=2048 (log=1)
Fragment size=2048 (log=1)
50288 inodes, 100390 blocks
5019 blocks (5.00%) reserved for the superuser
First data block=0
Maximum filesystem blocks=103809024
7 block groups
16384 blocks per group, 16384 fragments pergroup
7184 inodes per group
Superblock backups stored on blocks:
 16384, 49152, 81920
Writing inode tables: done 
Creatingjournal (4096 blocks): done
Writing superblocks and filesystemaccounting information: done
This filesystem will be automaticallychecked every 31 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

 

磁盘检测(fsck)

语法: fsck [-t 文件体系格局] [-ACay]

选项与参数

-t  :文件体系格局。

-A  :根据/etc/fstab 的内容,将需求的设备扫瞄一次。

-a  :自动修正检查到的有问题的扇区.

-y  :与 -a 相似,可是某些filesystem 仅支撑 -y 这个参数

-C  :能够在查验的进程傍边,运用一个直方图来显现现在的进展!

 

EXT2/EXT3 的额定选项功用:(e2fsck 这支指令所供给)

-f  :强制检查!一般来说,假如 fsck 没有发现任何 unclean 的旗标,不会自动进入细部检查的,假如您想要强制 fsck 进入细部检查,就得加上 -f

-D  :针对文件体系下的目录进行优化装备。

 

举例

[root@localhost ~]# fsck -Cf /dev/sda7
fsck 1.39 (29-May-2006)
e2fsck 1.39 (29-May-2006)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure 
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
TKFDISK: 11/50288 files (9.1%non-contiguous), 7673/100390 blocks 

阐明:需求磁盘检查的分区不能挂载在体系上,需求先被卸载才干磁盘检测

 

大容量磁盘分区(parted)

因为fdisk无法支撑到高于2TB以上的分区,此刻就需求parted来处理了

 

语法:parted [设备] [指令 [参数]]

选项与参数:

新增分区:mkpart [primary|logical|extended] [ext3|vfat]开端完毕

分区表:print

删去分区:rm [partition]

 

举例1:检查分区表

[root@bogon ~]# parted /dev/sda print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system 标志
 1 32.3kB 107MB 107MB 主分区 ext3 发动
 2 107MB 10.6GB 10.5GB 主分区 ext3 
 3 10.6GB 15.8GB 5240MB 主分区 ext3 
 4 15.8GB 21.5GB 5634MB 扩展分区 
 5 15.8GB 16.9GB 1045MB 逻辑分区 linux-swap 
信息: 假如必要,不要忘掉更新 /etc/fstab。 


 

经过以上信息能够看出,扩展分区到21.5G,逻辑分区运用到16.9G,那么16.9G~21.5G只部分空间还为被运用(未被分区)

 

举例2:新增分区

[root@bogon ~]# parted /dev/sda mkpart logical ext3 16.9G 18.9G
信息: 假如必要,不要忘掉更新 /etc/fstab。 
[root@bogon ~]# parted /dev/sda print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system 标志
 1 32.3kB 107MB 107MB 主分区 ext3 发动
 2 107MB 10.6GB 10.5GB 主分区 ext3 
 3 10.6GB 15.8GB 5240MB 主分区 ext3 
 4 15.8GB 21.5GB 5634MB 扩展分区 
 5 15.8GB 16.9GB 1045MB 逻辑分区 linux-swap 
 6 16.9GB 18.9GB 2023MB 逻辑分区 


 

举例3:删去分区

[root@bogon ~]# parted /dev/sda rm 6
信息: 假如必要,不要忘掉更新 /etc/fstab。 
[root@bogon ~]# parted /dev/sda print
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sda: 21.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Number Start End Size Type File system 标志
 1 32.3kB 107MB 107MB 主分区 ext3 发动
 2 107MB 10.6GB 10.5GB 主分区 ext3 
 3 10.6GB 15.8GB 5240MB 主分区 ext3 
 4 15.8GB 21.5GB 5634MB 扩展分区 
 5 15.8GB 16.9GB 1045MB 逻辑分区 linux-swap 
信息: 假如必要,不要忘掉更新 /etc/fstab。 
阐明:parted分区提交即履行,因而运用起来需当心
版权声明
本文来源于网络,版权归原作者所有,其内容与观点不代表牛牛娱乐立场。转载文章仅为传播更有价值的信息,如采编人员采编有误或者版权原因,请与我们联系,我们核实后立即修改或删除。

猜您喜欢的文章