东莞清溪镇做网站公司,洛阳工程建设信息网站,阿里云配置wordpress,陕西网站设计2019独角兽企业重金招聘Python工程师标准 概览#xff1a; 设备文件的创建 权限 设备名 类型 主设备号 次设备号 mknod [-m MODE] NAME type [MAJOR MINOR] 创建时#xff0c;先查看是否存在设备号的冲突 零磁道零扇区是MBR#xff1a;Maste… 2019独角兽企业重金招聘Python工程师标准 概览 设备文件的创建 权限 设备名 类型 主设备号 次设备号 mknod [-m MODE] NAME type [MAJOR MINOR] 创建时先查看是否存在设备号的冲突 零磁道零扇区是MBRMaster Boot Record 主引导记录 512Bytes: 引导启动OS 前446bytes: 存放程序bootloader 64bytes: 分区表每16bytes标记一个分区一共4个分区主分区 2bytes: 55AA, MBR有效性标记 标记当前mbr是否有效 fdisk是不支持GPT格式的硬盘分区parted是可以支持的 parted [options] [device [command [options...]...]] 直接跟设备不跟其他会分区 -l, --list 会列出所有分区信息 lists partition layout on all block devices command mklabel label-type Create a new disklabel (partition table) of label-type. label-type should be one of bsd, dvh, gpt, loop, mac, msdos, pc98, or sun. mkpart part-type [fs-type] start end Make a part-type partition with filesystem fs-type (if specified), beginning at start and ending at end (by default in megabytes). fs-type can be one of fat16, fat32, ext2, HFS, linux-swap, NTFS, reiserfs, or ufs. part-type should be one of primary, logical, or extended. move partition start end Move partition so that it begins at start and ends at end. Note: move never changes the minor number. rm partition Delete partition. print Display the partition table. # parted /dev/sdb mkpart primary ext4 1 10G #parted /dev/sdb rm 1 # parted /dev/sdb print 磁盘管理 I/O设备 磁盘 网卡 文件read, write, open, close 设备文件特殊文件 只有inode而没有数据 关联至一个驱动程序进而跟对应的硬件设备打交道 /dev: b, c 每个设备都有其设备号 主设备号用于标记设备类型 次设备号用于标记同一类型中的不同设备 mknod - make block or character special files -m, --modeMODE set file permission bits to MODE, not arw - umask mknod [OPTION]... NAME TYPE [MAJOR MINOR] 主设备号可以相同次设备号不能相同 TYPE may be: b create a block (buffered) special file 有缓存 c, u create a character (unbuffered) special file 无缓存的 p create a FIFO 设备文件的命名由ICANN互联网名称与数字地址分配机构Internet Corporation for Assigned Names and Numbers [rootlinux_basic tmp]#mknod -m 664 blocktest b 1 20 [rootlinux_basic tmp]#ls -l total 0 brw-rw-r--. 1 root root 1, 20 Jan 4 07:38 blocktest [rootlinux_basic tmp]#rm blocktest rm: remove block special file blocktest? y [rootlocalhost tmp]# mknod test c 1 30 [rootlocalhost tmp]# ls -l total 0 lrwxrwxrwx. 1 root root 8 Dec 2 13:10 file1 - softfile -rw-r--r--. 1 root root 0 Dec 2 13:09 softfile crw-r--r--. 1 root root 1, 30 Dec 2 13:27 test 磁盘设备文件命名 /dev/hd: IDE: 并口接口, 133MB/s /dev/sd: USB: 串行 SATA: 串行接口6Gbps/8 SCSI: 并行(Small Computer System Interface) 小型计算机系统接口 SAS串行 rpm转数 /dev/sd[a-z] 分区数字 /dev/sda1 /dev/sda2 分区编号 主扩展分区1-4 逻辑分区5开始 硬盘分区 磁道track 扇区sector 柱面cylinder 分区根据柱面划分在同一盘片上的两面磁头同时读取速度快 零磁道零扇区是MBRMaster Boot Record 主引导记录 512Bytes: 引导启动OS 前446bytes: 存放程序bootloader 64bytes: 分区表每16bytes标记一个分区一共4个分区主分区 2bytes: 55AA, MBR有效性标记 标记当前mbr是否有效 1T: 3主1扩展切割1个或多个逻辑分区 [rootlinux_basic tmp]#fdisk -l | grep -A 3 ^Disk /dev/.* Disk /dev/sda: 48.3 GB, 48318382080 bytes 255 heads磁头数, 63 sectors/track每磁道多少扇区, 5874 cylinders柱面 Units cylinders of 16065 * 512 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes -- Disk /dev/mapper/vg_lvm-lv1: 12.9 GB, 12884901888 bytes 255 heads, 63 sectors/track, 1566 cylinders Units cylinders of 16065 * 512 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes -- Disk /dev/mapper/vg_lvm-lv2: 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 /proc: [rootlinux_basic tmp]#cat /proc/partitions major minor #blocks name 8 0 47185920 sda 8 1 204800 sda1 8 2 10485760 sda2 8 3 36494336 sda3 253 0 12582912 dm-0 253 1 10485760 dm-1 分区创建 fdisk - Partition table manipulator for Linux 操作Linux分区表 查看fdisk -l [DEVICE]... fdisk工具最多可以识别15个分区 创建分区fdisk [DEVICE] 交互式界面有许多子命令 p: 显示磁盘分区表 p print the partition table n: new新建分区 n add a new partition d: delete删除分区 d delete a partition t: 修改分区的系统ID t change a partitions system id l: 列表出所有已知的系统ID l list known partition types 83 Linux 82 Linux swap / So 8e Linux LVM fd Linux raid auto w: 保存并退出 w write table to disk and exit q: 不保存退出 q quit without saving changes 选n后出现 e extended p primary partition (1-4) 对于已经有分区处于使用状态的磁盘来讲新建分区后需要让内核重读其分区表 CentOS 5: # partprobe [DEVICE] CentOS 6: partx -a [DEVICE] partx - telling the kernel about presence and numbering of on-disk partitions. -a add specified partitions or read disk and add all partitions 读磁盘新增的分区 kpartx -af [DEVICE] kpartx - Create device maps from partition tables -a Add partition mappings -l List partition mappings that would be added -a -f force creation of mappings; overrides ’no_partitions’ feature 查看/proc/partitions,有显示则创建成功 分区创建工具sfdisk和parted ------------------------------------------------------------------ Command (m for help): n Command action e extended p primary partition (1-4) e Partition number (1-4): 1 First cylinder (1-6527, default 1): Using default value 1 Last cylinder, cylinders or size{K,M,G} (1-6527, default 6527): 5G 注意这里设定大小时的格式 Command (m for help): p Disk /dev/sdb: 53.7 GB, 53687091200 bytes 255 heads, 63 sectors/track, 6527 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 Device Boot Start End Blocks Id System /dev/sdb1 1 654 5253223 5 Extended Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [rootlvm ~]# partx -a /dev/sdb Warning: Disk has a valid GPT signature but invalid PMBR. Assuming this disk is *not* a GPT disk anymore. Use gpt kernel option to override. Use GNU Parted to correct disk. BLKPG: Device or resource busy error adding partition 1 [rootlvm ~]# kpartx -af /dev/sdb Warning: Disk has a valid GPT signature but invalid PMBR. Assuming this disk is *not* a GPT disk anymore. Use gpt kernel option to override. Use GNU Parted to correct disk. [rootlvm ~]# cat /proc/partitions major minor #blocks name 8 0 52428800 sda 8 1 204800 sda1 8 2 10485760 sda2 8 16 52428800 sdb 8 17 1 sdb1 说明创建成功了 ------------------------------------------------------------------------------- 死循环的一个简单脚本 [rootlvm ~]# bash -n hello.sh [rootlvm ~]# ./hello.sh Hello:ld Again hello:jhfld Again hello:n [rootlvm ~]# cat hello.sh #!/bin/bash # read -p Hello: kir while true;do if [ $kir n ];then break; else read -p Again hello: kir fi done ------------------------------------------------------------------ 练习写一个脚本 1、提示输入一个对其执行分区的新硬件设备文件 2、提醒用户接下来的操作销毁所有的数据你继续吗 y或yes: 继续 n或no退出 其它字符提醒输错了再来一次 3、对磁盘新建分区 主分区1大小512M 主分区2大小2G 4、创建完成后显示创建的结果 成功完成及修改次数 ---------------------------------------------------------------- [rootlvm shells]# cat disk_part.sh #!/bin/bash # read -p Input a partition disk device path: disk read -p The following operation will damage the all data on the disk.yes|no(y|n)? flag while true;do if [ $flag n -o $flag no ];then break; elif [ $flag y -o $flag yes ];then echo n p 1 512M n p 2 2G w|fdisk $disk /dev/null partx -a $disk kpartx -af $disk fdisk -l | grep $disk read -p The following operation will damage the all data on the disk.yes|no(y|s)? flag else echo Input error. read -p Again input: flag fi done 转载于:https://my.oschina.net/u/1762991/blog/665603