liunx初级学习之管理系统中的简单分区和文件系统2-4
2017-04-24 14:20
411 查看
1 fdisk /dev/vdb ##新建分区 2 command (m for help): m ##帮助 3 Command action 4 a toggle a bootable flag 5 b edit bsd disklabel 6 c toggle the dos compatibility flag 7 d delete a partition ##删除分区 8 g create a new empty GPT partition table 9 G create an IRIX (SGI) partition table 10 l list known partition types ##列出系统可用的分区类型 11 m print this menu 12 n add a new partition ##新建分区 13 o create a new empty DOS partition table 14 p print the partition table ##显示分区 15 q quit without saving changes ##不保存推出 16 s create a new empty Sun disklabel 17 t change a partition's system id ##修改分区id 18 u change display/entry units 19 v verify the partition table 20 w write table to disk and exit ##保存更改到分区表中 21 x extra functionality (experts only); 22 Command (m for help): n 23 Partition type: 24 p primary (0 primary, 0 extended, 4 free) 25 e extended 26 Select (default p): ##不输入默认新建主分区 27 Using default response p 28 Partition number (1-4, default 1): 29 First sector (2048-20971519, default 2048): 30 Using default value 2048 31 Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): 32 Using default value 20971519 33 Partition 1 of type Linux and of size 100MiB is set ##输入大小 34 Command (m for help): w ##保存更改至分区表 35 The partition table has been altered! ##分区已经建立完成 36 Calling ioctl() to re-read partition table. 37 Syncing disks. 38 [root@station ~]# partprobe ##同步分区信息 39 [root@station ~]# cat /proc/partitions ##查看分区信息 40 major minor #blocks name 41 253 0 10485760 vda 42 253 1 10484142 vda1 43 253 16 10485760 vdb 44 253 17 10484736 vdb1 45 [root@station ~]# fdisk /dev/vdb 46 Welcome to fdisk (util-linux 2.23.2). 47 48 Changes will remain in memory only, until you decide to write them. 49 Be careful before using the write command. 50 51 52 Command (m for help): n 53 Partition type: 54 p primary (1 primary, 0 extended, 3 free)##一个主分区,零个扩展分区,三个为被利用 55 e extended ##扩展区 56 Select (default p): p 57 Partition number (2-4, default 2): ##建立第二个主分区 58 59 First sector (206848-20971519, default 206848): 60 Last sector, +sectors or +size{K,M,G} (206848-20971519, default 20971519): +100M 61 ##设置第二块主分区大小为100M 62 Partition 2 of type Linux and of size 100 MiB is set 63 64 Command (m for help): p 65 66 Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors 67 Units = sectors of 1 * 512 = 512 bytes 68 Sector size (logical/physical): 512 bytes / 512 bytes 69 I/O size (minimum/optimal): 512 bytes / 512 bytes 70 Disk label type: dos 71 Disk identifier: 0xb499081e ##显示存在的分区 72 73 Device Boot Start End Blocks Id System 74 /dev/vdb1 2048 206847 102400 83 Linux 75 /dev/vdb2 206848 411647 102400 83 Linux 76 77 Command (m for help): n 78 Partition type: 79 p primary (2 primary, 0 extended, 2 free) 80 e extended 81 Select (default p): 82 Using default response p 83 Partition number (3,4, default 3): 84 First sector (411648-20971519, default 411648): 85 Using default value 411648 86 Last sector, +sectors or +size{K,M,G} (411648-20971519, default 20971519): +80M 87 Partition 3 of type Linux and of size 80 MiB is set 88 89 Command (m for help): n 90 Partition type: 91 p primary (3 primary, 0 extended, 1 free) 92 e extended 93 Select (default e): p 94 Selected partition 4 95 First sector (575488-20971519, default 575488): 96 Using default value 575488 97 Last sector, +sectors or +size{K,M,G} (575488-20971519, default 20971519): 98 Using default value 20971519 99 Partition 4 of type Linux and of size 9.7 GiB is set ##默认剩余的全部给第四分区 100 101 Command (m for help): p 102 Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors 103 Units = sectors of 1 * 512 = 512 bytes 104 Sector size (logical/physical): 512 bytes / 512 bytes 105 I/O size (minimum/optimal): 512 bytes / 5 4000 12 bytes 106 Disk label type: dos 107 Disk identifier: 0xb499081e 108 109 Device Boot Start End Blocks Id System 110 /dev/vdb1 2048 206847 102400 83 Linux 111 /dev/vdb2 206848 411647 102400 83 Linux 112 /dev/vdb3 411648 575487 81920 83 Linux 113 /dev/vdb4 575488 20971519 10198016 83 Linux 114 ##建立了四个主分区 115 Command (m for help): n 116 If you want to create more than four partitions, you must replace a 117 primary partition with an extended partition first. ##最多只能建四个主分区,如果还需需建立分区则为扩展分区 118 Command (m for help): d 119 Partition number (1-4, default 4): 4 ##删除第四个分区 120 Partition 4 is deleted 121 Command (m for help): n 122 Partition type: 123 p primary (3 primary, 0 extended, 1 free) 124 e extended 125 Select (default e): e ##建立扩展分区 126 Selected partition 4 127 First sector (575488-20971519, default 575488): 128 Using default value 575488 129 Last sector, +sectors or +size{K,M,G} (575488-20971519, default 20971519): +800M 130 Partition 4 of type Extended and of size 800 MiB is set ##创建一个大小为800 131 132 Command (m for help): p 133 134 Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors 135 Units = sectors of 1 * 512 = 512 bytes 136 Sector size (logical/physical): 512 bytes / 512 bytes 137 I/O size (minimum/optimal): 512 bytes / 512 bytes 138 Disk label type: dos 139 Disk identifier: 0xb499081e 140 141 Device Boot Start End Blocks Id System 142 /dev/vdb1 2048 206847 102400 83 Linux 143 /dev/vdb2 206848 411647 102400 83 Linux 144 /dev/vdb3 411648 575487 81920 83 Linux 145 /dev/vdb4 575488 2213887 819200 5 Extended 146 此处省略部分同上操作 147 Command (m for help): p 148 149 Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors 150 Units = sectors of 1 * 512 = 512 bytes 151 Sector size (logical/physical): 512 bytes / 512 bytes 152 I/O size (minimum/optimal): 512 bytes / 512 bytes 153 Disk label type: dos 154 Disk identifier: 0xb499081e 155 156 Device Boot Start End Blocks Id System 157 /dev/vdb1 2048 206847 102400 83 Linux 158 /dev/vdb2 206848 411647 102400 83 Linux 159 /dev/vdb3 411648 575487 81920 83 Linux 160 /dev/vdb4 575488 2213887 819200 5 Extended 161 /dev/vdb5 577536 782335 102400 83 Linux 162 /dev/vdb6 784384 989183 102400 83 Linux 163 Command (m for help): wq ##保存退出 164 The partition table has been altered! 165 166 Calling ioctl() to re-read partition table. 167 Syncing disks. 168 [root@station ~]# partprobe 169 [root@station ~]# cat /proc/partitions 170 major minor #blocks name 171 172 253 0 10485760 vda 173 253 1 10484142 vda1 174 253 16 10485760 vdb 175 253 17 102400 vdb1 176 253 18 102400 vdb2 177 253 19 81920 vdb3 178 253 20 1 vdb4 179 253 21 102400 vdb5 180 253 22 102400 vdb6 181 [root@station ~]# blkid 182 /dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1" TYPE="xfs"##获取文件系统类型 183 [root@station ~]# mkfs.xfs /dev/vdb6 ##将分区格式化,改为xfs格式 184 meta-data=/dev/vdb6 isize=256 agcount=4, agsize=6400 blks 185 = sectsz=512 attr=2, projid32bit=1 186 = crc=0 187 data = bsize=4096 blocks=25600, imaxpct=25 188 = sunit=0 swidth=0 blks 189 naming =version 2 bsize=4096 ascii-ci=0 ftype=0 190 log =internal log bsize=4096 blocks=853, version=2 191 = sectsz=512 sunit=0 blks, lazy-count=1 192 realtime =none extsz=4096 blocks=0, rtextents=0 193 194 195 [root@station ~]# vim /etc/fstab ##修改配置文件,使永久生效 196 /dev/vdb6 /mnt xfs defaults 0 0 197 #指定盘 挂载位置 修改格式 不检测 不备份 198 Command (m for help): t 199 Selected partition 1 200 Hex code (type L to list all codes): l 201 202 0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris 203 1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT- 204 2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT- 205 3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT- 206 此处省略部分 207 18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto 208 1e Hidden W95 FAT1 80 Old Minix 209 Hex code (type L to list all codes): 82 ##设置linux swap的id 210 Changed type of partition 'Linux' to 'Linux swap / Solaris' 211 Command (m for help): p 212 213 Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors 214 Units = sectors of 1 * 512 = 512 bytes 215 Sector size (logical/physical): 512 bytes / 512 bytes 216 I/O size (minimum/optimal): 512 bytes / 512 bytes 217 Disk label type: dos 218 Disk identifier: 0xb499081e 219 220 Device Boot Start End Blocks Id System 221 /dev/vdb1 2048 8390655 4194304 82 Linux swap / Solaris 222 临时挂载 写入配置文件开机自动挂载
223 [root@station ~]# mkswap /dev/vdb1 ##会准备好将分区用作交换区 224 [root@station ~]# swapon -a /dev/vdb1 ##将激活新交换区 225 [root@station ~]# swapon -s ##将显示当前交换区的状态 226 [root@station ~]# swapoff /dev/vdb2 ##将停用该特定交换区 227 [root@station ~]# swapon -a /dev/vdb2 -p 1 ##激活该交换区并将优先级临时改为1 228 [root@station ~]# swapon -s 229 [root@station ~]# vim /etc/fstab ##修改配置文件永久调整优先级 dev/vdb1 swap swap defaults, 0 0 dev/vdb2 swap swap defaults,pri=1 0 0 将vdb2的优先级改为1
230[root@station ~]# fdisk /dev/vdb <<end ##输入参数自动建立分区又 > n > p > > > +100M > wq > end
[root@station ~]# vim /bin/fdisk.sh ##写配置文档建立分区$1表示位置$2表示p/e即主分区或者逻辑分区 $3表示分区大小 1#!/bin/bash 2 fdisk $1<<end 3 n 4 $2 5 6 7 $3 8 wq 9 end
[root@localhost
~]# cryptsetup luksFormat /dev/vdb1 ##对分区进行加密并设置密码WARNING!========This will overwrite data on /dev/vdb1 irrevocably.Are you sure? (Type uppercase yes): YES ##大写YESEnter passphrase: ##密码不显示Verify passphrase:
[root@localhost ~]# cryptsetup open /dev/vdb1 westos ##会将加密的卷/dev/vdb1解锁为/dev/mapper/westosEnter
passphrase for /dev/vdb1: ##输入设置的密码[root@localhost ~]# ll /dev/mapper/westos ##查看解锁后的卷
lrwxrwxrwx.
1 root root 7 Apr 25 00:59 /dev/mapper/westos -> ../dm-0[root@localhost ~]# mkfs.xfs /dev/mapper/westosmeta-data=/dev/mapper/westos isize=256 agcount=4, agsize=31872 blks = sectsz=512 attr=2, projid32bit=1 =
crc=0data = bsize=4096 blocks=127488, imaxpct=25 = sunit=0 swidth=0 blksnaming =version 2 bsize=4096 ascii-ci=0 ftype=0log =internal log bsize=4096 blocks=853,
version=2 = sectsz=512 sunit=0 blks, lazy-count=1realtime =none extsz=4096 blocks=0, rtextents=0[root@localhost ~]# mount /dev/mapper/westos /mnt[root@localhost mnt]# cd[root@localhost ~]# umount /mnt[root@localhost
~]# cd /mnt[root@localhost mnt]# ls[root@localhost mnt]# cd
[root@localhost
~]# ll /dev/mapper/total 0crw-------. 1 root root 10, 236 Apr 24 23:26 controllrwxrwxrwx. 1 root root 7 Apr 25 01:04 westos -> ../dm-0
[root@localhost
~]# cryptsetup open /dev/vdb1 westos ##输入密码解锁Enter passphrase for /dev/vdb1: [root@localhost ~]# mount /dev/mapper/westos /mnt[root@localhost ~]# cd /mnt[root@localhost mnt]# lsfile1 file10 file2 file3 file4 file5 file6 file7 file8 file9
[root@localhost
mnt]# vim /etc/fstab ##设置自动挂载,在配置文件写入 /dev/mapper/westos /mnt/ xfs defaults 0 0[root@localhost mnt]# vim /etc/crypttab ##解密读取文件,写入 westos /dev/vdb1 /root/diskpass [root@localhost mnt]# vim /root/diskpass ##密码写入配置文件,自动读取 [root@localhost
mnt]# chmod 600 /root/diskpass ##授予执行权限[root@localhost mnt]# cryptsetup luksAddKey /dev/vdb1 /root/diskpass ##添加密码Enter any passphrase: [root@localhost mnt]#
相关文章推荐
- Linux学习第四单元-管理系统中的简单分区和文件系统
- ##II 第四单元##管理系统中的简单分区和文件系统
- 管理系统中的简单分区和文件系统
- Linux运维笔记-文档总结-管理系统中的简单分区和文件系统
- 管理系统简单的分区和文件系统
- 第二课unit4 管理系统中的简单分区和文件系统
- unit4~~管理系统中的简单分区和文件系统
- Linux运维笔记----管理系统中的简单分区和文件系统
- 管理系统中的简单分区和文件系统
- 【基础部分】之管理系统中的简单分区和文件系统
- 管理系统中的简单分区和文件系统
- Linux系统学习第三章:磁盘与文件系统管理(三)硬盘分区、格式化、检验与挂载
- RHEL-RH134-UNIT4--管理系统中的简单分区和文件系统
- 管理系统中的简单分区和文件系统
- unit2.4管理系统中的简单分区和文件系统
- Linux--RH134---unit 4 管理系统中的简单分区和文件系统
- Linux高级管理之管理系统中的简单分区和文件系统
- 管理系统中的简单分区和文件系统
- 第四 管理系统中的简单分区和文件系统
- Linux学习笔记------讲9.3.1文件系统管理-----fdisk分区---分区过程