最近有臺服務器須要安裝ssd卡,由於安裝驅動須要內核2.6.32,而debian5機器默認仍是2.6.18,全部首先須要升級內核. linux
1.安裝2.6.32內核須要debian6的源 shell
root@10.1.1.200:~# uname -a Linux 10.1.1.200 2.6.18-6-amd64 root@10.1.1.200:~# vim /etc/apt/sources.list deb http://mirrors.163.com/debian squeeze main non-free contrib deb http://mirrors.163.com/debian-security squeeze/updates main contrib non-free2.安裝2.6.32頭文件和鏡像
root@10.1.1.200:~# apt-get install linux-headers-2.6.32-5-amd64 linux-image-2.6.32-5-amd64升完內核默認會將/boot/grub/menu.lst,/etc/fstab文件裏磁盤位置更換爲UUID,記得手動加入 console=tty0 console=ttyS1,115200 已供ipmi查看重啓過程界面狀態.
root@192.168.2.197:grub# cat menu.lst | egrep -v '^#|^$' default 0 timeout 5 color cyan/blue white/blue title Debian GNU/Linux, kernel 2.6.32-5-amd64 root (hd0,0) kernel /boot/vmlinuz-2.6.32-5-amd64 root=UUID=4f343e7c-3c29-4ce6-9bf6-0ee46c07ee28 ro console=tty0 console=ttyS1,115200 initrd /boot/initrd.img-2.6.32-5-amd64 title Debian GNU/Linux, kernel 2.6.32-5-amd64 (single-user mode) root (hd0,0) kernel /boot/vmlinuz-2.6.32-5-amd64 root=UUID=4f343e7c-3c29-4ce6-9bf6-0ee46c07ee28 ro single console=tty0 console=ttyS1,115200 initrd /boot/initrd.img-2.6.32-5-amd64 title Debian GNU/Linux, kernel 2.6.26-2-amd64 root (hd0,0) kernel /boot/vmlinuz-2.6.26-2-amd64 root=UUID=4f343e7c-3c29-4ce6-9bf6-0ee46c07ee28 ro console=tty0 console=ttyS1,115200 initrd /boot/initrd.img-2.6.26-2-amd64 title Debian GNU/Linux, kernel 2.6.26-2-amd64 (single-user mode) root (hd0,0) kernel /boot/vmlinuz-2.6.26-2-amd64 root=UUID=4f343e7c-3c29-4ce6-9bf6-0ee46c07ee28 ro single console=tty0 console=ttyS1,115200 initrd /boot/initrd.img-2.6.26-2-amd64 title Debian GNU/Linux, kernel 2.6.18-6-amd64 root (hd0,0) kernel /boot/vmlinuz-2.6.18-6-amd64 root=UUID=4f343e7c-3c29-4ce6-9bf6-0ee46c07ee28 ro console=tty0 console=ttyS1,115200 initrd /boot/initrd.img-2.6.18-6-amd64 title Debian GNU/Linux, kernel 2.6.18-6-amd64 (single-user mode) root (hd0,0) kernel /boot/vmlinuz-2.6.18-6-amd64 root=UUID=4f343e7c-3c29-4ce6-9bf6-0ee46c07ee28 ro single console=tty0 console=ttyS1,115200 initrd /boot/initrd.img-2.6.18-6-amd64 root@10.1.1.200:grub# cat /etc/fstab # /etc/fstab: static file system information. # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 # /dev/sda1 / ext3 noatime,commit=15,errors=remount-ro 0 1 UUID=4f343e7c-3c29-4ce6-9bf6-0ee46c07ee28 / ext3 noatime,commit=15,errors=remount-ro 0 1 # /dev/sda5 none swap sw 0 0 UUID=bd42e7e0-1f64-4d31-9e16-842a920b7162 none swap sw 0 0 # /dev/sda6 /opt ext3 noatime,commit=15,errors=remount-ro 0 0 UUID=670e1dbf-8848-4a25-b200-4483f95adcc1 /opt ext3 noatime,commit=15,errors=remount-ro 0 0 # /dev/sda7 /db_bak ext3 noatime,commit=15,errors=remount-ro 0 0 UUID=7f4f1207-d74e-4048-9e76-c4cd1081513b /db_bak ext3 noatime,commit=15,errors=remount-ro 0 0 # /dev/sda8 /export ext3 noatime,commit=15,errors=remount-ro 0 0 UUID=3500e14f-e89b-42c9-a4f2-0da4db8843ff /export ext3 noatime,commit=15,errors=remount-ro 0 0
這裏必定要覈對系統分區的UUID值和以上文件裏是否一致,可用blkid查詢 vim
root@10.1.1.200:grub# blkid /dev/sda1: UUID="4f343e7c-3c29-4ce6-9bf6-0ee46c07ee28" TYPE="ext3" /dev/sda5: TYPE="swap" UUID="bd42e7e0-1f64-4d31-9e16-842a920b7162" /dev/sda6: UUID="670e1dbf-8848-4a25-b200-4483f95adcc1" TYPE="ext3" SEC_TYPE="ext2" /dev/sda7: UUID="7f4f1207-d74e-4048-9e76-c4cd1081513b" TYPE="ext3" SEC_TYPE="ext2" /dev/sda8: UUID="3500e14f-e89b-42c9-a4f2-0da4db8843ff" TYPE="ext3" SEC_TYPE="ext2" root@10.1.1.200:grub# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 28G 1.9G 25G 8% / tmpfs 16G 0 16G 0% /lib/init/rw udev 10M 76K 10M 1% /dev tmpfs 16G 0 16G 0% /dev/shm /dev/sda6 917G 1.8G 869G 1% /opt /dev/sda7 459G 199M 435G 1% /db_bak /dev/sda8 238G 188M 225G 1% /export
重啓機器,內核升級完成 服務器
root@10.1.1.2:grub# uname -a Linux 10.1.1.2 2.6.32-5-amd64
模塊加載 ide
這裏先講解下內核是如何載入模塊的. oop
1.查看如今內核加載的模塊 spa
lsmod #能夠查看如今內核加載的模塊,是經過讀取/proc/modules/中的內容來查看的 code
root@10.1.1.200:~# lsmod Module Size Used by hio 29631 0 ipmi_si 30960 1 ipmi_devintf 6587 0 ipmi_poweroff 6705 0 ipmi_watchdog 12737 0 ipmi_msghandler 26634 4 ipmi_si,ipmi_devintf,ipmi_poweroff,ipmi_watchdog loop 11799 0 ......... crc_t10dif 1276 1 sd_mod raid1 18431 0 md_mod 73872 1 raid1
2.內核是如何載入模塊的 orm
當內核所須要的擴展功能不存在時,內核模塊管理守護進程kmod執行modprobe去加載內核模塊,兩種類型的參數能夠傳給modprobe xml
a.模塊的名字,如md
b.通用識別符,如block-major-9-*
當傳給modprobe的參數是通用識別符時,modprobe首先在modprobe -c 或/etc/modprobe.d/aliases中查找該字符串,若是它發現有一行像alias block-major-9-* md說明要加載的是md模塊,而後遍歷/lib/modules/2.6.32-5-amd64/modules.dep 來判斷是否有其餘內核模塊須要在加載此模塊前加載.該文件由depmod -a來建立, 保存着內核模塊的依賴關係.
root@10.1.1.200:~# modprobe -c | grep "md_mod" alias block-major-9-* md_mod alias md md_mod root@10.1.1.200:~# cat /etc/modprobe.d/aliases | egrep -v '^#|^$' | grep 'md' alias block-major-9-* md
最終modprobe調用inmod來先加載須要依賴的模塊,而後加載此模塊inmod將指向/lib/modules/2.6.32-5-amd64/kernel/....爲模塊的專門存放的目錄.
載入一個模塊有2種方法:
1)#insmod 後面必需要寫明所有的路徑
#insmod /lib/modules/2.6.32-5-amd64/kernel/drivers/md/md-mod.ko2) modprobe會調用insmod來加載模塊
#modprobe md
modeprobe和insmod均可以安裝模塊,可是,modeprobe會依靠分析模塊之間的依賴關係,而後又前後順序的加載必需的模塊,而後再加載當前的模塊,而insmod就只會加載你所制定的這個模塊,一旦它有一些依賴關係,容易出錯的.
卸載模塊:
#rmmod md 或#modprode -r md
modules經常使用參數
-c 查看modules的配置文件
root@10.1.1.200:~# modprobe -c | grep md_mod alias block-major-9-* md_mod alias md md_mod-l 列出內核中全部已經或者未掛載的全部模塊
root@10.1.1.200:~# modprobe -l | grep md-mod /lib/modules/2.6.32-5-amd64/kernel/drivers/md/md-mod.ko-r移除模塊
root@10.1.1.200:~# modprobe -r md
上面瞭解了模塊加載的過程,因爲ssd的驅動已經編譯好,這裏直接dpgk安裝便可
root@10.1.1.200:~# dpkg -i hio-1.0-0.7.amd64.deb Selecting previously deselected package hio. (Reading database ... 46823 files and directories currently installed.) Unpacking hio (from hio-1.0-0.7.amd64.deb) ... Setting up hio (1.0-0.7) ... root@10.1.1.200:~# modprobe -l | grep hio /lib/modules/2.6.32-5-amd64/kernel/drivers/hio/hio.ko root@10.1.1.200:~# lsmod | grep hio hio 29631 0 root@10.1.1.200:~# modprobe -c | grep hio alias pci:v000010EEd00000007sv*sd*bc*sc*i* hio再次查看ssd卡結果已識別/dev/hioa
root@10.1.1.200:~# fdisk -l Disk /dev/sda: 730.8 GB, 730815528960 bytes 255 heads, 63 sectors/track, 88849 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0x000e801e Device Boot Start End Blocks Id System /dev/sda1 1 3706 29768413+ 83 Linux /dev/sda2 3707 88849 683911147+ f W95 Ext'd (LBA) /dev/sda5 3707 4694 7936078+ 82 Linux swap / Solaris /dev/sda6 4695 41168 292977373+ 83 Linux /dev/sda7 41169 65484 195318238+ 83 Linux /dev/sda8 65485 88849 187679331 83 Linux Disk /dev/hioa: 642.8 GB, 642835808256 bytes 4 heads, 16 sectors/track, 19617792 cylinders Units = cylinders of 64 * 512 = 32768 bytes Disk identifier: 0x00000000 Disk /dev/hioa doesn't contain a valid partition table