純手工打造每一篇開源資訊與技術乾貨,數十萬程式設計師和Linuxer已經關注。
導讀linux添加硬碟後都需要一個操作操作才能使用那就是掛載,在企業環境中我們的數據盤和系統盤一般都是分開的。前幾天一個朋友讓我幫忙分下區把數據盤掛載到/home下去。(個人需求吧,有些公司一般都是專門在'/'下面創建一個data 來做數據盤)。操作記錄下了來分享給大家,新手複習,老鳥繞道(如果這些都看不懂的話,Linux需要惡補額!!!)需求:需要把系統盤搞到/home 下面。
思考:/home 下面是用戶默認的家目錄,如果用戶家目錄有數據是會被覆蓋的。找朋友確認是剛安裝的系統才開始搞的。更改分區大小首先想到的是lvm,但是看了客戶的磁碟信息發現不需要考慮這些,怎麼簡單怎麼來。
[root@localhost /]# fdisk -l 查看硬碟信息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分區嗎?經過和朋友確認發現我想多了,只是掛載,磁碟已經拔掉了。
磁碟分區
[root@localhost /]# 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 SystemCommand (m for help): n \\創建分區Partition type:
p primary (0 primary, 0 extended, 4 free)
e extendedSelect (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 setCommand (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 LinuxCommand (m for help): w \\保存改分區The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
分區格式化
[root@localhost /]# mkfs \\tab 萬能操作mkfs mkfs.btrfs mkfs.cramfs mkfs.ext2 mkfs.ext3 mkfs.ext4 mkfs.minix mkfs.xfs
[root@localhost /]# mkfs.xfs /dev/sdb1 格式化sdb1meta-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
查看檢查分區
[root@localhost /]# lsblkNAME 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
掛載分區,找到uuid,寫入fstab
[root@localhost /]# blkid /dev/sdb1 查看sdb1 的uuid 寫入fstab uuid 最穩定 /dev/sdb1 也可以
/dev/sdb1: UUID="ffbd4feb-c55e-40ca-86d3-c43919bd9060" TYPE="xfs"
[root@localhost /]# echo "/dev/sdb1: UUID="ffbd4feb-c55e-40ca-86d3-c43919bd9060" TYPE="xfs" " >> /etc/fstab
[root@localhost /]# vim /etc/fstab
-bash: vim: command not found
[root@localhost /]# vi /etc/fstab 寫入fstab[root@localhost /]# tail -n 2 /etc/fstabffbd4feb-c55e-40ca-86d3-c43919bd9060 /home xfs defaults 0 0#/dev/sdb1 /home xfs defaults 0 0 \\uuid 和 /dev/sdb1 區別??[root@localhost /]# mount -a 重新讀取配置文件
檢查掛載成果,掛載成功!!
[root@localhost /]# df -ThFilesystem 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[root@localhost /]# lsblkNAME 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,收工!!
PS:菜鳥級教程,新手複習,老鳥勿噴!如果這些你都看不懂的話,真的要惡補了!!!
本文原創地址: http://www.linuxprobe.com/linux-mount-disk.html作者:陶武傑,審核員:馮振華
《Linux就該這麼學》是由資深運維專家劉遄及全國多名紅帽架構師(RHCA)基於最新RHEL7系統共同編寫的高質量Linux技術自學教程,極其適合用於Linux技術入門教程或講課輔助教材。
☀ 劉遄老師QQ:5604241 微信:gnu_chuan
☀ 學員助教QQ:5604674
☀ Linux技術交流A群(滿):560843
☀ Linux技術交流B群:340829
☀ Linux技術交流C群:463590
☀ Linux技術交流D群:915246(新群,火熱加群中……)
☀ 官方站點:www.linuxprobe.com
☀ 電腦在線閱讀效果更佳:
http://www.linuxprobe.com/chapter-00.html
按住圖片3秒,即可自動關注。
點擊左下角查看更多熱門技術