LFS : 制作分区和挂载分区

前言

上一步,向虚拟机里面加了新硬盘,检查了环境,补全了LFS编译要用到的组件。
这一步,将新加入的硬盘分区,并挂载。
手册中并没有详细描述这步,花了一天看了linux howto 中的分区资料,又用了一天做实验。
现在对新硬盘分区和自动挂载实现了。
在做这步时,对fdisk的使用,编辑/etc/fstab,已经清楚了。
这步在日常任务中用的是最少的,就像刚开始玩windows,每个月都要重装windows. 现在,几年都不做一次。

实验

查看分区

要对新加入的硬盘进行分区,或对已有的硬盘进行重新分区。得先看看硬盘有没有分区信息。

[root@localhost ~]# fdisk -l /dev/sdb

Disk /dev/sdb: 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: 0x73ba496a

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1          50      401593+  83  Linux
/dev/sdb2              51          67      136552+  82  Linux swap / Solaris
/dev/sdb3              68         117      401625   83  Linux
/dev/sdb4             118        2610    20025022+  83  Linux

删除分区

如果目标硬盘上有分区信息,清掉,重新分区。

#------------------------------------------------------------------------------
# 删除分区
#   如果是新加的没格式化的硬盘就不用这步, 得保证分区前, 没有任何分区
#------------------------------------------------------------------------------
[root@localhost ~]# fdisk /dev/sdb

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').

# m命令是帮助,列出了所有可用的命令
Command (m for help): m
Command 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 (m for help): p

Disk /dev/sdb: 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: 0x73ba496a

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1          50      401593+  83  Linux
/dev/sdb2              51          67      136552+  82  Linux swap / Solaris
/dev/sdb3              68         117      401625   83  Linux
/dev/sdb4             118        2610    20025022+  83  Linux

删除分区

按照p命令显示出来得分区顺序,用d命令,输入分区序号,删除分区

Command (m for help): d
Partition number (1-4): 1

Command (m for help): d
Partition number (1-4): 2

Command (m for help): d
Partition number (1-4): 3

Command (m for help): d
Selected partition 4

Command (m for help): p

确认删除后的分区信息

应该是看到没有任何分区信息才对。

Disk /dev/sdb: 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: 0x73ba496a

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

保存并退出fdisk

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

在fdisk之外,再确认下分区信息没有了

[root@localhost ~]# fdisk -l /dev/sdb

Disk /dev/sdb: 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: 0x73ba496a

   Device Boot      Start         End      Blocks   Id  System

规划硬盘分区划分

新加的虚拟硬盘是20GB, 参照LFS7.7手册和Linux Partition HOWTO, 计划分区信息如下:

硬盘容量为20GB
主分区一个
    * /boot 200M
扩展分区一个(硬盘剩下的容量全分给他)
    * /         1GB (total size + 1 = 1GB)
    * /swap     2GB (total size + 2 = 3GB)
    * /var      4GB (total size + 4 = 7GB)
    * /usr      2GB (total size + 2 = 9GB)
    * /opt      2GB (total size + 2 = 11GB)
    * /tmp      4GB (total size + 4 = 15GB)
    * /usr/src  2GB (total size + 2 = 17GB)
    * /home     3GB (total size + 3 = 20GB) (尽可能多,将剩下的扩展分区都给/home)

开始划分新分区

查看设备信息

[root@localhost ~]# ls -lF --color /dev/sdb
brw-rw----. 1 root disk 8, 16 4月  15 18:55 /dev/sdb

设备信息
brw-rw----.   1        root     disk    8,                   16                   4月  15 18:55 /dev/sdb
permissions   unknown  owner    group   major device number  minor device number  date          device name

查看分区类型, 先记录下来(fdisk 具体硬盘时l命令也可以看)

主要看82,83, 是新版linux的分区类型
82 Linux swap / Solaris
83 Linux

[root@localhost ~]# /sbin/sfdisk -T
Id  Name

 0  Empty
 1  FAT12
 2  XENIX root
 3  XENIX usr
 4  FAT16 <32M
 5  Extended
 6  FAT16
 7  HPFS/NTFS
 8  AIX
 9  AIX bootable
 a  OS/2 Boot Manager
 b  W95 FAT32
 c  W95 FAT32 (LBA)
 e  W95 FAT16 (LBA)
 f  W95 Ext'd (LBA)
