LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-22-2019, 08:23 AM   #1
Sharvin26
LQ Newbie
 
Registered: Feb 2019
Posts: 14

Rep: Reputation: Disabled
Flashing Debian Image on SD card Partition


I have an sd card with 2 Partitions. mmcblk0 is the disk and mmcblk0p1, mmcblk0p2 are the 2 partitions I have created.

I am trying to flash the Debian OS on the Partition using the dd command.

dd if=os.img bs=10M of=/dev/mmcblk0p1

I am getting the following output

3565158400 bytes (3.6 GB, 3.3 GiB) copied, 297 s, 12.0 MB/s
106+1 records in
106+1 records out
3565158400 bytes (3.6 GB, 3.3 GiB) copied, 296.587 s, 12.0 MB/s

Now when I try to mount the partition using mount -t auto /dev/mmcblk0p1 mydir

I am getting the following error:

mount: wrong fs type, bad option, bad superblock on /dev/mmcblk0p1,
missing codepage or helper program, or other error
In some cases useful info is found in syslog - try
dmesg | tail or so.

My dmesg | tail Output:

[ 856.292964] F2FS-fs (mmcblk0p1): Magic Mismatch, valid(0xf2f52010) - read(0x0)
[ 856.292983] F2FS-fs (mmcblk0p1): Can't find valid F2FS filesystem in 1th superblock
[ 856.305466] F2FS-fs (mmcblk0p1): Magic Mismatch, valid(0xf2f52010) - read(0x0)
[ 856.305483] F2FS-fs (mmcblk0p1): Can't find valid F2FS filesystem in 2th superblock
[ 856.315244] F2FS-fs (mmcblk0p1): Magic Mismatch, valid(0xf2f52010) - read(0x0)
[ 856.315256] F2FS-fs (mmcblk0p1): Can't find valid F2FS filesystem in 1th superblock
[ 856.324437] F2FS-fs (mmcblk0p1): Magic Mismatch, valid(0xf2f52010) - read(0x0)Units: sectors of 1 * 512 = 512 bytes

Even I am not able to boot from the partition.

But if I try the dd command on mmcblk0 disk it is working perfectly. I am able to mount and boot.

According to my understanding, Linux OS is designed to be installed on a disk, not on a partition and dd is to be used for the flashing on the disk.

I want to write a Debian image on a Partition mmcblk0p1 using a command line tool. How can I achieve this?

I tried dd, pv, cat, cp, ddsd, Dcfldd But ended up with the same result.
 
Old 02-22-2019, 02:53 PM   #2
jefro
Moderator
 
Registered: Mar 2008
Posts: 18,869

Rep: Reputation: 2825Reputation: 2825Reputation: 2825Reputation: 2825Reputation: 2825Reputation: 2825Reputation: 2825Reputation: 2825Reputation: 2825Reputation: 2825Reputation: 2825
You are trying to copy an image of a disk to a partition?

Where did you get this image?
 
Old 02-22-2019, 04:12 PM   #3
linus72
LQ Guru
 
Registered: Jan 2009
Location: Gordonsville-AKA Mayberry-Virginia
Distribution: Slack14.2/AntiX/Arco/Sparky/Hexagon
Posts: 5,245

Rep: Reputation: 362Reputation: 362Reputation: 362Reputation: 362
I dont think you can easily mount a dd'd partition...?
 
Old 02-22-2019, 04:17 PM   #4
Brains
Member
 
Registered: Apr 2009
Distribution: Debian testing
Posts: 962

Rep: Reputation: 241Reputation: 241Reputation: 241
Quote:
Originally Posted by Sharvin26 View Post
But if I try the dd command on mmcblk0 disk it is working perfectly. I am able to mount and boot
Your image is an image of a disk which includes the MBR. You need to make an image of the Debian partition which doesn't include the MBR of the disk. When you create partitions on the SD card, the SD card will have it's own MBR, you flash the partition image to the partition, then either chroot into that partition from the running Debian on the computer or from a running Debian live or Debian installation CD/DVD and issue command: grub-install /dev/sdx, "x" needs to correspond to the SD card device determined by the fdisk -l command.

