Linux添加硬盘
擼了今年阿里、頭條和美團的面試,我有一個重要發(fā)現(xiàn).......>>>
新增一塊硬盤
首先用fdisk -l 發(fā)現(xiàn)待分區(qū)的磁盤?/dev/sdb
root@ubuntu:/home/vincent# fdisk -l Disk /dev/sdb: 30 GiB, 32212254720 bytes, 62914560 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytesDisk /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: 0x83f32b97Device 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 root@ubuntu:/home/vincent#可以看到/dev/sdb/沒有分區(qū)
對/dev/sdb進行分區(qū)
root@ubuntu:/home/vincent# fdisk /dev/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 0x5440707b.Command (m for help): m Command (m for help): n Partition typep 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-62914559, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-62914559, default 62914559): Created a new partition 1 of type 'Linux' and of size 30 GiB.Command (m for help): w The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.重新查看硬盤分區(qū),發(fā)現(xiàn)/dev/sdb/?分了/dev/sdb1
格式化分區(qū)
root@ubuntu:/home/vincent# mkfs -t ext3 /dev/sdb mke2fs 1.42.13 (17-May-2015) Found a dos partition table in /dev/sdb Proceed anyway? (y,n) y Creating filesystem with 7864320 4k blocks and 1966080 inodes Filesystem UUID: d4b47420-ff25-479e-8641-9af726be66ef Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done root@ubuntu:掛載/dev/sdb
root@ubuntu:/home/vincent# mount /dev/sdb /mnt/開啟自動掛載/dev/sdb
在給系統(tǒng)新增了磁盤以后,如果重啟系統(tǒng)我們會發(fā)現(xiàn)找不到存儲了;但是使用fdisk -l可以看到存儲空間,說明存儲還在。這是因為關(guān)機后,掛載已經(jīng)自動卸載掉了。我們當然可以手動再次將其掛載,但如果每次重啟都需要這樣手動操作會很不方便;因此我們可以利用自動掛載,這樣系統(tǒng)每次開機的時候就可以自動將磁盤掛載上去了。
修改/etc/fstab文件
# /etc/fstab: static file system information.## Use 'blkid' to print the universally unique identifier for a# device; this may be used with UUID= as a more robust way to name devices# that works even if disks are added and removed. See fstab(5).## <file system> <mount point> <type> <options> <dump> <pass># / was on /dev/sda1 during installationUUID=d0a34ba5-22af-4897-913c-8cb8e8116000 / ext4 errors=remount-ro 0 1# swap was on /dev/sda5 during installationUUID=494805d7-8640-406d-96c8-3b90e85244e7 none swap sw 0 0/dev/fd0 /media/floppy0 auto rw,user,noauto,exec,utf8 0 0/dev/sdb /mnt auto defaults 0 0可以很明顯的看到文件有6列。
第1列是設(shè)備名或者卷標
第2列是掛載點(也就是掛載目錄)
第3列是所要掛載設(shè)備的文件系統(tǒng)或者文件系統(tǒng)類型
第4列是掛載選項,通常使用defaults就可以
第5列設(shè)置是否使用dump備份,置0為不備份,置1,2為備份,但2的備份重要性比1小?? ?
第6列設(shè)置是否開機的時候使用fsck檢驗所掛載的磁盤,置0為不檢驗,置1,2為檢驗,但置2盤比置1的盤晚檢驗。
將/dev/sdb掛載到/mnt, 文件系統(tǒng)自動選擇,不進行dump備份以及開機磁盤檢驗
注意:
(1)根目錄必須優(yōu)先于其他掛載點
(2)掛載點必須為已經(jīng)存在的目錄
(3)卸載時必須保證當前磁盤沒有發(fā)生讀寫操作
fdisk 最大只能創(chuàng)建2T的硬盤,如需要更大則使用parted命令:
parted /dev/sdb 進入分區(qū)命令行模式,可以隨時用help來查看命令用法 mklabel gpt 將MBR格式的磁盤格式化為GPT格式 mkpart primary 0 -1 將整個磁盤化為一個分區(qū),一般命名為/dev/sdb1 print 打印分區(qū)結(jié)果 quit 退出分區(qū)命令行模式?
總結(jié)
- 上一篇: docker 导入导出镜像
- 下一篇: Linux Shell脚本编程--jq命