Linux系統磁碟,linux磁碟

來源:互聯網
上載者:User

Linux系統磁碟,linux磁碟

所有有系統都一樣,都是一種軟體被安裝於某個硬體之上,這個硬體無外非是一種存放裝置,通常作業系統都是安裝在磁碟中,所以Linux系統也是一樣,都是安裝在磁碟中,但是它與Windows系統不一樣,因為Linux都是需要建立檔案系統才可以使用。

 

1、  磁碟分類

  目前市場上的磁碟分類有:IDE磁碟(多用於PC機)、SATA磁碟、SAS磁碟、SSD磁碟等這麼幾種分類,企業中伺服器大多為後面的兩種,SATA磁碟多用於企業內部的一些業務、SAS磁碟多用於對外的業務(一些業務平台)。

  SATA磁碟目前容量最大為4T、SAS磁碟一般都在300G--600G居多,企業生產環境中使用也最多的是這種容量的,實際生產中磁碟的使用主要是看效能需求,也就是磁碟的讀寫速度。

 

2、  磁碟的體繫結構

企業級伺服器多塊磁碟的情況

 

3、  磁碟容量的計算

磁碟的結構一般包括磁軌、盤面、扇區、碰頭等

一個磁軌的大小=512 位元組*扇區數
一個盤面的大小=磁軌的大小*磁軌數
一個磁碟的大小=盤面大小*磁頭數
因此
一個磁碟的容量=512 位元組*扇區數*磁軌數*磁頭數

 

4、  磁碟分割

所有磁碟的分區資訊都是儲存在分區表中,Linux系統僅支援4個分區表資訊(主要磁碟分割+擴充分區),一個分區表的大小在64bytes

Linux一般分為三個分區分別是:boot分區、swap分區、/根分區

Linux的分區編號:主要磁碟分割1-4,邏輯分區從5開始計算

實際生產環境分區要求

  1、  最少要有/和swap兩個分區

  2、  swap(虛擬記憶體)=1.5*實體記憶體大小,一般大小於或等於16G的實體記憶體的伺服器,swap分區一般都直接設定為16G大小

  3、  建議設定/boot分區,Linux引導分區,如核心檔案等,一般所有檔案一共才幾十M的大小,因此這個分區就設定為100-200M即可

 

5、  磁碟分割工具fdisk

fdisk是針對磁碟容量小於2T

[root@cairui ~]# fdisk --helpfdisk: invalid option -- '-'fdisk: Usage: fdisk [options] <disk>    change partition table fdisk [options] -l <disk> list partition table(s) fdisk -s <partition>      give partition size(s) in blocksOptions: -b <size>                 sector size (512, 1024, 2048 or 4096) -c                        switch off DOS-compatible mode -h                        print help -u <size>                 give sizes in sectors instead of cylinders -v                        print version -C <number>               specify the number of cylinders -H <number>               specify the number of heads -S <number>               specify the number of sectors per track: Success

[root@localhost ~]# fdisk /dev/sda1  #對/dev/sda1進行分區操作Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding a new DOS disklabel with disk identifier 0x02fadd9c.Changes will remain in memory only, until you decide to write them.After that, of course, the previous content won't be recoverable.Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)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): mCommand 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 actione extendedp primary partition (1-4)pPartition number (1-4): 1First cylinder (1-2610, default 1): 設定起始柱面Using default value 1Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610):設定大小或柱面Using default value 2610Command (m for help): mCommand actiona toggle a bootable flagb edit bsd disklabelc toggle the dos compatibility flagd delete a partitionl list known partition typesm print this menun add a new partitiono create a new empty DOS partition tablep print the partition tableq quit without saving changess create a new empty Sun disklabelt change a partition's system idu change display/entry unitsv verify the partition tablew write table to disk and exitx extra functionality (experts only)Command (m for help): wThe partition table has been altered!Calling ioctl() to re-read partition table.Syncing disks.Command (m for help): p 列印分區表資訊Disk /dev/sdb: 21.5 GB, 21474836480 bytes255 heads, 63 sectors/track, 2610 cylindersUnits = cylinders of 16065 * 512 = 8225280 bytesSector size (logical/physical): 512 bytes / 512 bytes121 / 753I/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0xb712cc55Device Boot Start End Blocks Id System/dev/sdb1 1 2610 20964793+ 83 Linux分區完成後執行 partprobe 通知系統磁碟分割表發生改變接下來進行格式化分區[root@Centos ~]# mkfs.ext3 /dev/sdb1mke2fs 1.41.12 (17-May-2010)Filesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks1310720 inodes, 5241198 blocks262059 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=4294967296160 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupSuperblock backups stored on blocks:32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,4096000Writing inode tables: doneCreating journal (32768 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 24 mounts or180 days, whichever comes first. Use tune2fs -c or -i to override.[root@Centos ~]# tune2fs -c -1 /dev/sdb1tune2fs 1.41.12 (17-May-2010)Setting maximal mount count to -1[root@Centos ~]# mount /dev/sdb1 /mnt 掛載分區至/mnt 下[root@Centos ~]# df -hFilesystem Size Used Avail Use% Mounted on/dev/mapper/VolGroup-lv_root 50G 3.5G 44G 8% /tmpfs 932M 0 932M 0% /dev/shm/dev/sda1 485M 39M 421M 9% /boot122 / 753/dev/mapper/VolGroup-lv_home 26G 215M 24G 1% /home/dev/sdb1 20G 172M 19G 1% /mnt

 

