练习一
1、创建一个1G的分区,文件系统为ext4,卷标为MYDATA,块大小为1024,预留管理空间为磁盘
分区的3%,要求开机后制动挂载至/data目录,并且自动挂载的设备要使用卷标进行引用。
fdisk /dev/sda
[root@xuelinux ~]# fdisk /dev/sda
WARNING: 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): n 新建分区,如果是个新硬盘会提示新建主分区(p)或者是扩展分区(e)
First cylinder (2258-2611, default 2258): 输入起始柱面默认即可
Using default value 2258
Last cylinder, +cylinders or +size{K,M,G} (2258-2611, default 2611): +1G 创建一个1G分区
Command (m for help): t t修改分区类型
Partition number (1-8): 8
Hex code (type L to list codes): L L查看系统支持的分区类型
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 41 PPC PReP Boot 85 Linux extended c7 Syrinx
5 Extended 42 SFS 86 NTFS volume set da Non-FS data
Hex code (type L to list codes): 83 输入分区类型
Command (m for help): p 显示已经建立好的分区表
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0001e9b8
Device Boot Start End Blocks Id System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 26 1046 8192000 83 Linux
/dev/sda3 1046 1556 4096000 83 Linux
/dev/sda4 1556 2611 8477696 5 Extended
/dev/sda5 1556 1811 2048000 83 Linux
/dev/sda6 1811 2066 2048000 83 Linux
/dev/sda7 2066 2258 1536000 82 Linux swap / Solaris
/dev/sda8 2258 2389 1059691 83 Linux
sda8即为刚才新建立的分区
ommand (m for help): w w保存退出新建分区建立成功
The partition table has been altered!
Calling ioctl() to re-read partition table.
[root@xuelinux ~]# partprobe partprobe通知内核重读分区表,让内核识别新建的分区
[root@xuelinux ~]# cat /proc/partitions
major minor #blocks name
8 0 20971520 sda
8 1 204800 sda1
8 2 8192000 sda2
8 3 4096000 sda3
8 4 1 sda4
8 5 2048000 sda5
8 6 2048000 sda6
8 7 1536000 sda7
8 8 1024000 sda8 内核已经识别到新建分区,只有识别到了分区才能进行格式化、挂载等操作。
[root@xuelinux ~]# mke2fs -t ext4 /dev/sda8 把/dev/sda8分区格式化为ext4类型
[root@xuelinux test]# mke2fs -L MYDATA /dev/sda8 设定新卷标为MYDATA
[root@xuelinux test]# mke2fs -m 3 /dev/sda8 预留分区的3%给管理空间
[root@xuelinux test]# mke2fs -b 1024 /dev/sda8 设置块大小为1024字节
然后把新建的分区写入/etc/fstab文档中,实现开机自动挂载,在该文档的最下面添加一行如下:
LABEL=‘MYDATA‘ /data ext4 defaults 0 0
实现卷标自动挂载为MYDATA
练习二
2、创建一个本地回环文件/var/swaptemp/swapfile来用于swap,要求大小为512MB,
卷标为SWAP-FILE,且开机自动启用此交换设备:
mkdir /var/swaptemp
dd if=/dev/zero of=/var/swaptemp/swapfile bs=512M count=1
mkswap LABEL=SWAP-FILE /var/swaptemp/swapfile
vim /etc/fstab
/var/swaptemp/swapfile swap swap defaults 0 0 写入/etc/fstab实现开机自动挂载
本文出自 “学linux历程” 博客,请务必保留此出处http://woyaoxuelinux.blog.51cto.com/5663865/1868152
linux命令练习:mount fdisk swap dd创建本地回环设备
原文地址:http://woyaoxuelinux.blog.51cto.com/5663865/1868152