Skip to content

Instantly share code, notes, and snippets.

@weshouman
Last active December 8, 2017 11:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weshouman/c958bb9d51f784e77104 to your computer and use it in GitHub Desktop.
Save weshouman/c958bb9d51f784e77104 to your computer and use it in GitHub Desktop.
Kris Occhipinti filesystem #study
#---------- Mounting ISO images linux tutorial ----------#
#http://youtu.be/Tsyk6vLr91k
mkdir mymountpoint
sudo mount ubuntu_or_whatever.iso mymountpoint/
#that's expected that an iso mounted would be write protected/read only =D
#just like a CD
sudo umount mymountpoint/
#some filesystems need the "-o loop" option
#so the mount is like
sudo mount -o loop ubuntu_or_whatever.iso mymountpoint/
#---------- Linux kernel and initrd Basics tutorial ----------#
# http://youtu.be/boxF9t29xZQ
# a tutorial inspecting different iso images
# commands here are based on Core-current.iso
# first step, mount and continue next steps :D
cd iso/boot
# grub and isolinux are different bootloaders!
# vmlinux is the kernel //name my differ
# to ensure we may use file command with it
# an output of 'blablabla: x86 boot sector' confirms that
file vmlinuz
# cpio some type of archiving
# gzib file: small compressed file, so common that
file core_or_whatever.gz
# initrd: initial ramdisk ... will follow
cd isolinux/
# Inspect the most important of config files: isolinux.cfg
less isolinux.cfg
# This one told us what the kernel we'll use
# and what initrd we'll use.
# cfg files may include other cfg files for organizing.
# Displayed messages are written in different files and included too.
# kernel is first loaded into the ram, initrd is loaded that makes some other tasks,
# then the main filesystem is loaded replacing the initrd
#---------- Extracting CPIO files on Linux initrd gz tutorial ----------#
# http://youtu.be/SZo6nQZV1bE
# Inspection on Core-current
mv iso/core.gz mytestdir/core.gz
gunzip core.gz
file core
# Will tell us its a CPIO archive!
# Now use the standard cpio program to extract
cpio -i < core
# NOTE: it will give some not permitted operations, as permissions are important,
# but the filesystem will extract :3
# thus we may need to use sudo!
# single step method
zcat core.gz |sudo cpio -i
# zcat is like cat but for gzip files
# get size in human friendly format!
du -h
#---------- Extracting LZMA Files on Linux initrd CPIO ----------#
# http://youtu.be/joOUG8an1O0
# Inspection on Slitaz
# Step 1: mount, get a copy of rootfs4.gz in read/write dir then continue ^_^
# we'll notice that 'gunzip rootfs4.gz' will return 'not in gzip format'
# using the file
file rootfs4.gz
# Its obvious that the .gz extension has nothing to do with it being
# LZMA compressed data
# Uncompress
unlzma rootfs4.gz -S .gz
# use -S to specify the suffix, that's removed to deduce the target name
file rootfs4
# Ensure its CPIO as we expect
sudo cpio -i < rootfs4
#---------- Extracting SQUASHFS files on Linux initrd.gz tutorial ----------#
# http://youtu.be/1mMXzgzHeE4
# Inspection on Mint
# 'unsquashfs-tools' may need to be apt-geted ^_^
unsquashfs myMintMountDir/casper/filesystem.squashfs
# notice that the extraction went into an autogenerated named directory
# so ... for a better naming :D
mv squashfs-root/ mint
cd mint && du -h
#uncompression from 888 to 3.0G :3
#---------- Create a Broken Linux Live CD Tutorial ----------#
# http://youtu.be/hB_Rsx0HGWY
# Create a dir with subdir inside
mkdir -p mylive/iso/isolinux
# mylive: iso file container
# iso: root dir for image //keep clean
# isolinux: save here info for bootloader, kernel and initrd
cd mylive/iso/isolinux
# Get a kernel
cp /boot/vmlinux-x.y-z=amd64 linux
# note: name isn't an issue, as we're gonna keep it consistent with the cfg file
# Get an initrd
cp /boot/initrd.img-x.y-z-amd64 initrd
# note: ensure the x, y and z are the same for kernel as for initrd
## another way to make initrd, not sure how its better!
sudo mkinitramfs -o initrd
# Get the isolinux.bin //don't know why :|
# if syslinux package is installed!
# search example for isolinux.bin
find /usr -name "isolinux.bin"
cp /usr/share/syslinux/themes/debian-wheezy/isolinux-live/isolinux.bin ./
# Make our own config
vim isolinux.cfg
# display boot.txt
# prompt 1
# default mylinux
# label mylinux
# kernel linux
# append initrd=initrd
# Make our own message
vim boot.txt
# =========welcome to mylinux cd =========
cd ../../
# Make the iso
xorrisofs -l -J -no-emul-boot -boot-load-size 5 -boot-info-table -b isolinux/isolinux.bin -c isolinux/boot.cat -o mylinux.iso iso
# "make-iso-fs" or some abbreviation, may be the alternative in older distros
# too many options ... only b was illustrated
# c: another file to be created
# b: where to find the bin for the boot loader
# l:
# J:
# no-emul-boot:
# boot-load-size:
# boot-info-table:
### Why its broken: cause the initrd we put is looking for our filesystem to call :D
### so it will end up giving us a shell
# Emulation time
# qemu should be apt-geted for that
qemu-system-x86_64 -cdrom mylinux.iso
# we should now see it failing ^_^
# note: usage of 86_64 cause we used a 64bit kernel
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment