date int64 1,220B 1,719B | question_description stringlengths 28 29.9k | accepted_answer stringlengths 12 26.4k | question_title stringlengths 14 159 |
|---|---|---|---|
1,485,760,371,000 |
The following find command will results multiple files and send mail all those
find /home/cde -ctime -1 -name "Sum*pdf*" -exec uuencode {} {} \; |mailx -s "subject" [email protected]
But I am getting attachments like homecdeSum123.pdf and homecdeSum324.pdf. How to get exact file names in my attachment.
|
If I understand you right, you want to have the attachments have filename like Sum123.pdf instead of homecdeSum123.pdf. I assume the latter name is produced by your mail program that removes the slashes in the path name when saving.
I think you should use a different way to call uuencode, removing the path name on the second parameter:
find /home/cde -ctime -1 -name "Sum*pdf*" | while read name; do uuencode "$name" "${name##*/}" | mailx -s "subject" [email protected]; done
This will send a separate mail for every file. The ${name##*/} part will take the variable $name, remove everything up to and including the last slash and return the result.
If you want to send all files in one mail, just put the mailx part of the pipe to the end:
find /home/cde -ctime -1 -name "Sum*pdf*" | while read name; do uuencode "$name" "${name##*/}"; done | mailx -s "subject" [email protected]
| Get only file name from find command and mail |
1,485,760,371,000 |
I'm running Debian
I've set up ssmtp as my MTA and this works perfectly
I can send mail using both mail and mailx with a standard user account
BUT... When I run sudo apticron I get:
send-mail: RCPT TO:<[user]@[mydomain].com> (550 Sender verify failed)
Any ideas? (I've blanked the email details myself - that's not part of the error)
UPDATE:
When running mail or mailx as root, these break too! They only work when I run them under my standard user account.
Error message I receive as root when running:
echo "test" | mail -s "test" [user]@[mydomain].com
is same as with apticron:
RCPT TO:[user]@[mydomain]> (550 Sender verify failed)
UPDATE 2:
sudo mail -v etc... shows that the root user actually replaces the first part of the email address with 'root' despite /etc/ssmtp/ssmtp.conf specifying FromLineOverride=NO:
[<-] 220 and/or bulk e-mail.
[->] EHLO [user]@[mydomain].com
[<-] 250 HELP
[->] AUTH LOGIN
[<-] 334 VXNlcm5hbWU6
[->] [redacted Base64 username]
[<-] 334 UGFzc3dvcmQ6
[<-] 235 Authentication succeeded
[->] MAIL FROM:<root@[mydomain.com]>
[<-] 250 OK
[->] RCPT TO:<[user]@[mydomain].com>
[<-] 550 Sender verify failed
send-mail: RCPT TO:<[user]@[mydomain].com> (550 Sender verify failed)
EDIT:
I've removed previously pasted code from apticron as clearly the problem lies with root not being able to send emails (this is no longer limited to an individual program)
|
Your remote mail server doesn't believe root@yourdomain in the SMTP envelope¹ is a valid email address, so it's refusing messages from you. And that's where apticron is trying to send from, so it doesn't work.
ssmtp allows you to override the default email address and relay on a per-user basis in the /etc/ssmtp/revaliases file. You can use this to set an acceptable (to your mail relay) address for root, by adding a line like:
root:EMAIL@DOMAIN:RELAY-HOST:RELAY-PORT
replacing the all-caps portions with email address and relay host you'd like to use.
Note: Much of this was from troubleshooting in chat, starting around this message.
1Note that the SMTP "envelope" sender is different than the From: field that shows up in your mail client. Though if you're lucky it's preserved in a different header.
| root can't send mail (apticron) but user can (mail/mailx) |
1,485,760,371,000 |
I followed this tutorial: https://computingforgeeks.com/how-to-install-and-configure-postfix-as-a-send-only-smtp-server-on-ubuntu-18-04-lts/
I'm trying to setup a send only mail from my Ubuntu 19 server. I followed the guide above and tried to install mailutils using:
apt install mailutils
It installed something but I'm not sure what as the mailutils command doesn't work as seen here:
I then installed via the following command:
apt install libmailutils-dev
That worked as mailutils command now runs, but I didn't get a GUI interface to select like how the guide shows it:
What do I need to do now since the Postfix install GUI didn't popup according to the guide?
Also is it an issue if I installed mailutils and then libmailutils-dev?
|
Run dpkg-reconfigure postfix to see the wizard/GUI
| Install Postfix using Mailutils on Ubuntu 19.04 server for sending out mail only |
1,485,760,371,000 |
I'm using mailx and sendmail functions to send mail from set of solaris machine with different versions. And the script send mail for most of the machine. Still issue is there on sending out mail for few servers. But there is no error shown while execute this script.
Script 1:
uuencode report.html report.html | mailx -s "mail subject" [email protected]
Script 2:
SELFDIR=`pwd`
DOCROOT=$SELFDIR"/"
MAIL_FROM="[email protected]"
MAIL_TO="[email protected]"
echo "From: "$MAIL_FROM > $DOCROOT"header.txt"
echo "To: "$MAIL_TO >> $DOCROOT"header.txt"
echo "Subject: The mail subject " >> $DOCROOT"header.txt"
echo "Content-Type: text/html" >> $DOCROOT"header.txt"
cat $DOCROOT"header.txt" $DOCROOT"report.html" | /usr/lib/sendmail -t
Simply is there any way to find the error or logs of the mail delivery failed to recognize the reason of failture?
|
It's been a long time since I last used sendmail on Solaris but I'm sure its -v flag will show what's going on:
(
echo 'From: [email protected]'
echo 'To: [email protected]'
echo 'Subject: from me to you'
echo
finger
) | sendmail -t -v
I'm also pretty sure that mailx passes this flag onwards:
echo hello, world | mailx -v -s "mail subject" [email protected]
Check /var/log/syslog for sendmail messages. Also take a read of The ultimate Solaris sendmail troubleshooting guide which helps with differences between Solaris versions 8, 9, 10.
| mailx execute successfully but not sending mail out |
1,485,760,371,000 |
I have this user who have a lot of cron jobs and I expected it to log stderr in its /var/mail/user. Sample below cron entry is working as expected in a different server.
* 30 * * * * /usr/local/bin/scripts/test.sh > /dev/null 2>&1
I've compared postfix/main.cf on both servers and cannot find anything different. Is there something else I need to check?
|
This is an explicit redirection in the cron command: > /dev/null 2>&1. It means both stdout and stderr are thrown away. There's no basis to expect any mail then. To keep stderr, leave just this redirection at the end: >/dev/null.
| Cron is not logging stderr in /var/mail/user |
1,485,760,371,000 |
I have an MBOX file created by dragging a folder from Outlook (For Mac v.16) into Finder (because the Export wizard in Outlook For Mac only generates OLM files).
I can look at the MBOX contents as plain text, and it looks sane. I would like to verify the number of messages contained. But mailx doesn't seem to see any messages:
% mailx -f archive.mbox
Mail version 8.1 6/6/93. Type ? for help.
"archive.mbox": 0 messages
? f
No applicable messages
? h
No applicable messages
?
I realize it's a very old version of mailx, but that is what shipped with the Mac.
How does mailx expect messages to be delimited in the MBOX file? Could I fix this with a simple find-replace?
|
It could be that mailx objects to DOS linefeeds or some other problem with the export from Outlook. The format should otherwise be very simple; records start with a "From " line which is followed by the message headers, a blank line, and then the message body and I think another blank line before the next "From " record. So to count the number of records
grep -c '^From ' archive.mbox
should suffice, as that pattern may not appear in a message body (this is why you may see "From" in messages prefixed with some character when using mailbox files).
There are other tools that can parse mailbox files e.g. Mail::Box (which I have not used) that might have better error messages than mailx.
| Why does mailx see 0 messages in my mbox file? |
1,485,760,371,000 |
When entering personal preferences like retain [email protected] inside command line mail, how can I have these saved so they are reloaded the next time I start mail?
|
There is no direct way to save the current settings. Instead, you have to write the desired settings to the user startup file, ~/.mailrc.
This is referenced in the manual page for mailx (see man mailx), which says,
At startup time, mail will execute commands in the system command file, /etc/mail.rc, unless explicitly told not to by using the -n option. Next, the commands in the user's personal command file ~/.mailrc are executed. mail then examines its command line options [...]
Here is an example, taken straight from /etc/mail.rc on my (Debian) system. As you can see the syntax is identical to that used on the command line:
set ask askcc append dot save crt
ignore Received Message-Id Resent-Message-Id Status Mail-From Return-Path Via Delivered-To
| How to retain retain et. al. in mail(x) |
1,485,760,371,000 |
I'm sending email from a script using mailx. The script is run daily by systemd, using .service and .timer files. For testing purposes I'm sending from the command line.
The mail is sent with the command
echo "Test message - you know the drill" | mailx -r "[email protected]" -s "Test Message" [email protected]
(personal data replaced for privacy)
This works. It's relayed by postfix to my gateway server (also postfix) which signs the outgoing message. This is then delivered to GMail which verifies the SPF data and DKIM signature, and the message is delivered to my inbox.
This is good, except it's displayed as Ubuntu <[email protected]>
I have other servers sending mail by the same method, and they all display similarly.
I'd like to change the display name to something more useful, per server. For example, Web Server <[email protected]> but something I'm doing is messing up the From address as it travels to the gateway server.
I've tried
echo "Test message - you know the drill" | mailx -r "Web Server [email protected]" -s "Test Message" [email protected]
and
echo "Test message - you know the drill" | mailx -r "Web Server <[email protected]>" -s "Test Message" [email protected]
But in both cases the From address is somehow lost by the local PostFix, and the message sent to the gateway server has a from address of [email protected] where smtp.private.example.uk is the FQDN of the gateway server. This is sent to GMail, but fails the SPF and DKIM tests and is unceremoniously dumped in spam as a result. (I don't know how the local postfix is getting the name of the gateway server)
So, how can I add the display name to the parameters I pass to mailx such that it survives the journey from server to server and is displayed correctly by GMail?
Mailx version 3.14 (GNU Mailutils)
Ubuntu 22.04
I've made only one change to main.cf for PostFix: added a relay-host address for the gateway server.
|
Since you want to use pre-installed programs and because you have postfix installed, we can use a postfix mode to give you greater control of what you send and how it looks.
This is done via sendmail -t. In this mode we use postfix as a mail submission agent (MSA), which is what mailx does anyway, and you can specify the whole header and body, and postfix will send it "as is"
A simple method is to use echo.
e.g.
echo "From: My name <me@myaddress>
To: You <you@youraddress>
Subject: You'll never guess what...
This is a test!" | /usr/sbin/sendmail -t
This lets you set any header to any value you like.
Now this doesn't change the envelope sender so the original name is visible in other lines, so it's not perfect (but you'd get that with mailx if the From address doesn't match the account's address), but it avoids any complications mailx or other mail user agents (MUAs) may bring in.
| How to include a display name when sending mail with mailx |
1,485,760,371,000 |
I am using mail from GNU Mailutils to read the contents of a Maildir. For emails that have already been marked as read, is there a way to mark them as unread in mail?
|
Update:
As of GNU Mailutils version 3.14 (released on 2022-01-02), GNU Mailutils implements the "unread" command. An email can be marked as unread by pressing U.
Old answer:
This feature is not mentioned in POSIX mailx, and is not implemented by GNU Mailutils' mailx. S-nail and the BSDs' mailx support an unread command to mark emails as unread. However, BSD implementations of mailx do not support the Maildir format, so the solution is to use S-nail, which supports the Maildir format. Alternatively, one could move away from mailx and switch to using a simple email client such as Mutt.
| mail: How do I mark an email as unread? |
1,485,760,371,000 |
I am running Oracle Linux 7 for the purpose of hosting an Oracle database.
As part of this process I run a script that mails a log file at the end on a daily basis.
Crux of my issue is that my script executes the mailx command as root with no issue. When I run as the normal operation user "oracle", it fails with this error:
temporary mail file: No such file or directory
The failing command is:
cat $ORACLE_BASE/admin/DBSID/dpdump/EXPORT.log | mailx -r "[email protected]" -s "subject" -S smtp="10.10.10.10:25" [email protected]
I have already verified that the oracle user is in the mail group and have checked that the /TMP directory is of standard permission values. I have also checked the permissions of the spool directory and its subfiles.
|
See Jim L. comment on my question. It drove me to the answer. I had a bad export command that referenced /Tmp. Altering this to what it should have been (/tmp) fixed the issue. Lord save me from dumb typos.
| mailx execution as non-root failing |
1,437,580,070,000 |
There are two messages in /var/mail/test.
mail
Mail version 8.1.2 01/15/2001. Type ? for help.
"/var/mail/test": 2 messages 2 new
>N 1 test@test Tue Feb 17 15:07 18/628 *** SECURITY information fo
N 2 test@test Tue Feb 17 15:25 18/628 *** SECURITY information fo
How to get the whole subject line of message 1 displayed in my console?
How to get the body of the message 1 displayed in my console?
|
Use Linux command line syntax as
Read email if you have only email.
echo p|mail |grep -A 1 "^Subject:"
Read 1st email, change the number you want to read email.
echo 'type 1'|mail |grep -A 1 "^Subject:"
| How to display entire subject line in `mail`? |
1,437,580,070,000 |
I have set some email server(postfix with tsl3) and i have reach the goal
to remove ssl2 from it,but thunderbird works perfect,mailx no.
I did
echo prova|mail -S smtp-use-starttls user@domain
and all mail are bounced
said: 530 5.7.0 Must issue a STARTTLS command first (in reply to MAIL FROM command))
I use this configuration
master.cf
smtp inet n - n - - smtpd
-o smtpd_sasl_auth_enable=yes
-o smtpd_enforce_tls=yes
-o smtpd_client_restrictions=permit_sasl_authenticated,permit_mynetworks,reject
main.cf
smtpd_sender_restrictions =
permit_sasl_authenticated,
permit_mynetworks,
reject_non_fqdn_sender,
reject_sender_login_mismatch,
reject_authenticated_sender_login_mismatch,
reject_unauthenticated_sender_login_mismatch,
reject
# TLS parameters
smtp_use_tls=yes
smtpd_use_tls=yes
smtpd_tls_received_header = yes
smtp_tls_note_starttls_offer = yes
smtpd_tls_auth_only = no
smtpd_tls_CAfile = /etc/ssl/certs/domain.local.crt
smtpd_tls_cert_file=/etc/ssl/certs/slackware.domain.local.crt
smtpd_tls_key_file=/etc/ssl/private/slackware.domain.local.key
smtpd_tls_mandatory_ciphers = high
smtpd_tls_mandatory_exclude_ciphers = aNULL, MD5
smtpd_tls_mandatory_protocols = SSLv3
Thunderbird ok,but mailx no,i try
mail -S smtp-use-starttls
Of course mail is linked with ssl.
|
Solution found
On main.cf
smtpd_tls_mandatory_protocols = !SSLv2, !SSLv3
smtpd_tls_protocols = !SSLv2, !SSLv3
smtp_tls_mandatory_protocols = !SSLv2, !SSLv3
smtp_tls_protocols = !SSLv2, !SSLv3
on master.cf
smtp inet n - n - - smtpd
-o smtpd_sasl_auth_enable=yes
-o smtpd_client_restrictions=permit_sasl_authenticated,permit_mynetworks,reject
Ssl3 and 2 disabled and mail received
| ssl3 mailx and bounce |
1,437,580,070,000 |
I am trying to attach multiple files in Unix, which are the result of a find command. When I try to send the mail, the attachments are missing.
dir=$path
echo "Entered into $spr/sum_master"
for fil in `find $dir -ctime -2 -type f -name "Sum*pdf*"`
do
uFiles=`echo "$uFiles ; uuencode $fil $fil"`
done
\($uFiles\) | mailx -s "subject" [email protected]
What is wrong with this code?
|
If uFiles ends up containing the string foo bar qux, then the last line runs the command (foo with the arguments bar and qux). This results in the error message (foo: command not found (or similar), and mail gets an empty input.
That's not the only problem with the script. The command that builds up the uFiles variable doesn't do at all what you think it does. Run bash -x /path/to/script to see a trace of the script, it'll give you an idea of what's happening. You're echoing the uuencode command instead of running it. You don't need echo there:
uFiles="$uFiles
$(uuencode "$fil" "$fil")"
That will make the loop work, but it's brittle; in particular, it will break on file names containing spaces and other special characters (see Why does my shell script choke on whitespace or other special characters? for more explanations). Parsing the output of find is rarely the easiest way to do something. Instead, tell find to execute the command you want to execute.
find "$dir" -ctime -2 -type f -name "Sum*pdf*" -exec uuencode {} {} \;
The output of that is the concatenation of the uuencoded files that you were trying to build. You can pass it as input to mail directly:
find "$dir" -ctime -2 -type f -name "Sum*pdf*" -exec uuencode {} {} \; |
mailx -s "subject" [email protected]
If you want to detect potential failures of the uuencode step, you can stuff it into a variable (but beware that it might be very big):
attachments=$(find "$dir" -ctime -2 -type f -name "Sum*pdf*" -exec uuencode {} {} \;)
if [ $? -ne 0 ]; then
echo 1>&2 "Error while encoding attachments, aborting."
exit 2
fi
if [ -z "$attachments" ]; then
echo 1>&2 "Notice: no files to attach, so mail not sent."
exit 0
fi
echo "$attachments" | mailx -s "subject" [email protected]
Alternatively, write a temporary file.
attachments=
trap 'rm -f "$attachments"' EXIT HUP INT TERM
attachments=$(mktemp)
find "$dir" -ctime -2 -type f -name "Sum*pdf*" -exec uuencode {} {} \; >"$attachments"
if [ $? -ne 0 ]; then
echo 1>&2 "Error while encoding attachments, aborting."
exit 2
fi
if ! [ -s "$attachments" ]; then
echo 1>&2 "Notice: no files to attach, so mail not sent."
exit 0
fi
mailx -s "subject" [email protected] <"$attachments"
| Attachment missing in Unix mail when multiple files were attached |
1,437,580,070,000 |
This is what I tried:
$ mailx -s "test email" cloud
Cc:
"again and agina"
.
EOT
Or,
$ mailx -s "test email" cloud
Cc:
"this is the first email"
<< EOT
But after pressing Enter nothing happens.
Why?
|
There is nothing magical about the thee-letter-string EOT. You have probably seen it used as a delimiter in here-document redirections in shell scripts from time to time. Almost any word may be used as a delimiter for a here-document redirection, although it's customary to use a short-ish descriptive word written in all upper-case letters; so you could, for example, send a message with mailx by giving the utility the message on its standard input stream like so:
mailx -s 'test message' myself <<'END_MESSAGE'
This is the message.
Possibly on many lines.
END_MESSAGE
This would use mailx non-interactively to send an email consisting of two lines of text to the user myself. The body of the message is quoted, i.e., the shell won't try to expand variables etc., in it, due to the quoting of the initial delimiter ('END_MESSAGE').
However, from seeing the two commands in the question, you appear to want to use mailx interactively to type a message into the utility.
If you have had the dot option set in your ~/.mailrc file (set dot), then typing a single dot on a line by itself as you did in the first part of your question would end the message body and cause the email to be sent:
$ cat ~/.mailrc
set dot
$ mailx -s 'test message' myself
Cc:
This is the message.
Possibly on many lines.
.
Typing the lone dot and pressing Enter causes the message to be sent.
If you don't have the dot option set or if you have the nodot option set in ~/.mailrc, the message body is instead ended using Ctrl+D on an otherwise empty line.
Pressing Ctrl+D sends (commits, submits) the current line to the program waiting for input, and if the current line is empty, this will signal the end of input. This is true not just for mailx but for most programs reading interactive input from their standard input stream.
Using . on an empty line is also how you signal the end of user input in the ed editor when finishing entering text after issuing the i, a, or c command to insert, append or change the text in the current editing buffer. It wouldn't surprise me if mailx inherited this custom from ed.
| Why doesn't "EOT" end the message body and send the message when using "mailx"? |
1,437,580,070,000 |
When logged into my server via SSH the $ mail command doesn't work properly. Instead of returning the list of mail it returns No mail for <user>.
$ mail works correctly when on a terminal at the machine, so it's definitely an issue with using SSH, which is how I will need to access it.
|
I'm able to correctly read user mails by giving in input the file path:
mail -f /var/spool/mail/$USER
I also encountered some issue reading (root)user email, I ssh logged in with user phil, then I changed user to root typing sudo su and then issuing mail command I got:
No mail for phil
So it seems that mail command try to read the email of the user with whom you opened the ssh connection. And as it came out the cause is a wrong value of $MAIL variable:
[root@preprod ~]# echo $MAIL
/var/spool/mail/phil
| How to make 'mail' command work properly via SSH? |
1,437,580,070,000 |
I'm trying to BCC e-mails through unix using the following command.
echo "E-mail message" | mailx -r [email protected] -s "E-mails Subject" ~b [email protected]
But I get the error ~b... User unknown.
If I use -b instead of ~b, I get the error illegal option -- b
If I use mail instead of mailx, I get exactly the same erros.
However, when I try it interactively in the following way, it works.
mail -r [email protected] -s Subject [email protected]
~b BCC_Receiver
E-mail message
.
CC:
I'd like to make this work in a single command. How can I do this?
When I type uname -a, this is the output: s00va9939577 1 7 00CD96834C00.
|
The -b option, to specify addresses on the command line, does not appear to be supported on your version.
Your second, interactive example works because mailx recognises it as tilde escape. These have to appear as the first thing on the line in the message body, rather than on the command line. They're in the specification, so they are more widely supported.
The following commands can be entered only from input mode, by beginning a line with the escape character (by default, <tilde> ( '˜' ))
[...]
~b name . . .
Add the names to the blind carbon copy (Bcc) list.
| Can't send mails with BCC using mailx "illegal option -- b" |
1,437,580,070,000 |
I am writing a program that will be sending external emails using postfix with the mail -s command and I need to verify that the email was sent to the specified address.
In which case, I am curious if postfix right away reports an error that I am able to get as a return code if email failed sending or if postfix will say it was a success as long as a valid email ([email protected]) was entered and then later report in a log file or such that the email was unable to be sent?
Also if the network is down, will postfix still return success as long as a valid email address is used, or will a failure be reported right away?
|
If your postfix configuration is set for logs you can check the logs for the status of a message.
It will contain information such as:
Mar 25 16:07:40 serverName postfix/smtp[3113]: B169ZZZ24F: host foo.net.mx1.name.foo.net[1.2.3.4] refused to talk to me: 421 Offline: HELO/FDNS
Mar 25 16:07:40 serverName postfix/smtp[3036]: 7ZZZFC2440: to=<[email protected]>, relay=mtaz.amz.yahoodns.net[66.196.118.35]:25, delay=11, delays=0.35/0/0.6/9.9, dsn=2.0.0, status=sent (250 ok dirdel)
Mar 25 16:07:36 serverName postfix/smtp[3073]: ZZZZ3C623E: to=<[email protected]>, relay=none, delay=0.55, delays=0.35/0/0.2/0, dsn=5.4.4, status=bounced (Host or domain name not found. Name service error for name=customer.com type=A: Host not found)
This info can be retrieved via a script with lines like: (Not my work. Thanks to whom ever, this is used everyday.)
grep 'status=sent' /var/log/mail.log | awk '{print $7}' | sed 's/to=<//g' | sed 's/>,//g'
grep 'status=deferred' /var/log/mail.log | awk '{print $7}' | sed 's/to=<//g' | sed 's/>,//g'
grep 'status=bounced' /var/log/mail.log | awk '{print $7}' | sed 's/to=<//g' | sed 's/>,//g'
| Does postfix using mail command report if an email was unable to be sent to an address? |
1,437,580,070,000 |
How to increase the width of listings in mail command prompt? Especially the message listing with the command h.
The current listing is truncated at 80 characters as showing below:
$ mail
Mail [5.2 UCB] [AIX 5.X] Type ? for help.
"/var/spool/mail/root": 467 messages 1 new 467 unread
U463 daemon Mon Mar 29 10:21 35/1291 "Output from cron job nice -n"
U464 daemon Mon Mar 29 10:26 32/1063 "Output from cron job nice -n"
U465 daemon Mon Mar 29 10:31 32/1065 "Output from cron job nice -n"
U466 daemon Mon Mar 29 10:51 32/1065 "Output from cron job nice -n"
>N467 daemon Mon Mar 29 11:21 32/1131 "Output from cron job nice -n"
?
It respects the pts total lines but not the columns:
$ echo "$COLUMNS x $LINES"
120 x 35
|
I do not think this is possible.
After examining the strings of /usr/bin/mail I choose two of them as how the message summaries are presented:
%c%c%3d To %-13.13s %16.16s %8s
%c%c%3d To %-13.13s %16.16s %8s "%s"
Further, I found an approximate of this 'mail' program.
UCB Mail Version 5.2 (6/21/85)
(I'll look for an alternative OSS program and see if I can port that to AIX.)
| Increasing the width of messages listing in mail prompt |
1,437,580,070,000 |
I'm trying to:
Attach multiple files into one email.
Have the email sent out using a Gmail account with the current date and time in the subject header.
I'm having trouble with the for a loop since I don't want to create multiple emails I just one to create one email with all the attachments included and have the current date and time used in the subject line.
#!/bin/bash
# to run type "bash email_live_listing.sh"
dt_now_start=`date +"%Y-%m-%d %T"`
fn_dt_now_start=`date '+%Y_%m_%d__%H_%M_%S'`; #use to generate file name with date
currentdir="$(pwd)" #get current directory
ls $currentdir/us*.pdf -tp | grep -v '/$fn_pdf' #place files into variable
echo "$fn_pdf"
ITER=0
for t in ${fn_pdf[@]}; do
swaks --to [email protected] -s smtp.gmail.com:587 -tls -au [email protected] -ap password --header "Subject: Updated file ${fn_dt_now_start}" --body "Email Text" --attach-type ./${fn_pdf} -S 2
let ITER+=1 #increment number
done
Ps: I'm using Ubuntu and Swaks since it's compact and lightweight, and will be run from a raspberry pi, but I'm willing to try other options.
|
Here's a bash script that might help others out that I got to work.
#!/bin/bash
currentdir="$(pwd)" #get current directory
fn_dt_now_start=`date '+%Y_%m_%d__%H_%M_%S'`; #use to generate date time
fn_txt=$(ls $currentdir/*.txt) #place txt files found into a variable
for t in ${fn_txt[@]}; do
attach_files="${attach_files} --attach-type ${t}" #will build list of files to attach
done
swaks --to [email protected] -s smtp.gmail.com:587 -tls -au [email protected] -ap <email_sending_from_password>] --header "Subject: Listings - ${fn_dt_now_start}" --body "Listings Email Text" ${attach_files} -S 2
| Attaching multiple files using bash and emailing it out using SWAKS or another program |
1,437,580,070,000 |
How can I pass a full raw/MIME message (raw file) to the Linux mailx command for delivery? I don't want to extract the recipient, subject, body etc from the message - I want to feed a complete existing raw mail message 'as is' to mailx for sending whilst retaining all existing headers.
An example message is as follows:
Received: (qmail 32389 invoked by uid 0); 13 Jun 2017 09:24:51 -0400
Date: Tue, 13 Jun 2017 09:24:51 -0400
From: [email protected]
To: [email protected]
Subject: Test Email
Message-ID: <593fe7a3.IgSR+/BLy+NYXlVZ%[email protected]>
User-Agent: Heirloom mailx 12.5 7/5/10
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
The test mail content
So I want to be able to feed the above to the mailx command on the command line.
The purpose of this is to make the server deliver the original message (exactly as it was read from the raw message file) via a secondary SMTP server - to do this we would use mailx's -S switch to specify the secondary SMTP server eg:
mailx -S smtp="backup-mail-server.com:25" < feed in the MIME message here somehow
How can I do this with mailx?
|
mailx -S smtp="backup-mail-server.com:25" < mailx -p -f /var/mail/nobody
This will read the RAW mail file, and pipe it into your send.
| Send raw message with mailx command |
1,437,580,070,000 |
Good Day, I'm still new in Linux CLI and I'm using RHEL 6. I'm executing command for sending email via terminal.
$ cat log.txt | mail -s "Logs" [email protected]
Hosted by outlook365
When I try this command, nothing happens. No errors but nothing happens.
Any tips?
Thank you.
|
Check the /var/log/maillog to see the logs related to the email being sent. Are the logs logging any errors?
| Executing command for sendmail not working |
1,437,580,070,000 |
I usually configure exim4 and bsd-mailx to send mail, via GMail or Google Apps, on my Debian machines. I use a very simple mail sent by smarthost; no local mail Exim configuration. I've always tested mailx with the following command:
/usr/bin/mailx -s "testing" "[email protected]" <<< "testing."
sudo exim4 -qff -v
However, it seems like the recipient I specify on the command line is ignored now, specifically when I use a different smarthost. I get the following output from the above commands:
LOG: queue_run MAIN
Start queue run: pid=25326 -qff
delivering 1ZHzbA-0006a6-2w (queue run pid 25326)
LOG: MAIN
Unfrozen by forced delivery
R: smarthost for me@example
T: remote_smtp_smarthost for me@example
Connecting to [removed]:25 ... connected
SMTP<< 220 *******************************************************************
SMTP>> EHLO example.localnet
SMTP<< [removed] Hello example.localnet [removed], pleased to meet you
250-SIZE 100000000
250-PIPELINING
250-8BITMIME
250 XXXA
SMTP>> MAIL FROM:<> SIZE=2266
SMTP>> RCPT TO:<me@example>
SMTP>> DATA
SMTP<< 250 Sender <> OK
SMTP<< 550 No such domain at this location
SMTP<< 503 Bad sequence of commands
SMTP>> QUIT
LOG: MAIN
** me@example R=smarthost T=remote_smtp_smarthost: SMTP error from remote mail server after RCPT TO:<me@example>: host [removed]: 550 No such domain at this location
LOG: MAIN
Frozen (delivery error message)
LOG: queue_run MAIN
End queue run: pid=25326 -qff
Note the difference in the recipient address I attempted to specify and the RCPT TO address that was actually used. As a possible hint of what's happening, the command mailx -s "test" will give the following error:
mailx: You must specify direct recipients with -t when -s, -c, or -b is used
However, the manpage for bsd-mailx makes no mention of the -t switch and it doesn't indicate using the -s switch is going to affect the command's behavior.
I can probably figure out how to make it work with the -t switch, but I'm wondering if it's possible to get it working the way I'm used to. Any suggestions?
|
There's no -t option for bsd-mailx, it's a bug regarding that error message. You could pass recipient addresses as simple arguments to mailx.
I suppose you are seeing delivery failure of a bounce mail: a mail to notify sender that develivery failure occured for a mail sent previously.
Your first mail must have been sent by local exim as from me@example (example is hostname?) to [email protected] (you specified it with mailx), but it's refused by the smart host (bounced), so bounce mail from <> to me@example was newly composed and sent by local exim, then it's also refused by the smart host (double bounced).
Check the delivery log (/var/log/mail.log?) of your smart host and its configuration. Is it configured to accept or relay mails to [email protected]?
| Can I specify a command line recipient using bsd-mailx and Debian 8? |
1,437,580,070,000 |
I need to send an email from my Ubuntu 12.04 machine. I am using mailx command to do that. Below is the command I am using which works fine.
echo "Test server started at `date +"%F %T"` on `hostname -f`" | mailx -r "[email protected]" -s "Test Email" "[email protected]"
But when I get an email, I see in my From section as [email protected] and in my To section, I can see [email protected] and [email protected].
Why not it is showing [email protected] in my From and only [email protected] in To once I get an email.
In general what I am trying to do is - I need to send an email from [email protected] to [email protected] so that in From section I should see [email protected] and in To section I should see [email protected] in my email instead of my machine name in the From section.
It looks to me that we need to change something while installing mailutils? I installed it using sudo apt-get install mailutils
How to send an email using mailx so that From and To appear correctly in the email?
I am running Ubuntu 12.04 -
david@machineA:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 12.04 LTS
Release: 12.04
Codename: precise
|
I believe mailutils doesn't support the -r option. Replace it with the heirloom-mailx package which does support the -r option (or use sendmail -r [or -f]).
http://manpages.ubuntu.com/manpages/lucid/man1/mail.1.html
-p, -r, --print, --read
print all mail to standard output
Install:
sudo apt-get install heirloom-mailx
| How to send an email using mailx so that From and To appear correctly in the email? |
1,437,580,070,000 |
Usually I only get the terminal output You have new mail in /var/mail/$USER after running certain upgrades but I've started getting it every couple days after running other commands, seemingly at random. The new mail in /var/mail/$USER is always to akin to this:
Message-Id: <E1YHfKT-0008LI-2d@debianator>
From: root <root@debianator>
Date: Sat, 31 Jan 2015 22:11:45 +0100
Adapter 0: off-line
Note that it doesn't happen every time i plug put the AC adapter.
I use a simple bash script (run by udev) to hibernate when battery is low and the AC adapter isn't connected. The script uses acpi to detect the latter and has been working for years without mailing me.
So what service could be mailing Adapter 0: off-line to me?
EDIT:
Below is the script I use to hibernate on low battery. On further inspection, I definitely think it's related. Note the if acpi -a | grep 'off-line' lines. When I run acpi -a | grep 'off-line I get the output Adapter 0: off-line. That is the exact output that is send to my mail - so how do I stop it?
Here is the script:
#!/bin/bash
# Critical battery level (acpi reports it at 5%)
CRITICAL=6
battery_level=`acpi -b | grep -o [0-9]*% | sed s/%//`
if [ ! $battery_level ]
then
exit
fi
if [ $battery_level -le $CRITICAL ]
then
if acpi -a | grep 'off-line'
then
# Warning
sudo -u andreas DISPLAY=":0.0" notify-send -u critical "Gimme power"
sleep 60s
if acpi -a | grep 'off-line'
then
sudo -u andreas DISPLAY=":0.0" notify-send -u critical "Shutting down"
sleep 2s
/bin/systemctl hibernate
fi
fi
|
It sounds like when a cronjob creates output, and it gets mailed to you.
I have no idea why this output is being mailed to you. But if you think it's from the script, maybe you could suppress the output:
- if acpi -a | grep 'off-line'
+ if acpi -a | grep 'off-line' >/dev/null
| Why do I get mail when I unplug my adapter? |
1,437,580,070,000 |
I am using RHEL 6.4. I have a script which runs in bash. The script sends an email using the command:
mailx -a report.txt "Monthly Report" "[email protected]" < messageBody.html
where report.txt is a pipe separated text file. The size of this file is unknown; sometimes this file may contain just 10-15 records, on other days it may have millions of records.
Now my questions are:
How do I determine what is the maximum file size that can be sent as an attachment?
How to change that size?
|
To check maximum size on systems using postfix as their mail transport agent, we can use the postconf command.
postconf -d | grep message_size
It will show you the size in bytes.
To change the value, Run
postconf -e 'message_size_limit = 20480000'
To make the changes effective, restart Postfix afterwards:
service postfix restart
(or equivalent on your system)
| What is the maximum size for attachment using unix mailx |
1,437,580,070,000 |
I am using uuencode with mailx to attach a zip file. In following code, the if block works perfectly and I get Deletions.zip as an attachment in the email. But, whenever the else block is executed I don't get the attachment but the binary code in the email body instead.
Code (Perl code invoking linux commands):
open(EF,'>', "/test/emailbody.txt") or die $!;
if ($#dzones != -1) {
unshift @dzones, "Following files have 20% or more deletions --\n\n";
unshift @dzones, "Start time: $localtime\n\n";
my $localtime = scalar localtime();
push @dzones, "End time: $localtime\n\n";
print EF @dzones;
`cd /test/DOUT/; zip -q9 /tmp/deletions.zip ./*.*`;
`(cat /test/emailbody.txt;uuencode /tmp/deletions.zip Deletions.zip) | mailx -s "Device deletions" vishal\@test.com`;
} else {
push @dzones, "No files have more than 20% deletions.\n\nPlease see attached for the deletions in different zones.\n\nThanks, Vishal\n\n";
print EF @dzones;
`cd /test/DOUT/; zip -q9 /tmp/deletions.zip ./*.*`;
`(cat /test/emailbody.txt;uuencode /tmp/deletions.zip Deletions.zip) | mailx -s "Device deletions" vishal\@test.com`;
}
close(EF);
When else block is executed, all I get is:
begin 644 Deletions.zip
M4$L#!!0``@`(`.U6,D4]>N/[=0$``&@&```D`!4`9&5L7VYE7T%L8F5R=&%?
… [snip] …
+`"H+``"R'```````
`
end
What am I doing wrong?
|
It looks like the causing problem is being caused during looping of while cat /test/emailbody.txt;
Remove the "," while printing in file. Following line of code has this problem:
push @dzones, "No files have more than 20% deletions.\n\nPlease see attached for the deletions in different zones.\n\nThanks, Vishal\n\n";
| Uuencode displaying attachment content in email body |
1,437,580,070,000 |
Well I have searched some of the possibilities to install command line mail clients but there are no easy ways to install. Is this even possible without compiling the mail client ?
|
Funny thing, almost 3 years later I am unable to find any progres regarding answering that question, today at LibreElec.
If it helps someone: to send an e-mail from my LibreElec Raspberry Pis, I ssh to my router and send an e-mail using the router. This is absolutelly the simplest solution. Actually, I consider that way beter than using separate mailers on separate (and different) systems. This way, I allways use the same syntax and the same program in the same way - regardles of the device sending me an e-mail.
Workaround can make use of any other device capable of doing it, it needent be a router. Obviously, you need to have such a mail sending device.
The actual code from my RPi script and Asus routers is (minus the obvious variables and with ssh keys allready authorised):
echo "Subject: Msg from Raspberry" > mail.txt
echo "From: [email protected]" >> mail.txt
echo "Date: `date -R`" >> mail.txt
cat mail.txt | ssh [email protected] "/usr/sbin/sendmail -S"$MAIL_SERVER" -f"$MAIL_TO" $MAIL_TO $MAIL2_TO"
rm mail.txt
A reminder: for the script to work from RPi LE autostart.sh when RPi is booting, one must use /storage/mail.txt (and not the relative form as in simplified sample above).
| Installing mailx on Openelec, Raspberry PI |
1,437,580,070,000 |
I've to send a HTML file with mailx command but when I receive the email with the mark up code showed like this :
<HTML><HEAD><TITLE>Title One /TITLE> <STYLE> body { width:900px; font-size: 10pt; font-family:verdana;
.../...
I used this command :
cat file.html | mailx -r [email protected] -s "Suject" -S content_type=text/html -S smtp=smtp.acme.com [email protected]
I tried this one too
cat file.html | mailx -a 'Content-Type: text/html' -r [email protected] -s "Suject" -S content_type=text/html -S smtp=smtp.acme.com [email protected]
I got this error message with this last one above :
Content-Type: text/html: No such file or directory
What is missing in the -a option ?
|
My mailx version is :
Heirloom mailx 12.5
This command solved my issue :
(echo "Content-Type: text/html"; cat file.html ) | mailx -r [email protected] -s "Suject" -S content_type=text/html -S smtp=smtp.acme.com [email protected]
| How to mailx working with Content-Type: text/html |
1,437,580,070,000 |
How do I specify a default sender 'from:' address in postfix config for emails through smtp?
I'm trying to send emails through SMTP and a relay from two different servers with Oracle Linux 8
The problem is that on one server when you send an email without the '-r' option to specify a sender it doesn't work returning the following message:
A Sender: field is required with multiple addresses in From: field.
No such file or directory
"/root/dead.letter" 1/6
. . . message not sent.
On the other server, sending an email like this works properly and it sends an email as [email protected]
I'll attach consoles of the attempts on both servers:
Sending Email without -r Option in Server 1
Linux server 5.4.17-2102.201.3.el8uek.x86_64 #2 SMP Fri Apr 23 09:05:57 PDT 2021 x86_64 x86_64 x86_64 GNU/Linux
NAME="Oracle Linux Server"
VERSION="8.4"
ID="ol"
ID_LIKE="fedora"
VARIANT="Server"
VARIANT_ID="server"
VERSION_ID="8.4"
PLATFORM_ID="platform:el8"
PRETTY_NAME="Oracle Linux Server 8.4"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:oracle:linux:8:4:server"
HOME_URL="https://linux.oracle.com/"
BUG_REPORT_URL="https://bugzilla.oracle.com/"
ORACLE_BUGZILLA_PRODUCT="Oracle Linux 8"
ORACLE_BUGZILLA_PRODUCT_VERSION=8.4
ORACLE_SUPPORT_PRODUCT="Oracle Linux"
ORACLE_SUPPORT_PRODUCT_VERSION=8.4
[root@server1 ~]# mailx -s "SMTP" [email protected]
test.
.
EOT
A Sender: field is required with multiple addresses in From: field.
No such file or directory
"/root/dead.letter" 1/6
. . . message not sent.
[root@server1 ~]#
Sending email without -r in Server 2
Linux server 5.4.17-2102.201.3.el8uek.x86_64 #2 SMP Fri Apr 23 09:05:57 PDT 2021 x86_64 x86_64 x86_64 GNU/Linux
NAME="Oracle Linux Server"
VERSION="8.4"
ID="ol"
ID_LIKE="fedora"
VARIANT="Server"
VARIANT_ID="server"
VERSION_ID="8.4"
PLATFORM_ID="platform:el8"
PRETTY_NAME="Oracle Linux Server 8.4"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:oracle:linux:8:4:server"
HOME_URL="https://linux.oracle.com/"
BUG_REPORT_URL="https://bugzilla.oracle.com/"
ORACLE_BUGZILLA_PRODUCT="Oracle Linux 8"
ORACLE_BUGZILLA_PRODUCT_VERSION=8.4
ORACLE_SUPPORT_PRODUCT="Oracle Linux"
ORACLE_SUPPORT_PRODUCT_VERSION=8.4
[root@server2 ~]# mailx -s "SMTP" [email protected]
test
.
EOT
[root@server2 ~]#
|
There are many versions of the mail program, including GNU mailutils and bsd-mailx.
As mail on server2 seems to work correctly, make sure that server1 has the same version as server2.
Use /usr/sbin/sendmail instead of mail to send your message. You're using postfix on both machines, and postfix's sendmail command understands both -r and -f options to set the sender address. See man postfix for details and more options.
| Oracle Linux postfix conf SMTP - Default sender 'from' issue |
1,437,580,070,000 |
I'm trying to make a Bash function like this:
function send_email {
local DEFAULT_EMAIL='[email protected]'
local email_subject="${1:-No subject line set, please check $0 on $(hostname -f)}"
local email_from="${2:-$DEFAULT_EMAIL}"
local email_to="${3:-$DEFAULT_EMAIL}"
mailx -s "$email_subect" -r "$email_from" "$email_to"
}
If I invoke it with something on stdin (echo foo | send_email "bar"), it works fine, mailx picks up the stdin and sends the mail, which arrives just fine. However, if there is nothing on stdin then mailx waits for input, even with -E set.
If it were just me, I'd just know that the function always needs to have something on stdin to work properly but I need to ensure this is easy to use by people less technical than myself.
Is there a way to rig it up to use stdin if available and use /dev/null if stdin is empty?
|
if dd of=stdindata iflag=nonblock >/dev/null 2>&1; then
mailx -s "$email_subect" -r "$email_from" "$email_to" <stdindata
else
mailx -s "$email_subect" -r "$email_from" "$email_to" </dev/null
fi
| Function call with stdin or /dev/null if empty |
1,437,580,070,000 |
On AIX, I want the mail program to use /root/.mbox instead of default /root/mbox.
I edit mailrc
vim .mailrc
set MBOX=/root/.mbox
the result is not good
mail
Mail [5.2 UCB] [AIX 5.X] Type ? for help.
"/var/spool/mail/root": 2 messages 2 unread
>U 1 root Tue Jun 22 01:48 13/349
U 2 root Tue Jun 22 01:49 13/349
? 1
Message 1:
From root Tue Jun 22 01:48:58 2021
Date: Tue, 22 Jun 2021 01:48:58 +0200
From: root
To: root
hello
? q
Saved 1 message in /root/mbox
Held 1 message in /var/spool/mail/root
I have tried different setting like those on mailrc
set MBOX=/root/.mbox
set MBOX /root/.mbox
set mbox /root/.mbox
set mbox=/root/.mbox
but still save to /root/mbox
|
Solution found, instead of use this method, valid on old Unix os like Sco Unix System V
myname@scosysv:/usr/myname$ vi .mailrc
".mailrc" 1 line, 19 characters
set MBOX=/usr/myname/.mbox
myname@scosysv:/usr/myname$ echo hello|mail myname
myname@scosysv:/usr/myname$ mail
SCO System V Mail (version 3.2) Type ? for help.
"/usr/spool/mail/myname": 1 message 1 new
>N 1 myname Tue Jun 22 02:04 8/215
& 1
Message 1:
From myname Tue Jun 22 02:04:28 2021
From: [email protected] ()
X-Mailer: SCO System V Mail (version 3.2)
To: myname
Date: Tue, 22 Jun 2021 2:04:28 PDT
Message-ID: <[email protected]>
Status: R
hello
& save
"/usr/myname/.mbox"[New file] 8/215
& Held 0 messages in /usr/spool/mail/myname.
On AIX we use this method
export MBOX=/root/.mbox
echo hello|mail root
mail
Mail [5.2 UCB] [AIX 5.X] Type ? for help.
"/var/spool/mail/root": 1 message 1 new
>N 1 root Tue Jun 22 02:16 12/339
? 1
Message 1:
From root Tue Jun 22 02:16:25 2021
Date: Tue, 22 Jun 2021 02:16:25 +0200
From: root
To: root
hello
? save
"/root/.mbox" [Appended] 12/339
of course the variable can be added on .bashrc file or rc file of your shell.
| Aix: why program mail ignore the mbox setting? |
1,395,153,498,000 |
If I use a MBR partitioning scheme and create a primary or extended partition with fdisk(version 2.20.1), then it starts on sector 2048. If I remember correctly, then older versions of fdisk started the first partition on sector 63. If MBR needs only 512 bytes, then why doesn't the first partition start on sector 2? What is kept on those 2047 sectors? Some stage of the boot-loader?
|
The old 32KiB gap between MBR and first sector of file system is called DOS compatibility region or MBR gap, because DOS required that the partitions started at cylinder boundaries (and each cylinder had 64 sectors i.e. 64 sectors * 512 bytes/sector= 32KiB space).
Legacy GRUB (GRUB1) could've used it to install GRUB1 1.5-stage bootloader there: http://www.gnu.org/software/grub/manual/grub.html#BIOS-installation.
Additional links:
http://www.pixelbeat.org/docs/disk/
https://superuser.com/questions/107235/how-do-boot-sectors-and-multiple-drives-works/108152#108152
http://www.dedoimedo.com/computers/grub.html
| area on disk after the MBR and before the partition start-point |
1,395,153,498,000 |
I have a CentOS 6 server with two hard drives in it. My old 3TB drive has been giving me some issues so I'm moving things over to a new drive. Because my / and /home partition are managed by a LVM it was easy to migrate those to the new drive. Now I want to move over my /boot partition and the MBR that makes it all start up.
I loaded up a live CD and rsynced over my /boot partition to the same size partition on my new drive. I also tried to copy over my MBR with the following commands:
dd if=/dev/sda of=mbrbackup bs=512 count=1
dd if=mbrbackup of=/dev/sdb bs=446 count=1
After doing this I rebooted, told my BIOS not to look at the old hard drive during the boot cycle and only look at the new drive but all I ended up with was a blinking cursor.
Did I miss a step here? Or is there something else I need to do to make things boot so I can completely remove my old drive?
EDIT: I'm starting to think rsync was not the way to copy the /boot partition from one drive to another. Based on this guide, I tried using the dump command instead. In this command I copied my old, unmounted boot partition to my new, empty, mounted boot partition.
dump -0f - /dev/sdaX | (cd /mnt/boot; restore -rf -)
I'm getting a grub error 15 on boot which is better than a blinking cursor but I don't know if that is any closer to a solution.
|
If the two hard-disks are of the same size (or the new one is bigger), why didn’t you just copy the old disk to the new disk? I.e.
dd if=/dev/sda of=/dev/sdb
Now, if the new hard-disk is bigger, change the partition sizes with parted or gparted. All this done booting from a live CD/USB-stick.
| Moving /boot and MBR to a new drive |
1,395,153,498,000 |
I have an HDD (or SSD, or flash drive) with FreeBSD installed on it, and somehow I broke the bootcode (first 446 bytes of MBR). How could I boot into this FreeBSD?
|
Assuming that there is 512-byte DOS-like MBR, and you have replaced first 446 bytes of it with some crap (zeros or just /dev/urandom output), or damaged the bootcode some other way. In this case MBR partition table is on it's place, but system cannot boot from this device.
Idea is to use other BSD-like system's loader to boot with your device and your kernel.
You should start booting to any BSD-like OS (I have tried with FreeBSD 6.0, 7.0, 8.0, 8.1, 8.2, 8.3, 8.4, 9.2 and Frenzy 1.4) from another HDD, CD, flash drive, PXE, virtual media via BMC/KVM, etc.
During boot process hit "Escape to loader prompt" option on loader screen (it would be "6" in older FreeBSD systems, "3" in FreeBSD 9, "8" in Frenzy)
Unload kernel and it's modules by typing unload
Find out the device you want to boot your FreeBSD from (usually something like disk0s1a) by typing lsdev
Set this device "current" by typing set currdev="disk0s1a"
Re-read loder.conf from your device (to be sure that all your kernel tunings and hacks would apply) by typing read-conf boot/loader.conf
Start OS and enjoy - just type boot-conf
When your OS starts, you could repair bootcode. I use sysinstall for it (Custom -> Partition, W, <Yes>, BootMgr ("Install the FreeBSD Boot Manager"), <OK>, Q, <Exit>, <Exit Install>), but it is deprecated since 9.0-RELEASE and removed from base since 10.0-RELEASE. Other way is to use backup, stored in /boot, to extract bootcode from it:
# gpart bootcode -b /boot/mbr /dev/yourbootdevice
| How to boot FreeBSD system with broken bootcode? |
1,395,153,498,000 |
I remembered reading one question how would you back up the MBR of a disk.
Two of the choices are
dd if=/dev/sda of=/dev/sdb bs=512 count=1
dd if=/dev/sda of=/dev/sdb bs=440 count=1
and the correct answer is
dd if=/dev/sda of=/dev/sdb bs=440 count=1
I am confused. Is the MBR size 440B or 512B ?
|
The MBR IS 512 bytes. So the first example is how you would back it up. The partition table is at the end, in the area after 440 bytes in - so, if you wanted to back it up WITHOUT the partition table, then you could use the second example (why you'd want that, I don't know).
| MBR size is 440 bytes or 512 bytes |
1,395,153,498,000 |
I've been examining the Ubuntu 20.04 and Fedora 32 live images, and saw that the first (ISO 9660) partition is set to cover the entire image (at least on the MBR's partition table, didn't check GPT yet). For Ubuntu this is around 2.7 GB; for Fedora it's 1.3 GB. However, after copying these ISOs to a USB stick using dd, gparted shows that the ISO 9660 partition covers the entire 32 GB stick.
Is this a gparted bug? The partition layout is a bit complicated, since the ISO 9660 partition is set to start at LBA 0, effectively covering even the MBR itself. I'm still not sure why this partition must cover the entire image though; I guess it's because when burning it to a DVD, the only filesystem you can have is ISO 9660.
|
We can say that it is a bug in gparted (and a corresponding bug in parted). These tools 'do not understand' the partition structure of iso files when cloned to USB pendrives (and other mass storage devices).
You can look at the drive with modern versions of fdisk and lsblk and get better results.
You can create a partition 'behind' the head of the drive and the image of the iso file. This partition can be used to store data, and even to serve as a partition for persistence in a persistent live system for example with Ubuntu 20.04 LTS and Debian 10 live. You can do it yourself with fdiskand mkfs, or easier with mkusb-plug. The mkusb-plug tools may not work in/with Fedora.
Example where lsblk and fdisk see a cloned live USB drive with Lubuntu:
$ lsblk -o model,name,size,fstype,label,mountpoint /dev/sdc
MODEL NAME SIZE FSTYPE LABEL MOUNTPOINT
Voyager GT 3.0 sdc 29,5G iso9660 Lubuntu 20.04.1 LTS amd64
├─sdc1 1,7G iso9660 Lubuntu 20.04.1 LTS amd64 /media/sudodus/Lubuntu 20.04.1 LTS amd64
└─sdc2 3,9M vfat Lubuntu 20.04.1 LTS amd64
$ LANG=C sudo fdisk -lu /dev/sdc
Disk /dev/sdc: 29,5 GiB, 31641829376 bytes, 61800448 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: 0x2d846e8c
Device Boot Start End Sectors Size Id Type
/dev/sdc1 * 0 3576319 3576320 1,7G 0 Empty
/dev/sdc2 3541360 3549295 7936 3,9M ef EFI (FAT-12/16/32)
| Linux live USB - Why does ISO 9660 partition cover the entire USB stick? |
1,395,153,498,000 |
I'm installing NixOs on a ThinkPad X220. Though I'm very comfortable in the shell, it's the first time I've set up my own system, and I'm running into some unknowns while trying to partition the hard drive with fdisk.
The laptop currently has Windows installed, and I intend to replace it entirely with NixOS. I ran fdisk to see the current partitions and to replace them with a fresh partitioning scheme.
After deleting the original partitions, I created a small (500MB) boot partition, and fdisk reported:
Partition #1 contains a ntfs signature.
Do you want to remove the signature? [Y]es/[N]o:
I'm not sure what this means, and googling "ntfs signature" didn't turn up anything illuminating, so I aborted the whole thing (for now).
Can anyone explain the significance of that warning? Will removing the ntfs signature have adverse affects down the road?
I also wonder if I should try to convert the drive from MBR to GPT, partly because a number of people seem to suggest using gdisk to manage partitions. I'm not sure whether this hardware supports GPT, and whether it boots via BIOS or UEFI.
For reference, a fuller log of my fdisk session:
[root@nixos:~]# fdisk /dev/sda
Welcome to fdisk ...
Command (m for help): p
Disk /dev/sda: 111.8 GiB, 120034123776 bytes, 234441648 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: 0x65f5b331
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 1026047 1024000 500M 7 HPFS/NTFS/exFAT
/dev/sda2 1026048 199606271 198580224 94.7G 7 HPFS/NTFS/exFAT
/dev/sda3 199606272 234441646 34835375 16.6G 5 Extended
/dev/sda5 199608320 234440703 34832384 16.6G bc Acronis FAT32 LBA
Command (m for help): d
Partition number (1-3,5, default 5): 5
Partition 5 has been deleted.
Command (m for help): d
Partition number (1-3, default 3): 3
Partition 3 has been deleted.
Command (m for help): d
Partition number (1,2, default 2): 2
Partition 2 has been deleted.
Command (m for help): d
Selected partition 1
Partition 1 has been deleted.
Command (m for help): p
Disk /dev/sda: 111.8 GiB, 120034123776 bytes, 234441648 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: 0x65f5b331
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-234441647, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-234441647, default 234441647): +500M
Created a new partition 1 of type 'Linux' and of size 500 MiB.
Partition #1 contains a ntfs signature.
Do you want to remove the signature? [Y]es/[N]o:
|
ok, the quick answer is:
Yes, you can remove the ntfs flag, which is a Windows thing, you won't need it when making your NixOs installation.
The second question, well some people prefer GPT over MBR because you can create unlimited partitions on the disk... I use MBR and have 3 primary partitions (3 Linux distros) and one extended partition which is my /home. The thing is that usually, windows must be on GPT partitions, thus if you want to have dual-boot or use UEFI, then you need GPT. On that case, you need to run gdisk to be able to set the GPT label.
| fdisk: partition contains a ntfs signature. remove it? |
1,395,153,498,000 |
I found lot of examples of MBR records on various systems, and they all have same structure, for example - as here.
So - first 512 bytes must have a Code area, Disc signature and Table of partitions.
My disk layout is:
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 596,2G 0 disk
├─sda1 8:1 0 2G 0 part /boot
├─sda2 8:2 0 16G 0 part [SWAP]
├─sda3 8:3 0 500G 0 part
│ ├─kubuntu_vg-root (dm-0) 252:0 0 30G 0 lvm /
│ └─kubuntu_vg-home (dm-1) 252:1 0 470G 0 lvm /home
└─sda4 8:4 0 78,2G 0 part /media/setevoy/4A50CF6C50CF5D77
sr0 11:0 1 1024M 0 rom
Bootable device is sda4 here:
/dev/sda4 * 1086326784 1250260991 81967104 7 HPFS/NTFS/exFAT
And
sda1 = /boot
sda2 = swap
sda3 = LVM physical volume with /home
Now, if I make:
$ sudo dd if=/dev/sda of=/tmp/mymbr bs=512 count=1
and run file on it - I can't see any similar to another MBR's googled:
$ file /tmp/mymbr
/tmp/mymbr: x86 boot sector
While an "correct" (aka - googled) example display partitions, disks's IDs etc:
# file mbr.bin
mbr.bin: x86 boot sector;
partition 1: ID=0×83, active, starthead 1, startsector 63, 40949622 sectors;
partition 2: ID=0×82, starthead 254, startsector 40949685, 2088450 sectors;
partition 3: ID=0x8e, starthead 254, startsector 43038135, 74172105 sectors, code offset 0×48
Size is correct:
$ ls -lh /tmp/mymbr
-rw-r--r-- 1 root root 512 жов 6 11:18 /tmp/mymbr
using hexdump - I can see some data in file, including partitions (466 + 16 bytes):
$ hexdump -C -s 446 /tmp/mymbr
000001be 00 20 21 00 83 35 70 05 00 08 00 00 00 00 40 00 |. !..5p.......@.|
000001ce 00 35 71 05 82 df 72 2d 00 08 40 00 00 00 00 02 |.5q...r-..@.....|
000001de 00 df 73 2d 83 b6 12 24 00 08 40 02 00 00 80 3e |..s-...$..@....>|
000001ee 80 fe ff ff 07 fe ff ff 00 08 c0 40 00 70 c5 09 |[email protected]..|
000001fe 55 aa
But what's wrong with file?
Maybe version?
$ file --version
file-5.14
magic file from /etc/magic:/usr/share/misc/magic
UPD 1
$ sudo fdisk -ls /dev/sda
Disk /dev/sda: 640.1 GB, 640135028736 bytes
255 heads, 63 sectors/track, 77825 cylinders, total 1250263728 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
Disk identifier: 0x6fa60981
Device Boot Start End Blocks Id System
/dev/sda1 2048 4196351 2097152 83 Linux
/dev/sda2 4196352 37750783 16777216 82 Linux swap / Solaris
/dev/sda3 37750784 1086326783 524288000 83 Linux
/dev/sda4 * 1086326784 1250260991 81967104 7 HPFS/NTFS/exFAT
|
You may have luck to see more information including partitions using
file -k # Don't stop at the first match, keep going.
Though on my systems it also does not show the partition table. (file 5.15 and 5.19).
But I wonder why file should print the partition table at all. IMO file is supposed to show what kind of data is it, not the the whole content. Better trust fdisk -l or other well known disk tools.
| Where is partitions in MBR? |
1,395,153,498,000 |
I have a Sony VIAO laptop setup as dual boot (Ubuntu 12.10/Windows 7). Since I wanted to try Archlinux, I installed VirtualBox in Ubuntu. To create a bootable USB stick (from the ISO image on my hard drive), I followed the instructions from archlinux installation guide. However, accidentally gave the following command:
sudo dd bs=4M if=/path/to/archlinux.iso of=/dev/sda && sync
Note /dev/sda instead of /dev/sdb. So the MBR was overwritten here. BAD mistake. Did not realise the mistake at that time and tried to install archlinux in the virtualbox (allocated 8GB of disk space), couldn't complete the process and shutdown.
Now, after booting, I get the first screen of the archlinux installation process. df only shows various partitions made during the archlinux installation process of 8GB of the total 320 GB harddisk.
I had not taken any backup of the MBR. Is there a way to restore the MBR or salvage some data?
Devendra
|
Sorry, but you had a Sony VIAO laptop set up as dual boot. Here's why: dd didn't overwrite just the MBR (i.e. the first 512B sector) - that would be quite annoying, but still fixable. It also took good part of at least the first partition on your hard drive. Unless you had a very interesting setup with system partitions not at the beginning of the dish, it means that at least one of your OSs is gone, since tha file system structures on its system partition are gone and, what's worse, some data as well. Hence even if you managed to reconstruct the partition layout to the original state and the MBR, you would end up with one working system at most.
Now the imminent question is: "What to do next?" and I take the liberty of giving some suggestions.
If you haven't had any important data on the laptop or have a backup (the first lesson of this Q&A), you may skip to number 2.
Recover data
A lot depends on whether you were actually using MBR or GPT which has a backup at the end of the disk. In the first case, you'll have to resort to a partition recovery with e.g. Parted Magic probably making use of TestDisk. For GPT the situation should be easier due to the second copy of GPT at the end of the disk. Recovery should be possible with just a (GPT-enabled) partition editor.
If you can mount all the needed filesystems, then you're done. If not, the other tools shipped with Perted Magic come in handy to help you with recovery.
Re-installation
There are two main points here.
Do you really need dual-boot? In other words: do you need Windows installed natively, or would a VM do? The main reason I can think of for booting Windows natively is anything GPU and/or memory hungry, typically any 3D software, games and anything that can make use of GPU for something else (these days for example Adobe Photoshop). Unless you are often using these, virtualized Windows should give you the same (or better) overall experience (since you can easily snapshot the system, and if you are concerned with security this gives you one more layer of separation between Windows and the world out there).
No matter what the setup is going to be, always have separate partitions for any user data. If you already had it like this, you had much less to worry about when recovering the data. In any case it is the second lesson anybody should take from this Q&A.
Virtualisation
If you already have an ISO image on your disk, the easiest way to boot it is to boot a VM with an empty drive and the ISO file as a CDROM. No need to copy anything anywhere.
| Overwritten MBR: Is partial/complete recovery possible? |
1,395,153,498,000 |
I have one built-in hard disk /dev/sda which looks like this:
Disk /dev/sda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders, total 312581808 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
Disk identifier: 0x00042134
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 293048319 146523136 83 Linux
/dev/sda2 293050366 312580095 9764865 5 Extended
/dev/sda5 293050368 312580095 9764864 82 Linux swap / Solaris
Now I can easily find the MBR with xxd /dev/sda | less, it's located in the first sector. According to Wikipedia the VBR must be in the first sector within the first bootable partition, in my case /dev/sda1. But in the first sector of /dev/sda1 I only see zeroes when I do a xxd /dev/sda1 | less.
I actually thought to find binary code of GRUB in there, where could it be then?
|
It is usually not installed there. Most of the time, GRUB (stage 1) is installed in the MBR only, on Linux.
Although GRUB version 1 will always overflow a little in the 30 kB following the MBR (stage 1.5, i.e. filesystem drivers), with GRUB version 2, the code installed within the MBR can load some other and bigger code (stage 1.5) by raw reading any sectors from the disk (but will usually stick to GRUB 1 behavior -- that is, loading code from the 30 kB after MBR).
Those 30 kB are usually available non-partitionned "free" disk space, because for historical reasons it is pretty rare for the first partition of a disk to start before sector 63, which leaves at least 512*62 = 31 kiB after MBR.
Then, it loads some files, usually from /boot, like the menu (menu.lst or grub.cfg), more filesystem drivers, etc. This is stage 2.
After that, is has enough to launch an OS.
As for the VBR now, it is not commonly used on Linux partitions because it is not reliable enough, but MS Windows usually installs one at the beginning of system (C:\) partitions. GRUB will just execute it if you want to start Windows. This process is called chainloading: a bootloader which launches another one. This also means that the filesystem used there must leave untouched the beginning of its partition, because it could overwrite the VBR otherwise! The amount of "untouched" space available depends on the filesystem, so there is no good guarantee: it could well be very small...
About loading stage 1.5 from an "unusual" place, as I said, GRUB 2 can load its stage 1.5 from any sector on the disk. It may be from a file, but this can be dangerous because the filesystem can decide to move that file to other sectors on the disk anytime (or even worse, fragment it!), and GRUB would need to update the new sector number in the MBR each time...
An interesting case is GUID Partition Tables (GPT). They are too big to ensure that enough space (30 kB) will always be available for stage 1.5. The recommended solution in that case is to use a dedicated "boot loader partition" (not a problem since GPT can support 128 partitions) that will not host a filesystem but GRUB's stage 1.5 data. This way, it shall not move anywere, and you can give it plenty of space.
You should really read wikipedia's GRUB article where I got most of this information.
| Where to find the VBR on the /dev/sda1 partition? |
1,395,153,498,000 |
Under the MBR model, we could create four primary partitions one of which could an extended partition that's further subdivided into logical partitions.
Consider this GPT schematic taking from Wikipedia:
Partition entries range from LBA 1 to LBA 34, presumably we ran out of that space and I understand that's a fair amount of partitions, is it possible to make an extended partition if the disk partitioned with GPT? If possible how many extended partitions per GPT partition table we can make?
I'm not sure if this is a standard to have partition entries within the range LBA 1 to LBA 34, maybe we could expand partition entries beyond that?
Practically this is a fair amount of partitions, I have no intention to do that.
|
128 partitions is the default limit for GPT, and it's probably painful in practice to use half that many...
Linux itself originally also had some limitations in its device namespace. For /dev/sdX it assumes no more than 15 partitions (sda is 8,0, sdb is 8,16, etc.). If there are more partitions, they will be represented using 259,X aka Block Extended Major.
You could certainly still do more partitions in various ways. Loop devices, LVM, or even GPT inside GPT. Sometimes this happens naturally when handing partitions as block devices to virtual machines, they see the partition as virtual disk drive and partition that.
Just don't expect such partitions inside partitions to be picked up automatically.
As @fpmurphy1 pointed out in the comments, I was wrong: You can change the limit, using gdisk, expert menu, resize partition table. This can also be done for existing partition tables, provided there is unpartitioned space (a 512-byte sector for 4 additional partition entries) at the start and end of the drive. However I'm not sure how widely supported this is; there doesn't seem to be an option for it in parted or other partitioners I've tried.
And the highest limit you can set with gdisk seems to be 65536 but it's bugged:
Expert command (? for help): s
Current partition table size is 128.
Enter new size (4 up, default 128): 65536
Value out of range
And then...
Expert command (? for help): s
Current partition table size is 128.
Enter new size (4 up, default 128): 65535
Adjusting GPT size from 65535 to 65536 to fill the sector
Expert command (? for help): s
Current partition table size is 65536.
Eeeh? Whatever you say.
But try to save that partition table and gdisk is stuck in a loop for several minutes.
Expert command (? for help): w
--- gdisk gets stuck here ---
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
22253 root 20 0 24004 11932 3680 R 100.0 0.1 1:03.47 gdisk
--- unstuck several minutes later ---
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): Your option? (Y/N): y
OK; writing new GUID partition table (GPT) to /dev/loop0.
Warning: The kernel is still using the old partition table.
The new table will be used at the next reboot or after you
run partprobe(8) or kpartx(8)
The operation has completed successfully.
And here's what parted has to say about the successfully completed operation:
# parted /dev/loop0 print free
Backtrace has 8 calls on stack:
8: /usr/lib64/libparted.so.2(ped_assert+0x45) [0x7f7e780181f5]
7: /usr/lib64/libparted.so.2(+0x24d5e) [0x7f7e7802fd5e]
6: /usr/lib64/libparted.so.2(ped_disk_new+0x49) [0x7f7e7801d179]
5: parted() [0x40722e]
4: parted(non_interactive_mode+0x92) [0x40ccd2]
3: parted(main+0x1102) [0x405f52]
2: /lib64/libc.so.6(__libc_start_main+0xf1) [0x7f7e777ec1e1]
1: parted(_start+0x2a) [0x40610a]
You found a bug in GNU Parted! Here's what you have to do:
Don't panic! The bug has most likely not affected any of your data.
Help us to fix this bug by doing the following:
Check whether the bug has already been fixed by checking
the last version of GNU Parted that you can find at:
http://ftp.gnu.org/gnu/parted/
Please check this version prior to bug reporting.
If this has not been fixed yet or if you don't know how to check,
please visit the GNU Parted website:
http://www.gnu.org/software/parted
for further information.
Your report should contain the version of this release (3.2)
along with the error message below, the output of
parted DEVICE unit co print unit s print
and the following history of commands you entered.
Also include any additional information about your setup you
consider important.
Assertion (gpt_disk_data->entry_count <= 8192) at gpt.c:793 in function
_parse_header() failed.
Aborted
So parted refuses to work with GPT that has more than 8192 partition entries. Nobody ever does that, so it has to be corrupt, right?
This is what happens when you don't stick to defaults.
| Are there extended partitions in GPT partition table? |
1,395,153,498,000 |
Through some legacy code I'm using dd to save and restore (parts) of a bootsector after unzipping the .iso of the system onto the hard drive (from a live cd).
I use the following command to save the mbr (first 446 bytes thus everything BUT the partition table):
dd if=/dev/sda of=/mnt/mbr.bin bs=446 count=1
Then I restore the .iso of the hard drive and afterwards use the following command to restore the boot sector:
dd if=/mnt/mbr.bin of=/dev/sda bs=446 count=1
Now as I'm having the problem that before I had ONLY a windows xp installed and AFTER using the above method it lets me choose between a linux startup and a windows xp startup I guess something is going severly wrong there.
My question here is: Should these two commands above be sufficient for saving and then later on restoring a boot sector?
|
The MBR is basically a 512 byte segment on the very first sector of your hard drive and it is composed of 3 parts: the boot code (446 bytes long), the partition table (64 bytes long) and the boot code signature (2 bytes long). Not sure what went wrong on your side but this works for me:
This will definetly backup the boot code itself and nothing else:
[root@host]# dd if=/dev/sda of=/tmp/mbr.img_backup bs=446 count=1
Next you want to wipe the MBR clean including partition table which you don't wish to save together with bootcode signature:
[root@host]# dd if=/dev/zero of=/dev/sda bs=512 count=1
And now you restore the boot code:
[root@host]# dd if=/tmp/mbr.img_backup of=/dev/sda bs=446 count=1
| Using dd in order to save and restore a boot sector? |
1,395,153,498,000 |
I'm looking at replacing my current MBR-partitioned 2 TB system drive with quite possibly a 3 TB drive. Copying the files should not pose a problem, but are there any gotchas to watch out for, particularly with regards to the boot loader, keeping in mind that MBR doesn't support anything more than 2 TB so I'll have to move to GPT? Or is it sufficient to partition the new drive, copying all files, update /etc/fstab in its new place, physically replace the old system drive with the new and then re-running grub-install?
I'm using Linux with GRUB 2 (specifically 1.99-27+deb7u1 on Debian Wheezy) on a single-boot system (no second OS installed to take into consideration).
|
Grub2 supports GPT, so you'll have no problem booting from the new drive. Whether your BIOS can boot a GPT drive is a different matter. If you switch your BIOS from legacy mode to EFI mode, you'll need to install the grub-efi package.
You'll need to install the bootloader on the new drive. The easiest way is to copy the data to the new drive first, then chroot into it and run grub-install, passing it the new drive as a command line argument. If you have both drives at this point, you may need to edit /boot/grub/device.map.
There are several ways to copy the files. The nicest way is to set up mirroring between the two drives via mdraid (Linux software RAID) or LVM. This has the advantage that you can keep using the system while it's setting up the mirror; once it's done, install the bootloader, reboot, break the mirror, and if desired enlarge at least one filesystem to make use of the extra space. If your filesystems are on PC partitions, you can convert them to RAID1, but it's fiddly. You can take this opportunity to put your filesystems on LVM volumes over RAID1 volumes — it's simple and makes maintenance easier.
If a large proportion of a filesystem is occupied, it's faster to copy the filesystem wholesale than to copy the files. It's difficult to give a threshold because that depends not only on the amount of disk space that's in use but also on the distribution of file sizes. To copy a filesystem wholesale, you can use cat </dev/sdOLD1 >/dev/sdNEW1 where sdOLD is the old disk (e.g. sda) and sdNEW is the new disk (e.g. sdb). Don't do this while the filesystem is mounted.
If you copy all the files, make sure to preserve all the metadata, especially ownership and partitions. cp -ax /media/old-root /media/new-root works.
If you've rearranged the partitions, make sure to update /etc/fstab. You may need to update /etc/crypttab if you have encrypted volumes.
| Copying OS from one drive to another migrating from MBR to GPT - what to watch out for? |
1,395,153,498,000 |
I currently have FreeBSD version FreeBSD 10.0-RELEASE. Installed using a ZFS root. I'm attempting to mount a MBR partitioned drive but I can't get the partition nodes, /dev/ada4p1, etc. The partitions are formatted to EXT2.
Is there a kernel module or command I need to run to gain access to partitions on ada4?
[root@core /mnt]# ls -l /dev/ada*
crw-r----- 1 root operator 0x76 May 2 10:29 /dev/ada0
crw-r----- 1 root operator 0x79 May 2 10:29 /dev/ada0p1
crw-r----- 1 root operator 0x7b May 2 10:29 /dev/ada0p2
crw-r----- 1 root operator 0x7d May 2 10:29 /dev/ada0p3
crw-r----- 1 root operator 0x8b May 2 10:29 /dev/ada0p4
crw-r----- 1 root operator 0x9f May 2 10:29 /dev/ada0p4.eli
crw-r----- 1 root operator 0x8d May 2 10:29 /dev/ada1
crw-r----- 1 root operator 0x98 May 2 10:30 /dev/ada1.eli
crw-r----- 1 root operator 0x8f May 2 10:29 /dev/ada2
crw-r----- 1 root operator 0xa1 May 2 10:30 /dev/ada2.eli
crw-r----- 1 root operator 0x91 May 2 10:29 /dev/ada3
crw-r----- 1 root operator 0xa2 May 2 10:30 /dev/ada3.eli
crw-r----- 1 root operator 0x93 May 2 10:29 /dev/ada4
[root@core /mnt]# fdisk /dev/ada4
******* Working on device /dev/ada4 *******
parameters extracted from in-core disklabel are:
cylinders=7752021 heads=16 sectors/track=63 (1008 blks/cyl)
Figures below won't work with BIOS for partitions not in cyl 1
parameters to be used for BIOS calculations are:
cylinders=7752021 heads=16 sectors/track=63 (1008 blks/cyl)
Media sector size is 512
Warning: BIOS sector numbering starts with sector 1
Information from DOS bootblock is:
The data for partition 1 is:
sysid 131 (0x83),(Linux native)
start 1, size 3906250000 (1907348 Meg), flag 0
beg: cyl 0/ head 0/ sector 2;
end: cyl 1023/ head 254/ sector 63
The data for partition 2 is:
sysid 131 (0x83),(Linux native)
start 3906250752, size 3907784704 (1908098 Meg), flag 0
beg: cyl 1023/ head 254/ sector 63;
end: cyl 1023/ head 254/ sector 63
The data for partition 3 is:
<UNUSED>
The data for partition 4 is:
<UNUSED>
|
It seems your Linux formatted /dev/ada4 MBR disk is not recognized properly by FreeBSD geom driver. So it can be seen through the legacy fdisk utility, but not through gpart show ada4.
It might be due to the fact that this ada4 device is obviously using some non-standard MBR extension to handle 2TB+ disks (2 partitions that are almost 2 TB each).
From MBR wikipedia:
MBR partition entries and the MBR boot code used in commercial operating systems, however, are limited to 32 bits. Therefore, the maximum disk size supported on disks using 512-byte sectors (whether real or emulated) by the MBR partitioning scheme (without using non-standard methods) is limited to 2 TB. Consequently, a different partitioning scheme must be used for larger disks, as they have become widely available since 2010. The MBR partitioning scheme is therefore in the process of being superseded by the GUID Partition Table (GPT). The official approach does little more than ensuring data integrity by employing a protective MBR. Specifically, it does not provide backward compatibility with operating systems that do not support the GPT scheme as well. In the meanwhile, multiple forms of hybrid MBRs have been designed and implemented by third-parties in order to maintain partitions located in the first physical 2 TB of a disk in both partitioning schemes "in parallel" and/or to allow older operating systems to boot off GPT partitions as well. The present, non-standard nature, of these solutions can cause various compatibility problems in certain scenarios though.
FreeBSD preference is now about GPT partitioning scheme and both MBR and the fdisk utility are to consider legacy regarding non-removable media.
| How to create MBR partition /dev/ nodes FreeBSD for mounting |
1,395,153,498,000 |
It seems as though I always have to install files to a --boot-directory when using grub-install.
What if I already have existing grub files in /boot on my partitions? Shouldn't I just need to install the MBR parts of grub and point it to one of my existing partitions' /boot/grub? I was unable to find such an option.
I've downgraded my GPT to MBR and removed my BIOS boot partition, which means I need to reinstall Grub to my MBR, if I haven't misunderstood anything. Without doing that I'm left with a grub rescue prompt that can't even list my partitions when doing ls. I realise that my menu entries might still not work after reinstalling grub to the MBR since they refer to partitions like hd0,gpt5, but having a usable prompt would be good enough, and it would have allowed me to confirm my understanding of grub more easily.
Do I have to write to a --boot-directory whenever I want to install grub, even if a directory already exists?
|
When GRUB boots from a MBR, the number of legacy BIOS compatibility steps it needs to take at the beginning of the boot process means that the code actually in the MBR is only capable of loading one disk block whose LBA number is patched in to the MBR code at the time of installation. That block is usually the first block of GRUB core image. It contains the code to load more blocks, and a list of block numbers that defines where the rest of the GRUB core image is located.
On a MBR-partitioned disk, there is usually unused space between the MBR and the start of the first partition. With MS-DOS, the original convention was to start the first partition at the start of the next disk track, which usually means there will be at least 63 disk blocks before the first partition, including the MBR. On modern systems, the first MBR partition is now more commonly placed to start at exactly 1MiB from the beginning of the disk, i.e. at block #2048, to optimize the data alignment for disks, SSDs and SAN storage systems that may internally use a block size bigger than 512 bytes.
So, on a MBR-partitioned disk, the beginning of the disk is normally arranged like this:
block #0: MBR
block #1: first block of GRUB core image, contains the block list
blocks #2...#n: the rest of the GRUB core image
block #2048: beginning of the first partition.
Note that the loading of the GRUB core image works exclusively by pre-determined block numbers: until the GRUB core image is fully loaded and extracted, GRUB will have no awareness of partition tables nor filesystems of any kind.
On a GPT-partitioned disk, the blocks immediately after block #0 are occupied by the GPT partition table, so the GRUB core image is embedded into a "BIOS boot partition" instead. That just means the block number embedded into the MBR will not be 1, but instead the number of the first block of the BIOS boot partition, and the rest of the blocks belonging to the core image will be likewise shifted. So on a GPT-partitioned disk with BIOS-style GRUB on it, the physical layout will be something like this, assuming the BIOS boot partition is the first one on the disk:
block #0: GPT protective MBR, with GRUB MBR code embedded
blocks #1...#(x-1): actual GPT partition table
block #x: the first block of the BIOS boot partition, contains first block of GRUB core image with the block list
blocks #(x+1)...#(x+n): the rest of the GRUB core image
The fact that you can still get to GRUB rescue mode indicates that although you said you removed your BIOS boot partition, you did not yet overwrite its blocks; although the space occupied by the BIOS boot partition may now be unallocated space between partitions, or unused space in another resized partition, it still has its old contents, and GRUB can still load those blocks and find its core image. But nothing in particular shields those blocks now from getting overwritten: as soon as that happens for whatever reason, the GRUB core image will be destroyed and GRUB will fail to get even as far as the rescue mode.
Contents of the GRUB core image
The GRUB core image contains several things:
the GRUB kernel: this is the only part technically required to get into GRUB rescue mode.
embedded initial GRUB root path, to indicate which disk, partition and directory within it holds the GRUB configuration file and the GRUB modules directory. In Linux, these normally appear as /boot/grub/grub.cfg and /boot/grub/i386-pc respectively when the Linux system is running normally.
a set of embedded GRUB modules, containing at least the code to read and understand the partition table and the filesystem type used on the partition referred to by the initial GRUB root path. As the core image may need to fit into less than 63 disk blocks, this set of modules is usually kept as minimal as possible on MBR systems.
optionally, an embedded GRUB configuration file with one or more GRUB commands
optionally, an embedded disk image, similar to the ones used by the memdisk tool of the SYSLINUX bootloader family
optionally, a GPG public key used to sign other GRUB modules and the OS kernel for security (and to satisfy Secure Boot acceptance requirements on UEFI versions of GRUB)
All this is LZMA compressed to minimize its size, so it cannot be easily read or modified manually.
Since you're now dropping into rescue mode and cannot list your partitions, that indicates the GRUB core image contains the partitioning module for GPT (part_gpt.mod), but not for MBR (part_msdos.mod). Without the MBR partitioning module, it cannot access the partition containing /boot/grub/i386-pc directory, even if the GRUB core image would contain the filesystem driver module applicable to it... and so GRUB cannot load the normal.mod which would let you proceed beyond the rescue mode.
What needs to happen now
The GRUB core image may need to be rewritten to a safe location, probably into the space between the MBR and the beginning of the first partition, which was previously occupied by the structures of the GPT partition table. As the BIOS boot partition was removed, the current location is not safe: it might be reallocated to another partition and get overwritten without warning in the future.
while rewriting the GRUB core image, the GPT partitioning module embedded within it needs to be replaced with the MBR partitioning module. Since all the components are supposed to be at hand in uncompressed form (at /usr/lib/grub/i386-pc or similar directory), the simplest way to do it is just take all the appropriate uncompressed components, build a new core image out of them and compress it. Uncompressing the old one and modifying it is just not worth the trouble: why write another piece of code when reusing the code used when initially installing GRUB from scratch works just fine?
Since the location of the GRUB core image will most likely change, the MBR code needs to be rewritten too.
The grub-install command will need to somehow ensure that the normal.mod and other GRUB modules located in /boot/grub/i386-pc are of the same version as the new GRUB core image. Sure, it could compare the existing files to the set of files it used to rebuild the core image, but again... why write and debug code for another special case when simply overwriting the existing contents of /boot/grub/i386-pc with the already-existing GRUB installation routine works just fine?
The total uncompressed size of all the i386-pc GRUB components is definitely less than 4 MiB. That's nothing. Trying to avoid rewriting that if it already exists is simply not worth the trouble, unless you're working with something special like the old first-generation PATA SSDs with very restricted number of write cycles available.
How native UEFI would do it?
Since UEFI firmware includes FAT32 filesystem support as standard, the native UEFI version of the GRUB bootloader can be packaged as a single grubx64.efi file that contains all the necessary modules, including normal.mod if you wish. It gets loaded as a regular file: no need to fiddle with block numbers or embedded code in fixed disk locations at all.
| Grub: install only the MBR parts, not the boot directory? |
1,395,153,498,000 |
I create a file of 100MB size, and using losetup assign it to /dev/loop0.
Consequently I use fdisk to create an empty DOS partition table, and a new partition that spans the entire disk.
One thing that is unusual to me and I cannot understand, is that the aforementioned partition begins at the 63rd sector; this implies that the partition table takes up 62 sectors, i.e. 31Kb.
I was under the impression that all data regarding partition entries is recorded in the master boot record, the first sector of the drive, and thus only the first 512 bytes of the disk should be off bounds.
Examining the drive, the sectors after the first are not completely filled with null, so clearly there is some detail I am missing regarding partition tables.
fdisk print (display type = sectors):
Device Boot Start End Blocks Id System
/dev/loop0p1 * 63 192779 96358+ 83 Linux
|
The MBR partition format is three decades old, and subject to weirdness for historical reasons.
Back then, the computer needed to know the geometry of the hard disk. How is data organized on a hard disk? In three dimensions: cylinder, heads and sectors.
(Diagram by LionKimbro)
The geometry was stored with maximum values that were large enough for the time: 8 bits for the number of heads (1–255), 6 bits for the number of sectors on a track (1–63), and 10 bits for the number of tracks per head, i.e. the number of cylinders (1–1023), with one sector containing 512 bytes. Nowadays computers don't need to know the actual geometry of the disk (and those numbers aren't even meaningful), but the format remains, and disks using MBR partitioning have a size that's expressed in CHS format, but all that matters is that the product of the three numbers is equal to the total number of sectors.
The starting address of the start of a partition is expressed in CHS format, and a lot of older operating systems didn't support partitions spanning different tracks, i.e. a partition had to be aligned on a cylinder boundary. That means a multiple of 63 sectors for the first partition.
There's a space of 31 kB that isn't used for partition content. It can be used for a bootloader.
The modern GPT partition format, which is the standard for newer PCs with >1 TB disks, likes to align partition on 1 MB boundaries, so there's about 1023 kB free before the start of the first partition. Again, this can be used by a bootloader. Modern operating systems align MBR partitions on 1MB boundaries too, dropping the CHS compatibility, and ensuring that partitions fall on a sector boundary on drives with 4 kB sectors (= 8 traditional sectors of 512 kB). Aligning partitions on a sector boundary (as in, the actual sector size used by the disk, i.e. its preferred transfer size) helps performance.
| Partition table consuming 32K of data? |
1,395,153,498,000 |
I read an article on aligning file-systems on partitions and this said that:
When manipulating MBR disks, be aware that the alignment of extended
partitions is unimportant. These partitions hold one-sector data
structures that define logical partitions, so in a real sense,
extended partitions can't be properly aligned.
Could someone explain in more detail why alignment of extended partitions is unimportant?
|
Alignment is important on partitions containing data, in order to maximise the chance that block operations will match whatever the underlying block structure is (4K on modern hard drives, more than that on flash-based drives).
Extended partitions don't contain data, they're simply containers for logical partitions. The only operation which is done on extended partitions is reading the single 512-byte sector which defines the logical partitions, and writing it when modifying the logical partition structure (so hardly ever). Because that operation only involves a single sector, it can never match a larger block size, so any writes will be sub-optimal and there's no way of improving that. The alignment of the extended partition itself doesn't affect the possible alignment of the logical partitions it contains, so there's no need to align it there either.
| alignment of extended partitions |
1,434,468,866,000 |
I've tried installing OpenSUSE 13.2, Debian 8/8.1 and Ubuntu 15.04 (all them amd64). Debian/Ubuntu won't show disks and OpenSUSE can't format the partitions created on them.
During the install, OpenSUSE detects disks and even allow me to delete old partitions, create a new partition table,and to create new partitions. But won't format the new partitions raising the error "can't mount /dev/sda1: device or resource is busy". When debian install didn't detect the HDDs, I tried to mount them by myself and received the same error.
During Debian / Ubuntu Install, I choose "manual" partitioning option, but it won't show my hard drives.
Everywhere else in the system where I check for the HDDs, they are detected correctly: fdisk -l, cfdisk -l, lsblk, /sys/block/, parted, dmesg. All commands shows both my /dev/sda and /dev/sdb and their partitions correctly.
The hardware is a hybrid UEFI capable Ultrabook (Dell Inspiron 14z 5423) which has both a SSD and a SATA HDD.
Things I've tried so far:
- Used fixparts (windows) trying to find GPT stray. Nothing found.
- Used AOMEI Partition Assistent Pro (windows) to fix MBR, but no luck detecting partitions during debian install. So I went back to AOMEI and also resized both disks partition and added a EXT3 partition to each disk.
- Created a new partition table in UEFI mode (which converted the disk from mbr to gpt)
- Changed BIOS settings to all possible combinations: SATA Type both ATA and AHCI, Boot Type both UEFI and Legacy, UEFI with both Secure Boot On and Off, UEFI looking for Option ROM On and Off...
any suggestions will be much apprecited!
|
I finally figured it out myself.
Solution:
First I booted OpenSUSE from USBKEY in UEFI mode.
In the intaller partitioner, I removed all partitions in the SSD and HDD
Then I created a new partition table for each disk, still using the partitioner.
Booted up from Ubuntu 15.04 USBKEY installer and it finally could manage partitions and install the system properly.
Although it sounds simple, it took some time and required two operating systems to solve the issue.
Since I booted in UEFI mode, when I created a new partition table, I believe it converted the disks to GPT format, and Ubuntu could finally "detect" and manage the disks partitions.
It remains a mystery why it didn't work in MBR/Legacy mode at all, even after creating a new partition table, and why OpenSUSE couldn't format/mount the partitions it created.
Finally I got linux on it.
| Can't format HDDs and install linux to Dell hybrid ultrabook |
1,434,468,866,000 |
I have a laptop for work. I originally had Windows 7 on it then I installed Linux Mint 17 to dual boot.
During my installation of Mint 17 I accidentally installed GRUB on the wrong partition (sda2). Now when I try and log into Windows for my work, it brings me right back to the Grub boot screen.
Is there any way to move GRUB from one partition to another? Which would the correct partition to install GRUB? Perhaps using a live DVD or something like System Rescue CD or Parted Magic etc.?
I need to access both Windows 7 and Linux Mint. As a normal standard dual boot.
I have attached my boot information which I got using bootinfoscript here
|
I have used this, http://www.supergrubdisk.org/rescatux/, in the past, I believe thats what your looking for, it allows you to choose which partition to install/repair grub on. It even has a option to restore windows master boot record.
You could also try windows repair cd, heres a safe copy I have used myself, https://kickass.to/windows-7-repair-discs-32-bit-and-64-bit-iso-t8147350.html#main
| How to move GRUB installation to a different partition? |
1,434,468,866,000 |
What is the difference between the GPT and the BIOS disc partitioning systems?
when
boot drive is below 2TB
on a BIOS system or UEFI boot disabled
grub on BIOS system with GPT partitioned needs an extra 1MB partition, I think this is somewhat messy.
|
You have four primary partitions and want to add a fifth... and you can't just redeclare them extended/logical because those need an extra sector for each partition.
Also GPT has a backup at the end of the disk so if you ever lost a partition table to MSDOS and had to resort to TestDisk, with GPT you might be able to do without.
grub on BIOS system with GPT partitioned needs an extra 1MB partition
It's closer to 64KB actually, at least it was around that when I last checked what was actually written to that partition. And with msdos partitions as well, grub has to put its core somewhere. The only difference is that with GPT the grub developers thought it'd be nice to make it official-like by having a dedicated partition type for it.
| Advantage of GPT over MBR partition table [closed] |
1,434,468,866,000 |
When I run grub-install /dev/vda -v I see this line in the output:
grub-mkimage --directory '/usr/lib/grub/i386-pc' --prefix '(,msdos1)/boot/grub' --output '/boot/grub/i386-pc/core.img' --dtb '' --format 'i386-pc' --compression 'auto' 'ext2' 'part_msdos' 'biosdisk'
How do I configure GRUB to add specific modules in the list of grub-mkimage arguments?
Backstory: I am trying to migrate a BIOS/MBR installation of PureOS from ext4 to btrfs, so I need to add btrfs module to the GRUB image before running grub-install.
The instruction here is nice but it is for UEFI/GPT.
|
I assume you're asking for the information available in the man pages of grub-install:
-d, --directory=DIR
use images and modules under DIR [default=/usr/lib/grub/<platform>]
...
--modules=MODULES
pre-load specified modules MODULES
So you can use --modules=btrfs on your grub-install command to add this module.
The default modules are checked by the grub-install tool itself by looking at the system and gathering the important information (such as the fs type).
| Where does grub-install take the arguments for grub-mkimage from? |
1,434,468,866,000 |
How to boot GPT based system to Linux and Windows? This is not a question of starting from a fresh GPT based system, but starting from a MBR converted to GPT based system.
My Asus laptop initial setup,
I disabled the Secure Boot Control, and
I enabled [Launch CSM] (Compatibility Support Module)
I partitioned my HD using MBR
All my systems on my Asus laptop were boot from such BIOS/MBR/CSM mode, including Win8 and all my Linux
However, I found that my USB is booted only in EFI style, and Windows 10 is refusing to be installed to my BIOS/MBR/CSM mode system when my USB is booted in EFI style.
So I converted my MBR disk to GPT, and of course, as Krunal warned, such practice ruined my system boot, and I need make everything bootable again.
Alright, so now is my question.
In BIOS/MBR/CSM mode, I have an active MBR partition, all my systems were boot from it (using extlinux), including Win8 and all my Linux.
In GPT mode, however, this is where the problem begins for me.
To mark a GPT Partition bootable under Linux, I saw I need to set the "boot flag" in GParted, which I did (marked my previous active MBR partition as type code of EF00 which stands for "EFI System"), and GParted consequently set ESP (EFI System Partition) flag as well.
However, according to GUID Partition Table (GPT) specific instructions from wiki.archlinux, I need a type code ef02 flag bios_grub in order to boot. But I don't have any spare room for such partition.
So I basically don't know which way to go, and don't want to further mess up with my already-messed-up and unbootable system.
My current partition schema (I didn't think it is relevant but since somebody asked for it):
Disk /dev/sda: 698.65 GiB, 750156374016 bytes, 1465149168 sectors
Disk model: HGST HTS541075A9
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: AA9AB709-8A5D-468D-990E-155BA6A2FBB3
Device Start End Sectors Size Type
/dev/sda1 2048 129026047 129024000 61.5G Microsoft basic data
/dev/sda2 129026048 169986047 40960000 19.5G EFI System
/dev/sda3 169988096 186372095 16384000 7.8G Linux filesystem
/dev/sda4 186374144 200710143 14336000 6.9G Linux filesystem
/dev/sda5 200712192 215046143 14333952 6.9G Linux filesystem
/dev/sda6 215048192 231432191 16384000 7.8G Linux filesystem
/dev/sda7 231434240 247818239 16384000 7.8G Linux filesystem
/dev/sda8 247820288 264204287 16384000 7.8G Linux filesystem
/dev/sda9 264206336 276494335 12288000 5.9G Linux filesystem
/dev/sda10 276496384 288784383 12288000 5.9G Linux filesystem
/dev/sda11 288786432 329746431 40960000 19.5G Linux filesystem
/dev/sda12 329748480 452628479 122880000 58.6G Microsoft basic data
/dev/sda13 452630528 493590527 40960000 19.5G Linux swap
/dev/sda14 493592576 903192575 409600000 195.3G Linux filesystem
/dev/sda15 903194624 1465147391 561952768 268G Linux filesystem
So clear instructions on how to boot Linux (and Windows) from such environment is really appreciated. Thanks.
UPDATE/Conclusion:
/dev/sda2 was my active MBR partition before, and as explained above, I changed its type from Linux filesystem to EFI System. But it is in ext4 format so it cannot be used as an EFI System.
So, all I need to fix my above problems are:
revert sda2's type back to Linux filesystem,
split out a FAT32 partition as the ESP partition from my sda13 19.5G Linux swap,
change the firmware from CSM to native EFI mode
then follow advice below from @telcoM
|
As far as I know, Windows does not handle such a converted system disk as a special case once the conversion is done, so it should be treated exactly the same as a disk in a "fresh" GPT-based system.
In particular, Windows imposes the limitation that GPT-partitioned system disks must always boot Windows in UEFI native style: that is, using BIOS-style boot process on GPT-partitioned disks is not allowed.
First, a primer on differences between MBR and GPT partitioning:
In GPT, there is no division to primary/extended/logical partitions like MBR partitioning has. All GPT partitions are just partitions.
Although there is a "legacy BIOS bootable" partition attribute bit in GPT partition table, it is not used at all when booting in UEFI style.
MBR-partitioned disk normally has a gap of unused disk blocks between the block #0 (the actual Master Boot Record) and the beginning of the first partition. On modern systems, the first partition is usually aligned exactly 1 MiB from the beginning of the disk, so if the common 512-byte blocks are used, the first partition will begin at block #2048. The gap between MBR and the first partition is used by bootloaders like GRUB. On GPT-partitioned disks, this area is occupied by the actual GPT partition table and cannot be used.
On MBR-partitioned disks, partition type is identified by a single byte. On GPT-partitioned disks, the type of each partition is identified by an UUID.
MBR-partitioned disks have a 32-bit disk signature; GPT-partitioned disks have a 128-bit UUID for the same purpose. Each GPT partition also has an unique UUID in the partition table: it can be used to uniquely identify a partition even if the filesystem used in it is unknown. Linux displays this as a PARTUUID; for MBR-partitioned disks, a combination of the MBR disk signature and partition number is used in lieu of a real partition UUID.
The MBR partition table exists in block #0; if extended partitions are used, the beginning of each logical partition has an add-on partition table. The GPT partition table starts in block #1 and occupies multiple blocks; there is also a backup GPT partition table at the very end of the disk. This often causes a surprise if you are used to wiping the partitioning off a disk by just zeroing a number of blocks at the beginning of a disk only.
Since partition type UUIDs are inconvenient for humans to use, different partitioning programs have used various methods to shorten them. gdisk will use four-digit type codes; Gparted represents the different partition type UUIDs by various flags (which is, in my opinion, an unfortunate choice).
A native UEFI-style boot process is also very different from classic BIOS-style boot process:
A BIOS-style boot process begins by (usually) assigning the BIOS device ID 0x80 (=first BIOS hard disk) to the device that is currently selected by the BIOS settings as the boot drive. When booting in UEFI style, the firmware settings ("BIOS settings" in an UEFI system) define a boot path: it can take many forms, but the most common one for installed operating systems will specify a partition UUID and a boot file pathname.
When booting BIOS-style, the firmware checks for a 2-byte boot signature at the end of block #0 of the selected boot disk, and then just executes the about 440 bytes of machine code that fits in the MBR block in addition of the actual partition table. When booting UEFI-style, the firmware has a built-in capability to understand some types of filesystems: the UEFI specification says a compliant UEFI firmware must understand FAT32, but it may understand other filesystem types too. An UEFI "bootable disk" must contain a partition with a special type UUID: this is called the EFI System Partition, or ESP for short. The firmware will look for an ESP partition whose unique UUID matches the one specified by the boot path, and then attempts to load the specified boot file from that partition.
When booting UEFI-style from a removable media, or from a disk that has not previously been configured to the firmware settings, the firmware looks for an ESP partition that contains a filesystem the firmware can read, and a file with a particular pathname. For 64-bit x86 hardware, this UEFI fallback/removable media boot path will be \EFI\boot\bootx64.efi when expressed in Windows-style, or <ESP mount point>/EFI/boot/bootx64.efi in Linux-style.
The ESP partition has a standard structure: each installed OS must set up a sub-directory \EFI\<vendor or distribution name>\ and only place their bootloader files within it. The \EFI\boot\ sub-directory is reserved for the fallback/removable-media bootloaders, which follow the Highlander rule: there can be only one (for each system architecture).
By setting the GParted "boot flag" on a non-ESP partition, you effectively changed the type UUID of that partition to ESP type UUID. That was a mistake: now the disk has two partitions with type ESP. You should change the type of the partition you changed back to what it originally was. In GParted, that would mean removing the "boot" and "esp" flags; in gdisk, it would probably mean setting the type code to 8300 ("Linux filesystem") or perhaps 8304 ("Linux x86-64 root").
Since you also have Windows on the same disk, trying to use a BIOS-Boot partition (gdisk type code ef02) is not recommended: that would usually force you to go to firmware settings and enable/disable CSM each time you wanted to switch between operating systems. Instead, you would want to use the live Linux boot media to mount your on-disk installation to e.g. /mnt, and then chroot to it to replace the current BIOS-style bootloader (usually GRUB with the i386-pc architecture type) with a native UEFI one (e.g. GRUB with x86_64-efi architecture type). Basically (all the following commands as root):
mount <your root filesystem device> /mnt
mount -o rbind /dev /mnt/dev
mount -t proc none /mnt/proc
mount -t sysfs none /mnt/sys
chroot /mnt /bin/bash
Now your session will be using the environment of your installed Linux OS, and you should be able to use package manager and any other tools pretty much as usual (caveat: if you have parts of the standard system like /var as separate partitions, mount them now too!)
The first step should be adding a mount point for the ESP and mounting it. First run lsblk -o +UUID to find the UUID of your ESP partition; since its filesystem type is most likely FAT32, it should be of the form xxxx-yyyy. Replace <ESP UUID> in the following commands with the actual UUID:
mount UUID=<ESP UUID> /boot/efi
echo "UUID=<ESP UUID> /boot/efi vfat umask=0077,shortname=winnt,flush 0 2" >>/etc/fstab
The next step is switching the bootloader type.
Unfortunately you didn't mention which Linux distribution you're using. If it's Debian, or Ubuntu, or some distribution derived from those, it would be a matter of using the standard package management tools to remove the grub-pc and grub-pc-bin packages and install grub-efi-amd64 and grub-efi-amd64-bin in their stead, then running grub-install /dev/sda (or whichever disk contains your ESP partition), and finally running update-grub to rebuild the GRUB configuration.
At this point, you can exit the chroot, undo the mounts and see if your system can boot now.
(if you had to mount any extra partitions, unmount them now)
exit
umount /mnt/dev
umount /mnt/proc
umount /mnt/sys
umount /mnt
reboot
You might also want to install the efibootmgr utility, as it allows you to view, backup and modify the firmware boot settings while Linux is running. (Windows can do the same with its bcdedit command, but in my opinion that command is much more awkward to use than efibootmgr.)
| MBR converted to GPT based system, how to boot Linux and Windows |
1,434,468,866,000 |
I'm trying to understand the ms-dos partition table, and there's the following diagram:
It comes from this site. Almost everything is pretty clear to me, but there's one thing I don't get. As you can see, the third partition is an extended partition, and it has several logical disks. The extended and primary entries in MBR look the same. Both have partition type, starting sector and number of sectors which describe the partitions.
Where is the info that would link to the first EBR on the extended partition?
How does the system know what to look for on the extended partition?
Let's say that we've lost the extended entry in MBR. How to restore it? If I create a new extended entry via fdisk, it won't see the logical disks. How to connect the first EBR to the extended entry in MBR?
|
I made an 300MB extended partition with a 100MB logical partition; deleted just the extended partition; then recreated it - all with fdisk. At every stage I observed the first logical partition's EBR sector, and it turned out, that when fdisk creates the extended partition, it resets the first EBR.
Then I re-created the first logical partition with the same size, and I was able to mount it and read the little test data I left there.
Then deleted them again, and created it again, but with a 200MB logical partition. I was able to mount then too, but the file system was still 100MB.
So if you already created the extended partition, I'm afraid, you too have overwritten the first EBR.
I guess, if you know exactly the logical partition's start and end sectors, you can recreate and use all of them. But if you do not know exact sectors, then fdisk will write EBR into a filesystem data sector and corrupt it.
Creating a logical partition that fills the whole extended partition will probably make the first logical partition accessible.
I also read, that parted's rescue command can find lost partitions.
| How does system know where the first logical disk starts? |
1,434,468,866,000 |
Currently dual booting Windows 8 and Linux Mint 14, sooner or later I will give more space to my Linux system.
Is resizing my Linux partition from the beginning a safe operation ?
If yes, could you provide the name of an utility that would help me achieve this ?
I am asking this because systematically when I did that under Windows using Acronis Disk Director the system was broken, I couldn't boot to Windows anymore because of an NTLDR missing. So unless I thought in advance to make a recovery disk I was unable to use it again !
|
gparted is a nice GUI tool for resizing partitions, or ext partitions at any rate. I have not tried it on NTFS filesystems, although apparently it can.
So yes, you can resize now or later. Just backup your personal tish first, just in case. Of course, if you know what is good for you, you keep that backed-up anyway ;)
Note that you should not resize a mounted partition, so if you want to resize /, you will have to boot a live CD (I'm sure they all have gparted) and do it from there.
| Can I safely resize my partition from its beginning? |
1,434,468,866,000 |
I am reading through the UEFI standard. On page 115, section 5 it discusses the GPT disk layout. I'm a bit confused as to exactly how this works. From the below, it sounds like UEFI will ignore the MBR.
A legacy MBR may be located at LBA 0 (i.e., the first logical block)
of the disk if it is not using the GPT disk layout (i.e., if it is
using the MBR disk layout). The boot code on the MBR is not executed
by UEFI firmware.
So is this basically saying if you put the firmware in legacy boot mode, this is how to define an MBR which will play nicely with that legacy boot mode? Am I correct in saying that if the system's firmware were in UEFI mode, then a system with an MBR defined as specified in chapter 5 would not be bootable?
|
So is this basically saying if you put the firmware in legacy boot mode, this is how to define an MBR which will play nicely with that legacy boot mode?
Yes, it's possible to have a disk that's boot table in both BIOS and UEFI mode. Many tools to create a bootable USB stick can do that
Am I correct in saying that if the system's firmware were in UEFI mode then a system with an MBR defined as specified in chapter 5 would not be bootable?
No, that part of the spec only says The boot code on the MBR is not executed by UEFI firmware which means the the 446-byte region in the MBR containing the binary instructions for booting the system won't be run in UEFI mode
It's still possible to boot from an MBR disk in UEFI mode if you create a proper ESP (EFI System Partition) on it. UEFI systems only boot executable images in the ESP
So by putting a proper BIOS boot loader in the MBR and a UEFI boot loader in the ESP you can have a disk that boots in either mode
| Can you use MBR with UEFI - a question about the UEFI specification |
1,434,468,866,000 |
I have an ext4 partition backed up with dd on a MBR hard drive that I would like to restore to a new GPT hard drive. Can I just create an empty partition of the exact same size on that new GPT drive and overwrite that partition with the one I want to restore or I have to do something else because the partition was backed up on a MBR drive?
Thanks.
Edit:
The partition on the MBR hard drive was primary. It was the third partition on the drive. I made the backup with dd.
|
Can I just create an empty partition of the exact same size on that
new GPT drive and overwrite that partition with the one I want to
restore?
Yes.
The MBR/GPT distinction is metadata stored outside of the partition. So when you made a partition backup using dd you only backed up the content of that partition (the filesystem), which does not include anything about the partitioning scheme.
| Using dd to restore a partition backup from MBR disk to GPT one |
1,434,468,866,000 |
I have an img (made with dd) of a FreeBSD installation on a 1TB HD.
This time i need to use a smaller disk (500GB), and of course if I try just to restore the same image it won't work, but even if I tried to manually adjust partition table and MBR my system doesn't boot.
What i did:
After dding, i went straight to sfdisk in order to adjust MBR ending sector, then i used parted to shrink partition to correct boundary.
To my calculations, given that the partition begins at sector 2048, for a 500GB disk it is correct to set ending sector at 976771120 (976773168 total).
New partition is then 2048 -> 976771120, and new MBR also uses this logic. In fact, I can reach FreeBSD boot manager 1st stage, but then i'm stuck at boot prompt (error 66). Maybe i'm not aware of how next bootloader stages work, probably is it not enough to fix partition scheme and MBR to make FreeBSD boot? There could be some conf file read early somewhere that also needs to be fixed? Not my primary OS so I'm on a trial/error process. Thanks
EDIT: added output, sorry for pic but my only choice. Didn't remember that real data were really few( <2GB).
First disk, 500GB scheme (not working).
Second disk, 1TB original scheme (working).
I could already go with this and proceed with my work, but i think it's still interesting to understand what went wrong.
|
That seems slightly masochistic to me.
Personally I would have done a dd for backup. Then I would shrink it and make sure it works before trying to move it (shrink->reboot->check->final dd).
I assume that you had less than 500 GB of data. But you do not know how it was structured on the disk.
You have then used sfdisk and parted to modify the partitions? But what have you done to conserve the filesystems? A naive change of the partition will not reorder the data in the file system nor manage the layout of the truncated filesystem.
So what you are missing is handling your filesystem. On FreeBSD you would typically use UFS or ZFS. For UFS you should look into growfs(8) (See Resizing UFS /root partition on FreeBSD). If you're using ZFS everything is a whole different ballgame as it is a combined volume manager and file system!
So to be able to answer your direct question we need a lot of additional information. The implicit question on how to get to your data is however much easier. Setup a bare and bootable FreeBSD installation on your new disk. Then copy the data.
Mount an image
When you have a dd image of your disk you can mount it. Either do it on a different system or have a portable USB disk/networkdrive.
So if you have the full original copy of /dev/ada0 as ada0.dd - then you can use the image as a virtual memory disk:
# mdconfig -a -t vnode -u 0 -f /home/realpclaudio/ada0.dd
This will give us /dev/md0 which should be your full disk.
You can then check everything looks good.
# fdisk /dev/md0
This should look exactly like your old disk. We can then start looking at the data but this depends on your file system.
UFS
We mount the UFS file system on the disk.
# mount -t ufs -o ro /dev/md0s1a /mnt
That is most likely the root file system of the 1st slice. If yoou have further slices you can mount them as well.
# mount -t ufs -o ro /dev/md0s1e /mnt/var
# mount -t ufs -o ro /dev/md0s1g /mnt/home
ZFS
If you are using ZFS you can then manage the disk using the ZFS tools (see zpool Administration.
# zpool import -o altroot=/mnt mypool
# zfs list
| Shrink FreeBSD partition |
1,434,468,866,000 |
I am using hexedit to show/edit disk MBR (512 Bytes, copied with dd).
When I open the file, hexedit displays the file as 9 columns, 4 bytes
per column (36 bytes per line). That is very unfortunate. I need to have
it aligned in a meaningful way (ie 8 columns, 32 columns per line)
I could not find any way to do it in the manual page.
Is there a trick I could use ?
UPDATE:
here are the commands I use:
dd if=/dev/sda of=sda.img bs=512 count=1
hexedit sda.img
regarding the output I get, it looks similar to slm's, only with 9 columns instead of 8.
|
Apparently it keys off of the width of your terminal. If you size the terminal just right you can get hexedit to show you 8 columns instead of 9.
Example
00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................................
00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................................
00000040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................................
00000060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................................
00000080 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................................
000000A0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................................
000000C0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................................
000000E0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................................
00000100 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................................
00000120 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................................
00000140 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................................
00000160 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................................
00000180 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................................
000001A0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................................
000001C0 01 00 EE FE FF FF 01 00 00 00 AF 32 CF 1D 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ...........2....................
000001E0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 AA ..............................U.
00000200
00000220
00000240
00000260
00000280
I had the column width of the above terminal set to 151x55.
$ resize
COLUMNS=151;
LINES=55;
export COLUMNS LINES;
| hexedit: change number of columns (bytes per line) |
1,434,468,866,000 |
I've just installed my OSes on a new HDD: Windows 7 and Debian 7. As usual I first installed Windows, then Debian.
At the first attempt, GRUB seems to not have been installed properly, because my computer would just boot into Windows. I found this on debian.org, so I followed its advice:
When there is more than one disk available during installation (for example one hard disk and one USB stick, as it is commonly the case when booting the installer from a USB stick), grub-install may run into problems: it was reported several times, that the GRUB bootloader was installed onto the USB stick instead of the hard disk containing the newly-installed system.
To avoid running into this, make sure to answer "No" when the following question is asked during the installation process: "Install the GRUB boot loader to the master boot record?"; it should be possible to specify the right device at the next step: "Device for boot loader installation".
After I did this, GRUB would show up on boot, but when I selected Windows, the screen would go black and immediately pop back to the GRUB menu. I installed GRUB into the first partition, as that was the one with the boot flag.
My partitions are as follows:
100MB System Reserved
195GB Windows
2GB Swap
40GB Linux
I managed to fix the MBR with the Windows CD afterwards, but of course, now Debian is unavailable.
Should I have installed GRUB somewhere else, or is it a different problem ?
|
Assuming you're partitioning with MBR and not GPT.
First, you can backup and eventually restore your mbr (assuming hda is the target disk):
dd if=/dev/hda of=/path/mbr-backup bs=512 count=1 # backup
dd if=/path/mbr-backup of=/dev/hda bs=512 count=1 # restore
Obviously would be hda1 if you installed grub in the partition and not the disk.
Note if it is in the disk (hda) don't change your partition table between backup and restore.
Second, if your Debian is currently installed, just boot a Live CD and mount the Debian root somewhere:
mkdir /tmp/x
mount /dev/hda1 /tmp/x # Debian root partition
# mount some needed filesystem
mount proc /tmp/x/proc -t proc
mount sysfs /tmp/x/sys -t sysfs
mount --bind /dev /tmp/x/dev
Chroot into the partition and reinstall grub
chroot /tmp/x
grub-install /dev/hda # or hda1 for the partition
Don't know yet if you need an update-grub also (should verify)
The grub's os-prober should find your Windows, then if it doesn't boot there's some other problem in the chain loader.
update
If your disk is partitioned as GPT see this FAQ
Windows and GPT FAQ
in particular this one:
Can Windows 7, Windows Vista, and Windows Server 2008 read, write, and
boot from GPT disks?
Yes, all versions can use GPT partitioned disks for data. Booting is
only supported for 64-bit editions on UEFI-based systems.
If you have BIOS use MBR partitioning, if you have UEFI then use GPT.
| Installing GRUB in a dual-boot |
1,434,468,866,000 |
I have a hard drive which is encrypted using LUKS. It was originally an external hard drive. Recently I removed the casing and connected it directly (via SATA). However, when I connect it directly, I'm unable to view the partition, and it doesn't prompt for the password. Out of 4 TB, it shows an unknown partition of 500GB and free space of 3.5TB.
I removed it from the system and connected it as an external hard drive again, and ubuntu detects the partitions, and prompts for the password.
Also, the partitioning is shown as MBR, when in reality it is GPT
|
It's probably a problem with the sector size. Some USB enclosures claim their drives have 4KiB sectors, when the drive represents itself as 512 byte sectors or vice versa. Partition tables (both msdos and gpt) unfortunately depend on the sector size. If the sector size changes, the partition table becomes invalid.
Now, this is a problem that could be solved in software - Linux could be made smart enough to interpret a GPT partition table correctly, regardless of the physical sector size the drive claims to have. But it doesn't do that, and it's probably not part of the standard, so ...
What you need to do is get the exact byte offsets of your partitions while in the USB closure
parted /dev/usbdrive unit b print free
and then see if those partition offsets work for the internal drive
losetup --find --show --read-only --offset 1048576 /dev/internaldrive
file -s /dev/loopX
and if that works out okay, re-create the partition table with the same (byte) offsets for the internal disk (make a backup of the first/last few megabytes of the disk first)
parted /dev/internaldisk unit b mklabel gpt mkpart 1048576 42424242 ...
I don't know if there is a partitioner that is smart enough to 'repair' such wrong-sector-size partition tables automagically. It would beat the manual approach but ...
| LUKS on an internal hard drive |
1,434,468,866,000 |
I am trying to learn and especially understand how partitionning and boot-loaders work. The problem is that I got it all twisted in my mind. In the end I don't understand anything anymore.
I know how to partition a hard drive using fdisk, parted, gdisk.
I tried chainloading iso files (such as ubuntu.iso, arch.iso) with syslinux.
To illustrate my confusion, here is what I have done :
Creating a linux partition :
$ gdisk /dev/sdb
Command (? for help): n
Partition number (1-128, default 1):
First sector (34-7821278, default = 36) or {+-}size{KMGTP}:
Last sector (36-7821278, default = 7821278) or {+-}size{KMGTP}:
Current type is 'Linux filesystem'
Hex code or GUID (L to show codes, Enter = 8300):
Changed type of partition to 'Linux filesystem'
Command (? for help): p
Disk /dev/sdb: 7821312 sectors, 3.7 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): F7F2BE49-B8D8-4910-8E69-381DEBD954DC
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 7821278
Partitions will be aligned on 4-sector boundaries
Total free space is 2 sectors (1024 bytes)
Number Start (sector) End (sector) Size Code Name
1 36 7821278 3.7 GiB 8300 Linux filesystem
Command (? for help): w
Final checks complete. About to write GPT data. THIS WILL OVERWRITE EXISTING
PARTITIONS!!
Do you want to proceed? (Y/N): Y
OK; writing new GUID partition table (GPT) to /dev/sdb.
The operation has completed successfully.
Then I formatted this partition as an ext2 :
$ mkfs.ext2 /dev/sdb1
Now I want to install MBR with syslinux (taken from the very few tutorials I found)
$ syslinux -m /dev/sdb1
syslinux: invalid media signature (not a FAT filesystem?)
So it needs to be a FAT partition. However I read that syslinux supports Fat32, ext2, ext3, ext4 file (https://wiki.archlinux.org/index.php/syslinux#Installation)
1) What is wrong here, since syslinux is supposed to support ext2 partitions?
So I formatted the partition as a Fat32 partition :
$ mkfs.vfat -F 32 /dev/sdb1
Now installing the syslinux MBR works:
$ syslinux -m /dev/sdb1
$ syslinux -i /dev/sdb1
2) Do I have to install a MBR, isn't syslinux compatible with GPT? I read on documentations that GPT has more advantages over MBR, such as allowing the creation of way more primary partitions. Did I misunderstand?
I then found that I need to flag the partition as bootable (http://www.linuxquestions.org/questions/linux-general-1/booting-iso-images-from-a-usb-disk-917161/). Can I do that with gdisk ? It seems to me it is not possible as the manual does not talk about boot flagging. In the other hand, fdisk allows me to do so. However here is another issue :
$ fdisk /dev/sdb
WARNING: GPT (GUID Partition Table) detected on '/dev/sdb'! The util fdisk doesn't support GPT. Use GNU Parted.
3) Does gdisk automaticaly create a GPT ?
$ gdisk /dev/sdb
GPT fdisk (gdisk) version 0.8.8
Partition table scan:
MBR: protective
BSD: not present
APM: not present
GPT: present
4) Where does this MBR come from? How can MBR and GPT coexist like this?
As you can see, as soon as I tried doing more in depth partition manipulations, I realized everything was mixed up. I would sincerely appreciate if you could answer my questions and especially provide me with additional documentation : https://wiki.archlinux.org and http://www.syslinux.org/wiki actually made my understanding worse than ever. Many thanks.
|
1) What is wrong here, since syslinux is supposed to support ext2 partitions?
Yes, Syslinux supports ext2 fs via Extlinux. If you are using a UEFI/EFI based system then you need a fat32 partition. For GPT only you don't need to have a fat32 partition, just go with the traditional. i.e. ext?
2) Do I have to install a MBR, isn't syslinux compatible with GPT? I read on documentations that GPT has more advantages over MBR, such as allowing the creation of way more primary partitions. Did I misunderstand?
It's up to you what do you want to use, both partition table msdos and gpt are supported.
In case of GPT you can use gdisk to set legacy bios boot flag. It's necessary to have a legacy bios boot flag on boot partition. After entering in gdisk menu use 'x' to go into expert mode and then use 'a' to set attributes.
3) Does gdisk automaticaly create a GPT ?
Yes, Visit http://linux.die.net/man/8/gdisk
For How To, visit http://wiki.gentoo.org/wiki/Syslinux
| Understanding syslinux and partitioning |
1,434,468,866,000 |
I just installed a new SSD and I want to move all the files from the HDD to my SSD.
I cloned the partitions from the hdd to the ssd.
I run on a dual boot - windows 10 and ubuntu 15.10.
So, now I have the exact same files on the ssd and hdd.
What I want to do is change the MBR of the ssd drive and make it the default drive that I boot to.
This is an image of the partitions on the SSD drive:
When I boot right now, it goes to the grub2 that sits on the HDD drive.
What do I need to do in order to boot from the ssd drive and have the grub2 point to the windows partition(/dev/sda2) and linux partition(/dev/sda5) instead of the hdd drive (/dev/sdb*)?
EDIT:
This it the fstab of the new partition: (sda)
# <file system> <mount point> <type> <options> <dump> <pass>
# / was on /dev/sda8 during installation
UUID=fa170041-7a3a-487f-8b90-3551fa4c132a / ext4 errors=remount-ro 0 1
# /home was on /dev/sda10 during installation
UUID=358504e1-f708-49bf-9c21-c407ab8538a2 /home ext4 defaults 0 2
# swap was on /dev/sda9 during installation
UUID=7a87f53e-4f86-4ebb-8a5e-02952d00cf8f none swap sw 0 0
UUID=4CAF-DDF2 /boot/efi vfat defaults 0 1
This it the fstab of the old partition: (was sda and now it is sdb)
# <file system> <mount point> <type> <options> <dump> <pass>
# / was on /dev/sda8 during installation
UUID=36e9e347-3000-4771-bfb7-d950b67b1be9 / ext4 errors=remount-ro 0 1
# /boot/efi was on /dev/sda1 during installation
#UUID=4CAF-DDF2 /boot/efi vfat umask=0077 0 1
# /home was on /dev/sda10 during installation
UUID=358504e1-f708-49bf-9c21-c407ab8538a2 /home ext4 defaults 0 2
# swap was on /dev/sda9 during installation
UUID=3443992d-49a2-4687-9e83-4bfa5ddcb7e4 none swap sw 0 0
UUID=4CAF-DDF2 /boot/efi vfat defaults,noauto 0 1
What I can see is that the operating system is booting from the old partition(sdb) but the /home directory is of the new partition(sda).
My problem is, how do I make the grub boot on the new operating system
|
I found what my problem was, I changed the efi -(hd0,gpt5) but I didn't change the UUID!!
| changing grub boot drive |
1,434,468,866,000 |
Is there a way to perform a safe reduce in rootlv at rescue mode? Most of the internet's explanations tells, basically, that it can be done using the following steps sequence:
vgchange;
fsck;
resize2fs;
lvreduce;
reboot
I tried it a several times; but all I get when system pass through POST is the same error:
FATAL: INT18: BOOT FAILURE
Is that a way to do that safely?
|
The steps I was doing were right at all. The problem was the way I was booting my system. BIOS found CentOS media, then installation menu has been shown to me. I was trying to boot choosing option "boot from hard drive" and after that I have received the error described before.
I repeated the steps again, but from this time I ejected CentOS' media before reboot. Bingo! It worked very well.
So, for help another person that eventually needs to reduce rootlv, here's howto:
Boot from a CentOS media (option rescue mode. Don't mount your system when asked by the wizard);
Activate rootvg (vgchange -ay rootvg. In case of you don't know vg's name, type vgs command)
Run fsck on rootlv (for example: fsck -f /dev/mapper/rootvg-rootlv. In case of you don't know lv's name, type lvs command)
Run resize2fs /dev/mapper/rootvg-rootlv 10G (taking on the size you'd like your LV to stay — 10 GB, for example, when you reduce 15 GB to 10 GB)
Run lvreduce -L 10 GB /dev/mapper/rootvg-rootlv (the step 4 can be skipped if you use -r parameter here)
Reboot the machine.
| How to reduce ext4 rootlv on centos 6 |
1,434,468,866,000 |
As I understand it, the GRUB bootloader on a BIOS system (and most other bootloaders for that matter) are comprised of 3 parts. The first part (stage 1) is stored in the first 448 bytes, which is responsible for passing control to the so-called stage 1.5, located a little later in memory. This stage finally loads stage 2 from the /boot folder, and transfers control to it.
How does stage 1 know which disk stage 1.5 resides on? Once the code in stage 1 begins execution, there's no way for it to be aware of which disk it was loaded from (unless this information is somehow passed to stage 1 or the BIOS itself also loads stage 1.5 into memory?)
For stage 1.5 to stage 2, again, how does does stage 1.5 known which disk (and which partition) the /boot directory resides on?
|
If you look at the sources of GRUB, available here, you find stage1 is actually defined at grub/grub-core/boot/i386/pc/boot.S.
It can perform a floppy boot if configured. It does boot from a configured harddisk, and it needs to know which C/H/S it has to load stage1.5 from. The only automatic function it has is determining which drive the boot sector was loaded from, if not configured otherwise. A functional BIOS will load that value into DL before passing control to stage1. Some don't and grub falls back to the first harddisk.
stage1.5 is already able to understand partitions and filesystems, so it doesn't rely on C/H/S values any more. The drive it loads from is still the same as above though.
| How does BIOS bootloader know which disk to use? |
1,434,468,866,000 |
I was reading Linux boot process and stumbled upon below questions:
When mbr gets write on first sector during installation.?
446 byte of mbr code will be same for either Linux or windows?
How can the mbr know that where is my grub?
I have gone through google but could not find any satisfactory answer.
|
The MBR gets written when Grub is installed, or when any other boot loader is installed
What the MBR contains depends on the boot loader that is installed. If Grub is installed, it can be used to boot both Linux and Windows.
Grub is (partially) installed in the MBR. The code in the MBR knows where to load the rest.
Having said that, I must point out that the MBR is quickly losing significance. It is not used to boot machines with UEFI firmware (unless the legacy compatibility mode is used). Practically all new PCs are shipped with UEFI today. UEFI machines have a different way of booting, and also use a different partitioning scheme, that does not use the partition table in the MBR.
| Question related to MBR |
1,434,468,866,000 |
I am talking about disk signatures in context of the MBR. The area from 440 to 444 bytes.
Let's say I got a bootable raw image (bootable in a virtual machine).
How can I set the disk signature to a fixed (non-random) value while keeping the raw image bootable? How to automate (script) that?
(If you are wondering if that is useful and for what... It is useful in context of verifiable builds.)
|
Take your image, extract the first sector:
dd if=image of=mbr.dat bs=512 count=1
write "AAAAA" to position 440-444 and do not truncate the file:
echo -en "\x41\x41\x41\x41\x41" | dd of=mbr.dat conv=notrunc seek=440 bs=1
Use a hexeditor like okteta to verify that it did what you wanted. Then write it back:
dd if=mbr.dat of=image conv=notrunc
See my wikiblog http://www.linuxintro.org/wiki/dd
| How to change the disk signature of a raw image? |
1,434,468,866,000 |
I had a Linux distribution which had installed grub on MBR.
Then I installed second Linux distribtion on a different partition but did not install grub in it.
Then I went to first Linux distribution and ran update-grub. So second Linux distribution also was picked up and is presented in menu at startup.
Now I want to remove first Linux distribution. How do I install grub in second Linux distribution so that it is linked to grub in MBR also?
|
Reinstall from working (not liveCD/DVD/USB) system - first find Ubuntu drive (example is drive sdb but use your drive not partitions):
sudo parted -l
if it's "/dev/sdb" then just run:
sudo grub-install /dev/sdb
If that returns any errors run:
sudo grub-install --recheck /dev/sdb
Then just to redo menu:
sudo update-grub
| Transferring Grub on MBR connection to different Linux distribution |
1,434,468,866,000 |
I have a laptop, which has a 500GB hard disk and with MBR partition, and I install my windows8.1 on it, but I left ~75G unused which I would like to use it for OpenSuse13.1. Now I have 2 USB, one is Gnome Live 13.1, another is standard DVD install ISO.
I tried to insert Gnome live 13.1 and no problems, it recognized my unused 75G partition, and recommend my Linux partition as below:
/dev/sda6 --> swap
/dev/sda7 --> /
/dev/sda8 --> /home
I cancelled this installation and try with DVD iso, and now I get an error when I try to use my 75G unused partition as below:
Your system states that it requires an EFI boot setup, since the selected disk does not contain a GPT disk label YaST will create a GPT label on this disk. You need to mark all partitions on this disk for removal.
I would like to keep my windows and create a dual boot system, but I am stuck here. anyone please give me some suggestions?
|
It sounds like you're either booting Windows 8.1 in legacy/BIOS/MBR mode (as opposed to EFI/GPT mode), or YaST is buggy and thinks that you have EFI booting enabled even though you don't. Another possibility is that your laptop's BIOS boots optical drives in EFI mode by default, causing YaST to load in EFI/GPT-only mode. Therefore, if there's a BIOS option in your laptop to turn off EFI booting, I suggest you set it. Another thing to try, is when you bring up the laptop's boot menu to select "boot from DVD-ROM", if there are 2 options "Boot from DVD - EFI" and "Boot from DVD - BIOS/legacy", pick "BIOS/legacy".
If you're really stuck, why don't you Google your laptop's exact model number with terms like "boot optical drive in BIOS/legacy mode" - this should hopefully point you in the right direction.
| How to install after windows 8.1 with MBR partition |
1,434,468,866,000 |
I am writing an update utility for an embedded Linux device for which I am responsible.
I'm creating a basic side-by-side setup, where updates are applied to a staging partition and then the bootloader is switched to the staging partition, changing the primary partition into the new staging one.
However, the embedded device uses a CF card, which are known for sometimes writing data out of order, etc. For this reason, if I mount a file system as read/write, there's a chance of corruption. Therefore, I cannot mount my bootloader partition RW in order to point to the new partition.
Is there a location on disk to which I can safely write a single byte, where the byte represents a 0 for the first partition or a 1 for the second? Even a CF card can't screw up a single byte write, which should happen atomically.
I'm using a plain-old DOS MBR format disk.
|
Create a third, tiny, partition to hold your data. Any other location on your disk will sooner or later bring trouble if indeed you cannot rely on the filesytems.
Sometimes the last few clusters of a disk cannot be addressed in the FAT entry, that may be an option but it heavily depends on exact size of the device.
Does the embedded CPU / device have EEPROM? That would be an ideal place for a single byte.
| Location on disk to write a byte-flag? |
1,434,468,866,000 |
I have a CentOS server on VMware that has, among others, a disk of 1.5TB, with a single xfs partition using the whole disk. This disk/partition is running out of space, so I need to increase its size to 2.5TB.
So I increased the size on VMware and tried to delete and add the partition, which failed. Of course, the original partition is MBR and the new one must be GPT, but when trying to remove/add the partition, the conversion fails. I've found the original partition is at sector 128 and the new one tries to start at sector 2048, which I tried to modify, but I couldn't (I guess because GPT needs more space than MBR?).
Then I come with the idea of moving the original partition so it starts at sector 2048, convert the partition to GPT, then increase the size of the partition.
Does it make sense? Is that possible? Specially the first part of moving the partition. Thanks!
Update
For formatting reasons, here's the output of the suggested command:
parted /dev/disk unit s print free
Disk /dev/sdb: 5368709120s
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Numero Inicio Fin Tamaño Typo Sistema de ficheros Banderas
63s 127s 65s Free Space
1 128s 3259013119s 3259012992s primary xfs
3259013120s 5368709119s 2109696000s Free Space
|
So you have one msdos partition that starts at sector 128.
This is uncommon since the standard would be MiB alignment, starting at sector 2048 (for 512 byte logical sector size).
With GPT, you can still use the start sector 128, that isn't a problem:
# parted /dev/loop0 unit s print free
Model: Loopback device (loopback)
Disk /dev/loop0: 3259017216s
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
34s 127s 94s Free Space
1 128s 3259017182s 3259017055s
However, parted will complain to you when you create it:
# parted /dev/loop0
(parted) mklabel gpt
(parted) mkpart
Partition name? []?
File system type? [ext2]?
Start? 128s
End? 100%
Warning: The resulting partition is not properly aligned for best performance:
128s % 2048s != 0s
Ignore/Cancel? Ignore
If you do not care about MiB alignment (and since your data is already there, you have no choice, anyway) you can just ignore this warning. A start sector of 128 would still be 4K aligned (64K aligned), so that would be fine too.
GPT also stores a backup at the end of disk, so the end sector can sometimes be the issue. However you're lucky and you have 4096 free sectors at the end of your disk, so there is no issue in your case. Otherwise you'd have to grow the disk first before converting to GPT.
If you want to achieve MiB alignment, you'd have to shift all data. The safest way to do so (if you have enough space) would be to just copy it over to a new disk entirely. Relocating data in place can be risky.
| Increase disk size and change from MBR to GPT |
1,561,645,469,000 |
So, somehow the partition table on my disk went bananas: at the next boot the system would not start, I got repeatedly kicked in the BIOS and I had no viable boot options. The BIOS still detected the disks properly, so I started a LiveDVD to see what's going on.
So, in the disk with the OS, /dev/sdb, 128GB SSD, there is no partition table. Both gpart and fdisk report it empty. fdisk report the disklabel type to be gpt.
I tried running testdisk, which identifies the partition table type to be Intel (and not EFI GPT). I tried searching for partitions with both types, but only Intel was successful.
So, first question: is Intel partition type a MBR? Why does EFI GPT not work even if the disk label is GPT?
When starting, the tool finds this partition only:
Disk /dev/sdb - 128 GB / 119 GiB - CHS 15566 255 63
Partition Start End Size in sectors
1 P EFI GPT 0 0 2 15566 29 63 250069679
When I run a Quick Search (or even a full search), the tool finds some partitions, and among these there are 5 partitions that make sense:
FAT32 0 32 33 33 69 36 532480 [SYSTEM]
Linux 33 69 37 163 207 44 2097152
Linux Swap 163 240 14 931 97 62 12328960
Linux 931 97 63 9038 187 45 130244608
Linux 9038 187 46 15565 209 4 104857600
Second question is related to the values displayed: there are 3 values in the start column (e.g. 0 32 33) and 3 in the end column (e.g. 33 69 36), how do I interpret these values?
If I look inside these partitions, using the P: list file command, I can see that
The first partition contains EFI stuff, such as
drwxr-xr-x 0 0 0 31-Jan-2019 19:26 EFI
drwxr-xr-x 0 0 0 13-Mar-2019 18:29 System
-rwxr-xr-x 0 0 0 21-May-2019 10:55 mach_kernel;5ce3af18
-rwxr-xr-x 0 0 34 13-Mar-2019 18:29 mach_kernel
drwxr-xr-x 0 0 0 26-Oct-2018 00:52 8310a92cdfe04b36b5a63736b6419b48
The second partition is the boot partition, contains efi, grub2, vmlinuzs etc.
The fourth partition contains home folders and the last one contains the root.
Since I can see the files, I recovered /etc/fstab and /etc/lvm/, which indeed show that the system was configured using LVM.
I am not sure if partitions were extended/logical in some way, I don't even know if that makes sense with GPT and it's not limited to MBR.
Third question, given that testdisk can identify some partitions, I could try to restore the partition table using those values, but what about LVM? What about GPT? How can I restore the previous situation, given that these partitions seem to be properly identified?
Thanks a lot!
EDIT:
I throw in the question regarding the extended partitions because apparently I have no way to set them all to primary (this make me think it's MBR) and I would need an extended one, but I am unable to create it.
EDIT 2:
Here all the partitions found by an in depth search:
Disk /dev/sdb - 128 GB / 119 GiB - CHS 15566 255 63
Partition Start End Size in sectors
>* FAT32 0 32 33 33 69 36 532480 [SYSTEM] *
P Linux 33 69 37 163 207 44 2097152 *
P Linux Swap 163 240 14 931 97 62 12328960 *
D Linux 931 97 63 9038 187 45 130244608 *
D Linux 4873 98 26 12980 188 8 130244608
D Linux 4875 43 33 12982 133 15 130244608
D Linux 9038 187 46 15565 209 4 104857600 *
D FAT12 9695 133 39 9695 198 39 4096
D HPFS - NTFS 15502 117 40 15566 19 5 1021952
The partitions with files are 1st (EFI), 2nd (/boot), 4th (/home), 7th (/). I marked with a * at the end of the line the apparently legit partitions.
Edit
I ended up copying the drive with dd, reinstalling the OS and recovering the data by mounting the old partitions in this way.
|
Before you go any further create (dd) an image of the disk that you can use to restore it if things go badly wrong.
It seems from your post that you have read the TestDisk guide. If not best to read it.
Question 1
Testdisk should identify the available partition types automatically and the fact that it found an INTEL partition is not a worry. You found the partitions, verified the content by examination, they are what you want to recover. Don't forget that testdisk is using the same schema to find your files that it will write to to a repaired partition table. So that all looks good.
Question 2
If you look at the guide you should be able to see that the figures you are interested in are the first figures in the start and finish column. When these are contiguous then the partitions don't have gaps between them and it is likely that they are part of a coherent partition schema. This is good and, again, the fact that testdisk can use the partition table it has created/inferred from the disk to get down to file level is again confidence inspiring.
The only issue that gives me any cause for concern is that the start and end addresses are the same and not consecutive. That said, testdisk should choke if you ask it to write an invalid table.
Question 3 .... should i...?
LVM will not be seen at this level but will be picked up at boot when the repaired OS loads the LVM modules and reads the LVM layout from your resurrected system.
GPT / MBR are just different formats of partition table. Since the one being used by testdisk finds your files it is the one you should use in recovery.
In your position I would proceed and repair the table as per the schema you list safe and confident in knowing that I had prepared an image that I can restore to the original disk and try again if it goes wrong.
If it's any comfort I had a 1TB drive go ping and went through similar pangs deciding what to do. In the end all went well using the default schema selected by testdisk but I had a backup in my hand.....just in case.
If there are a lot of partitions to choose from then I suggest you post the complete output and then you may get some more specific assistance.
Edit
TBH I am a little nonplussed with the 5 partitions/MBR conundrum.
The best I can offer is what I would do in your situation, which is make copies of the image, attempt to recover one more partitions as MBR from each image (by mounting the image in testdisk, not the SSD) and then reconstruct the original disk on new media with a GPT schema. If that works then migrate the whole shebang back to your SSD. You would need to reinstall grub and play with the GUIDs in fstab when you migrate back to make everything mount but that is not rocket science.
The bottom line is that you can try whatever you like on copies of the image without fear. Just keep the original drive and one image safe.
| Recovering lost partition table with TestDisk |
1,561,645,469,000 |
There's a video driver problem with GPT, the Apple A1286 Mid-2010 MacBook Pro machines, and NVIDIA GT330M drivers, and running Nouveau has its own problems, so I want to install Cinnamon Mint 19.1 using MBR partitioning so I can use the proprietary drivers. It will be the sole OS on this PC.
I had formatted the internal HDD from a LiveUSB generated by Rufus for MBR, but Mint 19.1 wants to repartition using GPT. How do I install Mint 19.1 and retain the MBR partition table?
|
Installed OK on the MBR-partitioned drive in this 2010 MacBook Pro A1286 once I
deleted the ext4 partition sda1 which had the entire drive
created a 1MB partition at the front as sda1 for MBR use. Then,
created an ext4 partition sda2 for the rest of the drive for root.
Now, Mint 19.1 install is complete, and I can work on the NVIDIA driver issue, serely confident that no other Apple strangeness will complicate this install. {/sarcasm}
| Want MBR install of Mint 19.1 |
1,561,645,469,000 |
I have an internal NoteBook HDD hooked up to a Linux machine externally via USB and want to check if this HDD has some sort of boot record on it.
I have no access to BIOS and can not boot my device from this HDD
externally
I can not hook this HDD up internally to any machine at
the moment
Should there be a boot record I have no idea what type it may have been.
The HDD is mounted as a 250 GB empty drive and I can paste file into the main folder and delete them with no issues so seems it is working fine as a storage device.
The output for
sudo file -s /dev/sdb5
is:
/dev/sdb5: data
Is there a way to find out using the command line in Linux if there is any boot records on it and if so what type?
|
BIOS boot loader, MBR
Please check the whole drive (point to the drive's head end),
sudo file -s /dev/sdX
sudo file -s /dev/sdb # example: device b
Do not point to a partition,
sudo file -s /dev/sdb5 # example: device b, partition 5
UEFI bootloader
In UEFI mode the computer needs nothing in the boot sector at the head end, but right behind it there should be a partition table.
There is usually a small EFI system partition with a FAT file system.
There is often (but must not be) a GUID partition table, GPT.
Check with
sudo parted -ls
sudo fdisk -l
sudo gdisk -l /dev/sdX
Cloned iso file
You can clone from an iso file to a USB pendrive or another mass storage device. Then there will be an iso9660 file system, and it can often be booted both in BIOS and UEFI mode.
Check with
sudo lsblk -f
sudo lsblk -m
| How to find boot record of external HDD |
1,561,645,469,000 |
I have a MBR table that have a few partition that was deleted previously.
What are the ways to reassemble the MBR Partition entry and restore the deleted partitions without using 3rd party tools or software like testdisk.. etc.
|
Every filesystem has a signature. So if you know which filesystems were used on the partitions, then you can use a hex editor to open the block device and search for the filesystems. Filesystems tend to start at (or near) the beginning of partitions, so when you find the beginning of a filesystem there's a good chance you've also found the start sector of a partition.
Partitions tend to end right before the start of the next partition, so that's how you'd determine the end sector; Except for the last partition, of course.
Once you have your start/end sectors you can simply use a partitioning tool to create those partitions. Then, cross your fingers and try mounting the filesystems.
Of course, there are some scenarios which would make this process difficult or impossible:
If the filesystem is stored in an encrypted block device (ex. LUKS).
If there are filesystems or disk images, such as those used for virtual machines. Without more information you wouldn't be able to tell the difference between a disk image and a partition.
What I've described above is essentially what testdisk automates for you.
| Reassemble deleted MBR Partition |
1,561,645,469,000 |
After installing Linux Debian on external HDD (not live Boot), is no booting possible. If I start the PC it automaticly jumps in grub-rescue. How should I fix it? On the Internal HDD is just Windows 10 installed.
Thank you for your Help.
|
Answerer by Anwar on Askubuntu.com
If you were able to boot Ubuntu in the past, but not now, follow these steps to solve the problem.
First type ls command and Press Enter to see all the available
partitions. The entries will be shown as (hd0,msdos1) (hd0,msdos2) (hd0,msdos5) etc.
Then type ls (hd0,msdos1)/ to see the content of the drive. if you
see entries like vmliuz or initrd, it is your Linux partition. If you
fail with (hd0,msdos1), try with (hd0,msdos2) and so on, until you
recognize your Ubuntu partition.
When you correctly identify your Ubuntu partition, type
root=(hdX,msdosX) , replace the X with correct identified number. For
example, if you see vmlinuz and initrd entries by entering ls
(hd0,msdos5), the command will be root=(hd0,msdos5).
then type configfile /boot/grub/grub.cfg and type Enter. This will
bring you Previous Ubuntu grub menu.
Then choose the entry to boot Ubuntu.
After you booted up, Open a terminal and type sudo update-grub and
press Enter. This will update the grub menu and prevent future
problems.
In the case that you are not able to boot to Ubuntu after installation, re-installing Ubuntu is the best option. You can check this question:
How to install Ubuntu OS Having already installed Windows OS
| Boot problems after installing Linux Ubuntu [closed] |
1,561,645,469,000 |
I'm trying to understand the partition table of my MTK-6572 based android smartphone (Karbonn-A35). The idea is to enlarge the internal Storage partition (mounted as /data) and correspondingly shrink the Phone Storage partition (mounted as /mnt/sdcard), so that I can install more apps on the phone without getting the "Disk Full" error. However, there is one thing I want to understand before proceeding to change the EBR1 partition file. Presently, here is how my MBR & EBR1 look like (yeah, I'm also wondering why the heck do they create an extended partition of 2TiB in size, whilst my sdcard is just 2GB!):
$disktype MBR
--- MBR
Regular file, size 512 bytes
DOS/MBR partition map
Partition 1: 2.000 TiB (2199023255040 bytes, 4294967295 sectors from 1024)
Type 0x05 (Extended)
Partition 2: 10 MiB (10485760 bytes, 20480 sectors from 18432)
Type 0x83 (Linux)
Partition 3: 10 MiB (10485760 bytes, 20480 sectors from 38912)
Type 0x83 (Linux)
Partition 4: 650 MiB (681574400 bytes, 1331200 sectors from 113152)
Type 0x83 (Linux)
$disktype EBR1
--- EBR1
Regular file, size 512 bytes
DOS/MBR partition map
Partition 1: 376 MiB (394264576 bytes, 770048 sectors from 1443328)
Type 0x83 (Linux)
Partition 2: 1.293 GiB (1388314624 bytes, 2711552 sectors from 2213376)
Type 0x83 (Linux)
Partition 3: 1.998 TiB (2196501691904 bytes, 4290042367 sectors from 4924928)
Type 0x83 (Linux)
If you see the 4th and 5th partitions (i.e. the end of 4th in MBR and beginning of 1st in EBR1), there is some overlap. The fourth partition says 1331200 sectors from 113152. But when you count 1331200 sectors from 113152, you get 1444352 from where the next partition should begin. However, the next partition (i.e. the 1st in EBR) begins from 1443328 which is a bit earlier than that. Isn't that a kind of overlap for those few sectors (1444352−1443328=1024)? Those 1024 sectors are both part of 4th and 5th partitions? Or am I missing something about my understanding about partition tables?
That's one thing, another thing is about the third partition in EBR1. This wikipedia article on EBR says that only the first two entries in an EBR are supposed to be used:
EBRs have essentially the same structure as the MBR; except only the first two entries of the partition table are supposed to be used, besides having the mandatory boot record signature (or magic number) of 0xAA55 at the end of the sector.
Then how come the EBR1 of my device contains three entries? Again, is this a non-standard thing or am I missing something?
edit
Hex output of the EBR1 showing the three entries:
|
Extended boot records only need contain two values, and your EBRs probably do. The second entry in an EBR points to the next EBR (unless it is the last one in the chain).
Your disktype utility walks the chain of three EBRs and display each of the entries as if they were a multiple entry MBR.
(This is explained in the Values section of the wikipedia article)
| A basic query about Linux partitioning |
1,561,645,469,000 |
I ran fdisk with these options,
fdisk -H 32 -S 32 /dev/sdc
Then I made a new label, and created an aligned first partition.
Disk /dev/sdc: 7743 MB, 7743995904 bytes
32 heads, 32 sectors/track, 14770 cylinders, total 15124992 sectors
However when I run,
fdisk -l /dev/sdc
My heads are reported at 16, like this,
Disk /dev/sdc: 7743 MB, 7743995904 bytes
16 heads, 32 sectors/track, 29541 cylinders, total 15124992 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
Disk identifier: 0xd84c4698
Device Boot Start End Blocks Id System
/dev/sdc1 8192 15124991 7558400 c W95 FAT32 (LBA)
Why does the disk not show the 32, as I specified when creating the partitions? Is it just displaying 16, but everything is still actually as I specified?
Really just want to make sure I'm still correctly aligned.
|
Units = sectors of 1 * 512 = 512 bytes
Your partition starts at (Start) 8192 × (Unit size) 512 = 4MiB
I don't know what your intention was, but it doesn't look too bad as it is on a 32×32-boundary too (4096).
Don't know why fdisk says 16, but it looks all right to me. Maybe check the manual page man fdisk for more details.
| Fdisk partition alignment, NAND, not showing specified heads |
1,561,645,469,000 |
After installing Linux on a computer (Debian in particular), should I bother backing up the MBR or the GPT and use something like monit to periodically compare the MBR/GPT against this backup? Is this worth the trouble, or is there any better way, or is it not applicable anymore?
I recall in the past about boot sector viruses getting into the MBR of a disk and not being able to detect them unless I previously had a copy of the MBR sitting around against which I can compare.
In the past, I've backed up the MBR as follows:
# dd if=/dev/sdX of=hostname-sdX-mbr.dd bs=466 count=1
For GPT partitions now, I was considering this:
# sgdisk --backup=hostname-nvme0nX-gpt.sgdisk /dev/nvme0nX
Then re-running these same commands inside a monit task followed by a diff to see if anything changed.
My general partitioning scheme on these hosts is as follows:
Partition 1: /boot/efi
Partition 2: /boot
Partition 3: Encrypted partition
LVM
vg: Swap partition
vg: root partition (/)
|
The EFI/GPT partitioning scheme cannot contain malware, so it's not necessary. Monitoring changes in it is still a welcome security measure in case a possible intruder will want to mess with your partitions.
With EFI/GPT the system boots from the EFI System partition (FAT32/FAT16) and binary files on it must remain the same except for rare GRUB updates and GRUB configuration files.
As for GRUB configuration files: Fedora and other Linux distros which use blscfg/Boot Loader Configuration specification never change the said files.
| Backing up MBR/GPT for detecting boot sector viruses |
1,561,645,469,000 |
Is there any command to list all partition type codes recognizable by currently installed
distribution (In my case Ubuntu 18.04.03 LTS)
I know the following website exists Andries E. Brouwer 1995-2002 - homepages.cwi.nl
yet there should be any command inbuilt in the linux console.
I know that cgdisk shows all partition codes while creating new partition
Provided screenshots from my own system while formatting a pendrive creating bootable Ubuntu 20.04 lts usb
Yet again my question is, Is there any command that can show all recognizable partition
type codes for MBR and GPT for the current distribution or if there is any
man pages that has reference?
Or may be this is different for the different tools?
Example of MBR partition types codes thestarman.pcministry.com
|
Ok finally I found that it's mainly dependent of the filesystem and the volume
identification hex code is/should be present in the filesystem documentation
as seen below for NTFS and EXT4
Conclusion: There is not specific command or tool only for listing partitions hex code besides the function of cgdisk, gdisk, cfdisk, fdisk, etc while creating the partition.
gdisk - list partition hex code previous to creation
cgdisk, cfdisk and fdisk - list partition hex code during creation only
NTFS Partition $VOLUME_INFORMATION 0x70 Attribute
http://dubeyko.com/development/FileSystems/NTFS/ntfsdoc.pdf
EXT4 Partition Identifier for MBR (right column)
https://en.wikipedia.org/wiki/Ext4
This post partially answers the question also
Why does parted need a filesystem type when creating a partition, and how does its action differ from a utility like mkfs.ext4?
"A partition can have a type. The partition type is a hint as in "this partition is designated to serve a certain function". Many partition types are associated with certain file-systems, though the association is not always strict or unambiguous. You can expect a partition of type 0x07 to have a Microsoft compatible file-system (e.g. FAT, NTFS or exFAT) and 0x83 to have a native Linux file-system (e.g. ext2/3/4)."
So apparently the code is not always strictly associated as shown in the previous answer.
For example EXT4 83h Any native Linux file system (see 93h, corresponds with 43h)
https://en.wikipedia.org/wiki/Partition_type#PID_83h
Or Solaris ZFS for example as seen in BFh and 82h sections
https://en.wikipedia.org/wiki/Partition_type#PID_BFh
https://en.wikipedia.org/wiki/Partition_type#PID_82h
Additional examples information gathered during the research
ZFS Attributes BF01 BF07 EF02
BF01 special hex type code Solaris Partition
BF07 special hex type code Solaris Reserved 1
EF02 special hex type code BIOS Boot Partition
https://www.it-swarm-es.tech/es/gdisk/codigos-hex-de-gdisk/961390299/
| Command to list partition type codes in deb and rpm distributions for MBR and GPT |
1,561,645,469,000 |
My system was dual booted with CentOS 7 and Windows 8.
After I reinstalled the latest Windows 10 Pro and removed windows 8, my system is only booting with Windows 10 as the Grub2 is not appearing at the boot time.
I assume Grub2 is over written by Windows MBR. I might need to reinstall grub on my system. I don't have any clue on how to attempt this Grub2 installation as CentOS 7 is the latest version which is having many changes
|
The solution was simple with the below steps.
Booted my system with CentOS 7 disk into a rescue mode.
Now mount my root partition by running the chroot command as follows.
chroot /mnt/sysimage
Then I installed MBR with the below command.
grub-install /dev/sda
after installing the grub boot loader I rebooted the system, and it was up with any changes to the system.
| CentOS 7 grub option is missing after upgrading windows 8 to 10 |
1,561,645,469,000 |
I have tried installing Arch Linux and what I ended up with was a partition scheme like this:
/dev/sda:
/dev/sda1 NTFS partition (Windows 7)
/dev/sda2 ext4 (Arch)
/dev/sda3 swap
I don't know why, but for some reason I have been unable to mount the NTFS partition under Linux.
It's worth mentioning that the first partition is, for some reason, detected as an EFI partition and as on a GPT-formatted disk (my computer doesn't have an EFI bootloader and the drive has always had an MBR partition table).
I deleted the sda2 and sda3 using the Windows repair disk and was about to install a second Windows 7 installation alongside the first partition, but an error reported that the entire disk is a GPT drive!
The "Used" and "Free space available" sections indicate that the data on the first partition is still there, it's just that I cannot access the actual partition by any means. It seems that the first partition is with an MBR partition table on a GPT style disk.
How do I access the data on the partition?
|
This is utterly strange, but I have solved my problem.
As I'm not sure what exactly solved the issue, I'll describe what happened.
First of all, I tried to access the partition from Arch Linux, which
was installed on the same drive. This didn't work;
I deleted the Linux partitions;
I've unplugged the computer from the electric source and left it
overnight (this helped me a few times, especially while fixing
recursive fault errors during boot);
The next morning I created an Ubuntu LiveUSB, booted the computer from it and mounted the malfunctioning partition using the following command:
sudo mkdir /mnt/disk
sudo mount /dev/sda1 /mnt/disk
After executing the above commands I was able to access the partition and backup all of my files.
| Recover Windows partition in a GPT disk (previously MBR) |
1,561,645,469,000 |
Trying to clean the mbr code part on a disk using the pfsense 2.7.0 live disk (pfsense is based on freebsd) under shell command.
being /dev/da0 my drive following the suggested code for clean just the mbr code keeping the partitions the command should be:
dd if=/dev/zero of=/dev/da0 bs=446 count=1
however... the result is:
dd: /dev/da0: Invalid argument
1+0 records in
0+0 records out
0 bytes transferred in 0.000089 secs (0 bytes/sec)
instead... if I use as code just dd if=/dev/zero of=/dev/da0 it just erases everything without errors :(
I'm doing this tests in a vm so I can recover the hd many times to test this passage... however this thing is giving me headaches...
EDIT: It seems that if I use bs=512 or bs=1M it doesn't gives errors. However doing so also the partitions table part would be deleted...
EDIT2: I tried to use the command dd if=/dev/da0 of=/tmp/mbr_file bs=512 count=1 and it create for me a file with the mbr, I wonder what commands can I use for edit in binary mode the file filling the first 446 bytes with 0 and then use dd if=/tmp/mbr_file of=/dev/da0 bs=512 count=1 to restore it.
What could I use? vi?
|
Ok, I did many test and came to this conclusion...
Because pfsense is a damn stripped version of freebsd and LOT of tools are missing I had to do this to clear the first 446 byes in the disk preserving the partition table located at the latest 66 bytes of the first 512 bytes block.
dd if=/dev/da0 of=/tmp/mbr_file_original bs=512 count=1
dd if=/dev/zero of=/tmp/mbr_file_zerofilled bs=446 count=1
cat /tmp/mbr_file_original | ( dd of=/dev/null bs=446 count=1; dd bs=66 count=1 ) > /tmp/mbr_file_partitions_table
cat /tmp/mbr_file_partitions_table >> /tmp/mbr_file_zerofilled
mv /tmp/mbr_file_zerofilled /tmp/mbr_file_new
dd if=/tmp/mbr_file_new of=/dev/da0 bs=512 count=1
then for testing the copied mbr content
dd if=/dev/da0 of=/tmp/mbr_file_test bs=512 count=1
hexdump /tmp/mbr_file_test | less
In short what I did is:
copy the mbr to a mbr_file_original
created a zero filled 446 bytes file called mbr_file_zerofilled
then BECAUSE SOMEONE YEAH I'M LOOKING AT YOU removed practically every useful tool even hex editors, leaving just this hack available used this line cat mbr_file | ( dd of=/dev/null bs=446 count=1; dd bs=66 count=1 ) > mbr_file_partition_table to extract from original mbr_file the last 66 bytes.
At this point using cat I concat 2 files and renamed to a mbr_file_new for the sake of clarity and then used dd to save back the mbr to the da0 device
this time without errors because I used 512 bytes in one time.
| using dd for clean MBR code doesn't work on pfSense |
1,561,645,469,000 |
Inspired by UEFI, I want to skip the stage of the bootloader (grub, lilo, syslinux) and boot linux directly. Is this possible? Cant I just boot the kernel directly, or have a minimalistic bootloader that fits in the MBR?
|
The space available in the MBR itself is tiny. (About 400 bytes or something.) That's way too small to fit an entire filesystem driver. Without a filesystem driver, there's no way to figure out where on disk the kernel is stored, and hence you can't load the kernel.
You could try hard-coding the location of the kernel into the MBR itself. But then if the file ever moves on disk (e.g., you defrag the disk), the system stops booting.
EFI apparently includes a FAT driver, meaning you can put a bunch of files on a partition that's formatted with FAT and load executables from there. So you could maybe put the Linux kernel onto that somehow... I don't know enough about EFI to say much about it.
| Is there a way to boot linux directly from MBR? |
1,561,645,469,000 |
Has anyone tried updating to Windows 10 on a dual boot machine? I'm concerned that Windows 10 might mess with the MBR.
Is there a way to preserve the MBR and easily restore it if Windows in fact changes it? The other OS on the dual boot is Lubuntu.
|
You can save your MBR to a file using dd
dd if=/dev/sdX of=~/MBR.backup bs=512 count=1
Where X is the device you want the backup from. Mind the if parameter it is the device (sda) not the partition (sda1,sda2,sdb1, etc...)
| How to back up a MBR |
1,561,645,469,000 |
I'm analyzing a compact flash using fdisk and by comparing it to the contents of the partition table on the CF's master boot record. I don't understand what the "Start" and "End" columns mean. Some of the documentation that I read says that it means the starting sector and ending sector of that partition, but when I compare the fdisk output to the address of the partition in the MBR partition table, the result don't seem to agree.
Fdisk -l reports that the first partition starts at 3 but ends at 2241.
However a hexdump of the partition table in the MBR shows that the partition starts at sector 0x800 according to the LBA address. While the CHS addres shows Cylinder 1, Head 1, Sector 3.
So what does fdisk mean by Start 3, and End 2241?
|
CentOS 6's fdisk still defaults to using cylinders as the default units when displaying the partition table. As commented by zevzek, this is obsolete and you should use fdisk -u=sectors -l to better match the reality of modern storage devices and also how later versions of fdisk display it by default.
The CHS values in the actual partition table have pretty restrictive maximum values:
the cylinders field is just 10 bits wide (= values 0-1023)
the heads field is 8 bits wide (= values 0-255)
the sectors field is 6 bits wide (= values 0-63)
So from your partition table, the start CHS (3 bytes) begins at location 0x1bf, with beginning H = 1, S = 3 and C = 1. This does not look correct.
Location 0x1c2 is the partition type (0x83), and immediately after that is the end CHS value (3 bytes) at location 0x1c3 onwards.
The second red frame in your hex dump is not pointing at the correct location:
the value at 0x1c3 is the end H value (0x14 = 20).
The value at 0x1c4 specifies the end sector value in the bottom 6 bits, and the two most significant bits of the end cylinder value in the top 2 bits. So 0xe8 = 11 101000 in binary, so the end S would be 40.The top two bits of the end C value represent a hexadecimal digit 3.
The value at 0x1c5 specifies the low byte of the end C value: together with the high two bits from the previous byte, the end cylinder value is 0x3b4 = 948.
(These values would represent a partition of only about 378 MB, so compared to the 4-byte partition size value later the partition table, the end CHS value in the partition table is clearly complete nonsense.)
But no matter how you slice it, this creates a limit at 7.87 GiB / 8.45 GB, at which points the bit values of the CHS fields in the partition table become all-ones, and those fields cannot represent any values larger than that.
This was further complicated by the IDE disk controller specification having a different set of CHS limits: an IDE controller could accept CHS values of up to 65536 cylinders (0-65535) and 255 (1-255) sectors, but only up to 16 (0-15) heads. If you just use the CHS values as-is, then together with the MBR limits, this would cause a limit at just 504 MiB / 528.4 MB.
Because of this, since July 1994, there has been a geometry translation convention to adapt the CHS values to the current use case. So the 2242 cylinders, 21 heads and 40 sectors are what the hardware says is the real geometry, and the values used in the partition table are based on translated, fake geometry in order to make the values fit in the fields of the partition table and the oldest BIOS system calls. This translation would usually involve choosing a number N, dividing the physical C value by N and multiplying the physical H value by N. The value of N would often be 2, 4, 8, or 15. (Yes, 15 instead of 16, to work around a bug in MS-DOS, old versions of Windows, and some old BIOSes.)
And when going beyond 8.45 GB, the CHS values are useless anyway, so any modern OS will usually straight up ignore the CHS values, and instead will use the 4-byte values of the LBA number of the first block of the partition and the total number of blocks in the partition to actually define the partition's location and size. Those 4-byte values should always be exact and unambiguous.
While using the classic 512-byte sector size, those 4-byte values will be enough for disk sizes up to (2^32 - 1) blocks in size, or in other words, just under 2 TiB, or 2.19 TB.
In the case of your partition, your second red frame in the hex dump actually points at 0x1c6 onwards, which is the LBA# of the first block of the partition: since it's represented in little-endian format, the value is 0x800 in hex, or 2048 in decimal. This follows the modern standard convention of starting the first partition at exactly 1 MiB from the beginning of the disk.
The length of the partition is specified starting from offset 0x1ca, and is 0x1cb000 = 1 880 064 blocks, or 918 MiB / 940 MB.
You can see that even the hardware-reported CHS geometry of 21 heads, 40 sectors/track, 2242 cylinders results in just 2242 * 40 * 21 = 1 883 280 sectors, or 1883280 * 512 = 964 249 360 bytes, while the actual disk capacity is reported as 964 583 424 bytes.
This is another indication that the CHS "geometry" is just an approximation for legacy devices and OSs, while the exact capacity is something different.
I guess fdisk just does everything using the LBA representation, and when requested to display the partition start and end values as cylinders, just calculates them based on the LBA position and size values, completely ignoring the start/end CHS values in the partition table. Likewise, the Blocks column seems to be actually displaying the size of the partition in base-2 kilobytes.
| What does fdisk's Start and End values mean when looking at a compact flash |
1,561,645,469,000 |
I am partitioning an external 1TB HDD for a small embedded Linux system. I want to encrypt the swap partition. According to the cryptsetep FAQ, you need to use kernel device names (/dev/sda, etc) in /etc/crypttab:
Specifying it directly by UUID does not work, unfortunately, as the UUID
is part of the swap signature and that is not visible from the outside
due to the encryption and in addition changes on each reboot.
This may become a problem if I attach/rearrange drives later and the device name changes. For example, say the swap is on /dev/sda3. Then I attach a different drive which becomes /dev/sda, pushing the original drive to /dev/sdb. If there exists a third partition on the new drive (now called sda3), it will try to encrypt that drive and use it as swap.
One option given is to make sure sure the partition number is not present on additional disks. So, finally, my question:
Can I use non-contiguous partition numbers? Will they persist across reboots? In other words, could I do this? Note the gap between sda4 and sda8:
/dev/sda1 primary /boot
/dev/sda2 primary /
/dev/sda3 primary /home
/dev/sda4 extended
/dev/sda8 swap (encrypted)
If so, I would feel pretty safe about never seeing sda8 on any other drive.
|
Partition numbers cannot conflict. Physically cannot.
The partitions are recorded in a Partition Table, special place in the 0-block of the disk. These records are not a named records, they are placed in an array. The index in that array (plus one) later become a number in the list of partitions you see in terminal. Read wiki for example: https://en.wikipedia.org/wiki/Disk_partitioning
And yes, Partition Table can have empty cells. Ot is just an indexed array. Any record in it can have a zero for Partition Type and all tools would know that this record is empty.
| Do MBR partition numbers need to be contiguous? |
1,561,645,469,000 |
I am trying to better understand disks, partitions, and partition tables (mbr vs gpt). In the process I checked the disks on one of my machines (single boot ubuntu 20.04), and found that all of my disks are gpt. However I also found out that some of the partitions have a partition table too. What got me even more confused is that the /boot/efi partition is mbr even though it is on a disk that is gpt. At that point I wasn't sure whether the disk was gpt or otherwise so I tried to convert the /boot/efi to gpt but in the process ended up rendering my machine unbootable. When I looked online for how to convert between the two styles I found that the conversion is done on the disk rather than the partition, but I already have my disk partitioned as gpt. So my question can be divided into three parts (and it all depends on my understanding as laid out above being correct):
1- What does it even mean to have a partition table inside a partition?
2- How can a disk be gpt but the /boot/efi partition on it be mbr? And why?
3- If a system has two hard disks, but one operating system, can each one of these disks have their own different partition tables (one mbr the other gpt)?
|
Yes, its possible.
"Instead of a primary partition, you can also define (exactly) one extended partition in the primary boot sector that contains all the disk space that is not allocated to any primary partition. In the extended partition further logical partitions can be set up, which in principle are structured in the same way as the primary partitions, with the difference that only the primary partitions can be booted directly. With a utility like Linux Loader (LILO), the operating system can be booted from any partition, even on other hard disks, but LILO itself must always be installed on a primary partition of the first hard disk."
Source: https://www.nextop.de/lhb/node231.html
Annotation:
The above example is not limited to the use of LiLo as boot manager.
It is to be noted that on a GPT hard disk no extended or logical partitions must be created, since the historical restriction of the number of primary partitions with old DOS and WINDOWS versions, do not exist here.
| Can a disk partition have another nested inside it? |
1,561,645,469,000 |
When GPT is used partition ID can be set with sgdisk
$ sgdisk --partition-guid=1:"00000000-0000-0000-0000-000000000000" "/dev/vda"
$ readlink -f /dev/disk/by-partuuid/00000000-0000-0000-0000-000000000000
/dev/vda1
How can I use a predefined partition id with MSDOS partition table?
|
$ ID=00000001 # Disk identifier
$
(
echo x # Expert mode
echo i # Change disk indentifier
echo 0x"$ID" # New identifier
echo r # Return
echo w # Write
echo q # Quit
) | fdisk "/dev/vda"
$ readlink -f /dev/disk/by-partuuid/"$ID"-01
/dev/vda1
| sfdisk/parted: predictable/predefined partuuid for msdos partition table |
1,632,160,214,000 |
I'm trying to understand where GRUB stage 2 is located on my bootable compact flash. Below is the output of the file command which was run against an image of the MBR (first 512 bytes) of the compact flash.
It says that the stage 2 address is 0x2000, or in decimal 8192 which would put it at the 16th sector ( 8192 Bytes/512 Bytes per sector).
I though that the second stage of the bootloader was supposed to be in the bootable partitions in the VBR, or PBR. If that were the case then I would expect the address for it to be 0x100000, which is the beginning of the bootable partition at sector 2048. (2048 sectors x 512 Bytes = 1048576 = 0x100000 )
So in the output below, what does the stage 2 address of 0x2000 and stage 2 segment of 0x200 mean?
[centos@centos6 ~]$ file SQFlash_MBR
SQFlash_MBR: x86 boot sector; GRand Unified Bootloader, stage1 version 0x3,
stage2 address 0x2000, stage2 segment 0x200;
partition 1: ID=0x83, active, starthead 1, startsector 2048, 1880064 sectors, code offset 0x48
[centos@centos6 ~]$
|
Since the output mentions stage1 and stage2, we're talking about GRUB Legacy (i.e. GRUB version 0.97 or older) here. Modern versions would have a "core image" and a set of modules instead.
stage2 address and stage2 segment don't refer to disk sectors; they refer to the memory address stage 2 will be loaded to. The address is in the segment:offset format used by the x86 processors in 8086-compatibility mode ("real mode").
Since this is GRUB Legacy, the number of the next disk block GRUB will read was embedded into the MBR code when GRUB was installed to your compact flash as a single 32-bit value. MBR is block #0, and the next block GRUB will read will typically be block #1: it will contain the GRUB blocklist that defines sequence(s) of disk blocks to read for the next stage. That next stage could be either a "stage1.5" (a single read-only filesystem driver) or the full "stage2".
If stage1.5 is used, it will then in turn have embedded (disk,partition) identifier + pathname that identifies the location of stage2 as a regular file in a filesystem on a particular partition. The disk part might be omitted, in which case the disk is assumed to be the same that contains the stage1.5 component. Typically the pathname will be /grub/stage2 if a separate /boot partition is used, or /boot/grub/stage2 if /boot is just a regular directory on the root filesystem.
The information displayed by file is not sufficient to find out where the next stage is: you would need the contents of the blocklist block to find it.
| Where is GRUB stage 2 located on my bootable compact flash, according to the Master Boot Record? |
1,632,160,214,000 |
I'm a dual boot user running Windows 10 and Kali linux. I rebuild the MBR by mistake using partition wizard. Now I lost access to my linux
I lost swap area menu but I still have the partition
I tried to use easy BCD but it didn t work
|
Boot linux live
chroot in root
repair grub
| Accidentally modified MBR; can't boot to Linux anymore |
1,632,160,214,000 |
I have a NTFS hard drive internally attached to my computer and it's causing problems with the other Windows installation on my dual (or triple?) boot machine.
I'm not sure if the partition scheme is GPT or MBR, but how can I create a backup of the partition table using dd and then wipe it from the drive so it isn't recognized by the other Windows as it starts up?
|
To backup DOS label (MBR) use this:
dd if=/dev/sdX of=mbr bs=512 count=1
To backup GPT label use this:
dummy=$(parted -ms /dev/sdX print | tail -1| cut -b1)
size=$((128 * dummy + 1024))
dd if=/dev/sdX of=gpt bs=1 count=$size
To wipeout the labels use this:
dd if=/dev/zero of=/dev/sdX bs=Y count=Z
partprobe /dev/sdX
HTH
| Backup and then wipe partition table from head of drive |
1,632,160,214,000 |
I wanted to upgrade my 1.5TB HDD to a 4TB SSD, none of the internet resources I found correctly matched my situation from beginning to end, and I ended up spending about 20 hours getting it to work, so I'm compiling my findings here for future travelers.
|
Base details: I have an old Dell Inspiron 5720 running Ubuntu 20.04.6. I started with a 1.5TB HDD and bought a 4TB SSD. I discovered that MBR, the partition table my old drive used, did not support partitions larger than ~2TB, so I was going to have to switch to GPT. Apparently this almost inevitably entails switching your boot system from BIOS to UEFI, as well, which was really the primary source of problems. (There's evidence there was a broken UEFI installation already present, as well, which may have complicated things.)
I copied Kali Linux onto a USB stick to help with the proceedings. You can skip down to where I start listing steps, if you want the tl;dr. I'm leaving the rest, and the lines in parentheses, in case the details help somebody figure out what's wrong with theirs.
The following is the first thing I tried, which DID NOT WORK.
It seemed like it would be safer to mess with a partition while it was not in use, so I booted the usb. I plugged the SSD in with an adapter. I opened gparted, and if I remember correctly, on the SSD I created a GPT partition table. I then (in gparted) selected the HDD, copied the first partition, selected the SSD, pasted, and likewise for the second partition. Reading UEFI guides, I MAY have created a third partition at the end for the UEFI partition, or I may have added that later when my first attempts failed. I then waited for the copy to finish (like 4 hours), turned off the computer, and swapped hard drives, and tried to boot. No dice. I think the error was "No operation system", or something equally nearly-right. Long story short, I tried a whole bunch of things for many hours, and none of them worked. I then switched to plan B.
Plan B, which eventually DID work.
Most of the guides expected you to be booted into the system you wanted to convert, so first I swapped drives again and booted the usb and copied my hdd directly onto the ssd with dd if=/dev/sda bs=1M of=/dev/sdc, checking I had the right device. (I nearly copied it the wrong way.) The next morning, I swapped hard drives and booted successfully. (The HDD was no longer used at any point past here.) Next I (installed?) ran gdisk /dev/sda. It said that there was a working MBR table, but also a corrupt GPT table. I think it asked me which to proceed with, so I selected (1)MBR; and I don't THINK it made me select anything else before putting me into the main menu, so after poking around the options, did w for write. Rebooted. Got a blinking cursor on a black screen. Eliding a lot of testing and false starts, but restating the first steps so the list is complete:
(Suggestion: check that your bios supports UEFI and otherwise update it; doing that earlier might have fixed some of my problems.)
Be careful about copying, some of these commands use my specific drive numbers
Boot from usb
Copy hdd onto ssd, e.g. dd if=/dev/HDD bs=1M of=/dev/SSD (get it right!!)
Turn off computer
Swap drives, put HDD somewhere safe in case you mess up and need to start over
Reboot into ssd
gdisk /dev/sda
(If it asks you to pick between a working MBR and a broken GPT, pick MBR)
w for "write"
Reboot into usb
(though it MIGHT work and not wreck your data to continue on to the following from your main os, and without the mounting and chroot stuff. Might still need to mount the efi partition.)
Connect to the internet
sudo bash
apt update
apt install zfsutils-linux
modprobe zfs
mount /dev/sda5 /mnt # sda5 was my main installation partition
mount /dev/sda1 /mnt/boot/efi # sda1 I think was the partition originally intended to be the efi partition
modprobe efivarfs
mount -t proc proc /mnt/proc
mount -t sysfs sys /mnt/sys
mount -o bind /dev /mnt/dev
mount --bind /run /mnt/run
chroot /mnt bash
apt install grub-efi
update-grub
grub-install --target=x86_64-efi /dev/sda
update-grub # not sure whether it's supposed to go before or after install
(Hopefully I haven't missed any steps etc.)
I eventually realized my bios, Phoenix SecureCore Tiano version A03, was too old to support UEFI. So I:
Downloaded the newest firmware from https://www.dell.com/support/home/en-us/drivers/driversdetails?driverid=khvck
Downloaded the FreeDOS FullUSB image from https://www.freedos.org/download/
dd'd the img file onto a usb
Replugged the usb
Mounted the usb's partition
Copied the bios EXE onto it
sync and shut down
Booted that USB (must be writable or the exe fails to extract)
Ran the exe file, which installed the new bios, version A17
Confirmed the bios now COULD work with UEFI, saw new options in the menus etc.
(Boot still failed, though I forget exactly how)
(I then used the boot menu to select the hard drive - Ubuntu started to boot, but showed "watchdog: BUG: soft lockup", and after a few minutes I restarted)
Selected hard drive from boot menu
Got a grub screen, and selected a maintenance mode shell
modprobe zfs
update-grub
grub-install
update-grub
reboot
(Bios now showed "ubuntu" in the uefi boot list, which worked, but the bios wouldn't automatically boot into it)
Selected hard drive in boot list, successful boot
sudo add-apt-repository ppa:yannubuntu/boot-repair
sudo apt install boot-repair
boot-repair
Ran suggested fixes, noting the sda1/efi/ubuntu/grubx64.efi path it gave in the success dialog
(Reboot failed)
(I turned off Legacy Boot ROM option in the bios, and it DID boot correctly, but took away my other boot options, so I turned it back on.)
In bios, I selected "add boot", gave the boot option a name, left selected the only target present (some long string that I think referred to my hard drive or partitions or something), and the third box let me navigate to "EFI\ubuntu\grubx64.efi", and created the boot option.
Made sure that option was the first of the UEFI boot options. (It had all the legacy options above the uefi ones, and wouldn't let me change that.)
It finally booted unaided
I used gparted from my os to resize my main partition
Successfully rebooted
I don't know how much of that is necessary, and how much could have been avoided by e.g. updating the bios first, and maybe skipping some of the boot-into-usb steps, but this is what ended up working, cobbled together from dozens of different SO posts and reddit posts and forum threads.
| Convert MBR/BIOS to GPT/UEFI (infodump) |
1,632,160,214,000 |
Long ago I've installed Windows 7 in legacy (BIOS) mode with MBR (why? who knows) and made 4 primary partitions, one for Windows and the others for files. Later I've changed one primary into logical and installed linux dualboot. I use GRUB2 to launch OS. And since then I've also got second HDD which doesn't have any OS on it.
Now I want to install another Linux distro.
The question: should I change another primary into logical and install linux2 in primary or I will be able to install linux2 as logical?
And if I want to install linux2 on second HDD, does it have it's own partition limit even if system is loading from first HDD? I mean if I install another linux on second HDD in primary partition, will it be fith primary partition and mess up everything?
|
Later I've changed one primary into logical and installed linux dualboot.
Primary would have been also good. I always used as many primary partitions as possible and if I needed more partitions, I changed the 4th primary into an extended partition with logical partitions inside.
should I change another primary into logical and install linux2 in primary or I will be able to install linux2 as logical?
Choose what is more convenient for you.
And if I want to install linux2 on second HDD, does it have it's own partition limit even if system is loading from first HDD?
It's the same (MBR) partition limit as for the first HDD. 4 primary partitions max. or 3 primary and one extended partition
with more than enough logical partitions (I honestly don't know the exact number).
I mean if I install another linux on second HDD in primary partition, will it be fith primary partition and mess up everything?
It will be the first primary partition of the second disk. No problem.
| Does BIOS MBR limit linux distros installments? |
1,632,160,214,000 |
I installed a triple boot system (Windows 10 Home 21H1/Windows 7 Pro/Debian 11), on three different partitions on a partitioned disk in MBR, and at boot I can start each system without problem. But in GRUB menu all the Windows systems are accessible from a single entry named "Windows 10" (in reason of the first installation) which run Windows Boot Manager and let me choose the Windows' system I want to boot. So 2 menus displayed for boot each Windows system. It is not practical.
I asked to myself if there is a solution to make the Windows entries from WBM directly accessible from GRUB menu without go through WBM. I searched and tested a lot of different solutions but none worked.
I believe it is possible but I do not know how ...
The last attempt I tried :
root@host:~# lsblk -lo NAME,FSTYPE,LABEL,UUID
NAME FSTYPE LABEL UUID
sda
sda1 ntfs W10H 7A42F6E942F6A8D1
sda2 ntfs W7P 0628B81B28B80C25
sda3 ext4 a696a4ab-3120-4028-bd87-c2aaa40499bd
...
root@host:~# cat /etc/grub.d/40_custom
#!/bin/sh
exec tail -n +3 $0
...
menuentry "Windows 7" --class windows --class os {
insmod part_msdos
insmod ntfs
insmod ntldr
set root='(hd0,msdos2)'
search --no-floppy --set=root --fs-uuid 0628B81B28B80C25
ntldr ($root)/bootmgr
chainloader +1
}
root@host:~# update-grub
And when I booted this entry, I got :
error : /bootmgr file not available
As @telcoM suggested me, I asked for help in the global section of SE. I finally resolved my question with the help of @oldfred here and @Tom Yan there where I detailed my implementation.
|
Your GRUB ntldr command is currently looking for a file named bootmgr on the second partition of the first HDD, but that file does not exist there. Windows 10 and Windows 7 can both use the same Windows Boot Manager: in your system, they are currently configured to do just that, and the boot manager is configured to present a menu of the available OSs. Installers of modern Windows OSs look for existing Windows boot managers, and if one exists, will add the freshly-installed OS to the menu of the existing boot manager instead of installing another instance of it.
Since GRUB cannot pass any OS selection information to the Windows Boot Manager (or rather, the WBM cannot accept input from any other bootloader, only directly from the user), you would need to have two instances of it on your system: one configured to boot Windows 10 only, and another configured to boot Windows 7 only. Then you could use the GRUB menu to select which boot manager to use, and so select the Windows version.
Installing a second copy of Windows Boot Manager would be outside the scope of this Unix&Linux.SE: if you need advice on that, you might want to ask on SuperUser.SE instead.
| Triple boot MBR with GRUB avoid Windows Boot Manager |
1,632,160,214,000 |
I recently broke the screen of my Lenovo Ideapad 110S-11IBR, so I decided to use it as a NAS device.
After I tried to install a Debian-based NAS operating system I ran into a problem: Even though the installation was successful, when I tried to boot, the system could not detect any OS. I used a partitioning tool's live USB in order to test if the operating system was installed and it was. I tried other Linux distributions and I had the exact same problem. Something interesting I noticed was that in the boot options, I had the disk and "Windows Boot Manager." I tried DBAN in order to fully wipe the disk and possibly get rid of "Windows Boot Manager", but DBAN failed to locate the disk. I also installed Windows in order to check if it would boot correctly and it did.
If anyone has any idea about what to do, it would be much appreciated
Note: the "disk" I am talking about is the internal 32Gb disk.
|
In the question comments, you confirmed that the internal 32 GB disk is actually a SD/MMC card.
The presence of "Windows Boot Manager" indicates the system is UEFI capable, and that Windows was installed to boot in UEFI mode.
Perhaps the laptop is currently configured to prefer booting in legacy BIOS-compatible mode (causing you to install the NAS in BIOS mode unless you're extra careful in booting the installer), but the SD/MMC boot support in the system firmware is only implemented for the UEFI mode?
Check the BIOS settings, set it to boot "UEFI only" if possible, and try the installer again. Or maybe the NAS operating system installer is legacy BIOS boot only?
| How can I properly install Debian on a laptop that used to have windows? (There is probably a problem with MBR) |
1,632,160,214,000 |
System: Linux Mint 20 x64 cinnamon booted on mbr formatted disk.
I inserted a new hdd containing a gpt and a ntfs partition (next to a small MSR partition, which doesn't matter here I guess). GParted detects the hdd but the mount option is greyed out. Why is that? And what can I do to mount this partition?
|
Like suggested in the comments the problem was indeed the hybernation flag. The ntfs-3g driver cannot safely mount the ntfs disk as Windows is in a hybernation state. This article explains it perfectly: all-explaining article
some possible solutions:
if you have access to Windows: boot into windows and do a normal shutdown/restart, fast-boot in Win8/10 must be disabled. Boot in Linux and ntfs disk will be accessible.
if you have no access to Windows: ntfs-3g remove_hiberfile, it completely deletes hiberfil.sys and will cause you to lose all unsaved information in the hibernated Windows programs. But your ntfs partition can be ounted again as rw. here is how
| Can I mount a gpt disk with ntfs partition on an mbr booted linux system |
1,632,160,214,000 |
I am using Windows 10, Ubuntu and Debian 10 in my machine. Everything was fine untill some Debian update (or so as I think).
Now when i restart my system only a underscore is displayed on my screen for 2-4 minutes and then the grub list of OSs appears.
I thought something was wrong with my HDD so i booted in windows and installed EasyBCD and wrote the windows MBR over grub, then the system booted perfectly without delay when Windows bootloader took over. Again i booted in Debian using Windows bootloader(EasyBCD), same underscore appeared but this time with following message.
GRUB4DOS 0.4.6a 2018-11-05 root is (0x80,0)
Processing the preset-menu...
(hd0,4)
[Multiboot-kludge, loadaddr=0x10000, text-and-data=0x6591, bss=0x0, entry=0x10098c]
[![enter image description here][1]][1]
Following are some outputs that might help,
root@providence:~# systemd-analyze
Startup finished in 17.873s (kernel) + 36.640s (userspace) = 54.514s
graphical.target reached after 36.623s in userspace
Note that Windows 10 is installed in /dev/sda3 and Debian 10 is installed in /dev/sda8, where as the stupid /dev/sda1 is Windows System Reserved.
root@providence:~# fdisk -l
Disk /dev/sda: 465.8 GiB, 500107862016 bytes, 976773168 sectors
Disk model: ST9500420AS
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: 0xc8000000
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 206847 204800 100M 7 HPFS/NTFS/exFAT
/dev/sda2 206848 170128349 169921502 81G 7 HPFS/NTFS/exFAT
/dev/sda3 170144408 337927335 167782928 80G 7 HPFS/NTFS/exFAT
/dev/sda4 337927336 976771071 638843736 304.6G f W95 Ext'd (LBA)
/dev/sda5 337927338 459016191 121088854 57.8G 7 HPFS/NTFS/exFAT
/dev/sda6 459018240 467015679 7997440 3.8G 82 Linux swap / Solaris
/dev/sda7 467017728 856739009 389721282 185.9G 7 HPFS/NTFS/exFAT
/dev/sda8 856739840 976771071 120031232 57.2G 83 Linux
PS: I got mad and removed Ubuntu. Poor ubuntu.
What can i do to resolve this before i format everything. Thanks.
|
So...
After everything i booted into windows and saw something, that's when it clicked me.
Basically, when i saw windows was booting perfectly and grub was delaying, it implied that my HDD and BIOS were absolutely fine. Also my GRUB was fine too because i literally installed another OS with new grub and all.
The fault lied in my boot order. My CD/DVD drive is jammed and somehow was reading a disk. So whenever system boots, it'll try to read DVD first for few minutes then it'll jump to HDD.
I removed CD/DVD drive. Case closed.
| Grub menu taking too long to appear [closed] |
1,632,160,214,000 |
I want to configure OL6 kickstart to install a system that boots from BIOS but uses GPT partitioning instead of MBR, even for disks <2TB.
The relevant part of my kickstart file looks like this ($ROOTDRIVE has been correctly initialized):
%pre
parted -s $ROOTDRIVE mklabel gpt
bootloader --location=partition --append="elevator=deadline nomodeset inst.gpt" --driveorder=$ROOTDRIVE
part biosboot --fstype biosboot --size=1 --ondisk=$ROOTDRIVE
part /boot --fstype ext3 --size=500 --ondisk=$ROOTDRIVE
part pv.2 --size=1 --grow --ondisk=$ROOTDRIVE`
I have removed clearpart --all --drives=$ROOTDRIVE and zerombr as these supposedly wipe my parted GPT and reinstate MBR.
I believe the following in my conf should result in GPT:
parted mklabel gpt
--location=partition (not sure if I really need this?)
inst.gpt (may be available in OL7 only?)
part biosboot
Yet my resulting system still lists the primary drive as MBR (msdos label):
[root@localhost ~]$ parted -l
Model: VMware Virtual disk (scsi)
Disk /dev/sda: 172GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
My question: is there any kickstart config I can use to ensure I end up with GPT disks rather than MBR?
|
Newer versions of kickstart have a --disklabel flag for the clearpart option that can be set to gpt. It appears this was added in Fedora21/RHEL7 so I am not sure if it is available in OL6.
There is an older flag to clearpart, --initlabel, that mentions it "initializes the disk label to the default for your architecture" and would use gpt for Itanium architecture.
If no usable options exist in your version of kickstart, you can configure the disks in the kickstart preinstall script. You could use parted scripting, or whatever tool you use to configure your disks/RAID.
| How to force GPT partitions in kickstart for Oracle Linux 6 |
1,632,160,214,000 |
I have Debian Linux and Win7 installed on the one machine with grub loader and I need to load Windows 7 from partition with Virtual Box. Here my partiotions:
# VBoxManage internalcommands listpartitions -rawdisk /dev/sda
Number Type StartCHS EndCHS Size (MiB) Start (Sect)
1 0x07 0 /32 /33 12 /223/19 100 2048
5 0x83 13 /0 /52 37 /57 /20 190 208896
6 0x82 37 /89 /53 1023/254/63 61034 600064
7 0x83 1023/254/63 1023/254/63 554073 125599744
3 0x07 1023/254/63 1023/254/63 338467 1260341248 <--- here Win7
I tryed to follow this guied http://theunixtips.com/virtualbox-use-raw-disk-to-load-windows-under-linux/ (corresponds to official docs https://www.virtualbox.org/manual/ch09.html#rawdisk)
And make:
# install-mbr --force win.mbr
# VBoxManage internalcommands createrawvmdk -filename /path/win.vmdk -rawdisk /dev/sda -partitions 3 -relative -mbr win.mbr
Then I create virtual box machine from exiting win.vmdk file boot and I see:
MBR 1FA:
I press 'A', then '3' (number of partition)
and I see:
BOOTMGR is missing
Press Ctrl+Alt+Del to restart
I have SATA controller for disk.
Please, any help!
|
I just try to load without mbr, but with grub loader installed on my machine (partition number 5, I think):
VBoxManage internalcommands createrawvmdk -filename /home/tanya/vb/win.vmdk -rawdisk /dev/sda -partitions 1,3,5
And it works!
| Boot Windows 7 from partition on Linux: BOOTMGR is missing |
1,632,160,214,000 |
I am trying to install Qubes OS Linux on my Mac mini. However I want to install it in a MBR configuration on a separate internal HDD.
Is there a way to configure a mac to boot a MBR disk instead of UEFI?
|
I think you mean "GPT" instead of UEFI. UEFI is a type of firmware interface capable of running a bootloader, GPT/MBR are disk partition table types.
Now to actually answer your question: Yes, you sure can. However, editing UEFI boot entries is a bit fiddly on a Mac, as I don't believe it follows UEFI standards. As such, I would recommend using rEFInd to generate the boot entries for you.
| Boot MBR on Mac mini |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.