creating and formating partitions with script

Started by Dongalor, January 18, 2011, 12:08:30 PM

Previous topic - Next topic

Dongalor

Hello everybody,

I'm trying to create a installer using plop. 

What I'm doing :

I've edit  ploplinux/myscripts/runme.sh to execute my own script

My own script is doing the following:

- Create partitions:
Device       Boot Start    End     Blocks          Id       System
/dev/sda1     *     1         182     1461883+     83       Linux
/dev/sda2           183      243     489982+       82       Linux swap / Solaris
/dev/sda3           244      365     979965         83       Linux

- dd a debian img to /dev/sda1
- mkfs.ext3 /dev/sda3
- copy a file to /dev/sda3

After that, ploplinux starts normally and I can verify the creation of the partitions. I can mount /dev/sda3 and verify the content of /dev/sda3
 

The problem comes when I reboot. Debian in /dev/sda1 boot ok, but when I'm inside debian I can not mount /dev/sda3, getting the error :

EXT3-fs : error loading journal

Any ideas?

Thanks in advance.

The full script:

-----------------------------------------------------------------------------------------------------------------------------------------------

#!/bin/bash

SRC=/media/
DEVICE_GRUP=/dev/sda
DEVICE_SYSTEM=/dev/sda1
DEVICE_GAME=/dev/sda3
FILE=test_final_final

########## FORMAT FLASH ############################
echo -e "\033[1m Formating flash...\033[0m"
$SRC/formatInstallation.sh

########## EXTRACT LINUX SYSTEM ####################
echo -e "\033[1m Extracting SO...\033[0m"
echo "dd if=$SRC/testlin.img of=$DEVICE_SYSTEM"
dd if=$SRC/testlin.img of=$DEVICE_SYSTEM
sleep 10

########## EXTRACT GAME  ###########################
mkfs.ext3 /dev/sda3
mkdir /game
mount /dev/sda3 /game
cp $SRC/$FILE /game/
echo "file copied"
sleep 10
sync
umount /dev/sda3
sleep 10

########## GRUB  ###########################
echo -e "\033[1mConfiguring Grub...\033[0m"
echo "dd if=$SRC/grub.img of=$DEVICE_GRUP bs=512 count=1"
dd if=$SRC/grub.img of=$DEVICE_GRUP bs=512 count=1
sleep 20

########## EXTRACT CONF FILES  #####################
echo " extracting config files..."
mkdir /system
mount /dev/sda1 /system
cp $SRC/static /system/root/
cp $SRC/output /system/root/
cp $SRC/code system/root/
sync
sleep 15
umount /dev/sda1/
sleep 10


-----------------------------------------------------------------------------------------------------------------------------------------------

formatInstallation.sh :

-----------------------------------------------------------------------------------------------------------------------------------------------
#!/bin/sh
fdisk /dev/sda << EOF
d
1
d
2
d
3
d
4
n
p
1
1
+1500M
n
p
2
193
+500M
t
2
82
n
p
3
258
+1000M
a
1
w
EOF
-----------------------------------------------------------------------------------------------------------------------------------------------


Elmar

hi,

gives dmesg any more info after the failed mount in debian?

regards
elmar

Dongalor

Hi Elmar,

the part of dmesg related to this :


[   11.558291] Adding 489972k swap on /dev/sda2.  Priority:-1 extents:1 across:489972k
[   11.833475] EXT3 FS on sda1, internal journal
[   12.684535] loop: AES key scrubbing enabled
[   12.684535] loop: loaded (max 8 devices)
[   13.186445] JBD: no valid journal superblock found
[   13.186445] EXT3-fs: error loading journal.



I've tried to do the diferent steps of the script but manually (once plop is started, without the script), and everything looks ok.... I will repeat the process to be sure.

Elmar

does /dev/sda3 work when you reboot ploplinux after debian?

if not, then the problem is the fdisk script

Dongalor

no, /dev/sda3 does not work if I reboot with plop after debian.

I will take a look to fdsik script and hopefully see what's going on

Elmar

#5
i know whats the problem

at first, you do the fdisk stuff, then you do something else and then you overwrite the mbr with the grub stuff and your overwrite the created partition entries. thats the fault, because with the next boot, the partition values stored in grub.mbr are used. so first do the grub stuff and then use your fdisk script. take care that the partition table in grub.mbr is empty.

a few hints:
1) do not use fixed head start values in the fdisk script, use the value that fdisk says with an empty line

2) you do syncs and sleeps. sync forces to finish all writes from ram to the device. sync is not needed because an umount does the sync automatically before it releases the device. so you can remove the sleeps and syncs.

edit:
btw, when you want to use the partition values stored in grub.mbr then simply use this after you wrote grub.mbr


fdisk $DEVICE_GRUP << EOF
w
EOF


that the system loads the partition values

regards
elmar

Dongalor

You are right!

I've tried your solution and it works. Thanks a lot!