10  OPUS
11  Hidden FAT12
12  Compaq diagnostics
14  Hidden FAT16 <32M
16  Hidden FAT16
17  Hidden HPFS/NTFS
18  AST SmartSleep
1b  Hidden W95 FAT32
1c  Hidden W95 FAT32 (LBA)
1e  Hidden W95 FAT16 (LBA)
24  NEC DOS
39  Plan 9
3c  PartitionMagic recovery
40  Venix 80286
41  PPC PReP Boot
42  SFS
4d  QNX4.x
4e  QNX4.x 2nd part
4f  QNX4.x 3rd part
50  OnTrack DM
51  OnTrack DM6 Aux1
52  CP/M
53  OnTrack DM6 Aux3
54  OnTrackDM6
55  EZ-Drive
56  Golden Bow
5c  Priam Edisk
61  SpeedStor
63  GNU HURD or SysV
64  Novell Netware 286
65  Novell Netware 386
70  DiskSecure Multi-Boot
75  PC/IX
80  Old Minix
81  Minix / old Linux
82  Linux swap / Solaris
83  Linux
84  OS/2 hidden C: drive
85  Linux extended
86  NTFS volume set
87  NTFS volume set
88  Linux plaintext
8e  Linux LVM
93  Amoeba
94  Amoeba BBT
9f  BSD/OS
a0  IBM Thinkpad hibernation
a5  FreeBSD
a6  OpenBSD
a7  NeXTSTEP
a8  Darwin UFS
a9  NetBSD
ab  Darwin boot
af  HFS / HFS+
b7  BSDI fs
b8  BSDI swap
bb  Boot Wizard hidden
be  Solaris boot
bf  Solaris
c1  DRDOS/sec (FAT-12)
c4  DRDOS/sec (FAT-16 < 32M)
c6  DRDOS/sec (FAT-16)
c7  Syrinx
da  Non-FS data
db  CP/M / CTOS / ...
de  Dell Utility
df  BootIt
e1  DOS access
e3  DOS R/O
e4  SpeedStor
eb  BeOS fs
ee  GPT
ef  EFI (FAT-12/16/32)
f0  Linux/PA-RISC boot
f1  SpeedStor
f4  SpeedStor
f2  DOS secondary
fb  VMware VMFS
fc  VMware VMKCORE
fd  Linux raid autodetect
fe  LANstep
ff  BBT

开始按照分区规划, 使用fdisk划分/dev/sdb的分区信息

[root@localhost ~]# fdisk /dev/sdb

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): p

Disk /dev/sdb: 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: 0x73ba496a

   Device Boot      Start         End      Blocks   Id  System
# 主分区一个
#   * /boot 200M
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1): 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +200M
# 扩展分区一个(硬盘剩下的容量全分给他)
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e
Partition number (1-4): 2
First cylinder (27-2610, default 27): 
Using default value 27
Last cylinder, +cylinders or +size{K,M,G} (27-2610, default 2610): 
Using default value 2610
#   * /         1GB (total size + 1 = 1GB)
Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (27-2610, default 27): 
Using default value 27
Last cylinder, +cylinders or +size{K,M,G} (27-2610, default 2610): +1G
#   * /swap     2GB (total size + 2 = 3GB)
Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (159-2610, default 159): 
Using default value 159
Last cylinder, +cylinders or +size{K,M,G} (159-2610, default 2610): +2G
#   * /var      4GB (total size + 4 = 7GB)
Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (421-2610, default 421): 
Using default value 421
Last cylinder, +cylinders or +size{K,M,G} (421-2610, default 2610): +4G
#   * /usr      2GB (total size + 2 = 9GB)
Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (944-2610, default 944): 
Using default value 944
Last cylinder, +cylinders or +size{K,M,G} (944-2610, default 2610): +2G
#   * /opt      2GB (total size + 2 = 11GB)
Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (1206-2610, default 1206): 
Using default value 1206
Last cylinder, +cylinders or +size{K,M,G} (1206-2610, default 2610): +2G
#   * /tmp      4GB (total size + 4 = 15GB)
Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (1468-2610, default 1468): 
Using default value 1468
Last cylinder, +cylinders or +size{K,M,G} (1468-2610, default 2610): +4G
#   * /usr/src  2GB (total size + 2 = 17GB)
Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (1991-2610, default 1991): 
Using default value 1991
Last cylinder, +cylinders or +size{K,M,G} (1991-2610, default 2610): +2G
#   * /home     3GB (total size + 3 = 20GB) (尽可能多,将剩下的扩展分区都给/home)
Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (2253-2610, default 2253): 
Using default value 2253
# 留一个柱面(准备给扩展分区上标签用, 实验发现,无法给扩展分区上标签,只能给逻辑分区上标签)
Last cylinder, +cylinders or +size{K,M,G} (2253-2610, default 2610): 2609

设置硬盘第一个分区为可启动

* 将第一个分区设置为启动分区
Command (m for help): a
Partition number (1-12): 1

查看分好的分区信息

Command (m for help): p

Disk /dev/sdb: 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: 0x73ba496a

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1          26      208813+  83  Linux
/dev/sdb2              27        2610    20755980    5  Extended
/dev/sdb5              27         158     1060258+  83  Linux
/dev/sdb6             159         420     2104483+  83  Linux
/dev/sdb7             421         943     4200966   83  Linux
/dev/sdb8             944        1205     2104483+  83  Linux
/dev/sdb9            1206        1467     2104483+  83  Linux
/dev/sdb10           1468        1990     4200966   83  Linux
/dev/sdb11           1991        2252     2104483+  83  Linux
/dev/sdb12           2253        2609     2867571   83  Linux

保存修改并退出fdisk

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

在fdisk外部查看分区信息

[root@localhost ~]# fdisk -l /dev/sdb

Disk /dev/sdb: 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: 0x73ba496a

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *           1          26      208813+  83  Linux
/dev/sdb2              27        2610    20755980    5  Extended
/dev/sdb5              27         158     1060258+  83  Linux
/dev/sdb6             159         420     2104483+  83  Linux
/dev/sdb7             421         943     4200966   83  Linux
/dev/sdb8             944        1205     2104483+  83  Linux
/dev/sdb9            1206        1467     2104483+  83  Linux
/dev/sdb10           1468        1990     4200966   83  Linux
/dev/sdb11           1991        2252     2104483+  83  Linux
/dev/sdb12           2253        2609     2867571   83  Linux

整理分区和目录(挂载点)的对应关系

硬盘容量为20GB
主分区   /dev/sdb1 * /boot     200M                        1       26      208813+     83  Linux
扩展分区 /dev/sdb2                                          27      2610    20755980    5   Extended
逻辑分区 /dev/sdb5  * /         1GB (total size + 1 = 1GB)  27      158     1060258+    83  Linux
逻辑分区 /dev/sdb6  * /swap     2GB (total size + 2 = 3GB)  159     420     2104483+    83  Linux
逻辑分区 /dev/sdb7  * /var      4GB (total size + 4 = 7GB)  421     943     4200966     83  Linux
逻辑分区 /dev/sdb8  * /usr      2GB (total size + 2 = 9GB)  944     1205    2104483+    83  Linux
逻辑分区 /dev/sdb9  * /opt      2GB (total size + 2 = 11GB) 1206    1467    2104483+    83  Linux
逻辑分区 /dev/sdb10 * /tmp      4GB (total size + 4 = 15GB) 1468    1990    4200966     83  Linux
逻辑分区 /dev/sdb11 * /usr/src  2GB (total size + 2 = 17GB) 1991    2252    2104483+    83  Linux
逻辑分区 /dev/sdb12 * /home     3GB (total size + 3 = 20GB) 2253    2609    2867571  83 Linux

格式化分区

如果要反复做实验, 这步还是写个.sh方便.

相关的分区类型
80  Old Minix
81  Minix / old Linux
82  Linux swap / Solaris
83  Linux

# 只有交换分区类型是82(Linux swap), 其他分区类型是83(Linux)
mkfs.ext4 -T 83 /dev/sdb1
# mke2fs -T 83 -L lfs_ext /dev/sdb2 # 扩展分区无法用e2label来设置标签
mkfs.ext4 -T 83 /dev/sdb5

mkfs.ext4 -T 82 /dev/sdb6
mkswap -f /dev/sdb6
swapon /dev/sdb6

mkfs.ext4 -T 83 /dev/sdb7
mkfs.ext4 -T 83 /dev/sdb8
mkfs.ext4 -T 83 /dev/sdb9
mkfs.ext4 -T 83 /dev/sdb10
mkfs.ext4 -T 83 /dev/sdb11
mkfs.ext4 -T 83 /dev/sdb12

给分区上标签(必须在格式化分区后才有效)

e2label /dev/sdb1 lfs_boot
# e2label /dev/sdb2 lfs_ext # 扩展分区无法用e2label来设置标签
e2label /dev/sdb5 lfs_root
# e2label /dev/sdb6 lfs_swap # 交换分区没有label
e2label /dev/sdb7 lfs_var
e2label /dev/sdb8 lfs_usr
e2label /dev/sdb9 lfs_opt
e2label /dev/sdb10 lfs_tmp
e2label /dev/sdb11 lfs_usr_src
e2label /dev/sdb12 lfs_home

查看设备标签

[root@localhost dev]# ls -l /dev/disk/by-label
总用量 0
lrwxrwxrwx. 1 root root  9 415 19:59 CentOS_6.9_Final -> ../../sr0
lrwxrwxrwx. 1 root root 10 415 21:53 lfs_boot -> ../../sdb1
lrwxrwxrwx. 1 root root 11 415 21:54 lfs_home -> ../../sdb12
lrwxrwxrwx. 1 root root 10 415 21:53 lfs_opt -> ../../sdb9
lrwxrwxrwx. 1 root root 10 415 21:53 lfs_root -> ../../sdb5
lrwxrwxrwx. 1 root root 11 415 21:53 lfs_tmp -> ../../sdb10
lrwxrwxrwx. 1 root root 10 415 21:53 lfs_usr -> ../../sdb8
lrwxrwxrwx. 1 root root 11 415 21:53 lfs_usr_src -> ../../sdb11
lrwxrwxrwx. 1 root root 10 415 22:05 lfs_var -> ../../sdb7

查看设备挂载点

[root@localhost ~]# lsblk
NAME                        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sr0                          11:0    1   408M  0 rom  
sdb                           8:16   0    20G  0 disk 
├─sdb1                        8:17   0 203.9M  0 part 
├─sdb2                        8:18   0     1K  0 part 
├─sdb5                        8:21   0     1G  0 part 
├─sdb6                        8:22   0     2G  0 part 
├─sdb7                        8:23   0     4G  0 part 
├─sdb8                        8:24   0     2G  0 part 
├─sdb9                        8:25   0     2G  0 part 
├─sdb10                       8:26   0     4G  0 part 
├─sdb11                       8:27   0     2G  0 part 
└─sdb12                       8:28   0   2.8G  0 part 
sda                           8:0    0    20G  0 disk 
├─sda1                        8:1    0   500M  0 part /boot
└─sda2                        8:2    0  19.5G  0 part 
  ├─VolGroup-lv_root (dm-0) 253:0    0  17.5G  0 lvm  /
  └─VolGroup-lv_swap (dm-1) 253:1    0     2G  0 lvm  [SWAP]
sdc                           8:32   0    30G  0 disk

手工挂载分区

如果是反复做实验,这步也要做.sh才方便

export LFS=/mnt/lfs

mkdir -pv $LFS/boot
mount -v -t ext4 /dev/sdb1 $LFS/boot

mkdir -pv $LFS/root
mount -v -t ext4 /dev/sdb5 $LFS/root

mkdir -pv $LFS/var
mount -v -t ext4 /dev/sdb7 $LFS/var

mkdir -pv $LFS/usr
mount -v -t ext4 /dev/sdb8 $LFS/usr

mkdir -pv $LFS/opt
mount -v -t ext4 /dev/sdb9 $LFS/opt

mkdir -pv $LFS/tmp
mount -v -t ext4 /dev/sdb10 $LFS/tmp

mkdir -pv $LFS/usr/src
mount -v -t ext4 /dev/sdb11 $LFS/usr/src

mkdir -pv $LFS/home
mount -v -t ext4 /dev/sdb12 $LFS/home

手工卸载分区(重新做实验的时候才需要执行)

这步只是记录一下,正常情况下,只需要挂载,不需要卸载设备.

# 如果卸载不掉,去根目录再卸载一次.
# 如果还是卸载不掉,用lsof命令看下谁在用设备
# if no lsof command, run => yum install lsof
umount -v /dev/sdb1
umount -v /dev/sdb5
umount -v /dev/sdb7
umount -v /dev/sdb8
umount -v /dev/sdb9
umount -v /dev/sdb10
umount -v /dev/sdb11
umount -v /dev/sdb12

查看已经挂载的设备信息

确认下挂载脚本写错没有. 设备挂载的目录必须事先建立好,设备必须存在,已经分区,格式化好

[root@localhost dev]# cat /etc/mtab 
/dev/mapper/VolGroup-lv_root / ext4 rw 0 0
proc /proc proc rw 0 0
sysfs /sys sysfs rw 0 0
devpts /dev/pts devpts rw,gid=5,mode=620 0 0
tmpfs /dev/shm tmpfs rw,rootcontext="system_u:object_r:tmpfs_t:s0" 0 0
/dev/sda1 /boot ext4 rw 0 0
none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0
/dev/sdb1 /lfs/boot ext4 rw 0 0
/dev/sdb5 /lfs/root ext4 rw 0 0
/dev/sdb7 /lfs/var ext4 rw 0 0
/dev/sdb8 /lfs/usr ext4 rw 0 0
/dev/sdb9 /lfs/opt ext4 rw 0 0
/dev/sdb10 /lfs/tmp ext4 rw 0 0
/dev/sdb11 /lfs/usr/src ext4 rw 0 0
/dev/sdb12 /lfs/home ext4 rw 0 0

查看设备容量占用情况

刚分区,格式化后的设备,设备容量占用为1%.

[root@localhost dev]# df -i
Filesystem            Inodes IUsed   IFree IUse% Mounted on
/dev/mapper/VolGroup-lv_root
                     1148304 28380 1119924    3% /
tmpfs                 488561     1  488560    1% /dev/shm
/dev/sda1             128016    38  127978    1% /boot
/dev/sdb1              13056    11   13045    1% /lfs/boot
/dev/sdb5              66384    11   66373    1% /lfs/root
/dev/sdb7             262944    11  262933    1% /lfs/var
/dev/sdb8             131648    12  131636    1% /lfs/usr
/dev/sdb9             131648    11  131637    1% /lfs/opt
/dev/sdb10            262944    11  262933    1% /lfs/tmp
/dev/sdb11            131648    11  131637    1% /lfs/usr/src
/dev/sdb12            179520    11  179509    1% /lfs/home

准备自动挂载设备

查看设备信息(卷标, UUID)

dumpe2fs -h /dev/sdb1
dumpe2fs -h /dev/sdb5
# 交换分区没有UUID
dumpe2fs -h /dev/sdb7
dumpe2fs -h /dev/sdb8
dumpe2fs -h /dev/sdb9
dumpe2fs -h /dev/sdb10
dumpe2fs -h /dev/sdb11
dumpe2fs -h /dev/sdb12

修改/etc/fstab,实现自动挂载设备

修改完的/etc/fstab文件如下

[root@localhost dev]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Thu Apr 12 08:31:10 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
#
# column1 = device_name, label or UUID (use dumpe2fs -h /dev/sdbx get it)
# column2 = mount point
# column3 = file system type. e.g. ext4
# column4 = parameter of file system. e.g. defaults
# column5 = if backup by dump. e.g. 0 = no backup by dump
# column6 = if verify disk section on OS boot. e.g. 0 = no verify
#
# if want modify /etc/fstab, do below
# umount /dev/whatever
# modify and save /etc/fstab
# mount -a
/dev/mapper/VolGroup-lv_root              /                  ext4    defaults        1 1
UUID=5fea821f-b2bc-4cde-9ec2-a6e176aa7d08 /boot              ext4    defaults        1 2
/dev/mapper/VolGroup-lv_swap              swap               swap    defaults        0 0
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

#
# why not lable not exist by OS?
#

# /dev/sdb1 label = lfs_boot, mount to => /mnt/lfs/boot
# lfs_boot                                  /mnt/lfs/boot      ext4    defaults        0 0
# /dev/sdb1                                  /mnt/lfs/boot      ext4    defaults        0 0

# /dev/sdb5 label = lfs_root, mount to => /mnt/lfs/root
# lfs_root                                  /mnt/lfs/root      ext4    defaults        0 0
/dev/sdb5                                  /mnt/lfs/root      ext4    defaults        0 0

# /dev/sdb6 is swap
/dev/sdb6                                 swap               swap    defaults        0 0

# /dev/sdb7 label = lfs_var, mount to => /mnt/lfs/var
# lfs_var                                  /mnt/lfs/var        ext4    defaults        0 0
/dev/sdb7                                  /mnt/lfs/var        ext4    defaults        0 0

# /dev/sdb8 label = lfs_usr, mount to => /mnt/lfs/usr
# lfs_usr                                  /mnt/lfs/usr        ext4    defaults        0 0
/dev/sdb8                                  /mnt/lfs/usr        ext4    defaults        0 0

# /dev/sdb9 label = lfs_opt, mount to => /mnt/lfs/opt
# lfs_opt                                  /mnt/lfs/opt        ext4    defaults        0 0
/dev/sdb9                                  /mnt/lfs/opt        ext4    defaults        0 0

# /dev/sdb10 label = lfs_tmp, mount to => /mnt/lfs/tmp
# lfs_tmp                                  /mnt/lfs/tmp        ext4    defaults        0 0
/dev/sdb10                                  /mnt/lfs/tmp        ext4    defaults        0 0

# /dev/sdb11 label = lfs_usr_src, mount to => /mnt/lfs/usr/src
# lfs_usr_src                              /mnt/lfs/usr/src    ext4    defaults        0 0
/dev/sdb11                                 /mnt/lfs/usr/src    ext4    defaults        0 0

# /dev/sdb12 label = lfs_home, mount to => /mnt/lfs/home
# lfs_home                                 /mnt/lfs/home       ext4    defaults        0 0
/dev/sdb12                                 /mnt/lfs/home       ext4    defaults        0 0

临时挂载验证

如果/etc/fstab没写错,用’mount -a’命令后,设备就都挂载上了。
如果/etc/fstab写错了,用’mount -a’命令后, 有错误提示,可以根据提示修改/etc/fstab后,再重新’mount -a’

mount -a

查看设备挂载情况

[root@localhost dev]# mount
/dev/mapper/VolGroup-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/sdb1 on /mnt/lfs/boot type ext4 (rw)
/dev/sdb5 on /mnt/lfs/root type ext4 (rw)
/dev/sdb7 on /mnt/lfs/var type ext4 (rw)
/dev/sdb8 on /mnt/lfs/usr type ext4 (rw)
/dev/sdb9 on /mnt/lfs/opt type ext4 (rw)
/dev/sdb10 on /mnt/lfs/tmp type ext4 (rw)
/dev/sdb11 on /mnt/lfs/usr/src type ext4 (rw)
/dev/sdb12 on /mnt/lfs/home type ext4 (rw)

重新启动后再验证设备挂载情况

reboot
or 
shutdown -r now

设备自动挂载完成

只要’mount -a’能挂上所有设备,OS重启后,也能自动挂载上/etc/fstab中描述的所有设备.

备注

在/etc/fstab中开始是指定lable作为挂载的设备名称,但是不好使。
现在用的是/dev/sdbx, 这样有问题,等系统做好后,能自己跑时(将宿主系统拿掉了),会变为/dev/sdax.
这个设备名称要换成UUID才靠谱v,后续实验再改进。

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页