The partition you create on the SD card can be a little larger, after you get it running you can expand the file system to engulf the free space.

With the grub-install command, you either need all grub related packages needed in the cache of the image or have internet access so it can roundup the need packages from the repositories.

Below is the steps to chroot into the partition if you do it from Debian Live or from Debian running on the computer. If using the Debian installation media, you select advanced options/rescue or similar, there will be many typical installation questions before it ask which partition you want to mount as the root partition, this is where you would select the root partition of the SD card, then you select command prompt and it'll automatically put you in a chroot. If it don't offer the SD card's root partition as an option to mount, you'll have to chroot into it manually.
Code:
mount /dev/xxxx /mnt
mount --bind /dev /mnt/dev 
mount --bind /dev/pts /mnt/dev/pts
mount --bind /proc /mnt/proc
mount --bind /sys /mnt/sys
mount -o bind /run /mnt/run
chroot /mnt
apt-get update
fdisk -l
grub-install /dev/xxx
exit
umount /mnt/run
umount /mnt/sys
umount /mnt/proc
umount /mnt/dev/pts
umount /mnt/dev
umount /mnt

Last edited by Brains; 02-23-2019 at 12:35 AM.
 
1 members found this post helpful.
Old 02-22-2019, 04:43 PM   #5
Brains
Member
 
Registered: Apr 2009
Distribution: Debian testing
Posts: 962

Rep: Reputation: 241Reputation: 241Reputation: 241
You also can cut out the MBR off the image you have using dd. The MBR of the disk contains the size of the disk, as such that will be the size of the SD card if you use it's MBR, as such you will not be able to make a second partition to reclaim the rest of the SD card.

Run fdisk -l command on the image file, and determine where the partition starts, below is an example showing it starts at 2048, the example below is from a UEFI system but should give you an idea:
Code:
[root@localhost jo]# fdisk -l os.img
Disk /dev/sda: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: D8125842-5ED4-42C3-94B2-8F34ED7E698E

Device       Start      End  Sectors  Size Type
/dev/sda1     2048   411647   409600  200M EFI System
/dev/sda2   411648  2508799  2097152    1G Linux filesystem
/dev/sda3  2508800 41940991 39432192 18.8G Linux LVM
The run dd on the image file to create a new image:
Code:
dd if=os.img of=os2.img skip=2048 count=409600
EDIT: I added a count value in case there are other partitions on the disk image

Last edited by Brains; 02-23-2019 at 02:26 AM.
 
2 members found this post helpful.
Old 02-22-2019, 11:50 PM   #6
Sharvin26
LQ Newbie
 
Registered: Feb 2019
Posts: 14

Original Poster
Rep: Reputation: Disabled
Hello Brian,
Thanks for the solution.

When I performed fdisk on my Image I got the following result:
root: fdisk -l os.img
Disk os.img: 3.3 GiB, 3565158400 bytes, 6963200 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x7aac34a0

Device Boot Start End Sectors Size Id Type
os.img1 * 8192 6963199 6955008 3.3G 83 Linux

This is my sd card result

fdisk -l /dev/mmcblk0
Disk /dev/mmcblk0: 7.4 GiB, 7948206080 bytes, 15523840 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xd16b4640

Device Boot Start End Sectors Size Id Type
/dev/mmcblk0p1 2048 7761919 7759872 3.7G e W95 FAT16 (LBA)
/dev/mmcblk0p2 7761920 15521791 7759872 3.7G e W95FAT16 (LBA)

How can I cut out the MBR off the image in the above case?

Last edited by Sharvin26; 02-23-2019 at 12:04 AM.
 
Old 02-23-2019, 12:10 AM   #7
Brains
Member
 
Registered: Apr 2009
Distribution: Debian testing
Posts: 962

