1.Linux常用命令(六)
1.有关磁盘与文件系统的命令
mount 设备目录 挂载点 挂载文件系统
Linux系统下,所有设备必须挂载后才能使用; 挂载相当于给一个孤立存在的设备设置一个接入口,所有用户都需要通过该接口访问该设备 这个接口称之为挂载点 |
- -a 根据/etc/fstab文件内容挂载
- -t 文件系统类型 指定挂载的文件系统类型
- -o 挂载参数 指定挂载参数
[root@aspen ~]# ls /dev/cdrom/
ls: cannot access /dev/cdrom/: Not a directory
[root@aspen ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 is write-protected, mounting read-only
[root@aspen ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 18G 1.9G 16G 11% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.6M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda1 1014M 127M 888M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/sr0 4.3G 4.3G 0 100% /mnt
[root@aspen ~]# ls /mnt/
CentOS_BuildTag EULA images LiveOS repodata RPM-GPG-KEY-CentOS-Testing-7
EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7 TRANS.TBL
umount 卸载已挂载的文件系统
[root@aspen ~]# umount /mnt/
[root@aspen ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 18G 1.9G 16G 11% /
devtmpfs 476M 0 476M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.6M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda1 1014M 127M 888M 13% /boot
tmpfs 98M 0 98M 0% /run/user/0
fdisk 磁盘名 MBR分区表磁盘分区命令(仅支持2TB以下的磁盘分区)
- -l 查看系统磁盘分区
操作选项
p 显示磁盘分区信息
n 创建磁盘分区
d 删除磁盘分区
w 保存分区并退出命令
m 查看所有操作选项
parted 磁盘名 GPT分区表磁盘分区命令(常用于2TB以上的磁盘分区)
|
[root@aspen ~]# fdisk -l
Disk /dev/sda: 107.4 GB, 107374182400 bytes, 209715200 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: 0x000c45ea
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 411647 204800 83 Linux
/dev/sda2 411648 2508799 1048576 82 Linux swap / Solaris
/dev/sda3 2508800 209715199 103603200 83 Linux
Disk /dev/sdb: 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
[root@aspen ~]# fdisk /dev/sdb
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 0x28e66d85.
Command (m for help): p
Disk /dev/sdb: 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: 0x28e66d85
parted 磁盘名 GPT分区表磁盘分区命令(常用于2TB以上的磁盘分区)
mkfs 分区 为指定分区创建文件系统
-t 文件系统类型 指定磁盘分区的文件系统类型
-t 文件系统类型 == mkfs.文件系统 |
[root@aspen ~]# mkfs.xfs /dev/sdb
meta-data=/dev/sdb isize=512 agcount=4, agsize=1310720 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=5242880, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@aspen ~]# mount /dev/sdb /data
[root@aspen ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
......
/dev/sdb xfs 20G 33M 20G 1% /data
[root@aspen ~]# umount /data/
[root@aspen ~]# mkfs -t ext4 /dev/sdb
mke2fs 1.42.9 (28-Dec-2013)
/dev/sdb is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5242880 blocks
262144 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2153775104
160 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
[root@aspen ~]# mount /dev/sdb /data
[root@aspen ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
......
/dev/sdb ext4 20G 45M 19G 1% /data
dd 转换或复制文件
参数
if=系统字符文件 指定输入文件
of=文件 指定输出文件
bs=容量 指定每次注入文件的容量
count=数字 指定注入次数
|
[root@aspen ~]# dd if=/dev/zero of=/tmp/500M bs=1M count=500
500+0 records in
500+0 records out
524288000 bytes (524 MB) copied, 4.98095 s, 105 MB/s
[root@aspen ~]# ll -h /tmp/500M
-rw-r--r-- 1 root root 500M Jun 14 14:35 /tmp/500M
mkswap 文件名 创建Linux交换分区
swapon 文件名 开启交换分区
- -s 显示系统Swap分区的组成
swapoff 文件名 关闭交换分区
Linux命令要养成操作前备份,操作后检查的好习惯
未完待续...