diff --git a/.gitignore b/.gitignore index 05f55fe..fa32696 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ rootfs.iso chibrax.tar.gz rootfs linux-firmware -disk.img \ No newline at end of file +disk.img +diskoffset \ No newline at end of file diff --git a/build.sh b/build.sh index 032e869..6a297e6 100755 --- a/build.sh +++ b/build.sh @@ -1,4 +1,5 @@ #!/bin/bash +sudo umount rootfs/proc -R sudo rm -rf rootfs/ sudo rm root.iso sudo rm chibrax.tar.gz @@ -24,8 +25,4 @@ sudo cp linux-firmware/* rootfs/usr/lib/firmware/ -r sudo cp rootfs\ overrides/* rootfs/ -r -echo "chrooted exit when you are done" -sudo chroot rootfs /bin/bash - -sudo rm rootfs/var/cache -rf - +sudo rm rootfs/var/cache -rf \ No newline at end of file diff --git a/copyRootfsIntoTheImage.sh b/copyRootfsIntoTheImage.sh new file mode 100755 index 0000000..92cf441 --- /dev/null +++ b/copyRootfsIntoTheImage.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# we depend on a properly build rootfs +if [ "$EUID" -ne 0 ] +then echo "Please run as root" + exit +fi + +if [ -z disk.img ] +then echo "Please run createLiveImage.sh first" + exit +fi + + +CHIBRAX_MOUNT_POINT="/tmp/chibraxMountPoint" + +OFFSET=$(cat diskoffset) +losetup --offset $OFFSET -f disk.img +LOOP=$(losetup -a | grep -v deleted | cut -d':' -f 1) + +echo ${LOOP} $CHIBRAX_MOUNT_POINT $OFFSET +mkdir $CHIBRAX_MOUNT_POINT -p +mount ${LOOP} $CHIBRAX_MOUNT_POINT + +echo "coping rootfs" +cp rootfs/* $CHIBRAX_MOUNT_POINT -r +echo "done" + +echo "finishing..." +umount $CHIBRAX_MOUNT_POINT +losetup -d $LOOP \ No newline at end of file diff --git a/createLiveImage.sh b/createLiveImage.sh index 50f4314..c149fcf 100755 --- a/createLiveImage.sh +++ b/createLiveImage.sh @@ -20,6 +20,8 @@ START_SECTOR=$(file disk.img | cut -d',' -f 8 | cut -d' ' -f3) echo "Start sector :" $START_SECTOR OFFSET=$((512*$START_SECTOR)) +echo $OFFSET > diskoffset + losetup --offset $OFFSET -f disk.img LOOP=$(losetup -a | grep -v deleted | cut -d':' -f 1) @@ -39,7 +41,7 @@ echo "installing grub" arch-chroot $CHIBRAX_MOUNT_POINT grub-install --target=i386-pc ${LOOP_ROOT} --modules=part_msdos arch-chroot $CHIBRAX_MOUNT_POINT grub-mkconfig -o /boot/grub/grub.cfg -PARTUUID=$(lsblk /dev/loop7 --fs | awk '{print $4}' | grep -v LABEL) +PARTUUID=$(lsblk $LOOP --fs | awk '{print $4}' | grep -v LABEL) echo "menuentry 'Chibrax OS' {" >> $CHIBRAX_MOUNT_POINT/boot/grub/grub.cfg echo " set root='hd0,msdos1'" >> $CHIBRAX_MOUNT_POINT/boot/grub/grub.cfg @@ -49,4 +51,5 @@ echo "}" >> $CHIBRAX_MOUNT_ umount $CHIBRAX_MOUNT_POINT losetup -d $LOOP_ROOT losetup -d $LOOP -chmod 755 disk.img \ No newline at end of file +#built by root but used by any, usefull to run the vm without root privileges +chmod 757 disk.img \ No newline at end of file