Rep: Reputation: 241Reputation: 241Reputation: 241
Code:
Device Boot Start End Sectors Size Id Type
os.img1 * 8192 6963199 6955008 3.3G 83 Linux
Code:
dd if=os.img of=os2.img skip=8192
No need for a count value as it's the only partition in the image.
Your /dev/mmcblk0p1 partition on the SD card is just under a MB larger, so that should be good for size, but you should change the partition type ID to 83, or reformat it to Linux ext4 which will do that. You can change the ID with fdisk.

Last edited by Brains; 02-23-2019 at 01:39 AM. Reason: Removed potentialy wrong advice
 
1 members found this post helpful.
Old 02-23-2019, 12:16 AM   #8
Brains
Member
 
Registered: Apr 2009
Distribution: Debian testing
Posts: 962

Rep: Reputation: 241Reputation: 241Reputation: 241
Sorry, your first partition on the card, /dev/mmcblk0p1 is actually about 400MB larger, if you're OK with that, leave it or shrink it by no more than 390MB.
EDIT: I also changed my code in my first post to do an update in case the image is a little old and there is a possibility the version of grub packages since last update has changed.

Last edited by Brains; 02-23-2019 at 12:19 AM.
 
Old 02-23-2019, 12:48 AM   #9
Brains
Member
 
Registered: Apr 2009
Distribution: Debian testing
Posts: 962

Rep: Reputation: 241Reputation: 241Reputation: 241
Had to refer to my notes

EDIT: It looks like my mind is sharper than my notes, so I removed the advice from my notes in this post.

Last edited by Brains; 02-23-2019 at 01:38 AM.
 
Old 02-23-2019, 12:58 AM   #10
Sharvin26
LQ Newbie
 
Registered: Feb 2019
Posts: 14

Original Poster
Rep: Reputation: Disabled
Thanks, Brains. It worked.

Last edited by Sharvin26; 02-23-2019 at 03:19 AM.
 
Old 02-23-2019, 01:02 AM   #11
Brains
Member
 
Registered: Apr 2009
Distribution: Debian testing
Posts: 962

Rep: Reputation: 241Reputation: 241Reputation: 241
To verify the partition image extracted is good, mount it with command:
Quote:
mount -o loop os2.img /mnt
If you go into /mnt directory you should see all directories in root, if so, your partition image is good.
 
1 members found this post helpful.
Old 02-23-2019, 03:18 AM   #12
Sharvin26
LQ Newbie
 
Registered: Feb 2019
Posts: 14

Original Poster
Rep: Reputation: Disabled
Yes, it's mounting properly. You solved a lot of my problems.
Thanks
 
Old 02-23-2019, 06:38 AM   #13
Brains
Member
 
Registered: Apr 2009
Distribution: Debian testing
Posts: 962

Rep: Reputation: 241Reputation: 241Reputation: 241
Quote:
Originally Posted by linus72 View Post
I dont think you can easily mount a dd'd partition...?
You probably won't say that again. Make a dd drive image of a small USB key with data on it and try this: Sharvin26's drive image partition starts at sector 8193, offset is 8192. To mount that partition in the drive image, specify the offset in bytes, since there are 512 bytes per sector, 8192 x 512 = 4194304
Code:
mount -oloop,offset=4194304 os.img /mnt
Perhaps it's because of the comma and offset right after the word loop that has had me structuring the command this way, whenever I would have a space between "-o" and "loop", I would get an error, but this always worked for me.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Root EVO 4G via flashing rooted gingerbread rom from a "gold card". glennly Linux - Newbie 1 06-20-2011 01:35 PM
Why can't i get GUI on mini2440 when NAND flashing qt image? neo3matrix Linux - Newbie 0 11-03-2009 06:11 AM
Flashing a broadcom wireless card nukoso Linux - Hardware 3 07-02-2008 09:47 AM
HD led flashing when playing DVD and horrible image. Linux.tar.gz Linux - Hardware 4 01-12-2006 08:51 PM
install but pcmcia card flashing but not working esteeven Debian 7 06-16-2004 05:00 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration