• 沒有找到結果。

NASA Lab

N/A
N/A
Protected

Academic year: 2022

Share "NASA Lab"

Copied!
61
0
0

加載中.... (立即查看全文)

全文

(1)

NASA Lab

Partition/Filesystem/Bootloader

TinRay, Yu-Chuan

(2)

➔ Conceptual

◆ Storage Structure

◆ Bootloader

➔ Practical & \Exercise/

◆ Linux Device File

◆ Storage Related Commands

◆ Boot Related Commands

Agenda

(3)

Before we start...

Download the image we will use first.

➔ VirtualBox .ova file

➔ CentOS Installation Minimal CD (.iso)

(4)

Storage Structure

(5)

Levels of Storage

➔ Application

◆ Read/Write file on filesystem.

➔ Filesystem

◆ Handle lock, permission, journal, index…

◆ EXT 2/3/4, ZFS, FAT32, NFS...

➔ Block Device

◆ Disk (?)

◆ What really stores things

Filesystem Level

Block Device/Level Application

(6)

Network Filesystem (NFS)

➔ Client use remote filesystem.

➔ Host provides a filesystem.

➔ Single host for multiple client.

➔ Multiple host for multiple client.

high performance (scalability)

high availability (redundancy)

➔ Ex. NFS, CephFS, GlusterFS Filesystem Level Application

Host Client

(7)

Simulated Block Device

➔ OS views as block devices (disks).

➔ May not really be disks.

➔ ★ can be fiber, SATA cable, network

Filesystem Level

Block Device/Level Application

Software

(8)

Example: Hardware RAID (Pic)

(9)
(10)

Example: Hardware RAID

➔ Multiple disks form a RAID and constitute a storage pool (or whatever).

➔ Then on that “storage pool”, allocate space for “virtual disks (image)”.

➔ OS can only see those “virtual disks” not those physical.

Disk Disk

Virtual Disk

(11)

Question

➔ Will hardware RAID know how many partitions are there on disks?

➔ So does partition belongs to block device level?

(12)

Example

➔ SAN (https://en.wikipedia.org/wiki/Storage_area_network)

➔ iSCSI (https://en.wikipedia.org/wiki/ISCSI)

➔ Ceph (http://ceph.com/)

(13)

Bootloader

Everything is mysterious…

If I am wrong please tell me.

(14)

How does W1nd0ws boot?

➔ Not necessary.

(15)

Your PC ran into a problem and need to restart. We’re just collecting some error info, and there we will restart for you.

(99% complete)

:(

(16)

:O

(17)

Solution: Install Linux!!

:D

(18)

How does Linux Boot? (Legacy/MBR)

(Roughly, if anything incorrect please tell me.) 1. BIOS self test

2. Read and test MBR in the order of bootable devices configured in BIOS.

3. Load bootstrap in MBR.

4. Bootstrap load bootloader.

5. Then bootloader load initrd ramdisk image, as well as kernel.

6. Then kernel magically bring up whole system :D

(19)

Boot Step 2, 3, 4

Step 2. Read and test MBR in the order of bootable devices configured in BIOS.

➔ Stupid BIOS can only see block level.

➔ MBR = Master Boot Record

◆ 0 ~ 446 Bytes: Bootstrap (program) code

◆ 446 ~ 510 Bytes: Partition table

◆ 510 ~ 512 Bytes: Boot signature

Step 3, 4

➔ BIOS load bootstrap -> bootstrap load bootloader

(20)

Boot Step 5

Then bootloader load initrd ramdisk image, as well as kernel.

➔ For GRUB2, GRUB menu shows up.

➔ It can handle some basic filesystem.

➔ Pass some parameters to kernel.

➔ Then its kernel’s term.

For more, see Jserv DA DA der blog.

Who is Jserv?

(21)

Question

Why MBR can only support 4 “primary partition”?

(22)

What is load?

➔ Do you remember From NAND to Tetris ?

➔ Load ≒ Put into memory.

➔ Pass control ≒ Set proper PC.

➔ So first hard-coded BIOS loads bootstrap.

➔ Then bootstrap loads bootloader.

➔ Then bootloader loads ramdisk.

➔ Then...

(23)

EFI mode

➔ Different from MBR/Legacy mode.

➔ Only works with GPT partition table. (HW bonus)

(24)

Story of bootstrap

“It is conjectured that Mr. Murphee will now be enabled to hand

himself over the Cumberland river or a barn yard fence by the straps of his boots.”

From wikipedia

(25)

Practical

(26)

Unix device files

➔ Block devices

◆ /dev/sdX, /dev/vdX (virtualized)

➔ Partition

◆ /dev/sdX1, etc…

◆ /dev/mapper/cl-root (LVM)

◆ /dev/cl/root (same as above)

➔ Pseudo devices

◆ /dev/null

(27)

Dangerous Command

➔ dd if=[device] of=[file]

➔ ex.

dd if=/dev/zero of=/dev/sda when you want to reinstall OS :D

(28)

\Exercise/

➔ You get a PC (VM image) that can not boot.

➔ Fix it with CentOS installation CD!

➔ Download VM from Google Drive

So why not just reinstall it?

Since we took NASA!!

(And it is not Windows)

(29)

How was the exercise created?

su root

rm -rf /boot/*

dd if=/dev/zero of=/dev/sda1 bs=1 count=446 Then delete /boot partition.

(30)

Step 0.

Try to boot it.

No grub ->

(31)

How does Linux Boot? (Legacy/MBR)

1. BIOS self test

2. Read and test MBR in the order of bootable devices configured in BIOS. MBR destroyed!

3. Load bootstrap in MBR.

4. Bootstrap load bootloader. /boot vanished!

5. Then bootloader load initrd ramdisk image, as well as kernel.

/boot/initramfs, vmlinuz deleted!

6. Then kernel magically bring up whole system :(

(32)

Overview of what we will do

➔ Boot with Installation CD.

➔ Fix broken stuffs with the broken system.

◆ So will use /usr/bin/ in broken system.

(33)

Step 1.

Inject CentOS CD and boot from it.

Then select

“Troubleshooting” > “Rescue a CentOS Linux system”

Then choose “3) Skip to shell”

(34)

Inject CD in

VirtualBox

(35)

Step 2:

Gather some information about the PC (VM).

(36)

Commands to Get Information

➔ lsblk -f

◆ See block devices as well as partitions even not mounted.

◆ -f to see partition UUID.

➔ df -h

◆ See usage of mounted partitions.

◆ -h to show in human friendly way.

(37)

Step 3:

In step2, find that /boot disappeared.

So create a partition for /boot.

(38)

How does Linux Boot? (Legacy/MBR)

1. BIOS self test

2. Read and test MBR in the order of bootable devices configured in BIOS. MBR destroyed!

3. Load bootstrap in MBR.

4. Bootstrap load bootloader. /boot vanished!

5. Then bootloader load initrd ramdisk image, as well as kernel.

/boot/initramfs, vmlinuz deleted!

6. Then kernel magically bring up whole system :(

(39)

parted

Used to partition disk

➔ help tell you everything

➔ mktable/mklabel: GPT/msdos

➔ mkpart

Note it will apply changes as soon as you press enter!!

(40)

mkfs

mkfs -t [fs_type] [device]

or

mkfs.ext4 mkfs.xfs

➔ dosfstools required for fat family.

(41)

Step 3: Solution

parted print

mkpart \n primary \n ext4 \n 2048s \n 1024MB quit

mkfs.ext4 /dev/sda1

(42)

Step 4.

mount and chroot into the broken system.

➔ mount the broken system on /mnt

➔ Then go into the broken system.

(command chroot)

(43)

mount

➔ mount /dev/sda1 /mnt

◆ then files in /dev/sda1 are under /mnt.

◆ -o to specify options

ex. -o ro to mount read only

➔ Mount special devices

(44)

You need to mount...

➔ root partition to /mnt

➔ boot partition to /mnt/boot

➔ And some special partitions as follow

mount -t proc /mnt/proc

mount -t sysfs sys /mnt/sys mount -B dev /mnt/dev

(45)

Step 4: Solution

mount /dev/mapper/cl-root /mnt mount /dev/sda1 /mnt/boot

mount -t proc proc /mnt/proc mount -t sysfs sys /mnt/sys mount -B dev /mnt/dev

mount -B /run/ /mnt/run/

chroot /mnt

(46)

Step 5.

Edit /etc/fstab for new /boot

(47)

/etc/fstab

Looks like

UUID=953-sdsd /boot xfs defaults 0 0

/dev/sda2 / xfs rw 0 0

/dev/sda3 /home xfs rw 0 0

➔ mount automatically when booting

➔ mount with less arguments.

➔ UUID is more robust!

(48)

From something like

UUID=9016f079-6b2f-4d59-9420-07e97e997767 /boot xfs defaults 0 0

to

/dev/sda1 /boot ext4 defaults 0 0

Step 5: Solution

(49)

How does Linux Boot? (Legacy/MBR)

1. BIOS self test

2. Read and test MBR in the order of bootable devices configured in BIOS. MBR destroyed!

3. Load bootstrap in MBR.

4. Bootstrap load bootloader. /boot vanished!

5. Then bootloader load initrd ramdisk image, as well as kernel.

/boot/initramfs, vmlinuz deleted!

6. Then kernel magically bring up whole system :(

(50)

Step 6.

Get back removed /boot/vmlinuz

Originally there are at least two files that looks like vmlinuz-linux

initramfs-linux.img

(51)

Making Initrd ramdisk

➔ Arch: mkinitcpio

➔ CentOS: mkinitrd

◆ mkinitrd and it will tell what to type.

(52)

Where can I get vmlinuz?

From installation CD!!

mount /dev/sr0 /mnt

rpm -i --replacepkgs \

/mnt/Packages/kernel-3.10.0-514.el7.x86_64.rpm

(53)

Step 7.

Install GRUB

(54)

How does Linux Boot? (Legacy/MBR)

1. BIOS self test

2. Read and test MBR in the order of bootable devices configured in BIOS. MBR destroyed!

3. Load bootstrap in MBR.

4. Bootstrap load bootloader. /boot vanished!

5. Then bootloader load initrd ramdisk image, as well as kernel.

/boot/initramfs, vmlinuz deleted!

6. Then kernel magically bring up whole system :(

(55)

GRUB-Related commands

Arch CentOS

➔ grub-install, grub2-install

◆ Install MBR on device

◆ grub2-install --target i386_pc [device]

➔ grub-mkconfig, grub2-mkconfig

◆ Detect existence of OSs and generate configuration file (/boot/grub/grub.cfg /boot/grub2/grub.cfg).

grub2-mkconfig > /boot/grub2/grub.cfg

◆ Best practice:

(56)

Step 7: Solution

grub2-install /dev/sda

grub2-mkconfig > /boot/grub2/grub.cfg

(57)

Finish!!

Remove the installation CD and reboot.

Boot from local drive option on CD menu will not work.

(58)

➔ Order of those steps is important!!

a. boot

b. gather information c. create /boot partition

d. mount and chroot the broken system require /boot created

e. edit fstab

f. get back vmlinuz

Wrap up

(59)

How does Linux Boot? (Legacy/MBR)

1. BIOS self test

2. Read and test MBR in the order of bootable devices configured in BIOS. MBR destroyed!

3. Load bootstrap in MBR.

4. Bootstrap load bootloader. /boot vanished!

5. Then bootloader load initrd ramdisk image, as well as kernel.

/boot/initramfs, vmlinuz deleted!

6. Then kernel magically bring up whole system :(

(60)

Misc: ext family commands

➔ e2label

◆ Change/See partition label.

➔ tune2fs

◆ Adjust tunable filesystem parameters on ext2/ext3/ext4 filesystems. (from its man page)

(61)

License

This slide is under Creative Commons

Attribution-NonCommercial-ShareAlike 4.0 International License.

參考文獻

相關文件

Breu and Kirk- patrick [35] (see [4]) improved this by giving O(nm 2 )-time algorithms for the domination and the total domination problems and an O(n 2.376 )-time algorithm for

• helps teachers collect learning evidence to provide timely feedback & refine teaching strategies.. AaL • engages students in reflecting on & monitoring their progress

Robinson Crusoe is an Englishman from the 1) t_______ of York in the seventeenth century, the youngest son of a merchant of German origin. This trip is financially successful,

fostering independent application of reading strategies Strategy 7: Provide opportunities for students to track, reflect on, and share their learning progress (destination). •

Strategy 3: Offer descriptive feedback during the learning process (enabling strategy). Where the

How does drama help to develop English language skills.. In Forms 2-6, students develop their self-expression by participating in a wide range of activities

Curriculum planning - conduct holistic curriculum review and planning across year levels to ensure progressive development of students’ speaking skills in content, organisation

Finally, based on the experience in the test run period, the operational construction lab will be equipped with more and more suitable construction equipments and safety facilities