grub install for specific drive without BIOS drive name mapping
grub --device-map=/dev/null
grub> device (hd0) /dev/sda
2016年2月4日 星期四
CentOS/RHEL rootfs on tmpfs
1: remember to disable selinux first
2: update mount process in /usr/share/dracut/modules.d/95rootfs-block/mount-root.sh
mkdir /mytmpfs
mount -t "$rootfs" -o "$rflags","$rootopts" \
"${root#block:}" "/mytmpfs" 2>&1 | vinfo
mount -t tmpfs -o size=100% none "$NEWROOT"
cp -rfa /mytmpfs/* "$NEWROOT"
sed -i '/\/boot\ /d' "$NEWROOT/etc/fstab"
sed -i '/\/boot\t/d' "$NEWROOT/etc/fstab"
sed -i '/\/ /d' "$NEWROOT/etc/fstab"
sed -i '/\/\t/d' "$NEWROOT/etc/fstab"
cat /dev/null > "$NEWROOT/root/.bash_history"
umount /mytmpfs
3: create new initrd
4: update grub boot menu
5: boot parameter parsing
imgfile=$(getarg imgfile=)
[ -f "$imgfile" ] && tar zxvf $imgfile -C $NEWROOT
http://linux.die.net/man/1/bash
Conditional Expressions boot process stage https://www.kernel.org/pub/linux/utils/boot/dracut/dracut.html#stages
2: update mount process in /usr/share/dracut/modules.d/95rootfs-block/mount-root.sh
mkdir /mytmpfs
mount -t "$rootfs" -o "$rflags","$rootopts" \
"${root#block:}" "/mytmpfs" 2>&1 | vinfo
mount -t tmpfs -o size=100% none "$NEWROOT"
cp -rfa /mytmpfs/* "$NEWROOT"
sed -i '/\/boot\ /d' "$NEWROOT/etc/fstab"
sed -i '/\/boot\t/d' "$NEWROOT/etc/fstab"
sed -i '/\/ /d' "$NEWROOT/etc/fstab"
sed -i '/\/\t/d' "$NEWROOT/etc/fstab"
cat /dev/null > "$NEWROOT/root/.bash_history"
umount /mytmpfs
3: create new initrd
4: update grub boot menu
5: boot parameter parsing
imgfile=$(getarg imgfile=)
[ -f "$imgfile" ] && tar zxvf $imgfile -C $NEWROOT
http://linux.die.net/man/1/bash
Conditional Expressions boot process stage https://www.kernel.org/pub/linux/utils/boot/dracut/dracut.html#stages
2015年11月19日 星期四
hexdump - format output
hexdump -s 0x2f -n 7 -e '7 1 "%c" ' 1
7 repeat 7 times
1 each time for 1 byte
2015年10月13日 星期二
Linux C dev tips
errno.h
strerror (errno)
dlfcn.h
void *handle;
handle = dlopen("libkido.so", RTLD_LAZY);
if (!handle) {
fprintf(stderr, "%s \n", dlerror());
exit(EXIT_FAILURE);
}
int (*test)() = dlsym (handle,"test3");
if (!test) {
fprintf(stderr, "%s \n", dlerror());
exit(EXIT_FAILURE);
}
int a;
a=(*test)();
Linux C program tips
compile object files
gcc -c 1.c --> automatically generate 1.o file
link object files and generate binary file
gcc -o app 1.o 2.o main.o
build archives -- static library
ar cr libkido.a 1.o 2.o main.o
gcc -L . -lkido -o app
build shared library
gcc -c -fPIC 1.c --> automatically generate 1.o file
gcc -shared -fPIC -o libkido.so main.o 1.o 2.o
gcc -o app -L . -lkido -Wl,-rpath,./ <-- if rpath is not defined, LD_LIBRARY_PATH need to be defined in environment variable to have the binary locate library file
2015年1月23日 星期五
gcc object file linking
gcc -c xxx.c --> automatically generate xxx.o
gcc yyy.c xxx.o --> automatically generate a.out
You can use functions defined in xxx.c without including any header files in yyy.c
訂閱:
文章 (Atom)