Linux下磁盘管理
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux下磁盘管理相关的知识,希望对你有一定的参考价值。
一、索引式文件系统特性
sector:最小物理存储单位,
superblock:记录整个文件系统的信息,包括inode、block总量、使用量、剩余量及文件系统格式等信息;
inode:记录文件属性,并指向文件实际存储的blokck号;
block:存储文件内容,一个block只能存储同一个文件的内容,block的大小好比往圆柱体里放正方体,正方体越小则放得越多,但存取速度也越慢;
二、磁盘管理
一)、查看磁盘及分区情况
[[email protected] ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 20G 0 disk ├─sda1 8:1 0 2M 0 part ├─sda2 8:2 0 500M 0 part /boot └─sda3 8:3 0 19.5G 0 part ├─centos_a-root 253:0 0 10G 0 lvm / ├─centos_a-swap 253:1 0 1G 0 lvm [SWAP] └─centos_a-home 253:2 0 8.5G 0 lvm /home sr0 11:0 1 1024M 0 rom [[email protected] ~]# parted /dev/sda print ###查看分割表 Model: VMware, VMware Virtual S (scsi) Disk /dev/sda: 21.5GB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 1 1049kB 3146kB 2097kB primary 2 3146kB 527MB 524MB primary xfs boot 3 527MB 21.5GB 20.9GB primary lvm
二)、磁盘分割
MBR使用fdisk,GPT使用gdisk,它们使用基本一样。分割一个5M的分区
[[email protected] ~]# fidsk /dev/sda bash: fidsk: command not found... Similar command is: ‘fdisk‘ [[email protected] ~]# fdisk /dev/sda 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. Command (m for help): n ##新建一个分区 Partition type: p primary (3 primary, 0 extended, 1 free) e extended Select (default e): ##msdos最多只能有4个分区,所以建立扩展分区 Using default response e Selected partition 4 First sector (41934848-41943039, default 41934848): ##默认即可 Using default value 41934848 ##↓输入分区大小 Last sector, +sectors or +size{K,M,G} (41934848-41943039, default 41943039): +10M Value out of range. Last sector, +sectors or +size{K,M,G} (41934848-41943039, default 41943039): Using default value 41943039 Partition 4 of type Extended and of size 4 MiB is set Command (m for help): p ##查看分区 Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x0007947d Device Boot Start End Blocks Id System /dev/sda1 2048 6143 2048 83 Linux /dev/sda2 * 6144 1030143 512000 83 Linux /dev/sda3 1030144 41934847 20452352 8e Linux LVM /dev/sda4 41934848 41943039 4096 5 Extended Command (m for help): w ###写入分区表 The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) Syncing disks. [[email protected] ~]# partprobe -s ##更新分区表 /dev/sda: msdos partitions 1 2 3 4 <>
三)、格式化分区
[[email protected] ~]# mkfs. ##格式化类型 mkfs.btrfs mkfs.ext2 mkfs.ext4 mkfs.minix mkfs.vfat mkfs.cramfs mkfs.ext3 mkfs.fat mkfs.msdos mkfs.xfs [[email protected] ~]# mkfs.ext4 /dev/sda4 ##可以使用-d指定block大小 mke2fs 1.42.9 (28-Dec-2013) mkfs.ext4: inode_size (128) * inodes_count (0) too big for a filesystem with 0 blocks, specify higher inode_ratio (-i) or lower inode count (-N).
四)、挂载
[[email protected] ~]# mount /dev/sda4 /ui ##挂载到目录 [[email protected] ~]# vim /etc/fstab ##追加,开机挂载 /dev/sda4 /fl etx4 defaults 0 0
以上是关于Linux下磁盘管理的主要内容,如果未能解决你的问题,请参考以下文章