分区
对硬盘分区:安装操作系统的时候有一个分区过程,新增加硬盘也会涉及到分区,如何给操作系统新增一台硬件设备。
启动操作系统。
Home是当前账号的根目录,Computer是/系统根目录。 ~是当前账号的根目录,/是系统的根目录。 root@ubuntu:~# pwd /root Passwd: root:x:0:0:root:/root:/bin/bash(所以root账号进来是/root目录) root@ubuntu:~# ls root@ubuntu:/# ls bin etc lib mnt root srv var boot home lib64 nginx-1.13.8 run sys vmlinuz cdrom initrd.img lost+found opt sbin tmp vmlinuz.old dev initrd.img.old media proc snap usr yw yw1989@ubuntu:~$ pwd /home/yw1989 Passwd: yw1989:x:1000:1000:ubuntu16.4,,,:/home/yw1989:/bin/bash(所以yw1989账号进来的根目录是/home/yw1989) yw1989@ubuntu:/$ ls bin etc lib mnt root srv var boot home lib64 nginx-1.13.8 run sys vmlinuz cdrom initrd.img lost+found opt sbin tmp vmlinuz.old dev initrd.img.old media proc snap usr yw yw1989@ubuntu:/$ cd home/yw1989 yw1989@ubuntu:~$ ls Desktop Documents examples.desktop Pictures Templates ywjuan dockerfile Downloads Music Public Videos ywjuanxin
root@ubuntu:/# fdisk -l (当前操作系统有几块硬盘,每块硬盘的分区情况,每块硬盘的大小) (硬盘也是一个硬件设备,存储在dev下面,第一块硬盘叫sda,第二快叫sdb,第三块叫sdc,sddd,20GB,后面是20GB有多少字节,) Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0xc48cecd2 (当前硬盘设备下有3个分区sda1,sda2,sda3,*表示这是一个启动分区,操作系统的时候就是基于sda1启动的,19G,占到2048 到39845887 扇区,sda2从39847934 到41940991, ) Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 39845887 39843840 19G 83 Linux /dev/sda2 39847934 41940991 2093058 1022M 5 Extended /dev/sda5 39847936 41940991 2093056 1022M 82 Linux swap / Solaris (第二块硬盘sdb,2G大小,这块硬盘没有进行分区,是无法使用的,) Disk /dev/sdb: 2 GiB, 2147483648 bytes, 4194304 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes
root@ubuntu:/dev# fdisk /dev/sdb(对sdb硬盘进行分区,进入sdb硬盘) Welcome to fdisk (util-linux 2.27.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table. Created a new DOS disklabel with disk identifier 0x0cade2ce. Command (m for help): m Help: DOS (MBR) a toggle a bootable flag b edit nested BSD disklabel c toggle the dos compatibility flag Generic d delete a partition :删除一个分区 F list free unpartitioned space l list known partition types n add a new partition :创建一个新的分区 p print the partition table :打印分区表 t change a partition type :显示分区系统的id号 v verify the partition table i print information about a partition Misc m print this menu :打印菜单帮助信息 u change display/entry units x extra functionality (experts only) Script I load disk layout from sfdisk script file O dump disk layout to sfdisk script file Save & Exit w write table to disk and exit :写入分区表到硬盘并退出 q quit without saving changes :退出不保存相应分区操作 Create a new label g create a new empty GPT partition table G create a new empty SGI (IRIX) partition table o create a new empty DOS partition table s create a new empty Sun partition table
(针对当前这个硬盘,首先看有没有分区表,如果有就针对分区表进行操作,没有就创建新的分区,没有Device Boot Start End Sectors Size Id Type 说明没有分区表,) Command (m for help): p :打印分区表 Disk /dev/sdb: 2 GiB, 2147483648 bytes, 4194304 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x0cade2ce Command (m for help): n :添加一个新的分区(是要创建主分区还是扩展分区,) Partition type p primary (0 primary, 0 extended, 4 free) :主分区 e extended (container for logical partitions) :扩展分区 Select (default p): p :(一个硬盘里面最多只能拥有4个主分区,) Partition number (1-4, default 1): 1 (只能有4个主分区1-4,主分区1) First sector (2048-4194303, default 2048): 2048 (扇区数,默认从2048扇区开始,) Last sector, +sectors or +size{K,M,G,T,P} (2048-4194303, default 4194303): 4194303 (要给这个主分区分多大空间,default 4194303表示就一个分区) Created a new partition 1 of type 'Linux' and of size 2 GiB.(这个硬盘就一个主分区)
Command (m for help): p (硬盘信息) Disk /dev/sdb: 2 GiB, 2147483648 bytes, 4194304 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x0cade2ce (这个硬盘的分区信息,sdb1这一个主分区) Device Boot Start End Sectors Size Id Type /dev/sdb1 2048 4194303 4192256 2G 83 Linux Command (m for help): w The partition table has been altered. (分区表已经被改变) Calling ioctl() to re-read partition table. Syncing disks. (可以重新读分区表并且同步硬盘) root@ubuntu:/dev# fdisk -l (硬盘信息) Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0xc48cecd2 (这个硬盘的分区信息) Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 39845887 39843840 19G 83 Linux /dev/sda2 39847934 41940991 2093058 1022M 5 Extended /dev/sda5 39847936 41940991 2093056 1022M 82 Linux swap / Solaris (硬盘信息) Disk /dev/sdb: 2 GiB, 2147483648 bytes, 4194304 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x7251b8e3 (这个硬盘的分区信息) Device Boot Start End Sectors Size Id Type /dev/sdb2 2048 4194303 4192256 2G 83 Linux
-----------------------前面是安装分区,后面是调整分区----------------------------------------------
root@ubuntu:/dev# fdisk sdb (进入这块硬盘,不是进入这个分区,) Welcome to fdisk (util-linux 2.27.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): p (打印sdb硬盘的分区信息) (硬盘信息) Disk sdb: 2 GiB, 2147483648 bytes, 4194304 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x7251b8e3 (这个硬盘的分区信息) Device Boot Start End Sectors Size Id Type sdb2 2048 4194303 4192256 2G 83 Linux Command (m for help): d (删除分区) Selected partition 2 Partition 2 has been deleted. Command (m for help): p (只有硬盘信息没有分区信息了) Disk sdb: 2 GiB, 2147483648 bytes, 4194304 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x7251b8e3 Command (m for help): n Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): p Partition number (1-4, default 1): First sector (2048-4194303, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-4194303, default 4194303): +500M (创建2个分区,第一个500M) Created a new partition 1 of type 'Linux' and of size 500 MiB. Command (m for help): p (硬盘信息) Disk sdb: 2 GiB, 2147483648 bytes, 4194304 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x7251b8e3 (分区信息,sdb1分区500M) Device Boot Start End Sectors Size Id Type sdb1 2048 1026047 1024000 500M 83 Linux (创建第二个分区) Command (m for help): n Partition type p primary (1 primary, 0 extended, 3 free) e extended (container for logical partitions) Select (default p): p Partition number (2-4, default 2): First sector (1026048-4194303, default 1026048): +500M Value out of range. First sector (1026048-4194303, default 1026048): +100M Value out of range. First sector (1026048-4194303, default 1026048): +1M Value out of range. First sector (1026048-4194303, default 1026048): Last sector, +sectors or +size{K,M,G,T,P} (1026048-4194303, default 4194303): +500M Created a new partition 2 of type 'Linux' and of size 500 MiB. Command (m for help): p Disk sdb: 2 GiB, 2147483648 bytes, 4194304 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x7251b8e3 Device Boot Start End Sectors Size Id Type sdb1 2048 1026047 1024000 500M 83 Linux sdb2 1026048 2050047 1024000 500M 83 Linux Command (m for help): n Partition type p primary (2 primary, 0 extended, 2 free) e extended (container for logical partitions) Select (default p): p Partition number (3,4, default 3): First sector (2050048-4194303, default 2050048): Last sector, +sectors or +size{K,M,G,T,P} (2050048-4194303, default 4194303): +500M Created a new partition 3 of type 'Linux' and of size 500 MiB. Command (m for help): w (保存退出) The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks. root@ubuntu:/dev# fdisk -l (对硬盘sdb就分了5个主分区一个扩展分区) Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0xc48cecd2 Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 39845887 39843840 19G 83 Linux /dev/sda2 39847934 41940991 2093058 1022M 5 Extended /dev/sda5 39847936 41940991 2093056 1022M 82 Linux swap / Solaris Disk /dev/sdb: 2 GiB, 2147483648 bytes, 4194304 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x7251b8e3 Device Boot Start End Sectors Size Id Type /dev/sdb1 2048 1026047 1024000 500M 83 Linux /dev/sdb2 1026048 2050047 1024000 500M 83 Linux /dev/sdb3 2050048 3074047 1024000 500M 83 Linux /dev/sdb4 3074048 4098047 1024000 500M 5 Extended /dev/sdb5 3076096 3895295 819200 400M 83 Linux /dev/sdb6 3897344 4081663 184320 90M 83 Linux root@ubuntu:/dev# fdisk sdb (进入第二块硬盘) Welcome to fdisk (util-linux 2.27.1). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Command (m for help): t Partition number (1-6, default 6): 1 Partition type (type L to list all types): L (分区这种文件操作系统有很多种,这里是156种,FAT32和NTFS是windows的分区,LINUX SWAP,LINUX extended是linux的分区,) 0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris 1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT- 2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT- 3 XENIX usr 3c PartitionMagic 84 OS/2 hidden or c6 DRDOS/sec (FAT- 4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx 5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data 6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / . 7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility 8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt 9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi ea Rufus alignment e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD eb BeOS fs f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ee GPT 10 OPUS 55 EZ-Drive a7 NeXTSTEP ef EFI (FAT-12/16/ 11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f0 Linux/PA-RISC b 12 Compaq diagnost 5c Priam Edisk a9 NetBSD f1 SpeedStor 14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f4 SpeedStor 16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ f2 DOS secondary 17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fb VMware VMFS 18 AST SmartSleep 65 Novell Netware b8 BSDI swap fc VMware VMKCORE 1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fd Linux raid auto 1c Hidden W95 FAT3 75 PC/IX bc Acronis FAT32 L fe LANstep 1e Hidden W95 FAT1 80 Old Minix be Solaris boot ff BBT