6、  磁碟分割工具parted

由於環境限制無法有2T或者以上大小的磁碟,只能類比環境來使用parted分區工具來進行分區

[root@Centos ~]# parted /dev/sdb mklabel gpt將磁碟轉換成 gpt 的格式[root@Centos ~]# parted /dev/sdb mkpart primary 0 200(200M)Warning: The resulting partition is not properly aligned for bestperformance.Ignore/Cancel? Ignore[root@Centos ~]# parted /dev/sdb p 列印分區表資訊Model: VMware, VMware Virtual S (scsi)Disk /dev/sdb: 1074MBSector size (logical/physical): 512B/512BPartition Table: gptNumber Start End Size File system Name Flags1 17.4kB 200MB 200MB primary[root@Centos ~]# parted /dev/sdb mkpart primary 201 1073分區並設定大小Information: You may need to update /etc/fstab.[root@Centos ~]# parted /dev/sdb p 列印分區表資訊Model: VMware, VMware Virtual S (scsi)Disk /dev/sdb: 1074MBSector size (logical/physical): 512B/512BPartition Table: gptNumber Start End Size File system Name Flags1 17.4kB 200MB 200MB primary2 201MB 1073MB 871MB primary[root@Centos ~]# mkfs.ext4 /dev/sdb1mke2fs 1.41.12 (17-May-2010)Filesystem label=OS type: LinuxBlock size=1024 (log=0)Fragment size=1024 (log=0)123 / 753Stride=0 blocks, Stripe width=0 blocks48960 inodes, 195296 blocks9764 blocks (5.00%) reserved for the super userFirst data block=1Maximum filesystem blocks=6737100824 block groups8192 blocks per group, 8192 fragments per group2040 inodes per groupSuperblock backups stored on blocks:8193, 24577, 40961, 57345, 73729Writing inode tables: doneCreating journal (4096 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 36 mounts or180 days, whichever comes first. Use tune2fs -c or -i to override.[root@Centos ~]# tune2fs -c -1 /dev/sdb1tune2fs 1.41.12 (17-May-2010)Setting maximal mount count to -1[root@Centos ~]# mount /dev/sdb1 /mnt[root@Centos ~]# df -hFilesystem Size Used Avail Use% Mounted on/dev/mapper/VolGroup-lv_root 50G 3.5G 44G 8% /tmpfs 932M 0 932M 0% /dev/shm/dev/sda1 485M 39M 421M 9% /boot/dev/mapper/VolGroup-lv_home 26G 215M 24G 1% /home/dev/sdb1 185M 5.6M 170M 4% /mnt
[root@cairui ~]# parted --helpUsage: parted [OPTION]... [DEVICE [COMMAND [PARAMETERS]...]...]Apply COMMANDs with PARAMETERS to DEVICE.  If no COMMAND(s) are given, run ininteractive mode.OPTIONs:  -h, --help                      displays this help message  -l, --list                      lists partition layout on all block devices  -m, --machine                   displays machine parseable output  -s, --script                    never prompts for user intervention  -v, --version                   displays the version  -a, --align=[none|cyl|min|opt]  alignment for new partitionsCOMMANDs:  align-check TYPE N                        check partition N for TYPE(min|opt)        alignment  check NUMBER                             do a simple check on the file system  cp [FROM-DEVICE] FROM-NUMBER TO-NUMBER   copy file system to another partition  help [COMMAND]                           print general help, or help on        COMMAND  mklabel,mktable LABEL-TYPE               create a new disklabel (partition        table)  mkfs NUMBER FS-TYPE                      make a FS-TYPE file system on        partition NUMBER  mkpart PART-TYPE [FS-TYPE] START END     make a partition  mkpartfs PART-TYPE FS-TYPE START END     make a partition with a file system  move NUMBER START END                    move partition NUMBER  name NUMBER NAME                         name partition NUMBER as NAME  print [devices|free|list,all|NUMBER]     display the partition table,        available devices, free space, all found partitions, or a particular        partition  quit                                     exit program  rescue START END                         rescue a lost partition near START        and END  resize NUMBER START END                  resize partition NUMBER and its file        system  rm NUMBER                                delete partition NUMBER  select DEVICE                            choose the device to edit  set NUMBER FLAG STATE                    change the FLAG on partition NUMBER  toggle [NUMBER [FLAG]]                   toggle the state of FLAG on partition        NUMBER  unit UNIT                                set the default unit to UNIT  version                                  display the version number and        copyright information of GNU Parted

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.