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): p102 Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors103 Units = sectors of 1 * 512 = 512 bytes104 Sector size (logical/physical): 512 bytes / 512 bytes105 I/O size (minimum/optimal): 512 bytes / 512 bytes106 Disk label type: dos107 Disk identifier: 0xb499081e108 109 Device Boot Start End Blocks Id System110 /dev/vdb1 2048 206847 102400 83 Linux111 /dev/vdb2 206848 411647 102400 83 Linux112 /dev/vdb3 411648 575487 81920 83 Linux 113 /dev/vdb4 575488 20971519 10198016 83 Linux114 ##建立了四个主分区115 Command (m for help): n116 If you want to create more than four partitions, you must replace a117 primary partition with an extended partition first. ##最多只能建四个主分区,如果还需需建立分区则为扩展分区118 Command (m for help): d119 Partition number (1-4, default 4): 4 ##删除第四个分区120 Partition 4 is deleted121 Command (m for help): n122 Partition type:123 p primary (3 primary, 0 extended, 1 free)124 e extended125 Select (default e): e ##建立扩展分区126 Selected partition 4127 First sector (575488-20971519, default 575488):128 Using default value 575488129 Last sector, +sectors or +size{K,M,G} (575488-20971519, default 20971519): +800M130 Partition 4 of type Extended and of size 800 MiB is set ##创建一个大小为800131 132 Command (m for help): p133 134 Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors135 Units = sectors of 1 * 512 = 512 bytes136 Sector size (logical/physical): 512 bytes / 512 bytes137 I/O size (minimum/optimal): 512 bytes / 512 bytes138 Disk label type: dos139 Disk identifier: 0xb499081e140 141 Device Boot Start End Blocks Id System142 /dev/vdb1 2048 206847 102400 83 Linux143 /dev/vdb2 206848 411647 102400 83 Linux144 /dev/vdb3 411648 575487 81920 83 Linux145 /dev/vdb4 575488 2213887 819200 5 Extended146 此处省略部分同上操作147 Command (m for help): p148 149 Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors150 Units = sectors of 1 * 512 = 512 bytes151 Sector size (logical/physical): 512 bytes / 512 bytes152 I/O size (minimum/optimal): 512 bytes / 512 bytes153 Disk label type: dos154 Disk identifier: 0xb499081e155 156 Device Boot Start End Blocks Id System157 /dev/vdb1 2048 206847 102400 83 Linux158 /dev/vdb2 206848 411647 102400 83 Linux159 /dev/vdb3 411648 575487 81920 83 Linux160 /dev/vdb4 575488 2213887 819200 5 Extended161 /dev/vdb5 577536 782335 102400 83 Linux162 /dev/vdb6 784384 989183 102400 83 Linux163 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 ~]# partprobe169 [root@station ~]# cat /proc/partitions170 major minor #blocks name171 172 253 0 10485760 vda173 253 1 10484142 vda1174 253 16 10485760 vdb175 253 17 102400 vdb1176 253 18 102400 vdb2177 253 19 81920 vdb3178 253 20 1 vdb4179 253 21 102400 vdb5180 253 22 102400 vdb6181 [root@station ~]# blkid182 /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 blks185 = sectsz=512 attr=2, projid32bit=1186 = crc=0187 data = bsize=4096 blocks=25600, imaxpct=25 188 = sunit=0 swidth=0 blks189 naming =version 2 bsize=4096 ascii-ci=0 ftype=0190 log =internal log bsize=4096 blocks=853, version=2191 = sectsz=512 sunit=0 blks, lazy-count=1192 realtime =none extsz=4096 blocks=0, rtextents=0193 194 195 [root@station ~]# vim /etc/fstab ##修改配置文件,使永久生效196 /dev/vdb6 /mnt xfs defaults 0 0197 #指定盘 挂载位置 修改格式 不检测 不备份198 Command (m for help): t199 Selected partition 1200 Hex code (type L to list all codes): l201 202 0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris203 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 auto208 1e Hidden W95 FAT1 80 Old Minix209 Hex code (type L to list all codes): 82 ##设置linux swap的id210 Changed type of partition 'Linux' to 'Linux swap / Solaris'211 Command (m for help): p212 213 Disk /dev/vdb: 10.7 GB, 10737418240 bytes, 20971520 sectors214 Units = sectors of 1 * 512 = 512 bytes 215 Sector size (logical/physical): 512 bytes / 512 bytes216 I/O size (minimum/optimal): 512 bytes / 512 bytes217 Disk label type: dos218 Disk identifier: 0xb499081e219 220 Device Boot Start End Blocks Id System221 /dev/vdb1 2048 8390655 4194304 82 Linux swap / Solaris222 临时挂载 写入配置文件开机自动挂载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 ##激活该交换区并将优先级临时改为1228 [root@station ~]# swapon -s229 [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]#
0 0