Linux如何掛載分割槽?【新手必看】
Linux新增硬碟後都需要一個操作操作才能使用那就是掛載,在企業環境中我們的資料盤和系統盤一般都是分開的。前幾天一個朋友讓我幫忙分下區把資料盤掛載到/home下去。(個人需求吧,有些公司一般都是專門在'/'下面建立一個data 來做資料盤)。操作記錄下了來分享給大家,新手複習,老鳥繞道。
需求:
需要把系統盤搞到/home 下面。
思考:
/home 下面是使用者預設的家目錄,如果使用者家目錄有資料是會被覆蓋的。找朋友確認是剛安裝的系統才開始搞的。更改分割槽大小首先想到的是lvm,但是看了客戶的磁碟資訊發現不需要考慮這些,怎麼簡單怎麼來。
檢視硬碟資訊
[[email protected]
Disk /dev/sda: 240.1 GB, 240057409536 bytes, 468862128 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
Disk label type: dos
Disk identifier: 0x00085ef7
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 17803263 8388608 82 Linux swap / Solaris
/dev/sda3 17803264 468860927 225528832 83 Linux
Disk /dev/sdb: 240.1 GB, 240057409536 bytes, 468862128 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
Disk /dev/sdc: 500.1 GB, 500107862016 bytes, 976773168 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
Disk label type: dos
Disk identifier: 0x0007a974
Device Boot Start End Blocks Id System
/dev/sdc1 2048 976773119 488385536 8e Linux LVM
Disk /dev/sdd: 240.1 GB, 240057409536 bytes, 468862128 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
Disk label type: dos
Disk identifier: 0x000a4688
Device Boot Start End Blocks Id System
/dev/sdd1 * 2048 1026047 512000 83 Linux
/dev/sdd2 1026048 468860927 233917440 8e Linux LVM
資料的操作是需要非常嚴謹的,看到了這麼多的硬碟,有看到了lvm分割槽。對於新裝的系統我第一感覺是:難道要我修復lvm分割槽嗎?經過和朋友確認發現我想多了,只是掛載,磁碟已經拔掉了。
找到對應硬碟分割槽格式化
磁碟分割槽
[[email protected] /]# fdisk /dev/sdb \\針對第二塊盤分割槽
Welcome to fdisk (util-linux 2.23.2).
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
Building a new DOS disklabel with disk identifier 0x6511fa23.
Command (m for help): p \\檢視已有分割槽
Disk /dev/sdb: 240.1 GB, 240057409536 bytes, 468862128 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
Disk label type: dos
Disk identifier: 0x6511fa23
Device Boot Start End Blocks Id System
Command (m for help): n \\建立分割槽
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p \\主分割槽
Partition number (1-4, default 1):
First sector (2048-468862127, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-468862127, default 468862127):
Using default value 468862127
Partition 1 of type Linux and of size 223.6 GiB is set
Command (m for help): p \\檢視確認分割槽
Disk /dev/sdb: 240.1 GB, 240057409536 bytes, 468862128 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
Disk label type: dos
Disk identifier: 0x6511fa23
Device Boot Start End Blocks Id System
/dev/sdb1 2048 468862127 234430040 83 Linux
Command (m for help): w \\儲存改分割槽
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
分割槽格式化
[[email protected]ocalhost /]# mkfs \\tab 萬能操作
mkfs mkfs.btrfs mkfs.cramfs mkfs.ext2 mkfs.ext3 mkfs.ext4 mkfs.minix mkfs.xfs
[[email protected] /]# mkfs.xfs /dev/sdb1 格式化sdb1
meta-data=/dev/sdb1 isize=256 agcount=4, agsize=14651878 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=58607510, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=28616, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
檢視檢查分割槽
[[email protected] /]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 223.6G 0 disk
├─sda1 8:1 0 500M 0 part /boot
├─sda2 8:2 0 8G 0 part [SWAP]
└─sda3 8:3 0 215.1G 0 part /
sdb 8:16 0 223.6G 0 disk
└─sdb1 8:17 0 223.6G 0 part
掛載分割槽到"/home"
掛載分割槽,找到uuid,寫入fstab
[[email protected] /]# blkid /dev/sdb1 檢視sdb1 的uuid 寫入fstab uuid 最穩定 /dev/sdb1 也可以
/dev/sdb1: UUID="ffbd4feb-c55e-40ca-86d3-c43919bd9060" TYPE="xfs"
[[email protected] /]# echo "/dev/sdb1: UUID="ffbd4feb-c55e-40ca-86d3-c43919bd9060" TYPE="xfs" " >> /etc/fstab
[[email protected] /]# vim /etc/fstab
-bash: vim: command not found
[[email protected] /]# vi /etc/fstab 寫入fstab
[[email protected] /]# tail -n 2 /etc/fstab
ffbd4feb-c55e-40ca-86d3-c43919bd9060 /home xfs defaults 0 0
#/dev/sdb1 /home xfs defaults 0 0 \\uuid 和 /dev/sdb1 區別??
[[email protected] /]# mount -a 重新讀取配置檔案
檢查掛載成果,掛載成功!!
[[email protected] /]# df -Th
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 xfs 215G 852M 215G 1% /
devtmpfs devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs tmpfs 7.8G 8.4M 7.8G 1% /run
tmpfs tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/sda1 xfs 497M 119M 378M 24% /boot
tmpfs tmpfs 1.6G 0 1.6G 0% /run/user/0
/dev/sdb1 xfs 224G 33M 224G 1% /home
[[email protected] /]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 223.6G 0 disk
├─sda1 8:1 0 500M 0 part /boot
├─sda2 8:2 0 8G 0 part [SWAP]
└─sda3 8:3 0 215.1G 0 part /
sdb 8:16 0 223.6G 0 disk
└─sdb1 8:17 0 223.6G 0 part /home
ok,收工!!
來源:http://www.linuxprobe.com/linux-mount-disk.html
距離Linux雲端計算免費課程火熱開啟倒計時9天,5天免費課程搶先聽,運維乾貨內容免費聽,點選文末“閱讀原文”即可免費聽運維課!火速搶先~~~~
PS:記得查收小編送你的免費大禮包呦~
▼▼點選【閱讀原文】,免費聽5天Linux運維乾貨分享課,火熱開講中,速來搶!