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