Liunx添加新硬盤其實和Windows的操做同樣,但一個是圖形化操做,另外一個是命令行操做,不過步驟是同樣,下面就動手演示和講解node
命令:fdisk -lvim
[root@center ~]# fdisk -l Disk /dev/vda: 21.5 GB, 21474836480 bytes #第一塊硬盤的信息和分區信息 255 heads, 63 sectors/track, 2610 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: 0x0003a7b4 Device Boot Start End Blocks Id System /dev/vda1 * 1 2611 20970496 83 Linux Disk /dev/vdb: 107.4 GB, 107374182400 bytes #第二塊硬盤的信息和分區信息 16 heads, 63 sectors/track, 208050 cylinders Units = cylinders of 1008 * 512 = 516096 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000
命令:fdisk /dev/vdbide
[root@center ~]# fdisk /dev/vdb Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel with disk identifier 0x1e694286. 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): n Command action e extended #e爲建立擴展分區 p primary partition (1-4) #p爲建立邏輯分區 p Partition number (1-4): 1 #在這裏輸入1,就進入劃分邏輯分區階段了; First cylinder (1-208050, default 1): 1 #分區的Start 值,這裏最好直接按回車,不然可能會形成空間浪費; Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-208050, default 208050): 208050 #分區的Over值,我就分一個區 Using default value 208050 Command (m for help): w #最後輸入w回車保存退出。 The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
fdisk能夠用m命令來看fdisk命令的內部命令;
a:命令指定啓動分區;
d:命令刪除一個存在的分區;
l:命令顯示分區ID號的列表;
m:查看fdisk命令幫助;
n:命令建立一個新分區;
p:命令顯示分區列表;
t:命令修改分區的類型ID號;
w:命令是將對分區表的修改存盤讓它發生做用;ui
命令:fdisk -l操作系統
[root@center ~]# fdisk -l Disk /dev/vda: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 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: 0x0003a7b4 Device Boot Start End Blocks Id System /dev/vda1 * 1 2611 20970496 83 Linux Disk /dev/vdb: 107.4 GB, 107374182400 bytes 16 heads, 63 sectors/track, 208050 cylinders Units = cylinders of 1008 * 512 = 516096 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x1e694286 Device Boot Start End Blocks Id System /dev/vdb1 1 208050 104857168+ 83 Linux #剛建立好的分區信息
命令:mkfs.ext4 /dev/vdb1命令行
[root@center ~]# mkfs.ext4 /dev/vdb1 mke2fs 1.41.12 (17-May-2010) Filesystem label= #文件系統標籤 OS type: Linux #操做系統類型 Block size=4096 (log=2) #塊大小 Fragment size=4096 (log=2) #分塊大小 Stride=0 blocks, Stripe width=0 blocks 6553600 inodes, 26214292 blocks 1310714 blocks (5.00%) reserved for the super user First data block=0 #第一個數據塊 Maximum filesystem blocks=4294967296 800 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000, 7962624, 11239424, 20480000, 23887872 Writing inode tables: done #寫入inode表 Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 26 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
Linux的分區類型介紹:
隨着Linux系統在如今業務中的應用,Linux文件系統的弱點也漸漸顯露出來了,其中系統缺省使用的ext2文件系統是非日誌文件系統。這在關鍵行業的應用是一個致命的弱點.而Ext3文件系統是直接從Ext2文件系統發展而來,目前ext3文件系統已經很是穩定可靠。它徹底兼容Ext2文件系統。
Ext3的特色:高可用性、數據的完整性、數據的完整性、數據轉換、多種日誌模式
一樣的Ext4徹底兼容Ext3,相對於Ext3來講,Ext4支持更大的存儲,Ext3目前所支持的最大16TB文件系統和最大2TB文件,而Ext4分別支持1EB的文件系統,以及16TB 的文件,還有就是Ext3目前只支持32,000個子目錄,而Ext4支持無限數量的子目錄,Ext4引入了現代文件系統中流行的extents概念,每一個 extent 爲一組連續的數據塊,上述文件則表示爲「該文件數據保存在接下來的25,600個數據塊中」,提升了很多效率。3d
命令:mkdir /data日誌
命令:mount /dev/vdb1 /datacode
命令:df -Thorm
[root@center ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/vda1 ext4 20G 1.1G 18G 6% / tmpfs tmpfs 3.9G 0 3.9G 0% /dev/shm /dev/vdb1 ext4 99G 60M 94G 1% /data #新掛載的分區
命令:vim /etc/fstab
/dev/vdb1 /data ext4 defaults 1 1
[root@center ~]# blkid /dev/vda1: UUID="b7aae0d4-268c-4b60-914a-f3b48e22819c" TYPE="ext4" /dev/vdb1: UUID="5de835dd-5322-46f0-8728-3d4ae7d83b54" TYPE="ext4" [root@center ~]# cat /etc/fstab # # /etc/fstab # Created by anaconda on Tue Mar 27 04:51:55 2018 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # UUID=b7aae0d4-268c-4b60-914a-f3b48e22819c / ext4 defaults 1 1 UUID=5de835dd-5322-46f0-8728-3d4ae7d83b54 /data ext4 defaults 1 1 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0
Swap分區其實和Windows上的虛擬內存同樣,Swap分區在系統的物理內存不夠用的時候,把物理內存中的一部分空間釋放出來,以供當前運行的程序使用。那些被釋放的空間可能來自一些很長時間沒有什麼操做的程序,這些被釋放的空間被臨時保存到Swap分區中,等到那些程序要運行時,再從Swap分區中恢復保存的數據到內存中。
下面介紹兩種建立swap的方法:
用fdisk命令對磁盤進行分區,添加swap分區,新建分區,在fdisk中用「t」命令將新添的分區id改成82
(Linux swap類型)
格式化swap分區,這裏的sdb2要看您加完後p命令顯示的實際分區設備名
mkswap /dev/sdb1
啓動新的swap分區
swapon /dev/sdb1
/dev/sdb1 swap swap defaults 0 0
1.建立要做爲swap分區的文件:增長1GB大小的交換分區,則命令寫法以下,其中的count等於想要的塊的數量(bs*count=文件大小)。
dd if=/dev/zero of=/root/swapfile bs=1M count=1024
2.格式化爲交換分區文件,創建swap的文件系統:
mkswap /root/swapfile
3.啓用交換分區文件:
swapon /root/swapfile
4.使系統開機時自啓用,在文件/etc/fstab中添加一行:
/root/swapfile swap swap defaults 0 0