bash能够生成随机数,范围是0-32768【65535/2】,它是一个系统变量$RANDOMlinux
[jiakang@jiakang tmp]$ echo $RANDOM 15163 [jiakang@jiakang tmp]$ echo $RANDOM 23259 [jiakang@jiakang tmp]$ echo $RANDOM 25631
熵池是存放随机数的池子,咱们上面bash生成的随机数安全性很低,甚至是经过算法能够破解,因此出现了熵池;
熵池是让/dev/random使用的,它产生的随机数是硬件不规律造成的,好比咱们间隔按鼠标的时间,安全性很是高,熵池中的值是剪切过来的,因此可能会被用完出现阻塞用户的进程。
/dev/urandom:也是取熵池中的随机数,可是取完后会用bash自动模拟,不会出现阻塞。算法
/dev/random
/dev/urandom安全
mknod mydev c 66 0【c表明字符设备,ls - l每行的最前面那个字符表明文件类型,66表明主设备号,0表明次设备号】bash
[root@jiakang a]# mknod mydev c 66 0 [root@jiakang a]# ls -il 总用量 28 412296 drwxr-xr-x. 3 root root 4096 3月 28 16:34 b 412310 -rwxr-xr-x. 1 root root 133 4月 13 14:34 case.sh 412301 crw-r--r--. 1 root root 66, 0 4月 15 18:42 mydev
还能够在建立设备的时候指定使用权限dom
[root@jiakang a]# mknod -m 640 mydev1 c 66 1 [root@jiakang a]# ls -l 总用量 28 drwxr-xr-x. 3 root root 4096 3月 28 16:34 b -rwxr-xr-x. 1 root root 133 4月 13 14:34 case.sh crw-r--r--. 1 root root 66, 0 4月 15 18:42 mydev crw-r-----. 1 root root 66, 1 4月 15 18:47 mydev1
当咱们有个硬件链接到linux上面,这个设备会有个本身的设备号,而后咱们的linux也有这个设备号,因此就对接上了。linux向这个设备号发送东西,就会发送到对应的硬件上。ide
下面是两个设备【终端设备】:
ui
[root@jiakang a]# tty /dev/pts/0 [jiakang@jiakang ~]$ tty /dev/pts/1 [root@jiakang a]# echo "hello jiakang" >> /dev/pts/1 [jiakang@jiakang ~]$ hello jiakang
根目录是文件系统的访问路口,如:/a/b,如今把b单独分区了,我要想访问b分区,必须先找到根目录的/a/b,b文件存的是b分区的访问入口;在/a/b/c中,如今再把c单独分区,那访问的时候先找根分区而后找到b文件相应的找到了b分区,再找c文件找到c分区。因此若是根很重要,根分区崩了,其余分区也没了this
查看磁盘、分区的使用状况 fdisk -l [/dev/PATH]操作系统
[root@jiakang ~]# fdisk -l盘【查看磁盘的使用状况】 Disk /dev/sda: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 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: 0x000478b0 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 287 2097152 82 Linux swap / Solaris Partition 2 does not end on cylinder boundary. /dev/sda3 287 1306 8182784 83 Linux [root@jiakang ~]# fdisk -l /dev/sda1【查看某个分区的使用状况】 Disk /dev/sda1: 209 MB, 209715200 bytes 255 heads, 63 sectors/track, 25 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: 0x00000000
fdisk /dev/sdacode
p:显示当前硬件的分区,包括没保存的改动
n:建立新分区【e:扩展分区 p:主分区】
d:删除一个分区
w:保存退出
q:不保存退出
t:修改分区类型【L:显示支持的分区类型】
l:显示所支持的全部类型
下面的代码我要建立一个新的主分区,可是没有多余的柱面【空间】了
[root@jiakang ~]# 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): m【m获取帮助】 Command action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only) Command (m for help): p【打印显示当前分区使用情况】 Disk /dev/sda: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 cylinders【共1305个柱面】 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: 0x000478b0 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 287 2097152 82 Linux swap / Solaris Partition 2 does not end on cylinder boundary. /dev/sda3 287 1306 8182784 83 Linux Command (m for help): n【建立新分区】 Command action e extended p primary partition (1-4) p【建立主分区】 Selected partition 4 No free sectors available Command (m for help): q【退出】 ...
删除第3个主分区,而后再从新划分柱面
... ... Command (m for help): d【删除分区】 Partition number (1-4): 3【删除第三个主分区】 Command (m for help): p Disk /dev/sda: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 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: 0x000478b0 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 287 2097152 82 Linux swap / Solaris Partition 2 does not end on cylinder boundary.
建立主分区3,扩展分区4,逻辑分区5
Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 3 First cylinder (287-1305, default 287): 【起始柱面,这直接回车就是默认】 Using default value 287 Last cylinder, +cylinders or +size{K,M,G} (287-1305, default 1305): +2G【结束柱面,指定大小】 Command (m for help): p Disk /dev/sda: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 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: 0x000478b0 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 287 2097152 82 Linux swap / Solaris Partition 2 does not end on cylinder boundary. /dev/sda3 287 548 2098834 83 Linux【这是新增的主分区3柱面287-548】 Command (m for help): n Command action e extended p primary partition (1-4) e【建立扩展分区】 Selected partition 4 First cylinder (549-1305, default 549): 【回车】 Using default value 549 Last cylinder, +cylinders or +size{K,M,G} (549-1305, default 1305): 【回车】 Using default value 1305 Command (m for help): n First cylinder (549-1305, default 549): Using default value 549 Last cylinder, +cylinders or +size{K,M,G} (549-1305, default 1305): +1G Command (m for help): p Disk /dev/sda: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 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: 0x000478b0 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 287 2097152 82 Linux swap / Solaris Partition 2 does not end on cylinder boundary. /dev/sda3 287 548 2098834 83 Linux /dev/sda4 549 1305 6080602+ 5 Extended /dev/sda5 549 680 1060258+ 83 Linux【类型编号83,类型Linux】
上面的sda5类型编号是83,类型为Linux,咱们能够调到其余类型
Command (m for help): t【修改分区类型】 Partition number (1-5): 5【修改第5个分区】 Hex code (type L to list codes): L【查看有哪些分区类型,83就是刚才的Linux】 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 ... ... Hex code (type L to list codes): 82【调整为82交换分区】 Changed system type of partition 5 to 82 (Linux swap / Solaris) Command (m for help): p Disk /dev/sda: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 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: 0x000478b0 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 287 2097152 82 Linux swap / Solaris Partition 2 does not end on cylinder boundary. /dev/sda3 287 548 2098834 83 Linux /dev/sda4 549 1305 6080602+ 5 Extended /dev/sda5 549 680 1060258+ 82 Linux swap / Solaris【改成了82】
w 保存退出修改
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: 设备或资源忙. 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. [root@jiakang ~]# fdisk -l Disk /dev/sda: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 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: 0x000478b0 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 287 2097152 82 Linux swap / Solaris Partition 2 does not end on cylinder boundary. /dev/sda3 287 548 2098834 83 Linux /dev/sda4 549 1305 6080602+ 5 Extended /dev/sda5 549 680 1060258+ 82 Linux swap / Solaris
上面的分区表成功后须要内核去识别,/proc/partitions目录是当前内核识别的分区表,能够经过partprobe去让内核从新识别,可是在这可能遇到下面的错误
[root@jiakang ~]# cat /proc/partitions major minor #blocks name 8 0 10485760 sda 8 1 204800 sda1 8 2 2097152 sda2 8 3 8182784 sda3 [root@jiakang ~]# partprobe Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (设备或资源忙). As a result, it may not reflect all of your changes until after reboot. Warning: 没法以读写方式打开 /dev/sr0 (只读文件系统)。/dev/sr0 已按照只读方式打开。 Warning: 没法以读写方式打开 /dev/sr0 (只读文件系统)。/dev/sr0 已按照只读方式打开。 Error: 无效的分区表 - /dev/sr0 出现递归分区。 [root@jiakang ~]# cat /proc/partitions major minor #blocks name 8 0 10485760 sda 8 1 204800 sda1 8 2 2097152 sda2 8 3 8182784 sda3 [root@jiakang ~]# ls -l /dev/sr0 brw-rw----+ 1 root cdrom 11, 0 4月 16 09:55 /dev/sr0
从上面的结果看,sr0是光驱设备,百度了下/dev/sr0这个设备,也所是光驱。因而管它重载分区表失败是否是因为“Error: 无效的分区表 - /dev/sr0 出现递归分区。”引发的,先把光驱移除了再说,反正是虚拟机上。
把虚拟机上的光驱设备移除后,从新启动系统,再从新新建分区,并从新执行partprobe命令重载分区表,错误信息“Error: 无效的分区表 - /dev/sr0 出现递归分区。”没有了,只是警告提示“设备或资源忙”还在。这时直接格式化新建的逻辑分区/dev/sda5仍是提示“没有那个文件或目录”。因而重启系统,再格式化/dev/sda5,这回成功了。
也就是说,以前新建分区格式化失败,是因为虚拟机的光驱/dev/sr0设备致使了分区表递归。另外因为是在同一块硬盘上操做,因此必需要重启系统才能使新建的分区写入分区表生效。
卸载光驱后:
[root@jiakang ~]# partprobe Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (设备或资源忙). As a result, it may not reflect all of your changes until after reboot. [root@jiakang ~]# cat /proc/partitions major minor #blocks name 8 0 10485760 sda 8 1 204800 sda1 8 2 2097152 sda2 8 3 8182784 sda3
重启系统
MDZZ!!!不知道有没有发现上面的刚开始柱面不足,我删除了第3个主分区,个人根目录及全部的文件都在里面,至关于删除了根目录,致使系统崩溃:“客户机操做系统已禁用 CPU。请关闭或重置虚拟机 ”
从新安装了一下linux,此次我加载了两块磁盘,新建了sdb1分区:
[root@localhost ~]# fdisk -l Disk /dev/sda: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 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: 0x0002b305 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 548 4194304 83 Linux Partition 2 does not end on cylinder boundary. /dev/sda3 548 809 2097152 82 Linux swap / Solaris Partition 3 does not end on cylinder boundary. /dev/sda4 809 1306 3988480 5 Extended /dev/sda5 810 1306 3987456 83 Linux Disk /dev/sdb: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 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: 0xd25c91c2 Device Boot Start End Blocks Id System /dev/sdb1 1 200 1606468+ 83 Linux
然而此次发现不用内核去识别了,直接就能够自动去识别,并且还能够格式化【我sdb1是新建的刚刚】
[root@localhost ~]# cat /proc/partitions major minor #blocks name 8 0 10485760 sda 8 1 204800 sda1 8 2 4194304 sda2 8 3 2097152 sda3 8 4 1 sda4 8 5 3987456 sda5 8 16 10485760 sdb 8 17 1606468 sdb1 [root@localhost ~]# mkfs -t ext4 /dev/sdb1 mke2fs 1.41.12 (17-May-2010) 文件系统标签= 操做系统:Linux ... ...
查阅资料获取的信息是:不是当前使用的磁盘不须要让内核从新去获取了,教训就是没事就快照,别不当心删了根目录!!
redhat6的partprobe失效能够用partx
[root@localhost ~]# partx -a /dev/sdb1 /dev/sdb